"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.controlActions = void 0;
const table_utils_1 = require("../../../../../table-utils/index.js");
const actions_1 = require("../../../../../utils/actions.js");
const remove_node_1 = require("../../../../../utils/remove-node.js");
const buttons_1 = require("./buttons.js");
const removeYfmTable = (state, dispatch, _, attrs) => {
    if (!attrs)
        return false;
    const { tablePos, tableNode } = attrs;
    if (dispatch) {
        const tr = state.tr;
        // After removing node plugin state doesn't change and it crashes
        tr.setMeta(buttons_1.tableControlsPluginKey, null);
        (0, remove_node_1.removeNode)({
            node: tableNode,
            pos: tablePos,
            tr: tr,
            dispatch,
        });
    }
    return true;
};
exports.controlActions = (0, actions_1.defineActions)({
    deleteRow: {
        isEnable: table_utils_1.removeRow,
        run: table_utils_1.removeRow,
    },
    deleteColumn: {
        isEnable: table_utils_1.removeColumn,
        run: table_utils_1.removeColumn,
    },
    appendColumn: {
        isEnable: table_utils_1.appendColumn,
        run: table_utils_1.appendColumn,
    },
    appendRow: {
        isEnable: table_utils_1.appendRow,
        run: table_utils_1.appendRow,
    },
    deleteTable: {
        isEnable: removeYfmTable,
        run: removeYfmTable,
    },
});
//# sourceMappingURL=actions.js.map
