mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 01:50:06 +02:00
add fragment handling to core onPaste
This commit is contained in:
@@ -532,21 +532,13 @@ class Content extends React.Component {
|
|||||||
|
|
||||||
// If html, and the html includes a `data-fragment` attribute, it's actually
|
// If html, and the html includes a `data-fragment` attribute, it's actually
|
||||||
// a raw-serialized JSON fragment from a previous cut/copy, so deserialize
|
// a raw-serialized JSON fragment from a previous cut/copy, so deserialize
|
||||||
// it and insert it normally.
|
// it and update the data.
|
||||||
if (data.type == 'html' && ~data.html.indexOf('<span data-fragment="')) {
|
if (data.type == 'html' && ~data.html.indexOf('<span data-fragment="')) {
|
||||||
const regexp = /data-fragment="([^\s]+)"/
|
const regexp = /data-fragment="([^\s]+)"/
|
||||||
const matches = regexp.exec(data.html)
|
const matches = regexp.exec(data.html)
|
||||||
const [ full, encoded ] = matches
|
const [ full, encoded ] = matches
|
||||||
const fragment = Base64.deserializeNode(encoded)
|
data.type = 'fragment'
|
||||||
let { state } = this.props
|
data.fragment = Base64.deserializeNode(encoded)
|
||||||
|
|
||||||
state = state
|
|
||||||
.transform()
|
|
||||||
.insertFragment(fragment)
|
|
||||||
.apply()
|
|
||||||
|
|
||||||
this.onChange(state)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.onPaste(e, data)
|
this.props.onPaste(e, data)
|
||||||
|
@@ -4,8 +4,6 @@ import Character from '../models/character'
|
|||||||
import Placeholder from '../components/placeholder'
|
import Placeholder from '../components/placeholder'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import String from '../utils/string'
|
import String from '../utils/string'
|
||||||
import keycode from 'keycode'
|
|
||||||
import { IS_WINDOWS, IS_MAC } from '../utils/environment'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default plugin.
|
* The default plugin.
|
||||||
@@ -482,12 +480,30 @@ function Plugin(options = {}) {
|
|||||||
|
|
||||||
function onPaste(e, data, state) {
|
function onPaste(e, data, state) {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
|
case 'fragment':
|
||||||
|
return onPasteFragment(e, data, state)
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'html':
|
case 'html':
|
||||||
return onPasteText(e, data, state)
|
return onPasteText(e, data, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On paste fragment.
|
||||||
|
*
|
||||||
|
* @param {Event} e
|
||||||
|
* @param {Object} data
|
||||||
|
* @param {State} state
|
||||||
|
* @return {State}
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onPasteFragment(e, data, state) {
|
||||||
|
return state
|
||||||
|
.transform()
|
||||||
|
.insertFragment(data.fragment)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On paste text, split blocks at new lines.
|
* On paste text, split blocks at new lines.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user