"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Slate = require("slate");
const TableCellElement = require("./TableCellElement.cjs");
const TableRowElementRenderer = require("./TableRowElementRenderer.cjs");
const index = require("../../../ContemberEditor/index.cjs");
const TableElement = require("./TableElement.cjs");
const tableRowElementType = "tableRow";
const isTableRowElement = (element) => Slate.Element.isElement(element) && element.type === tableRowElementType;
const createEmptyTableRowElement = (columnCount = 2) => ({
  type: tableRowElementType,
  children: Array.from({ length: columnCount }, () => TableCellElement.createEmptyTableCellElement())
});
const tableRowElementPlugin = {
  type: tableRowElementType,
  render: TableRowElementRenderer.TableRowElementRenderer,
  normalizeNode: ({ editor, path, element, preventDefault }) => {
    for (const [child, childPath] of Slate.Node.children(editor, path)) {
      if (Slate.Element.isElement(child)) {
        if (!TableCellElement.isTableCellElement(child)) {
          index.ContemberEditor.ejectElement(editor, childPath);
          Slate.Transforms.setNodes(editor, { type: TableCellElement.tableCellElementType }, { at: childPath });
        }
      } else {
        Slate.Transforms.removeNodes(editor, { at: path });
        return preventDefault();
      }
    }
    if (!index.ContemberEditor.hasParentOfType(editor, [element, path], TableElement.tableElementType)) {
      Slate.Transforms.unwrapNodes(editor, { at: path });
      return preventDefault();
    }
    if (path[path.length - 1] > 0 && element.headerScope) {
      Slate.Transforms.setNodes(editor, { headerScope: null }, { at: path });
      return preventDefault();
    }
  },
  canContainAnyBlocks: false
};
exports.createEmptyTableRowElement = createEmptyTableRowElement;
exports.isTableRowElement = isTableRowElement;
exports.tableRowElementPlugin = tableRowElementPlugin;
exports.tableRowElementType = tableRowElementType;
//# sourceMappingURL=TableRowElement.cjs.map
