@wordpress/block-editor
Version:
52 lines (44 loc) • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getPasteEventData = getPasteEventData;
var _blob = require("@wordpress/blob");
var _dom = require("@wordpress/dom");
/**
* WordPress dependencies
*/
function getPasteEventData({
clipboardData
}) {
let plainText = '';
let html = ''; // IE11 only supports `Text` as an argument for `getData` and will
// otherwise throw an invalid argument error, so we try the standard
// arguments first, then fallback to `Text` if they fail.
try {
plainText = clipboardData.getData('text/plain');
html = clipboardData.getData('text/html');
} catch (error1) {
try {
html = clipboardData.getData('Text');
} catch (error2) {
// Some browsers like UC Browser paste plain text by default and
// don't support clipboardData at all, so allow default
// behaviour.
return;
}
}
const files = (0, _dom.getFilesFromDataTransfer)(clipboardData).filter(({
type
}) => /^image\/(?:jpe?g|png|gif)$/.test(type)); // Only process files if no HTML is present.
// A pasted file may have the URL as plain text.
if (files.length && !html) {
html = files.map(file => `<img src="${(0, _blob.createBlobURL)(file)}">`).join('');
plainText = '';
}
return {
html,
plainText
};
}
//# sourceMappingURL=get-paste-event-data.js.map