import { __exports as s } from "./index-LexicalComposer.prod2.js";
import { __require as L } from "./index-LexicalComposerContext2.js";
import { __require as q } from "./index-Lexical.js";
import w from "react";
var c;
function k() {
  if (c) return s;
  c = 1;
  var m = L(), i = q(), n = w;
  let p = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u";
  var f = p ? n.useLayoutEffect : n.useEffect;
  let l = { tag: "history-merge" };
  function E(e, r) {
    if (r !== null) {
      if (r === void 0) e.update(() => {
        var t = i.$getRoot();
        if (t.isEmpty()) {
          let o = i.$createParagraphNode();
          t.append(o), t = p ? document.activeElement : null, (i.$getSelection() !== null || t !== null && t === e.getRootElement()) && o.select();
        }
      }, l);
      else if (r !== null) switch (typeof r) {
        case "string":
          let t = e.parseEditorState(r);
          e.setEditorState(t, l);
          break;
        case "object":
          e.setEditorState(r, l);
          break;
        case "function":
          e.update(() => {
            i.$getRoot().isEmpty() && r(e);
          }, l);
      }
    }
  }
  return s.LexicalComposer = function({ initialConfig: e, children: r }) {
    let t = n.useMemo(() => {
      const { theme: o, namespace: a, editor__DEPRECATED: _, nodes: x, onError: C, editorState: h, html: b } = e, g = m.createLexicalComposerContext(null, o);
      let d = _ || null;
      if (d === null) {
        const u = i.createEditor({ editable: e.editable, html: b, namespace: a, nodes: x, onError: (v) => C(v, u), theme: o });
        E(u, h), d = u;
      }
      return [d, g];
    }, []);
    return f(() => {
      let o = e.editable, [a] = t;
      a.setEditable(o !== void 0 ? o : !0);
    }, []), n.createElement(
      m.LexicalComposerContext.Provider,
      { value: t },
      r
    );
  }, s;
}
export {
  k as __require
};
