"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findTableCells = exports.findTableRows = exports.findParentCellOnPos = exports.findParentCell = exports.findParentRowOnPos = exports.findParentRow = exports.findParentBodyOnPos = exports.findParentBody = exports.findParentHeadOnPos = exports.findParentTableOnPosOnPos = exports.findParentTable = exports.isIntoTable = void 0;
const utils_1 = require("../../../pm/utils.js");
const const_1 = require("./const.js");
const isIntoTable = (state) => (0, utils_1.hasParentNodeOfType)(state.schema.nodes[const_1.TableNode.Table])(state.selection);
exports.isIntoTable = isIntoTable;
const findParentTable = (state) => (0, utils_1.findParentNodeOfType)(state.schema.nodes[const_1.TableNode.Table])(state.selection);
exports.findParentTable = findParentTable;
const findParentTableOnPosOnPos = ($pos) => (0, utils_1.findParentNodeOfTypeClosestToPos)($pos, $pos.doc.type.schema.nodes[const_1.TableNode.Table]);
exports.findParentTableOnPosOnPos = findParentTableOnPosOnPos;
const findParentHeadOnPos = ($pos) => (0, utils_1.findParentNodeOfTypeClosestToPos)($pos, $pos.doc.type.schema.nodes[const_1.TableNode.Head]);
exports.findParentHeadOnPos = findParentHeadOnPos;
const findParentBody = (state) => (0, utils_1.findParentNodeOfType)(state.schema.nodes[const_1.TableNode.Body])(state.selection);
exports.findParentBody = findParentBody;
const findParentBodyOnPos = ($pos) => (0, utils_1.findParentNodeOfTypeClosestToPos)($pos, $pos.doc.type.schema.nodes[const_1.TableNode.Body]);
exports.findParentBodyOnPos = findParentBodyOnPos;
const findParentRow = (state) => (0, utils_1.findParentNodeOfType)(state.schema.nodes[const_1.TableNode.Row])(state.selection);
exports.findParentRow = findParentRow;
const findParentRowOnPos = ($pos) => (0, utils_1.findParentNodeOfTypeClosestToPos)($pos, $pos.doc.type.schema.nodes[const_1.TableNode.Row]);
exports.findParentRowOnPos = findParentRowOnPos;
const findParentCell = (state) => (0, utils_1.findParentNodeOfType)([
    state.schema.nodes[const_1.TableNode.HeaderCell],
    state.schema.nodes[const_1.TableNode.DataCell],
])(state.selection);
exports.findParentCell = findParentCell;
const findParentCellOnPos = ($pos) => (0, utils_1.findParentNodeOfTypeClosestToPos)($pos, [
    $pos.doc.type.schema.nodes[const_1.TableNode.HeaderCell],
    $pos.doc.type.schema.nodes[const_1.TableNode.DataCell],
]);
exports.findParentCellOnPos = findParentCellOnPos;
const findTableRows = (table, schema) => (0, utils_1.findChildrenByType)(table, schema.nodes[const_1.TableNode.Row]);
exports.findTableRows = findTableRows;
const findTableCells = (table, schema) => (0, utils_1.findChildren)(table, (node) => [schema.nodes[const_1.TableNode.HeaderCell].name, schema.nodes[const_1.TableNode.DataCell].name].includes(node.type.name));
exports.findTableCells = findTableCells;
//# sourceMappingURL=helpers.js.map
