import { __exports as E } from "./index-LexicalTable.prod2.js";
import { __require as Te } from "./index-Lexical.js";
import { __require as Re } from "./index-LexicalUtils.js";
var ge;
function Me() {
  if (ge) return E;
  ge = 1;
  var l = Te(), m = Re();
  function T(r) {
    let e = new URLSearchParams();
    e.append("code", r);
    for (let t = 1; t < arguments.length; t++) e.append("v", arguments[t]);
    throw Error(`Minified Lexical error #${r}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`);
  }
  class W extends l.INTERNAL_PointSelection {
    constructor(e, t, o) {
      super(t, o), this.gridKey = e;
    }
    getCachedNodes() {
      return this._cachedNodes;
    }
    setCachedNodes(e) {
      this._cachedNodes = e;
    }
    is(e) {
      return R(e) ? this.gridKey === e.gridKey && this.anchor.is(e.anchor) && this.focus.is(e.focus) : !1;
    }
    set(e, t, o) {
      this.dirty = !0, this.gridKey = e, this.anchor.key = t, this.focus.key = o, this._cachedNodes = null;
    }
    clone() {
      return new W(this.gridKey, this.anchor, this.focus);
    }
    isCollapsed() {
      return !1;
    }
    extract() {
      return this.getNodes();
    }
    insertRawText() {
    }
    insertText() {
    }
    insertNodes(e) {
      let t = this.focus.getNode();
      if (!l.$isElementNode(t)) throw Error("Expected GridSelection focus to be an ElementNode");
      l.$normalizeSelection__EXPERIMENTAL(t.select(0, t.getChildrenSize())).insertNodes(e);
    }
    getShape() {
      var e = l.$getNodeByKey(this.anchor.key);
      if (l.DEPRECATED_$isGridCellNode(e) || T(103), e = l.DEPRECATED_$getGridCellNodeRect(e), e === null) throw Error("getCellRect: expected to find AnchorNode");
      var t = l.$getNodeByKey(this.focus.key);
      l.DEPRECATED_$isGridCellNode(t) || T(104);
      let o = l.DEPRECATED_$getGridCellNodeRect(t);
      if (o === null) throw Error("getCellRect: expected to find focusCellNode");
      t = Math.min(e.columnIndex, o.columnIndex);
      let n = Math.max(e.columnIndex, o.columnIndex), s = Math.min(e.rowIndex, o.rowIndex);
      return e = Math.max(e.rowIndex, o.rowIndex), { fromX: Math.min(t, n), fromY: Math.min(s, e), toX: Math.max(t, n), toY: Math.max(s, e) };
    }
    getNodes() {
      function e(p) {
        let { cell: w, startColumn: y, startRow: $ } = p;
        _ = Math.min(_, y), d = Math.min(d, $), a = Math.max(a, y + w.__colSpan - 1), h = Math.max(h, $ + w.__rowSpan - 1);
      }
      var t = this._cachedNodes;
      if (t !== null) return t;
      var o = this.anchor.getNode();
      t = this.focus.getNode();
      var n = m.$findMatchingParent(o, l.DEPRECATED_$isGridCellNode);
      o = m.$findMatchingParent(t, l.DEPRECATED_$isGridCellNode), l.DEPRECATED_$isGridCellNode(n) || T(103), l.DEPRECATED_$isGridCellNode(o) || T(104), t = n.getParent(), l.DEPRECATED_$isGridRowNode(t) || T(105), t = t.getParent(), l.DEPRECATED_$isGridNode(t) || T(106);
      var s = o.getParents()[1];
      if (s !== t) {
        if (t.isParentOf(o)) {
          if (t = s.getParent(), t == null) throw Error("Expected focusCellParent to have a parent");
          this.set(
            this.gridKey,
            o.getKey(),
            t.getKey()
          );
        } else {
          if (t = t.getParent(), t == null) throw Error("Expected gridParent to have a parent");
          this.set(this.gridKey, t.getKey(), o.getKey());
        }
        return this.getNodes();
      }
      let [i, c, f] = l.DEPRECATED_$computeGridMap(t, n, o), _ = Math.min(c.startColumn, f.startColumn), d = Math.min(c.startRow, f.startRow), a = Math.max(c.startColumn + c.cell.__colSpan - 1, f.startColumn + f.cell.__colSpan - 1), h = Math.max(c.startRow + c.cell.__rowSpan - 1, f.startRow + f.cell.__rowSpan - 1);
      o = _, n = d, s = _;
      for (var g = d; _ < o || d < n || a > s || h > g; ) {
        if (_ < o) {
          var C = g - n;
          --o;
          for (var u = 0; u <= C; u++) e(i[n + u][o]);
        }
        if (d < n) for (C = s - o, --n, u = 0; u <= C; u++) e(i[n][o + u]);
        if (a > s) for (C = g - n, s += 1, u = 0; u <= C; u++) e(i[n + u][s]);
        if (h > g) for (C = s - o, g += 1, u = 0; u <= C; u++) e(i[g][o + u]);
      }
      for (t = [t], o = null, n = d; n <= h; n++) for (s = _; s <= a; s++) ({ cell: g } = i[n][s]), C = g.getParent(), l.DEPRECATED_$isGridRowNode(C) || T(107), C !== o && t.push(C), t.push(g, ...fe(g)), o = C;
      return l.isCurrentlyReadOnlyMode() || (this._cachedNodes = t), t;
    }
    getTextContent() {
      let e = this.getNodes(), t = "";
      for (let o = 0; o < e.length; o++) t += e[o].getTextContent();
      return t;
    }
  }
  function R(r) {
    return r instanceof W;
  }
  function Y() {
    let r = l.$createPoint("root", 0, "element"), e = l.$createPoint("root", 0, "element");
    return new W("root", r, e);
  }
  function fe(r) {
    let e = [], t = [r];
    for (; 0 < t.length; ) {
      let o = t.pop();
      o === void 0 && T(112), l.$isElementNode(o) && t.unshift(...o.getChildren()), o !== r && e.push(o);
    }
    return e;
  }
  let le = /^(\d+(?:\.\d+)?)px$/, S = { BOTH: 3, COLUMN: 2, NO_STATUS: 0, ROW: 1 };
  class x extends l.DEPRECATED_GridCellNode {
    static getType() {
      return "tablecell";
    }
    static clone(e) {
      let t = new x(e.__headerState, e.__colSpan, e.__width, e.__key);
      return t.__rowSpan = e.__rowSpan, t.__backgroundColor = e.__backgroundColor, t;
    }
    static importDOM() {
      return { td: () => ({ conversion: ne, priority: 0 }), th: () => ({ conversion: ne, priority: 0 }) };
    }
    static importJSON(e) {
      let t = e.rowSpan || 1, o = D(e.headerState, e.colSpan || 1, e.width || void 0);
      return o.__rowSpan = t, o.__backgroundColor = e.backgroundColor || null, o;
    }
    constructor(e = S.NO_STATUS, t = 1, o, n) {
      super(t, n), this.__headerState = e, this.__width = o, this.__backgroundColor = null;
    }
    createDOM(e) {
      let t = document.createElement(this.getTag());
      return this.__width && (t.style.width = `${this.__width}px`), 1 < this.__colSpan && (t.colSpan = this.__colSpan), 1 < this.__rowSpan && (t.rowSpan = this.__rowSpan), this.__backgroundColor !== null && (t.style.backgroundColor = this.__backgroundColor), m.addClassNamesToElement(t, e.theme.tableCell, this.hasHeader() && e.theme.tableCellHeader), t;
    }
    exportDOM(e) {
      if ({ element: e } = super.exportDOM(e), e) {
        var t = this.getParentOrThrow().getChildrenSize();
        e.style.border = "1px solid black", 1 < this.__colSpan && (e.colSpan = this.__colSpan), 1 < this.__rowSpan && (e.rowSpan = this.__rowSpan), e.style.width = `${this.getWidth() || Math.max(90, 700 / t)}px`, e.style.verticalAlign = "top", e.style.textAlign = "start", t = this.getBackgroundColor(), t !== null ? e.style.backgroundColor = t : this.hasHeader() && (e.style.backgroundColor = "#f2f3f5");
      }
      return { element: e };
    }
    exportJSON() {
      return {
        ...super.exportJSON(),
        backgroundColor: this.getBackgroundColor(),
        headerState: this.__headerState,
        type: "tablecell",
        width: this.getWidth()
      };
    }
    getTag() {
      return this.hasHeader() ? "th" : "td";
    }
    setHeaderStyles(e) {
      return this.getWritable().__headerState = e, this.__headerState;
    }
    getHeaderStyles() {
      return this.getLatest().__headerState;
    }
    setWidth(e) {
      return this.getWritable().__width = e, this.__width;
    }
    getWidth() {
      return this.getLatest().__width;
    }
    getBackgroundColor() {
      return this.getLatest().__backgroundColor;
    }
    setBackgroundColor(e) {
      this.getWritable().__backgroundColor = e;
    }
    toggleHeaderStyle(e) {
      let t = this.getWritable();
      return t.__headerState = (t.__headerState & e) === e ? t.__headerState - e : t.__headerState + e, t;
    }
    hasHeaderState(e) {
      return (this.getHeaderStyles() & e) === e;
    }
    hasHeader() {
      return this.getLatest().__headerState !== S.NO_STATUS;
    }
    updateDOM(e) {
      return e.__headerState !== this.__headerState || e.__width !== this.__width || e.__colSpan !== this.__colSpan || e.__rowSpan !== this.__rowSpan || e.__backgroundColor !== this.__backgroundColor;
    }
    isShadowRoot() {
      return !0;
    }
    collapseAtStart() {
      return !0;
    }
    canBeEmpty() {
      return !1;
    }
    canIndent() {
      return !1;
    }
  }
  function ne(r) {
    var e = r.nodeName.toLowerCase();
    let t;
    return le.test(r.style.width) && (t = parseFloat(r.style.width)), e = D(e === "th" ? S.ROW : S.NO_STATUS, r.colSpan, t), e.__rowSpan = r.rowSpan, r = r.style.backgroundColor, r !== "" && (e.__backgroundColor = r), { forChild: (o, n) => N(n) && !l.$isElementNode(o) ? (n = l.$createParagraphNode(), l.$isLineBreakNode(o) && o.getTextContent() === `
` ? null : (n.append(o), n)) : o, node: e };
  }
  function D(r, e = 1, t) {
    return l.$applyNodeReplacement(new x(r, e, t));
  }
  function N(r) {
    return r instanceof x;
  }
  class I extends l.DEPRECATED_GridRowNode {
    static getType() {
      return "tablerow";
    }
    static clone(e) {
      return new I(e.__height, e.__key);
    }
    static importDOM() {
      return { tr: () => ({ conversion: Ce, priority: 0 }) };
    }
    static importJSON(e) {
      return O(e.height);
    }
    constructor(e, t) {
      super(t), this.__height = e;
    }
    exportJSON() {
      return { ...super.exportJSON(), type: "tablerow", version: 1 };
    }
    createDOM(e) {
      let t = document.createElement("tr");
      return this.__height && (t.style.height = `${this.__height}px`), m.addClassNamesToElement(t, e.theme.tableRow), t;
    }
    isShadowRoot() {
      return !0;
    }
    setHeight(e) {
      return this.getWritable().__height = e, this.__height;
    }
    getHeight() {
      return this.getLatest().__height;
    }
    updateDOM(e) {
      return e.__height !== this.__height;
    }
    canBeEmpty() {
      return !1;
    }
    canIndent() {
      return !1;
    }
  }
  function Ce(r) {
    let e;
    return le.test(r.style.height) && (e = parseFloat(r.style.height)), { node: O(e) };
  }
  function O(r) {
    return l.$applyNodeReplacement(new I(r));
  }
  function v(r) {
    return r instanceof I;
  }
  let _e = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u";
  class ie {
    constructor(e, t) {
      this.isHighlightingCells = !1, this.focusY = this.focusX = this.anchorY = this.anchorX = -1, this.listenersToRemove = /* @__PURE__ */ new Set(), this.tableNodeKey = t, this.editor = e, this.grid = { cells: [], columns: 0, rows: 0 }, this.focusCell = this.anchorCell = this.focusCellNodeKey = this.anchorCellNodeKey = this.gridSelection = null, this.hasHijackedSelectionStyles = !1, this.trackTableGrid();
    }
    getGrid() {
      return this.grid;
    }
    removeListeners() {
      Array.from(this.listenersToRemove).forEach((e) => e());
    }
    trackTableGrid() {
      let e = new MutationObserver((t) => {
        this.editor.update(() => {
          var o = !1;
          for (let n = 0; n < t.length; n++) {
            const s = t[n].target.nodeName;
            if (s === "TABLE" || s === "TR") {
              o = !0;
              break;
            }
          }
          if (o) {
            if (o = this.editor.getElementByKey(this.tableNodeKey), !o) throw Error("Expected to find TableElement in DOM");
            this.grid = P(o);
          }
        });
      });
      this.editor.update(() => {
        let t = this.editor.getElementByKey(this.tableNodeKey);
        if (!t) throw Error("Expected to find TableElement in DOM");
        this.grid = P(t), e.observe(t, { childList: !0, subtree: !0 });
      });
    }
    clearHighlight() {
      let e = this.editor;
      this.isHighlightingCells = !1, this.focusY = this.focusX = this.anchorY = this.anchorX = -1, this.focusCell = this.anchorCell = this.focusCellNodeKey = this.anchorCellNodeKey = this.gridSelection = null, this.hasHijackedSelectionStyles = !1, this.enableHighlightStyle(), e.update(() => {
        var t = l.$getNodeByKey(this.tableNodeKey);
        if (!A(t)) throw Error("Expected TableNode.");
        if (t = e.getElementByKey(this.tableNodeKey), !t) throw Error("Expected to find TableElement in DOM");
        t = P(t), U(e, t, null), l.$setSelection(null), e.dispatchCommand(
          l.SELECTION_CHANGE_COMMAND,
          void 0
        );
      });
    }
    enableHighlightStyle() {
      let e = this.editor;
      e.update(() => {
        let t = e.getElementByKey(this.tableNodeKey);
        if (!t) throw Error("Expected to find TableElement in DOM");
        m.removeClassNamesFromElement(t, e._config.theme.tableSelection), t.classList.remove("disable-selection"), this.hasHijackedSelectionStyles = !1;
      });
    }
    disableHighlightStyle() {
      let e = this.editor;
      e.update(() => {
        let t = e.getElementByKey(this.tableNodeKey);
        if (!t) throw Error("Expected to find TableElement in DOM");
        m.addClassNamesToElement(t, e._config.theme.tableSelection), this.hasHijackedSelectionStyles = !0;
      });
    }
    updateTableGridSelection(e) {
      if (e != null && e.gridKey === this.tableNodeKey) {
        let t = this.editor;
        this.gridSelection = e, this.isHighlightingCells = !0, this.disableHighlightStyle(), U(t, this.grid, this.gridSelection);
      } else e == null ? this.clearHighlight() : (this.tableNodeKey = e.gridKey, this.updateTableGridSelection(e));
    }
    setFocusCellForSelection(e, t = !1) {
      let o = this.editor;
      o.update(() => {
        var n = l.$getNodeByKey(this.tableNodeKey);
        if (!A(n)) throw Error("Expected TableNode.");
        if (!o.getElementByKey(this.tableNodeKey)) throw Error("Expected to find TableElement in DOM");
        n = e.x;
        let s = e.y;
        if (this.focusCell = e, this.anchorCell !== null) {
          let i = _e ? (o._window || window).getSelection() : null;
          i && i.setBaseAndExtent(this.anchorCell.elem, 0, this.focusCell.elem, 0);
        }
        if (!this.isHighlightingCells && (this.anchorX !== n || this.anchorY !== s || t)) this.isHighlightingCells = !0, this.disableHighlightStyle();
        else if (n === this.focusX && s === this.focusY) return;
        this.focusX = n, this.focusY = s, this.isHighlightingCells && (n = l.$getNearestNodeFromDOMNode(e.elem), this.gridSelection != null && this.anchorCellNodeKey != null && N(n) && (n = n.getKey(), this.gridSelection = this.gridSelection.clone() || Y(), this.focusCellNodeKey = n, this.gridSelection.set(this.tableNodeKey, this.anchorCellNodeKey, this.focusCellNodeKey), l.$setSelection(this.gridSelection), o.dispatchCommand(l.SELECTION_CHANGE_COMMAND, void 0), U(o, this.grid, this.gridSelection)));
      });
    }
    setAnchorCellForSelection(e) {
      this.isHighlightingCells = !1, this.anchorCell = e, this.anchorX = e.x, this.anchorY = e.y, this.editor.update(() => {
        var t = l.$getNearestNodeFromDOMNode(e.elem);
        N(t) && (t = t.getKey(), this.gridSelection = this.gridSelection != null ? this.gridSelection.clone() : Y(), this.anchorCellNodeKey = t);
      });
    }
    formatCells(e) {
      this.editor.update(() => {
        let t = l.$getSelection();
        R(t) || T(11);
        let o = l.$createRangeSelection(), n = o.anchor, s = o.focus;
        t.getNodes().forEach((i) => {
          N(i) && i.getTextContentSize() !== 0 && (n.set(i.getKey(), 0, "element"), s.set(i.getKey(), i.getChildrenSize(), "element"), o.formatText(e));
        }), l.$setSelection(t), this.editor.dispatchCommand(l.SELECTION_CHANGE_COMMAND, void 0);
      });
    }
    clearText() {
      let e = this.editor;
      e.update(() => {
        let t = l.$getNodeByKey(this.tableNodeKey);
        if (!A(t)) throw Error("Expected TableNode.");
        var o = l.$getSelection();
        R(o) || T(11), o = o.getNodes().filter(N), o.length === this.grid.columns * this.grid.rows ? (t.selectPrevious(), t.remove(), l.$getRoot().selectStart()) : (o.forEach((n) => {
          if (l.$isElementNode(n)) {
            let s = l.$createParagraphNode(), i = l.$createTextNode();
            s.append(i), n.append(s), n.getChildren().forEach((c) => {
              c !== s && c.remove();
            });
          }
        }), U(e, this.grid, null), l.$setSelection(null), e.dispatchCommand(
          l.SELECTION_CHANGE_COMMAND,
          void 0
        ));
      });
    }
  }
  function j(r) {
    for (; r != null; ) {
      let e = r.nodeName;
      if (e === "TD" || e === "TH") {
        if (r = r._cell, r === void 0) break;
        return r;
      }
      r = r.parentNode;
    }
    return null;
  }
  function P(r) {
    let e = [], t = { cells: e, columns: 0, rows: 0 };
    var o = r.firstChild;
    let n = r = 0;
    for (e.length = 0; o != null; ) {
      var s = o.nodeName;
      if (s === "TD" || s === "TH") {
        s = o, s = { elem: s, hasBackgroundColor: s.style.backgroundColor !== "", highlighted: !1, x: r, y: n }, o._cell = s;
        let i = e[n];
        i === void 0 && (i = e[n] = []), i[r] = s;
      } else if (s = o.firstChild, s != null) {
        o = s;
        continue;
      }
      if (s = o.nextSibling, s != null) r++, o = s;
      else if (s = o.parentNode, s != null) {
        if (o = s.nextSibling, o == null) break;
        n++, r = 0;
      }
    }
    return t.columns = r + 1, t.rows = n + 1, t;
  }
  function U(r, e, t) {
    let o = new Set(t ? t.getNodes() : []);
    Z(e, (n, s) => {
      let i = n.elem;
      o.has(s) ? (n.highlighted = !0, ae(r, n)) : (n.highlighted = !1, ce(r, n), i.getAttribute("style") || i.removeAttribute("style"));
    });
  }
  function Z(r, e) {
    ({ cells: r } = r);
    for (let t = 0; t < r.length; t++) {
      let o = r[t];
      if (o) for (let n = 0; n < o.length; n++) {
        let s = o[n];
        if (!s) continue;
        let i = l.$getNearestNodeFromDOMNode(s.elem);
        i !== null && e(s, i, { x: n, y: t });
      }
    }
  }
  function se(r, e) {
    e.disableHighlightStyle(), Z(e.grid, (t) => {
      t.highlighted = !0, ae(r, t);
    });
  }
  function Ee(r, e) {
    e.enableHighlightStyle(), Z(e.grid, (t) => {
      let o = t.elem;
      t.highlighted = !1, ce(r, t), o.getAttribute("style") || o.removeAttribute("style");
    });
  }
  let de = (r, e, t, o, n) => {
    const s = n === "forward";
    switch (n) {
      case "backward":
      case "forward":
        return t !== (s ? r.grid.columns - 1 : 0) ? (r = e.getCellNodeFromCordsOrThrow(t + (s ? 1 : -1), o, r.grid), s ? r.selectStart() : r.selectEnd()) : o !== (s ? r.grid.rows - 1 : 0) ? (r = e.getCellNodeFromCordsOrThrow(s ? 0 : r.grid.columns - 1, o + (s ? 1 : -1), r.grid), s ? r.selectStart() : r.selectEnd()) : s ? e.selectNext() : e.selectPrevious(), !0;
      case "up":
        return o !== 0 ? e.getCellNodeFromCordsOrThrow(t, o - 1, r.grid).selectEnd() : e.selectPrevious(), !0;
      case "down":
        return o !== r.grid.rows - 1 ? e.getCellNodeFromCordsOrThrow(t, o + 1, r.grid).selectStart() : e.selectNext(), !0;
      default:
        return !1;
    }
  }, Ne = (r, e, t, o, n) => {
    const s = n === "forward";
    switch (n) {
      case "backward":
      case "forward":
        return t !== (s ? r.grid.columns - 1 : 0) && r.setFocusCellForSelection(e.getCellFromCordsOrThrow(t + (s ? 1 : -1), o, r.grid)), !0;
      case "up":
        return o !== 0 ? (r.setFocusCellForSelection(e.getCellFromCordsOrThrow(t, o - 1, r.grid)), !0) : !1;
      case "down":
        return o !== r.grid.rows - 1 ? (r.setFocusCellForSelection(e.getCellFromCordsOrThrow(t, o + 1, r.grid)), !0) : !1;
      default:
        return !1;
    }
  };
  function b(r, e) {
    if (l.$isRangeSelection(r) || R(r)) {
      let t = e.isParentOf(r.anchor.getNode());
      return r = e.isParentOf(r.focus.getNode()), t && r;
    }
    return !1;
  }
  function ae(r, e) {
    r = e.elem, e = l.$getNearestNodeFromDOMNode(r), N(e) || T(131), e.getBackgroundColor() === null ? r.style.setProperty("background-color", "rgb(172,206,247)") : r.style.setProperty("background-image", "linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))"), r.style.setProperty("caret-color", "transparent");
  }
  function ce(r, e) {
    r = e.elem, e = l.$getNearestNodeFromDOMNode(r), N(e) || T(131), e.getBackgroundColor() === null && r.style.removeProperty("background-color"), r.style.removeProperty("background-image"), r.style.removeProperty("caret-color");
  }
  function V(r) {
    return r = m.$findMatchingParent(r, N), N(r) ? r : null;
  }
  function Q(r) {
    return r = m.$findMatchingParent(r, A), A(r) ? r : null;
  }
  function K(r, e, t, o, n) {
    let s = l.$getSelection();
    if (!b(s, o)) return !1;
    if (l.$isRangeSelection(s) && s.isCollapsed()) {
      if (t === "backward" || t === "forward") return !1;
      let { anchor: _, focus: d } = s;
      var i = m.$findMatchingParent(_.getNode(), N), c = m.$findMatchingParent(d.getNode(), N);
      if (!N(i) || !i.is(c)) return !1;
      if (c = Q(i), c !== o && c != null) {
        var f = r.getElementByKey(c.getKey());
        if (f != null) return n.grid = P(f), K(r, e, t, c, n);
      }
      if (c = r.getElementByKey(i.__key), f = r.getElementByKey(_.key), f == null || c == null) return !1;
      if (_.type === "element") c = f.getBoundingClientRect();
      else {
        if (c = window.getSelection(), c === null || c.rangeCount === 0) return !1;
        c = c.getRangeAt(0).getBoundingClientRect();
      }
      if (f = t === "up" ? i.getFirstChild() : i.getLastChild(), f == null || (r = r.getElementByKey(f.__key), r == null)) return !1;
      if (r = r.getBoundingClientRect(), t === "up" ? r.top > c.top - c.height : c.bottom + c.height > r.bottom) {
        if (L(e), r = o.getCordsFromCellNode(i, n.grid), e.shiftKey) t = o.getCellFromCordsOrThrow(r.x, r.y, n.grid), n.setAnchorCellForSelection(t), n.setFocusCellForSelection(t, !0);
        else return de(n, o, r.x, r.y, t);
        return !0;
      }
    } else if (R(s)) {
      let { anchor: _, focus: d } = s;
      return f = m.$findMatchingParent(_.getNode(), N), c = m.$findMatchingParent(d.getNode(), N), [i] = s.getNodes(), r = r.getElementByKey(i.getKey()), !N(f) || !N(c) || !A(i) || r == null ? !1 : (n.updateTableGridSelection(s), r = P(r), f = o.getCordsFromCellNode(f, r), f = o.getCellFromCordsOrThrow(f.x, f.y, r), n.setAnchorCellForSelection(f), L(e), e.shiftKey ? (e = o.getCordsFromCellNode(c, r), Ne(n, i, e.x, e.y, t)) : (c.selectEnd(), !0));
    }
    return !1;
  }
  function L(r) {
    r.preventDefault(), r.stopImmediatePropagation(), r.stopPropagation();
  }
  class F extends l.DEPRECATED_GridNode {
    static getType() {
      return "table";
    }
    static clone(e) {
      return new F(e.__key);
    }
    static importDOM() {
      return { table: () => ({ conversion: me, priority: 1 }) };
    }
    static importJSON() {
      return X();
    }
    constructor(e) {
      super(e);
    }
    exportJSON() {
      return { ...super.exportJSON(), type: "table", version: 1 };
    }
    createDOM(e) {
      let t = document.createElement("table");
      return m.addClassNamesToElement(t, e.theme.table), t;
    }
    updateDOM() {
      return !1;
    }
    exportDOM(e) {
      return { ...super.exportDOM(e), after: (t) => {
        if (t) {
          let o = t.cloneNode(), n = document.createElement("colgroup"), s = document.createElement("tbody");
          if (m.isHTMLElement(t) && s.append(...t.children), t = this.getFirstChildOrThrow(), !v(t)) throw Error("Expected to find row node.");
          t = t.getChildrenSize();
          for (let i = 0; i < t; i++) {
            let c = document.createElement("col");
            n.append(c);
          }
          return o.replaceChildren(n, s), o;
        }
      } };
    }
    canExtractContents() {
      return !1;
    }
    canBeEmpty() {
      return !1;
    }
    isShadowRoot() {
      return !0;
    }
    getCordsFromCellNode(e, t) {
      let { rows: o, cells: n } = t;
      for (t = 0; t < o; t++) {
        var s = n[t];
        if (s != null && (s = s.findIndex((i) => {
          if (i) return { elem: i } = i, l.$getNearestNodeFromDOMNode(i) === e;
        }), s !== -1)) return { x: s, y: t };
      }
      throw Error("Cell not found in table.");
    }
    getCellFromCords(e, t, o) {
      return { cells: o } = o, t = o[t], t == null ? null : (e = t[e], e ?? null);
    }
    getCellFromCordsOrThrow(e, t, o) {
      if (e = this.getCellFromCords(e, t, o), !e) throw Error("Cell not found at cords.");
      return e;
    }
    getCellNodeFromCords(e, t, o) {
      return e = this.getCellFromCords(e, t, o), e == null ? null : (e = l.$getNearestNodeFromDOMNode(e.elem), N(e) ? e : null);
    }
    getCellNodeFromCordsOrThrow(e, t, o) {
      if (e = this.getCellNodeFromCords(e, t, o), !e) throw Error("Node at cords not TableCellNode.");
      return e;
    }
    canSelectBefore() {
      return !0;
    }
    canIndent() {
      return !1;
    }
  }
  function me() {
    return { node: X() };
  }
  function X() {
    return l.$applyNodeReplacement(new F());
  }
  function A(r) {
    return r instanceof F;
  }
  function q(r) {
    if (r = m.$findMatchingParent(r, (e) => v(e)), v(r)) return r;
    throw Error("Expected table cell to be inside of table row.");
  }
  function ee(r) {
    if (r = m.$findMatchingParent(r, (e) => A(e)), A(r)) return r;
    throw Error("Expected table cell to be inside of table.");
  }
  function he(r, e) {
    let t = ee(r), { x: o, y: n } = t.getCordsFromCellNode(r, e);
    return { above: t.getCellNodeFromCords(o, n - 1, e), below: t.getCellNodeFromCords(o, n + 1, e), left: t.getCellNodeFromCords(o - 1, n, e), right: t.getCellNodeFromCords(o + 1, n, e) };
  }
  function H(r) {
    let e = r.getFirstDescendant();
    e == null ? r.selectStart() : e.getParentOrThrow().selectStart();
  }
  function te(r, e) {
    let t = r.getFirstChild();
    t !== null ? t.insertBefore(e) : r.append(e);
  }
  let pe = l.createCommand("INSERT_TABLE_COMMAND");
  return E.$createGridSelection = Y, E.$createTableCellNode = D, E.$createTableNode = X, E.$createTableNodeWithDimensions = function(r, e, t = !0) {
    let o = X();
    for (let s = 0; s < r; s++) {
      let i = O();
      for (let c = 0; c < e; c++) {
        var n = S.NO_STATUS;
        typeof t == "object" ? (s === 0 && t.rows && (n |= S.ROW), c === 0 && t.columns && (n |= S.COLUMN)) : t && (s === 0 && (n |= S.ROW), c === 0 && (n |= S.COLUMN)), n = D(n);
        let f = l.$createParagraphNode();
        f.append(l.$createTextNode()), n.append(f), i.append(n);
      }
      o.append(i);
    }
    return o;
  }, E.$createTableRowNode = O, E.$deleteTableColumn = function(r, e) {
    let t = r.getChildren();
    for (let n = 0; n < t.length; n++) {
      var o = t[n];
      if (v(o)) {
        if (o = o.getChildren(), e >= o.length || 0 > e) throw Error("Table column target index out of range");
        o[e].remove();
      }
    }
    return r;
  }, E.$deleteTableColumn__EXPERIMENTAL = function() {
    var r = l.$getSelection();
    if (!l.$INTERNAL_isPointSelection(r)) throw Error("Expected a INTERNAL_PointSelection");
    var e = r.anchor.getNode();
    r = r.focus.getNode();
    let [t, , o] = l.DEPRECATED_$getNodeTriplet(e);
    [e] = l.DEPRECATED_$getNodeTriplet(r);
    let [n, s, i] = l.DEPRECATED_$computeGridMap(o, t, e);
    var { startColumn: c } = s;
    let { startRow: f, startColumn: _ } = i;
    r = Math.min(c, _), c = Math.max(c + t.__colSpan - 1, _ + e.__colSpan - 1);
    let d = c - r + 1;
    if (n[0].length === c - r + 1) o.selectPrevious(), o.remove();
    else {
      var a = n.length;
      for (let h = 0; h < a; h++) for (let g = r; g <= c; g++) {
        let { cell: C, startColumn: u } = n[h][g];
        u < r ? g === r && C.setColSpan(C.__colSpan - Math.min(d, C.__colSpan - (r - u))) : u + C.__colSpan - 1 > c ? g === c && C.setColSpan(C.__colSpan - (c - u + 1)) : C.remove();
      }
      r = n[f], e = r[_ + e.__colSpan], e !== void 0 ? ({ cell: e } = e, H(e)) : ({ cell: e } = r[_ - 1], H(e));
    }
  }, E.$deleteTableRow__EXPERIMENTAL = function() {
    var r = l.$getSelection();
    if (!l.$INTERNAL_isPointSelection(r)) throw Error("Expected a INTERNAL_PointSelection");
    var e = r.anchor.getNode();
    r = r.focus.getNode();
    let [t, , o] = l.DEPRECATED_$getNodeTriplet(e);
    [r] = l.DEPRECATED_$getNodeTriplet(r);
    let [n, s, i] = l.DEPRECATED_$computeGridMap(o, t, r);
    ({ startRow: e } = s);
    var { startRow: c } = i;
    if (r = c + r.__rowSpan - 1, n.length === r - e + 1) o.remove();
    else {
      c = n[0].length;
      var f = n[r + 1], _ = o.getChildAtIndex(r + 1);
      for (let a = r; a >= e; a--) {
        for (var d = c - 1; 0 <= d; d--) {
          let { cell: h, startRow: g, startColumn: C } = n[a][d];
          if (C === d && (a === e && g < e && h.setRowSpan(h.__rowSpan - (g - e)), g >= e && g + h.__rowSpan - 1 > r)) if (h.setRowSpan(h.__rowSpan - (r - g + 1)), _ === null && T(122), d === 0) te(_, h);
          else {
            let { cell: u } = f[d - 1];
            u.insertAfter(h);
          }
        }
        d = o.getChildAtIndex(a), l.DEPRECATED_$isGridRowNode(d) || T(123, String(a)), d.remove();
      }
      f !== void 0 ? ({ cell: e } = f[0], H(e)) : ({ cell: e } = n[e - 1][0], H(e));
    }
  }, E.$getElementGridForTableNode = function(r, e) {
    if (r = r.getElementByKey(e.getKey()), r == null) throw Error("Table Element Not Found");
    return P(r);
  }, E.$getTableCellNodeFromLexicalNode = function(r) {
    return r = m.$findMatchingParent(r, (e) => N(e)), N(r) ? r : null;
  }, E.$getTableColumnIndexFromTableCellNode = function(r) {
    return q(r).getChildren().findIndex((e) => e.is(r));
  }, E.$getTableNodeFromLexicalNodeOrThrow = ee, E.$getTableRowIndexFromTableCellNode = function(r) {
    let e = q(r);
    return ee(e).getChildren().findIndex((t) => t.is(e));
  }, E.$getTableRowNodeFromTableCellNodeOrThrow = q, E.$insertTableColumn = function(r, e, t = !0, o, n) {
    let s = r.getChildren(), i = [];
    for (let _ = 0; _ < s.length; _++) {
      let d = s[_];
      if (v(d)) for (let a = 0; a < o; a++) {
        var c = d.getChildren();
        if (e >= c.length || 0 > e) throw Error("Table column target index out of range");
        c = c[e], N(c) || T(12);
        let { left: h, right: g } = he(c, n);
        var f = S.NO_STATUS;
        (h && h.hasHeaderState(S.ROW) || g && g.hasHeaderState(S.ROW)) && (f |= S.ROW), f = D(f), f.append(l.$createParagraphNode()), i.push({ newTableCell: f, targetCell: c });
      }
    }
    return i.forEach(({ newTableCell: _, targetCell: d }) => {
      t ? d.insertAfter(_) : d.insertBefore(_);
    }), r;
  }, E.$insertTableColumn__EXPERIMENTAL = function(r = !0) {
    function e() {
      let a = D(S.NO_STATUS).append(l.$createParagraphNode());
      return _ === null && (_ = a), a;
    }
    var t = l.$getSelection();
    if (!l.$INTERNAL_isPointSelection(t)) throw Error("Expected a PointSeleciton");
    var o = t.anchor.getNode();
    t = t.focus.getNode(), [o] = l.DEPRECATED_$getNodeTriplet(o);
    let [n, , s] = l.DEPRECATED_$getNodeTriplet(t), [i, c, f] = l.DEPRECATED_$computeGridMap(s, n, o);
    o = i.length, t = r ? Math.max(c.startColumn, f.startColumn) : Math.min(c.startColumn, f.startColumn), r = r ? t + n.__colSpan - 1 : t - 1, t = s.getFirstChild(), l.DEPRECATED_$isGridRowNode(t) || T(120);
    let _ = null;
    var d = t;
    e: for (t = 0; t < o; t++) {
      t !== 0 && (d = d.getNextSibling(), l.DEPRECATED_$isGridRowNode(d) || T(121));
      let a = i[t];
      if (0 > r) {
        te(d, e());
        continue;
      }
      let { cell: h, startColumn: g, startRow: C } = a[r];
      if (g + h.__colSpan - 1 <= r) {
        let u = h, p = C, w = r;
        for (; p !== t && 1 < u.__rowSpan; ) if (w -= h.__colSpan, 0 <= w) {
          let { cell: y, startRow: $ } = a[w];
          u = y, p = $;
        } else {
          d.append(e());
          continue e;
        }
        u.insertAfter(e());
      } else h.setColSpan(h.__colSpan + 1);
    }
    _ !== null && H(_);
  }, E.$insertTableRow = function(r, e, t = !0, o, n) {
    var s = r.getChildren();
    if (e >= s.length || 0 > e) throw Error("Table row target index out of range");
    if (e = s[e], v(e)) for (s = 0; s < o; s++) {
      let c = e.getChildren(), f = c.length, _ = O();
      for (let d = 0; d < f; d++) {
        var i = c[d];
        N(i) || T(12);
        let { above: a, below: h } = he(i, n);
        i = S.NO_STATUS;
        let g = a && a.getWidth() || h && h.getWidth() || void 0;
        (a && a.hasHeaderState(S.COLUMN) || h && h.hasHeaderState(S.COLUMN)) && (i |= S.COLUMN), i = D(i, 1, g), i.append(l.$createParagraphNode()), _.append(i);
      }
      t ? e.insertAfter(_) : e.insertBefore(_);
    }
    else throw Error("Row before insertion index does not exist.");
    return r;
  }, E.$insertTableRow__EXPERIMENTAL = function(r = !0) {
    var e = l.$getSelection();
    if (!l.$INTERNAL_isPointSelection(e)) throw Error("Expected a INTERNAL_PointSelection");
    e = e.focus.getNode();
    let [t, , o] = l.DEPRECATED_$getNodeTriplet(e), [n, s] = l.DEPRECATED_$computeGridMap(o, t, t);
    e = n[0].length;
    var { startRow: i } = s;
    if (r) {
      r = i + t.__rowSpan - 1;
      var c = n[r];
      i = O();
      for (var f = 0; f < e; f++) {
        let { cell: _, startRow: d } = c[f];
        d + _.__rowSpan - 1 <= r ? i.append(D(S.NO_STATUS).append(l.$createParagraphNode())) : _.setRowSpan(_.__rowSpan + 1);
      }
      e = o.getChildAtIndex(r), l.DEPRECATED_$isGridRowNode(e) || T(119), e.insertAfter(i);
    } else {
      for (c = n[i], r = O(), f = 0; f < e; f++) {
        let { cell: _, startRow: d } = c[f];
        d === i ? r.append(D(S.NO_STATUS).append(l.$createParagraphNode())) : _.setRowSpan(_.__rowSpan + 1);
      }
      e = o.getChildAtIndex(i), l.DEPRECATED_$isGridRowNode(e) || T(119), e.insertBefore(r);
    }
  }, E.$isGridSelection = R, E.$isTableCellNode = N, E.$isTableNode = A, E.$isTableRowNode = v, E.$removeTableRowAtIndex = function(r, e) {
    let t = r.getChildren();
    if (e >= t.length || 0 > e) throw Error("Expected table cell to be inside of table row.");
    return t[e].remove(), r;
  }, E.$unmergeCell = function() {
    var r = l.$getSelection();
    if (!l.$INTERNAL_isPointSelection(r)) throw Error("Expected a INTERNAL_PointSelection");
    r = r.anchor.getNode();
    let [e, t, o] = l.DEPRECATED_$getNodeTriplet(r);
    r = e.__colSpan;
    let n = e.__rowSpan;
    if (1 < r) {
      for (var s = 1; s < r; s++) e.insertAfter(D(S.NO_STATUS));
      e.setColSpan(1);
    }
    if (1 < n) {
      let [f, _] = l.DEPRECATED_$computeGridMap(o, e, e), { startColumn: d, startRow: a } = _, h;
      for (s = 1; s < n; s++) {
        var i = a + s;
        let g = f[i];
        h = (h || t).getNextSibling(), l.DEPRECATED_$isGridRowNode(h) || T(125);
        var c = null;
        for (let C = 0; C < d; C++) {
          let u = g[C], p = u.cell;
          u.startRow === i && (c = p), 1 < p.__colSpan && (C += p.__colSpan - 1);
        }
        if (c === null) for (c = 0; c < r; c++) te(h, D(S.NO_STATUS));
        else for (i = 0; i < r; i++) c.insertAfter(D(S.NO_STATUS));
      }
      e.setRowSpan(1);
    }
  }, E.INSERT_TABLE_COMMAND = pe, E.TableCellHeaderStates = S, E.TableCellNode = x, E.TableNode = F, E.TableRowNode = I, E.TableSelection = ie, E.applyTableHandlers = function(r, e, t, o) {
    function n(d) {
      return d = r.getCordsFromCellNode(d, i.grid), r.getCellFromCordsOrThrow(d.x, d.y, i.grid);
    }
    let s = t.getRootElement();
    if (s === null) throw Error("No root element.");
    let i = new ie(t, r.getKey()), c = t._window || window;
    e.__lexicalTableSelection = i, e.addEventListener("mousedown", (d) => {
      setTimeout(() => {
        if (d.button === 0 && c) {
          var a = j(d.target);
          a !== null && (L(d), i.setAnchorCellForSelection(a));
          var h = () => {
            c.removeEventListener("mouseup", h), c.removeEventListener(
              "mousemove",
              g
            );
          }, g = (C) => {
            const u = j(C.target);
            u === null || i.anchorX === u.x && i.anchorY === u.y || (C.preventDefault(), i.setFocusCellForSelection(u));
          };
          c.addEventListener("mouseup", h), c.addEventListener("mousemove", g);
        }
      }, 0);
    });
    let f = (d) => {
      d.button === 0 && t.update(() => {
        const a = l.$getSelection(), h = d.target;
        R(a) && a.gridKey === i.tableNodeKey && s.contains(h) && i.clearHighlight();
      });
    };
    c.addEventListener("mousedown", f), i.listenersToRemove.add(() => c.removeEventListener("mousedown", f)), i.listenersToRemove.add(t.registerCommand(
      l.KEY_ARROW_DOWN_COMMAND,
      (d) => K(t, d, "down", r, i),
      l.COMMAND_PRIORITY_HIGH
    )), i.listenersToRemove.add(t.registerCommand(l.KEY_ARROW_UP_COMMAND, (d) => K(t, d, "up", r, i), l.COMMAND_PRIORITY_HIGH)), i.listenersToRemove.add(t.registerCommand(l.KEY_ARROW_LEFT_COMMAND, (d) => K(t, d, "backward", r, i), l.COMMAND_PRIORITY_HIGH)), i.listenersToRemove.add(t.registerCommand(l.KEY_ARROW_RIGHT_COMMAND, (d) => K(t, d, "forward", r, i), l.COMMAND_PRIORITY_HIGH)), i.listenersToRemove.add(t.registerCommand(l.KEY_ESCAPE_COMMAND, (d) => {
      var a = l.$getSelection();
      return R(a) && (a = m.$findMatchingParent(
        a.focus.getNode(),
        N
      ), N(a)) ? (L(d), a.selectEnd(), !0) : !1;
    }, l.COMMAND_PRIORITY_HIGH));
    let _ = (d) => () => {
      var a = l.$getSelection();
      if (!b(a, r)) return !1;
      if (R(a)) return i.clearText(), !0;
      if (l.$isRangeSelection(a)) {
        const C = m.$findMatchingParent(a.anchor.getNode(), (u) => N(u));
        if (!N(C)) return !1;
        var h = a.anchor.getNode(), g = a.focus.getNode();
        if (h = r.isParentOf(h), g = r.isParentOf(g), h && !g || g && !h) return i.clearText(), !0;
        if (h = (g = m.$findMatchingParent(a.anchor.getNode(), (u) => l.$isElementNode(u))) && m.$findMatchingParent(g, (u) => l.$isElementNode(u) && N(u.getParent())), !l.$isElementNode(h) || !l.$isElementNode(g)) return !1;
        if (d === l.DELETE_LINE_COMMAND && h.getPreviousSibling() === null) return !0;
        if ((d === l.DELETE_CHARACTER_COMMAND || d === l.DELETE_WORD_COMMAND) && a.isCollapsed() && a.anchor.offset === 0 && g !== h) {
          a = g.getChildren();
          const u = l.$createParagraphNode();
          return a.forEach((p) => u.append(p)), g.replace(u), g.getWritable().__parent = C.getKey(), !0;
        }
      }
      return !1;
    };
    return [l.DELETE_WORD_COMMAND, l.DELETE_LINE_COMMAND, l.DELETE_CHARACTER_COMMAND].forEach((d) => {
      i.listenersToRemove.add(t.registerCommand(
        d,
        _(d),
        l.COMMAND_PRIORITY_CRITICAL
      ));
    }), e = (d) => {
      const a = l.$getSelection();
      return b(a, r) ? R(a) ? (d.preventDefault(), d.stopPropagation(), i.clearText(), !0) : (l.$isRangeSelection(a) && (d = m.$findMatchingParent(a.anchor.getNode(), (h) => N(h)), N(d)), !1) : !1;
    }, i.listenersToRemove.add(t.registerCommand(l.KEY_BACKSPACE_COMMAND, e, l.COMMAND_PRIORITY_CRITICAL)), i.listenersToRemove.add(t.registerCommand(l.KEY_DELETE_COMMAND, e, l.COMMAND_PRIORITY_CRITICAL)), i.listenersToRemove.add(t.registerCommand(
      l.FORMAT_TEXT_COMMAND,
      (d) => {
        let a = l.$getSelection();
        return b(a, r) ? R(a) ? (i.formatCells(d), !0) : (l.$isRangeSelection(a) && (d = m.$findMatchingParent(a.anchor.getNode(), (h) => N(h)), N(d)), !1) : !1;
      },
      l.COMMAND_PRIORITY_CRITICAL
    )), i.listenersToRemove.add(t.registerCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND, () => {
      var d = l.$getSelection();
      return b(d, r) && (R(d) ? i.clearHighlight() : l.$isRangeSelection(d) && (d = m.$findMatchingParent(d.anchor.getNode(), (a) => N(a)), N(d))), !1;
    }, l.COMMAND_PRIORITY_CRITICAL)), o && i.listenersToRemove.add(t.registerCommand(
      l.KEY_TAB_COMMAND,
      (d) => {
        var a = l.$getSelection();
        return !l.$isRangeSelection(a) || !a.isCollapsed() || !b(a, r) || (a = V(a.anchor.getNode()), a === null) ? !1 : (L(d), a = r.getCordsFromCellNode(a, i.grid), de(i, r, a.x, a.y, d.shiftKey ? "backward" : "forward"), !0);
      },
      l.COMMAND_PRIORITY_CRITICAL
    )), i.listenersToRemove.add(t.registerCommand(l.FOCUS_COMMAND, () => r.isSelected(), l.COMMAND_PRIORITY_HIGH)), i.listenersToRemove.add(t.registerCommand(l.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, (d) => {
      let { nodes: a, selection: h } = d;
      d = l.$INTERNAL_isPointSelection(h);
      var g = l.$isRangeSelection(h);
      if (d = g && m.$findMatchingParent(h.anchor.getNode(), (M) => l.DEPRECATED_$isGridCellNode(M)) !== null && m.$findMatchingParent(h.focus.getNode(), (M) => l.DEPRECATED_$isGridCellNode(M)) !== null || d && !g, a.length !== 1 || !l.DEPRECATED_$isGridNode(a[0]) || !d) return !1;
      var { anchor: C } = h, u = a[0];
      d = u.getChildren(), g = u.getFirstChildOrThrow().getChildrenSize(), u = u.getChildrenSize();
      var p = m.$findMatchingParent(C.getNode(), (M) => l.DEPRECATED_$isGridCellNode(M)), w = (C = p && m.$findMatchingParent(p, (M) => l.DEPRECATED_$isGridRowNode(M))) && m.$findMatchingParent(C, (M) => l.DEPRECATED_$isGridNode(M));
      if (!l.DEPRECATED_$isGridCellNode(p) || !l.DEPRECATED_$isGridRowNode(C) || !l.DEPRECATED_$isGridNode(w)) return !1;
      var y = C.getIndexWithinParent(), $ = Math.min(w.getChildrenSize() - 1, y + u - 1);
      u = p.getIndexWithinParent(), p = Math.min(C.getChildrenSize() - 1, u + g - 1), g = Math.min(u, p), C = Math.min(y, $), u = Math.max(u, p), y = Math.max(y, $), w = w.getChildren(), $ = 0;
      let re, oe;
      for (p = C; p <= y; p++) {
        var z = w[p];
        if (!l.DEPRECATED_$isGridRowNode(z)) return !1;
        var J = d[$];
        if (!l.DEPRECATED_$isGridRowNode(J)) return !1;
        z = z.getChildren(), J = J.getChildren();
        let M = 0;
        for (let G = g; G <= u; G++) {
          let B = z[G];
          if (!l.DEPRECATED_$isGridCellNode(B)) return !1;
          let ue = J[M];
          if (!l.DEPRECATED_$isGridCellNode(ue)) return !1;
          p === C && G === g ? re = B.getKey() : p === y && G === u && (oe = B.getKey());
          let Se = B.getChildren();
          ue.getChildren().forEach((k) => {
            l.$isTextNode(k) && l.$createParagraphNode().append(k), B.append(k);
          }), Se.forEach((k) => k.remove()), M++;
        }
        $++;
      }
      return re && oe && (d = Y(), d.set(a[0].getKey(), re, oe), l.$setSelection(d)), !0;
    }, l.COMMAND_PRIORITY_CRITICAL)), i.listenersToRemove.add(t.registerCommand(
      l.SELECTION_CHANGE_COMMAND,
      () => {
        let d = l.$getSelection(), a = l.$getPreviousSelection();
        if (l.$isRangeSelection(d)) {
          let { anchor: p, focus: w } = d;
          var h = p.getNode(), g = w.getNode();
          h = V(h), g = V(g);
          var C = h && r.is(Q(h)), u = g && r.is(Q(g));
          let y = C !== u;
          u = C && u, C = d.isBackward(), y ? (h = d.clone(), h.focus.set(r.getKey(), C ? 0 : r.getChildrenSize(), "element"), l.$setSelection(h), se(t, i)) : u && !h.is(g) && (i.setAnchorCellForSelection(n(h)), i.setFocusCellForSelection(n(g), !0));
        }
        return d && !d.is(a) && (R(d) || R(a)) && i.gridSelection && !i.gridSelection.is(a) ? (R(d) && d.gridKey === i.tableNodeKey ? i.updateTableGridSelection(d) : !R(d) && R(a) && a.gridKey === i.tableNodeKey && i.updateTableGridSelection(null), !1) : (i.hasHijackedSelectionStyles && !r.isSelected() ? Ee(t, i) : !i.hasHijackedSelectionStyles && r.isSelected() && se(t, i), !1);
      },
      l.COMMAND_PRIORITY_CRITICAL
    )), i;
  }, E.getCellFromTarget = j, E.getTableSelectionFromTableElement = function(r) {
    return r.__lexicalTableSelection;
  }, E;
}
export {
  Me as __require
};
