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