mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-15 03:33:59 +02:00
add logic to handle rich text pastes
This commit is contained in:
@@ -157,6 +157,24 @@ class Transfer {
|
|||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the rich text content of the data transfer.
|
||||||
|
*
|
||||||
|
* @return {String|Void}
|
||||||
|
*/
|
||||||
|
|
||||||
|
getRichText() {
|
||||||
|
if ('richtext' in this.cache) return this.cache.richtext
|
||||||
|
|
||||||
|
let richtext
|
||||||
|
const string = this.data.getData('text/rtf')
|
||||||
|
|
||||||
|
if (string != '') richtext = string
|
||||||
|
|
||||||
|
this.cache.richtext = richtext
|
||||||
|
return richtext
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the text content of the data transfer.
|
* Get the text content of the data transfer.
|
||||||
*
|
*
|
||||||
@@ -184,6 +202,13 @@ class Transfer {
|
|||||||
getType() {
|
getType() {
|
||||||
if (this.hasFragment()) return 'fragment'
|
if (this.hasFragment()) return 'fragment'
|
||||||
if (this.hasNode()) return 'node'
|
if (this.hasNode()) return 'node'
|
||||||
|
|
||||||
|
// COMPAT: Microsoft Word adds an image of the selected text to the data.
|
||||||
|
// Since files are preferred over HTML, this would cause the type to be
|
||||||
|
// considered `files`. But it also adds rich text data so we can check for
|
||||||
|
// that and properly set the type to `html`. (2016/11/21)
|
||||||
|
if (this.hasRichText() && this.hasHtml()) return 'html'
|
||||||
|
|
||||||
if (this.hasFiles()) return 'files'
|
if (this.hasFiles()) return 'files'
|
||||||
if (this.hasHtml()) return 'html'
|
if (this.hasHtml()) return 'html'
|
||||||
if (this.hasText()) return 'text'
|
if (this.hasText()) return 'text'
|
||||||
@@ -210,6 +235,16 @@ class Transfer {
|
|||||||
return this.getHtml() != null
|
return this.getHtml() != null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the data transfer has rich text content.
|
||||||
|
*
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
hasRichText() {
|
||||||
|
return this.getRichText() != null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the data transfer has text content.
|
* Check whether the data transfer has text content.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user