var make = function (run) {
var get = function (callback) {
run().then(callback, errorReporter);
var map = function (fab) {
return make(function () {
var bind = function (aFutureB) {
return make(function () {
return run().then(function (v) {
return aFutureB(v).toPromise();
var anonBind = function (futureB) {
return make(function () {
return run().then(function () {
return futureB.toPromise();
var toLazy = function () {
return LazyValue.nu(get);
var toCached = function () {
return make(function () {
var nu$1 = function (baseFn) {
return make(function () {
return new Promise(baseFn);
var pure$1 = function (a) {
return make(function () {
return Promise.resolve(a);
var par = function (asyncValues, nu) {
return nu(function (callback) {
return function (value) {
if (count >= asyncValues.length) {
if (asyncValues.length === 0) {
each(asyncValues, function (asyncValue, i) {
var par$1 = function (futures) {
return par(futures, Future.nu);
var traverse = function (array, fn) {
return par$1(map(array, fn));
var value = function () {
var subject = Cell(Option.none());
var clear = function () {
subject.set(Option.none());
subject.set(Option.some(s));
var isSet = function () {
return subject.get().isSome();
var pasteHtml$1 = function (editor, html, internalFlag) {
var internal = internalFlag ? internalFlag : InternalHtml.isMarked(html);
var args = ProcessFilters.process(editor, InternalHtml.unmark(html), internal);
if (args.cancelled === false) {
SmartPaste.insertContent(editor, args.content);
var pasteText = function (editor, text) {
text = editor.dom.encode(text).replace(/\r\n/g, '\n');
text = Newlines.convert(text, editor.settings.forced_root_block, editor.settings.forced_root_block_attrs);
pasteHtml$1(editor, text, false);
var getDataTransferItems = function (dataTransfer) {
var mceInternalUrlPrefix = 'data:text/mce-internal,';
if (dataTransfer.getData) {
var legacyText = dataTransfer.getData('Text');
if (legacyText && legacyText.length > 0) {
if (legacyText.indexOf(mceInternalUrlPrefix) === -1) {
items['text/plain'] = legacyText;
if (dataTransfer.types) {
for (var i = 0; i < dataTransfer.types.length; i++) {
var contentType = dataTransfer.types[i];
items[contentType] = dataTransfer.getData(contentType);
var getClipboardContent = function (editor, clipboardEvent) {
var content = getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
return Utils.isMsEdge() ? global$4.extend(content, { 'text/html': '' }) : content;
var hasContentType = function (clipboardContent, mimeType) {
return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
var hasHtmlOrText = function (content) {
return hasContentType(content, 'text/html') || hasContentType(content, 'text/plain');
var getBase64FromUri = function (uri) {
return uri.substr(idx + 1);
var isValidDataUriImage = function (settings, imgElm) {
return settings.images_dataimg_filter ? settings.images_dataimg_filter(imgElm) : true;
var extractFilename = function (editor, str) {
var m = str.match(/([\s\S]+?)\.(?:jpeg|jpg|png|gif)$/i);
return m ? editor.dom.encode(m[1]) : null;
var uniqueId = Utils.createIdGenerator('mceclip');
var pasteImage = function (editor, imageItem) {
var base64 = getBase64FromUri(imageItem.uri);
var name = editor.settings.images_reuse_filename && imageItem.blob.name ? extractFilename(editor, imageItem.blob.name) : id;
var img = new domGlobals.Image();
if (isValidDataUriImage(editor.settings, img)) {
var blobCache = editor.editorUpload.blobCache;
var blobInfo = void 0, existingBlobInfo = void 0;
existingBlobInfo = blobCache.findFirst(function (cachedBlobInfo) {
return cachedBlobInfo.base64() === base64;
blobInfo = blobCache.create(id, imageItem.blob, base64, name);
blobInfo = existingBlobInfo;
pasteHtml$1(editor, '<img src="' + blobInfo.blobUri() + '">', false);
pasteHtml$1(editor, '<img src="' + imageItem.uri + '">', false);
var isClipboardEvent = function (event) {
return event.type === 'paste';
var readBlobsAsDataUris = function (items) {
return mapM(items, function (item) {
return Future.nu(function (resolve) {
var blob = item.getAsFile ? item.getAsFile() : item;
var reader = new window.FileReader();
reader.onload = function () {
reader.readAsDataURL(blob);
var getImagesFromDataTransfer = function (dataTransfer) {
var items = dataTransfer.items ? map(from$1(dataTransfer.items), function (item) {
var files = dataTransfer.files ? from$1(dataTransfer.files) : [];
var images = filter$1(items.length > 0 ? items : files, function (file) {
return /^image\/(jpeg|png|gif|bmp)$/.test(file.type);
var pasteImageData = function (editor, e, rng) {
var dataTransfer = isClipboardEvent(e) ? e.clipboardData : e.dataTransfer;
if (editor.settings.paste_data_images && dataTransfer) {
var images = getImagesFromDataTransfer(dataTransfer);
readBlobsAsDataUris(images).get(function (blobResults) {
editor.selection.setRng(rng);
each(blobResults, function (result) {
pasteImage(editor, result);
var isBrokenAndroidClipboardEvent = function (e) {
var clipboardData = e.clipboardData;
return domGlobals.navigator.userAgent.indexOf('Android') !== -1 && clipboardData && clipboardData.items && clipboardData.items.length === 0;
var isKeyboardPasteEvent = function (e) {
return global$5.metaKeyPressed(e) && e.keyCode === 86 || e.shiftKey && e.keyCode === 45;
var registerEventHandlers = function (editor, pasteBin, pasteFormat) {
var keyboardPasteEvent = value();
var keyboardPastePlainTextState;
editor.on('keydown', function (e) {
function removePasteBinOnKeyUp(e) {
if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
keyboardPastePlainTextState = e.shiftKey && e.keyCode === 86;
if (keyboardPastePlainTextState && global$2.webkit && domGlobals.navigator.userAgent.indexOf('Version/') !== -1) {
e.stopImmediatePropagation();
keyboardPasteEvent.set(e);
window.setTimeout(function () {
keyboardPasteEvent.clear();
if (global$2.ie && keyboardPastePlainTextState) {
Events.firePaste(editor, true);
editor.once('keyup', removePasteBinOnKeyUp);
editor.once('paste', function () {
editor.off('keyup', removePasteBinOnKeyUp);
function insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal) {
var content, isPlainTextHtml;
if (hasContentType(clipboardContent, 'text/html')) {
content = clipboardContent['text/html'];
content = pasteBin.getHtml();
internal = internal ? internal : InternalHtml.isMarked(content);
if (pasteBin.isDefaultContent(content)) {
content = Utils.trimHtml(content);
isPlainTextHtml = internal === false && Newlines.isPlainText(content);
if (!content.length || isPlainTextHtml) {
if (hasContentType(clipboardContent, 'text/plain') && isPlainTextHtml) {
content = clipboardContent['text/plain'];
content = Utils.innerText(content);
if (pasteBin.isDefaultContent(content)) {
editor.windowManager.alert('Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.');
pasteText(editor, content);
pasteHtml$1(editor, content, internal);
var getLastRng = function () {
return pasteBin.getLastRng() || editor.selection.getRng();
editor.on('paste', function (e) {
var isKeyBoardPaste = keyboardPasteEvent.isSet();
var clipboardContent = getClipboardContent(editor, e);
var plainTextMode = pasteFormat.get() === 'text' || keyboardPastePlainTextState;
var internal = hasContentType(clipboardContent, InternalHtml.internalHtmlMime());
keyboardPastePlainTextState = false;
if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
if (!hasHtmlOrText(clipboardContent) && pasteImageData(editor, e, getLastRng())) {
if (global$2.ie && (!isKeyBoardPaste || e.ieFake) && !hasContentType(clipboardContent, 'text/html')) {
editor.dom.bind(pasteBin.getEl(), 'paste', function (e) {
editor.getDoc().execCommand('Paste', false, null);
clipboardContent['text/html'] = pasteBin.getHtml();
if (hasContentType(clipboardContent, 'text/html')) {
internal = InternalHtml.isMarked(clipboardContent['text/html']);
insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
global$3.setEditorTimeout(editor, function () {
insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
var registerEventsAndFilters = function (editor, pasteBin, pasteFormat) {
registerEventHandlers(editor, pasteBin, pasteFormat);
editor.parser.addNodeFilter('img', function (nodes, name, args) {
var isPasteInsert = function (args) {
return args.data && args.data.paste === true;
var remove = function (node) {
if (!node.attr('data-mce-object') && src !== global$2.transparentSrc) {
var isWebKitFakeUrl = function (src) {
return src.indexOf('webkit-fake-url') === 0;
var isDataUri = function (src) {
return src.indexOf('data:') === 0;
if (!editor.settings.paste_data_images && isPasteInsert(args)) {
src = nodes[i].attributes.map.src;
if (isWebKitFakeUrl(src)) {
} else if (!editor.settings.allow_html_data_urls && isDataUri(src)) {
var getPasteBinParent = function (editor) {
return global$2.ie && editor.inline ? domGlobals.document.body : editor.getBody();
var isExternalPasteBin = function (editor) {
return getPasteBinParent(editor) !== editor.getBody();
var delegatePasteEvents = function (editor, pasteBinElm, pasteBinDefaultContent) {
if (isExternalPasteBin(editor)) {
editor.dom.bind(pasteBinElm, 'paste keyup', function (e) {
if (!isDefault(editor, pasteBinDefaultContent)) {
var create = function (editor, lastRngCell, pasteBinDefaultContent) {
var dom = editor.dom, body = editor.getBody();
lastRngCell.set(editor.selection.getRng());
pasteBinElm = editor.dom.add(getPasteBinParent(editor), 'div', {
'style': 'position: fixed; top: 50%; width: 10px; height: 10px; overflow: hidden; opacity: 0'
}, pasteBinDefaultContent);
if (global$2.ie || global$2.gecko) {
dom.setStyle(pasteBinElm, 'left', dom.getStyle(body, 'direction', true) === 'rtl' ? 65535 : -65535);
dom.bind(pasteBinElm, 'beforedeactivate focusin focusout', function (e) {
delegatePasteEvents(editor, pasteBinElm, pasteBinDefaultContent);
editor.selection.select(pasteBinElm, true);
var remove = function (editor, lastRngCell) {
var pasteBinClone = void 0;
var lastRng = lastRngCell.get();
while (pasteBinClone = editor.dom.get('mcepastebin')) {
editor.dom.remove(pasteBinClone);
editor.dom.unbind(pasteBinClone);
editor.selection.setRng(lastRng);
var getEl = function (editor) {
return editor.dom.get('mcepastebin');
var getHtml = function (editor) {
var pasteBinElm, pasteBinClones, i, dirtyWrappers, cleanWrapper;
var copyAndRemove = function (toElm, fromElm) {
toElm.appendChild(fromElm);
editor.dom.remove(fromElm, true);
pasteBinClones = global$4.grep(getPasteBinParent(editor).childNodes, function (elm) {
return elm.id === 'mcepastebin';
pasteBinElm = pasteBinClones.shift();
global$4.each(pasteBinClones, function (pasteBinClone) {
copyAndRemove(pasteBinElm, pasteBinClone);
dirtyWrappers = editor.dom.select('div[id=mcepastebin]', pasteBinElm);
for (i = dirtyWrappers.length - 1; i >= 0; i--) {
cleanWrapper = editor.dom.create('div');
pasteBinElm.insertBefore(cleanWrapper, dirtyWrappers[i]);
copyAndRemove(cleanWrapper, dirtyWrappers[i]);
return pasteBinElm ? pasteBinElm.innerHTML : '';
var getLastRng = function (lastRng) {
var isDefaultContent = function (pasteBinDefaultContent, content) {
return content === pasteBinDefaultContent;
var isPasteBin = function (elm) {
return elm && elm.id === 'mcepastebin';
var isDefault = function (editor, pasteBinDefaultContent) {
var pasteBinElm = getEl(editor);
return isPasteBin(pasteBinElm) && isDefaultContent(pasteBinDefaultContent, pasteBinElm.innerHTML);
var PasteBin = function (editor) {
var lastRng = Cell(null);
var pasteBinDefaultContent = '%MCEPASTEBIN%';
return create(editor, lastRng, pasteBinDefaultContent);
return remove(editor, lastRng);