UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

46 lines (44 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.splitCell = exports.canSplitCellSelection = void 0; var _cellSelection = require("@atlaskit/editor-tables/cell-selection"); var _utils = require("@atlaskit/editor-tables/utils"); var _pluginFactory = require("../plugin-factory"); var canSplitCellSelection = exports.canSplitCellSelection = function canSplitCellSelection(selection) { var cellNode; if (!(selection instanceof _cellSelection.CellSelection)) { cellNode = (0, _utils.cellWrapping)(selection.$from); if (!cellNode) { return false; } } else { if (selection.$anchorCell.pos !== selection.$headCell.pos) { return false; } cellNode = selection.$anchorCell.nodeAfter; } return Boolean(cellNode && (cellNode.attrs.colspan !== 1 || cellNode.attrs.rowspan !== 1)); }; /** * We need to split cell keeping the right type of cell given current table configuration. * We are using editor-tables splitCellWithType that allows you to choose what cell type should be. */ var splitCell = exports.splitCell = function splitCell(state, dispatch) { var tableState = (0, _pluginFactory.getPluginState)(state); var _state$schema$nodes = state.schema.nodes, tableHeader = _state$schema$nodes.tableHeader, tableCell = _state$schema$nodes.tableCell; if (dispatch) { return (0, _utils.splitCellWithType)(function (_ref) { var row = _ref.row, col = _ref.col; if (row === 0 && tableState.isHeaderRowEnabled || col === 0 && tableState.isHeaderColumnEnabled) { return tableHeader; } return tableCell; })(state, dispatch); } return true; };