1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-26 16:44:22 +02:00
This commit is contained in:
Ian Storm Taylor
2017-03-30 12:44:55 -04:00
parent ef81dc856a
commit b0adb9252c
2 changed files with 27 additions and 22 deletions

View File

@@ -8,7 +8,7 @@
"kind": "text", "kind": "text",
"ranges": [ "ranges": [
{ {
"text": "With Slate you can build complex block types that have their own embeded content and behaviors, like rendering checkboxes inside check list items!" "text": "With Slate you can build complex block types that have their own embedded content and behaviors, like rendering checkboxes inside check list items!"
} }
] ]
} }

View File

@@ -237,12 +237,12 @@ class Content extends React.Component {
* @return {Boolean} * @return {Boolean}
*/ */
isInContentEditable = (event) => { isInEditor = (event) => {
const { element } = this const { element } = this
const { target } = event const { target } = event
return ( return (
(target.isContentEditable) && (target.isContentEditable) &&
(target === element || target.closest('[data-slate-editor]') === element) (target == element || target.closest('[data-slate-editor]') == element)
) )
} }
@@ -254,7 +254,7 @@ class Content extends React.Component {
onBeforeInput = (event) => { onBeforeInput = (event) => {
if (this.props.readOnly) return if (this.props.readOnly) return
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
const data = {} const data = {}
@@ -271,7 +271,11 @@ class Content extends React.Component {
onBlur = (event) => { onBlur = (event) => {
if (this.props.readOnly) return if (this.props.readOnly) return
if (this.tmp.isCopying) return if (this.tmp.isCopying) return
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
// If the element that is now focused is actually inside the editor, we
// need to ignore it. This can happen in situations where there is a nested
// `contenteditable="true"` node that isn't another Slate editor.
if (this.element.contains(event.relatedTarget)) return if (this.element.contains(event.relatedTarget)) return
const data = {} const data = {}
@@ -289,11 +293,12 @@ class Content extends React.Component {
onFocus = (event) => { onFocus = (event) => {
if (this.props.readOnly) return if (this.props.readOnly) return
if (this.tmp.isCopying) return if (this.tmp.isCopying) return
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
// COMPAT: When editor contains nested editable elements, in some situations,
// the focus goes to those elements. In Firefox, this must be prevented // COMPAT: If the editor has nested editable elements, the focus can go to
// because it results in issues with keyboard navigation. (2017/03/30) // those elements. In Firefox, this must be prevented because it results in
if (IS_FIREFOX && event.target !== this.element) { // issues with keyboard navigation. (2017/03/30)
if (IS_FIREFOX && event.target != this.element) {
this.element.focus() this.element.focus()
return return
} }
@@ -322,7 +327,7 @@ class Content extends React.Component {
*/ */
onCompositionStart = (event) => { onCompositionStart = (event) => {
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
this.tmp.isComposing = true this.tmp.isComposing = true
this.tmp.compositions++ this.tmp.compositions++
@@ -339,7 +344,7 @@ class Content extends React.Component {
*/ */
onCompositionEnd = (event) => { onCompositionEnd = (event) => {
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
this.tmp.forces++ this.tmp.forces++
const count = this.tmp.compositions const count = this.tmp.compositions
@@ -362,7 +367,7 @@ class Content extends React.Component {
*/ */
onCopy = (event) => { onCopy = (event) => {
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
const window = getWindow(event.target) const window = getWindow(event.target)
this.tmp.isCopying = true this.tmp.isCopying = true
@@ -387,7 +392,7 @@ class Content extends React.Component {
onCut = (event) => { onCut = (event) => {
if (this.props.readOnly) return if (this.props.readOnly) return
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
const window = getWindow(event.target) const window = getWindow(event.target)
this.tmp.isCopying = true this.tmp.isCopying = true
@@ -411,7 +416,7 @@ class Content extends React.Component {
*/ */
onDragEnd = (event) => { onDragEnd = (event) => {
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
this.tmp.isDragging = false this.tmp.isDragging = false
this.tmp.isInternalDrag = null this.tmp.isInternalDrag = null
@@ -426,7 +431,7 @@ class Content extends React.Component {
*/ */
onDragOver = (event) => { onDragOver = (event) => {
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
const { dataTransfer } = event.nativeEvent const { dataTransfer } = event.nativeEvent
const data = getTransferData(dataTransfer) const data = getTransferData(dataTransfer)
@@ -450,7 +455,7 @@ class Content extends React.Component {
*/ */
onDragStart = (event) => { onDragStart = (event) => {
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
this.tmp.isDragging = true this.tmp.isDragging = true
this.tmp.isInternalDrag = true this.tmp.isInternalDrag = true
@@ -476,7 +481,7 @@ class Content extends React.Component {
onDrop = (event) => { onDrop = (event) => {
if (this.props.readOnly) return if (this.props.readOnly) return
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
event.preventDefault() event.preventDefault()
@@ -534,7 +539,7 @@ class Content extends React.Component {
onInput = (event) => { onInput = (event) => {
if (this.tmp.isComposing) return if (this.tmp.isComposing) return
if (this.props.state.isBlurred) return if (this.props.state.isBlurred) return
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
debug('onInput', { event }) debug('onInput', { event })
const window = getWindow(event.target) const window = getWindow(event.target)
@@ -605,7 +610,7 @@ class Content extends React.Component {
onKeyDown = (event) => { onKeyDown = (event) => {
if (this.props.readOnly) return if (this.props.readOnly) return
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
const { altKey, ctrlKey, metaKey, shiftKey, which } = event const { altKey, ctrlKey, metaKey, shiftKey, which } = event
const key = keycode(which) const key = keycode(which)
@@ -683,7 +688,7 @@ class Content extends React.Component {
onPaste = (event) => { onPaste = (event) => {
if (this.props.readOnly) return if (this.props.readOnly) return
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
event.preventDefault() event.preventDefault()
const data = getTransferData(event.clipboardData) const data = getTransferData(event.clipboardData)
@@ -707,7 +712,7 @@ class Content extends React.Component {
if (this.tmp.isCopying) return if (this.tmp.isCopying) return
if (this.tmp.isComposing) return if (this.tmp.isComposing) return
if (this.tmp.isSelecting) return if (this.tmp.isSelecting) return
if (!this.isInContentEditable(event)) return if (!this.isInEditor(event)) return
const window = getWindow(event.target) const window = getWindow(event.target)
const { state, editor } = this.props const { state, editor } = this.props