"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findSelectedNodeOfType = exports.equalNodeType = exports.get$Cursor = exports.isWholeSelection = exports.isNodeSelection = exports.isTextSelection = void 0;
exports.get$CursorAtBlockStart = get$CursorAtBlockStart;
const prosemirror_state_1 = require("prosemirror-state");
const isTextSelection = (selection) => selection instanceof prosemirror_state_1.TextSelection;
exports.isTextSelection = isTextSelection;
const isNodeSelection = (selection) => selection instanceof prosemirror_state_1.NodeSelection;
exports.isNodeSelection = isNodeSelection;
const isWholeSelection = (selection) => selection instanceof prosemirror_state_1.AllSelection;
exports.isWholeSelection = isWholeSelection;
const get$Cursor = (selection) => {
    return (0, exports.isTextSelection)(selection) ? selection.$cursor : null;
};
exports.get$Cursor = get$Cursor;
function get$CursorAtBlockStart(selection) {
    const $cursor = (0, exports.get$Cursor)(selection);
    if (!$cursor || $cursor.parentOffset > 0 || $cursor.parent.isInline)
        return null;
    return $cursor;
}
const equalNodeType = function equalNodeType(nodeType, node) {
    return (Array.isArray(nodeType) && nodeType.indexOf(node.type) > -1) || node.type === nodeType;
};
exports.equalNodeType = equalNodeType;
const findSelectedNodeOfType = (nodeType) => {
    return function (selection) {
        if ((0, exports.isNodeSelection)(selection)) {
            const node = selection.node, $from = selection.$from;
            if ((0, exports.equalNodeType)(nodeType, node)) {
                return { node: node, pos: $from.pos, depth: $from.depth };
            }
        }
        return null;
    };
};
exports.findSelectedNodeOfType = findSelectedNodeOfType;
//# sourceMappingURL=selection.js.map
