"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = handleEditorPaste;
exports.pasteAsPlainText = pasteAsPlainText;

var _prosemirrorView = require("prosemirror-view");

var _ImageUploadPlaceholderPlugin = require("../ImageUploadPlaceholderPlugin");

function handleEditorPaste(view, event) {
  const {
    clipboardData
  } = event;

  if (!clipboardData) {
    return false;
  }

  const {
    files
  } = clipboardData;

  if (!files || !files.length) {
    return false;
  }

  const filesList = Array.from(files);

  if ((0, _ImageUploadPlaceholderPlugin.uploadImageFiles)(view, filesList)) {
    event.preventDefault();
    return true;
  }

  return false;
} // [FS] IRAD-1076 2020-10-16
// paste the text as a plain text.


function pasteAsPlainText(slice) {
  if (slice && slice.content && slice.content.content && 0 < slice.content.content.length) {
    for (let i = 0; i < slice.content.content.length; i++) {
      const node = slice.content.content[i];

      if (node.content && node.content.content && 0 < node.content.content.length && node.content.content[0].marks) {
        node.content.content[0].marks = [];
      }
    }

    return true;
  }

  return false;
}