"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Slate = require("slate");
const index = require("../../../ContemberEditor/index.cjs");
const TableRowElement = require("./TableRowElement.cjs");
const TableCellElementRenderer = require("./TableCellElementRenderer.cjs");
const tableCellElementType = "tableCell";
const isTableCellElement = (element) => Slate.Element.isElement(element) && element.type === tableCellElementType;
const createEmptyTableCellElement = () => ({
  type: tableCellElementType,
  children: [{ text: "" }]
});
const tableCellElementPlugin = {
  type: tableCellElementType,
  render: TableCellElementRenderer.TableCellElementRenderer,
  normalizeNode: ({ element, editor, path, preventDefault }) => {
    if (element.children.length === 1) {
      const onlyChild = element.children[0];
      if (Slate.Element.isElement(onlyChild) && editor.isDefaultElement(onlyChild)) {
        Slate.Transforms.unwrapNodes(editor, {
          at: [...path, 0]
        });
      }
    }
    if (!index.ContemberEditor.hasParentOfType(editor, [element, path], TableRowElement.tableRowElementType)) {
      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: true
};
exports.createEmptyTableCellElement = createEmptyTableCellElement;
exports.isTableCellElement = isTableCellElement;
exports.tableCellElementPlugin = tableCellElementPlugin;
exports.tableCellElementType = tableCellElementType;
//# sourceMappingURL=TableCellElement.cjs.map
