UNPKG

@gechiui/block-editor

Version:
56 lines (48 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPasteEventData = getPasteEventData; var _blob = require("@gechiui/blob"); var _dom = require("@gechiui/dom"); /** * GeChiUI dependencies */ function getPasteEventData(_ref) { let { clipboardData } = _ref; 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(_ref2 => { let { type } = _ref2; return /^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