"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "SelectedState", {
  enumerable: true,
  get: function get() {
    return _SelectedState.SelectedState;
  }
});
Object.defineProperty(exports, "findChangedNodesFromTransaction", {
  enumerable: true,
  get: function get() {
    return _findChangedNodesFromTransaction.findChangedNodesFromTransaction;
  }
});
exports.isLinkMark = void 0;
Object.defineProperty(exports, "isMediaNode", {
  enumerable: true,
  get: function get() {
    return _isMediaNode.isMediaNode;
  }
});
Object.defineProperty(exports, "isNodeBeforeMediaNode", {
  enumerable: true,
  get: function get() {
    return _isNodeBeforeMediaNode.isNodeBeforeMediaNode;
  }
});
exports.isParagraph = exports.isNodeSelectedOrInRange = void 0;
Object.defineProperty(exports, "isSupportedInParent", {
  enumerable: true,
  get: function get() {
    return _isSupportedInParent.isSupportedInParent;
  }
});
exports.isType = exports.isText = void 0;
exports.nodeToJSON = nodeToJSON;
exports.toJSON = toJSON;
Object.defineProperty(exports, "validNode", {
  enumerable: true,
  get: function get() {
    return _validNode.validNode;
  }
});
exports.validateNodes = void 0;
var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
var _SelectedState = require("./SelectedState");
var _validNode = require("./validNode");
var _findChangedNodesFromTransaction = require("./findChangedNodesFromTransaction");
var _isSupportedInParent = require("./isSupportedInParent");
var _isMediaNode = require("./isMediaNode");
var _isNodeBeforeMediaNode = require("./isNodeBeforeMediaNode");
/** Validates prosemirror nodes, and returns true only if all nodes are valid */
var validateNodes = exports.validateNodes = function validateNodes(nodes) {
  return nodes.every(_validNode.validNode);
};
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var isType = exports.isType = function isType(node, type) {
  return type && node && node.type === type;
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var isParagraph = exports.isParagraph = function isParagraph(node, schema) {
  return isType(node, schema.nodes.paragraph);
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var isText = exports.isText = function isText(node, schema) {
  return isType(node, schema.nodes.text);
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var isLinkMark = exports.isLinkMark = function isLinkMark(node, schema) {
  return isType(node, schema.marks.link);
};

/**
 * Returns if the current selection from achor-head is selecting the node.
 * If the node is not selected then null is returned.
 * If the node is selected then an enum is returned that describes weather the node
 * is fully selected by a range or if the "inside" of the node has been selected or clicked.
 */
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
var isNodeSelectedOrInRange = exports.isNodeSelectedOrInRange = function isNodeSelectedOrInRange(anchorPosition, headPosition, nodePosition, nodeSize) {
  if (typeof nodePosition !== 'number') {
    return null;
  }
  var rangeStart = Math.min(anchorPosition, headPosition);
  var rangeEnd = Math.max(anchorPosition, headPosition);
  var nodeStart = nodePosition;
  var nodeEnd = nodePosition + nodeSize;
  if (anchorPosition === headPosition) {
    return null;
  }
  if (rangeStart <= nodeStart && nodeEnd < rangeEnd || rangeStart < nodeStart && nodeEnd <= rangeEnd) {
    return _SelectedState.SelectedState.selectedInRange;
  }
  if (nodeStart <= anchorPosition && headPosition <= nodeEnd) {
    return _SelectedState.SelectedState.selectedInside;
  }
  return null;
};
var transformer = new _editorJsonTransformer.JSONTransformer();
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
function toJSON(node) {
  return transformer.encode(node);
}

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
function nodeToJSON(node) {
  return transformer.encodeNode(node);
}
// eslint-disable-next-line @atlaskit/editor/no-re-export

// eslint-disable-next-line @atlaskit/editor/no-re-export

// eslint-disable-next-line @atlaskit/editor/no-re-export

// eslint-disable-next-line @atlaskit/editor/no-re-export

// eslint-disable-next-line @atlaskit/editor/no-re-export

// eslint-disable-next-line @atlaskit/editor/no-re-export