import { Element, Transforms } from "slate";
import { ContemberEditor } from "../../../ContemberEditor/index.js";
import { tableRowElementType } from "./TableRowElement.js";
import { TableCellElementRenderer } from "./TableCellElementRenderer.js";
const tableCellElementType = "tableCell";
const isTableCellElement = (element) => Element.isElement(element) && element.type === tableCellElementType;
const createEmptyTableCellElement = () => ({
  type: tableCellElementType,
  children: [{ text: "" }]
});
const tableCellElementPlugin = {
  type: tableCellElementType,
  render: TableCellElementRenderer,
  normalizeNode: ({ element, editor, path, preventDefault }) => {
    if (element.children.length === 1) {
      const onlyChild = element.children[0];
      if (Element.isElement(onlyChild) && editor.isDefaultElement(onlyChild)) {
        Transforms.unwrapNodes(editor, {
          at: [...path, 0]
        });
      }
    }
    if (!ContemberEditor.hasParentOfType(editor, [element, path], tableRowElementType)) {
      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: true
};
export {
  createEmptyTableCellElement,
  isTableCellElement,
  tableCellElementPlugin,
  tableCellElementType
};
//# sourceMappingURL=TableCellElement.js.map
