// @ts-ignore // TODO: fix cjs build
import { removeParentNodeOfType } from 'prosemirror-utils';
import { TableNode } from "../const.js";
import { isIntoTable } from "../helpers.js";
const mdTamplate = `

| Heading | Heading |
| ------- | ------- |
| Text    | Text    |
| Text    | Text    |

`.trim();
const createTableFactory = (parser) => (state, dispatch) => {
    if (isIntoTable(state)) {
        return false;
    }
    if (dispatch) {
        const node = parser.parse(mdTamplate);
        dispatch(state.tr.replaceSelectionWith(node).scrollIntoView());
    }
    return true;
};
const removeTable = (state, dispatch) => {
    if (isIntoTable(state)) {
        dispatch?.(removeParentNodeOfType(state.schema.nodes[TableNode.Table])(state.tr));
        return true;
    }
    return false;
};
export const createTableAction = ({ markupParser }) => ({
    isActive: isIntoTable,
    isEnable: createTableFactory(markupParser),
    run: createTableFactory(markupParser),
});
export const deleteTableAction = {
    isEnable: removeTable,
    run: removeTable,
};
//# sourceMappingURL=tableActions.js.map
