"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fixPastedTableBodies = fixPastedTableBodies;
const prosemirror_model_1 = require("prosemirror-model");
const nodes_1 = require("../../../utils/nodes.js");
const utils_1 = require("./utils.js");
function fixPastedTableBodies(slice, schema) {
    if (slice.content.firstChild?.type === (0, utils_1.yfmTableBodyType)(schema)) {
        const tRows = [];
        let bodiesSize = 0;
        for (const { node, offset } of (0, nodes_1.getChildrenOfNode)(slice.content)) {
            if (node.type !== (0, utils_1.yfmTableBodyType)(schema))
                break;
            tRows.push(...(0, nodes_1.getChildrenOfNode)(node).map((item) => item.node));
            bodiesSize = offset + node.nodeSize;
        }
        const tableNode = (0, utils_1.yfmTableType)(schema).create(null, (0, utils_1.yfmTableBodyType)(schema).create(null, tRows));
        slice = new prosemirror_model_1.Slice(prosemirror_model_1.Fragment.from(tableNode).append(slice.content.cut(bodiesSize)), 0, 0);
    }
    return slice;
}
//# sourceMappingURL=paste.js.map
