"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.findInsertLocation = findInsertLocation;
var _state = require("@atlaskit/editor-prosemirror/state");
var _utils = require("@atlaskit/editor-prosemirror/utils");
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
function findInsertLocation(selection) {
  var _selection$$from$doc$ = selection.$from.doc.type,
    schema = _selection$$from$doc$.schema,
    name = _selection$$from$doc$.name;
  if (selection instanceof _state.NodeSelection) {
    return selection.node.type.name;
  }
  if (selection instanceof _cellSelection.CellSelection) {
    return schema.nodes.table.name;
  }

  // Text selection
  var parentNodeInfo = (0, _utils.findParentNode)(function (node) {
    return node.type !== schema.nodes.paragraph;
  })(selection);
  return parentNodeInfo ? parentNodeInfo.node.type.name : name;
}