import { Fragment, Slice } from 'prosemirror-model';
import { getChildrenOfNode } from "../../../utils/nodes.js";
import { yfmTableBodyType, yfmTableType } from "./utils.js";
export function fixPastedTableBodies(slice, schema) {
    if (slice.content.firstChild?.type === yfmTableBodyType(schema)) {
        const tRows = [];
        let bodiesSize = 0;
        for (const { node, offset } of getChildrenOfNode(slice.content)) {
            if (node.type !== yfmTableBodyType(schema))
                break;
            tRows.push(...getChildrenOfNode(node).map((item) => item.node));
            bodiesSize = offset + node.nodeSize;
        }
        const tableNode = yfmTableType(schema).create(null, yfmTableBodyType(schema).create(null, tRows));
        slice = new Slice(Fragment.from(tableNode).append(slice.content.cut(bodiesSize)), 0, 0);
    }
    return slice;
}
//# sourceMappingURL=paste.js.map
