import { jsxs as Y, jsx as i, Fragment as de } from "react/jsx-runtime";
import * as je from "react";
import { useEffect as U, useCallback as Z, forwardRef as Pe, useState as _, useRef as K, useMemo as ze, useContext as Le } from "react";
import { c as Re, u as se, E as Ie, X as Be, $ as De, K as me, a as _e, i as Me, h as Fe, O as oe, w as Oe, y as ue, A as He, x as ie, _ as Se, o as ge, b as Ae, f as We, d as Ke, e as Ue, g as xe, j as Xe, l as Ge, C as Ye, S as ne, k as re, m as fe, n as Ve, F as J, T as Ze, p as qe, q as Je, r as Qe, s as et, t as tt, v as nt, I as rt, z as ot, B as le, N as it, L as st, D as at, G as lt, H as ct, J as ut, M as dt, P as mt, Q as gt, R as ft } from "./index-BtS8RM-z.js";
import { d as ht } from "./LexicalNestedComposer.prod-nuvzNal3.js";
import { UnstyledButton as pt, LoadingOverlay as he, Flex as yt, Alert as vt, Tooltip as pe, ActionIcon as ye } from "@mantine/core";
import { c as bt } from "./collaboration-DO8v_8W0.js";
var Ct = Re("info-circle", "IconInfoCircle", [
  ["path", { d: "M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0", key: "svg-0" }],
  ["path", { d: "M12 9h.01", key: "svg-1" }],
  ["path", { d: "M11 12h1v4h1", key: "svg-2" }]
]);
const ve = /* @__PURE__ */ new Map([
  [":)", ["emoji happysmile", "🙂"]],
  [":D", ["emoji veryhappysmile", "😀"]],
  [":(", ["emoji unhappysmile", "🙁"]],
  ["<3", ["emoji heart", "❤"]],
  ["🙂", ["emoji happysmile", "🙂"]],
  ["😀", ["emoji veryhappysmile", "😀"]],
  ["🙁", ["emoji unhappysmile", "🙁"]],
  ["❤", ["emoji heart", "❤"]]
]);
function wt(e) {
  const t = e.getTextContent();
  for (let o = 0; o < t.length; o++) {
    const h = ve.get(t[o]) || ve.get(t.slice(o, o + 2));
    if (h !== void 0) {
      const [u, f] = h;
      let c;
      o === 0 ? [c] = e.splitText(o + 2) : [, c] = e.splitText(o, o + 2);
      const w = De(u, f);
      return c.replace(w), w;
    }
  }
  return null;
}
function Nt(e) {
  let t = e;
  for (; t !== null; ) {
    if (!t.isSimpleText())
      return;
    t = wt(t);
  }
}
function Et(e) {
  U(() => {
    if (!e.hasNodes([Ie]))
      throw new Error("EmojisPlugin: EmojiNode not registered on editor");
    return e.registerNodeTransform(Be, Nt);
  }, [e]);
}
function St() {
  const [e] = se();
  return Et(e), null;
}
const xt = /(^|$|[^A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ﬀ-ﬆﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼＡ-Ｚａ-ｚｦ-ﾾￂ-ￇￊ-ￏￒ-ￗￚ-ￜ])(congrats|congratulations|gratuluju|gratuluji|gratulujeme|blahopřeju|blahopřeji|blahopřejeme|Til lykke|Tillykke|Glückwunsch|Gratuliere|felicitaciones|enhorabuena|paljon onnea|onnittelut|Félicitations|gratula|gratulálok|gratulálunk|congratulazioni|complimenti|おめでとう|おめでとうございます|축하해|축하해요|gratulerer|Gefeliciteerd|gratulacje|Parabéns|parabéns|felicitações|felicitări|мои поздравления|поздравляем|поздравляю|gratulujem|blahoželám|ยินดีด้วย|ขอแสดงความยินดี|tebrikler|tebrik ederim|恭喜|祝贺你|恭喜你|恭喜|恭喜|baie geluk|veels geluk|অভিনন্দন|Čestitam|Čestitke|Čestitamo|Συγχαρητήρια|Μπράβο|અભિનંદન|badhai|बधाई|अभिनंदन|Честитам|Свака част|hongera|வாழ்த்துகள்|வாழ்த்துக்கள்|అభినందనలు|അഭിനന്ദനങ്ങൾ|Chúc mừng|מזל טוב|mazel tov|mazal tov)(^|$|[^A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ﬀ-ﬆﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼＡ-Ｚａ-ｚｦ-ﾾￂ-ￇￊ-ￏￒ-ￗￚ-ￜ])/i;
function Tt() {
  const [e] = se();
  U(() => {
    if (!e.hasNodes([me]))
      throw new Error("KeywordsPlugin: KeywordNode not registered on editor");
  }, [e]);
  const t = Z((h) => _e(h.getTextContent()), []), o = Z((h) => {
    const u = xt.exec(h);
    if (u === null)
      return null;
    const f = u[2].length, c = u.index + u[1].length;
    return {
      end: c + f,
      start: c
    };
  }, []);
  return Me(o, me, t), null;
}
const Te = Object.freeze({ "	": "\\t", "\n": "\\n" }), be = new RegExp(Object.keys(Te).join("|"), "g"), W = Object.freeze({ ancestorHasNextSibling: "|", ancestorIsLastChild: " ", hasNextSibling: "├", isLastChild: "└", selectedChar: "^", selectedLine: ">" }), kt = [(e) => e.hasFormat("bold") && "Bold", (e) => e.hasFormat("code") && "Code", (e) => e.hasFormat("italic") && "Italic", (e) => e.hasFormat("strikethrough") && "Strikethrough", (e) => e.hasFormat("subscript") && "Subscript", (e) => e.hasFormat("superscript") && "Superscript", (e) => e.hasFormat("underline") && "Underline"], $t = [(e) => e.hasTextFormat("bold") && "Bold", (e) => e.hasTextFormat("code") && "Code", (e) => e.hasTextFormat("italic") && "Italic", (e) => e.hasTextFormat("strikethrough") && "Strikethrough", (e) => e.hasTextFormat("subscript") && "Subscript", (e) => e.hasTextFormat("superscript") && "Superscript", (e) => e.hasTextFormat("underline") && "Underline"], jt = [(e) => e.isDirectionless() && "Directionless", (e) => e.isUnmergeable() && "Unmergeable"], Pt = [(e) => e.isToken() && "Token", (e) => e.isSegmented() && "Segmented"];
function zt(e, t, o, h, u = !1) {
  const f = e.getEditorState(), c = e._config, w = e._compositionKey, z = e._editable;
  if (o) {
    let l = "";
    return f.read(() => {
      l = function(a) {
        const N = document.createElement("div");
        return N.innerHTML = a.trim(), $e(N, 0).innerHTML;
      }(Fe(e));
    }), l;
  }
  let S = ` root
`;
  const B = f.read(() => {
    const l = oe();
    return ke(Oe(), (a, N) => {
      const k = `(${a.getKey()})`, L = a.getType() || "", $ = a.isSelected();
      S += `${$ ? W.selectedLine : " "} ${N.join(" ")} ${k} ${L} ${function(v, b, j = !1) {
        const D = b ? b(v, j) : void 0;
        if (D !== void 0 && D.length > 0) return D;
        if (ge(v)) {
          const r = v.getTextContent(), n = r.length === 0 ? "(empty)" : `"${Ce(r, j)}"`, s = function(m) {
            return [we(m), Lt(m), Rt(m)].filter(Boolean).join(", ");
          }(v);
          return [n, s.length !== 0 ? `{ ${s} }` : null].filter(Boolean).join(" ").trim();
        }
        if (Ae(v)) {
          const r = v.getURL(), n = r.length === 0 ? "(empty)" : `"${Ce(r, j)}"`, s = function(m) {
            return [It(m), Bt(m), Dt(m)].filter(Boolean).join(", ");
          }(v);
          return [n, s.length !== 0 ? `{ ${s} }` : null].filter(Boolean).join(" ").trim();
        }
        if (We(v)) return `ids: [ ${v.getIDs().join(", ")} ]`;
        if (Ke(v)) {
          const r = function(s) {
            let m = $t.map((E) => E(s)).filter(Boolean).join(", ").toLocaleLowerCase();
            return m !== "" && (m = "format: " + m), m;
          }(v);
          let n = r !== "" ? `{ ${r} }` : "";
          return n += v.__style ? `(${v.__style})` : "", n;
        }
        return "";
      }(a, h, u)}
`, S += function({ indent: v, isSelected: b, node: j, nodeKeyDisplay: D, selection: r, typeDisplay: n }) {
        if (!ge(j) || !ue(r) || !b || Se(j)) return "";
        const s = r.anchor, m = r.focus;
        if (j.getTextContent() === "" || s.getNode() === r.focus.getNode() && s.offset === m.offset) return "";
        const [E, p] = function(V, Q) {
          const q = Q.getStartEndPoints();
          if (ie(Q) || q === null) return [-1, -1];
          const [M, A] = q, ee = V.getTextContent(), te = ee.length;
          let X = -1, d = -1;
          if (M.type === "text" && A.type === "text") {
            const H = M.getNode(), G = A.getNode();
            H === G && V === H && M.offset !== A.offset ? [X, d] = M.offset < A.offset ? [M.offset, A.offset] : [A.offset, M.offset] : [X, d] = V === H ? H.isBefore(G) ? [M.offset, te] : [0, M.offset] : V === G ? G.isBefore(H) ? [A.offset, te] : [0, A.offset] : [0, te];
          }
          const g = (ee.slice(0, X).match(be) || []).length, P = (ee.slice(X, d).match(be) || []).length;
          return [X + g, d + g + P];
        }(j, r);
        if (E === p) return "";
        const y = v[v.length - 1] === W.hasNextSibling ? W.ancestorHasNextSibling : W.ancestorIsLastChild, F = [...v.slice(0, v.length - 1), y], O = Array(E + 1).fill(" "), R = Array(p - E).fill(W.selectedChar), I = n.length + 2, T = Array(D.length + I).fill(" ");
        return [W.selectedLine, F.join(" "), [...T, ...O, ...R].join("")].join(" ") + `
`;
      }({ indent: N, isSelected: $, node: a, nodeKeyDisplay: k, selection: l, typeDisplay: L });
    }), l === null ? ": null" : ue(l) ? function(a) {
      let N = "";
      const k = we(a);
      N += `: range ${k !== "" ? `{ ${k} }` : ""} ${a.style !== "" ? `{ style: ${a.style} } ` : ""}`;
      const L = a.anchor, $ = a.focus, v = L.offset, b = $.offset;
      return N += `
  ├ anchor { key: ${L.key}, offset: ${v === null ? "null" : v}, type: ${L.type} }`, N += `
  └ focus { key: ${$.key}, offset: ${b === null ? "null" : b}, type: ${$.type} }`, N;
    }(l) : He(l) ? function(a) {
      return `: table
  └ { table: ${a.tableKey}, anchorCell: ${a.anchor.key}, focusCell: ${a.focus.key} }`;
    }(l) : function(a) {
      return ie(a) ? `: node
  └ [${Array.from(a._nodes).join(", ")}]` : "";
    }(l);
  });
  if (S += `
 selection` + B, S += `

 commands:`, t.length) for (const { index: l, type: a, payload: N } of t) S += `
  └ ${l}. { type: ${a}, payload: ${N instanceof Event ? N.constructor.name : N} }`;
  else S += `
  └ None dispatched.`;
  const { version: x } = e.constructor;
  return S += `

 editor${x ? ` (v${x})` : ""}:`, S += `
  └ namespace ${c.namespace}`, w !== null && (S += `
  └ compositionKey ${w}`), S += `
  └ editable ${String(z)}`, S;
}
function ke(e, t, o = []) {
  const h = e.getChildren(), u = h.length;
  h.forEach((f, c) => {
    t(f, o.concat(c === u - 1 ? W.isLastChild : W.hasNextSibling)), Se(f) && ke(f, t, o.concat(c === u - 1 ? W.ancestorIsLastChild : W.ancestorHasNextSibling));
  });
}
function Ce(e, t = !1) {
  const o = Object.entries(Te).reduce((h, [u, f]) => h.replace(new RegExp(u, "g"), String(f)), e);
  return t ? o.replace(/[^\s]/g, "*") : o;
}
function Lt(e) {
  let t = jt.map((o) => o(e)).filter(Boolean).join(", ").toLocaleLowerCase();
  return t !== "" && (t = "detail: " + t), t;
}
function Rt(e) {
  let t = Pt.map((o) => o(e)).filter(Boolean).join(", ").toLocaleLowerCase();
  return t !== "" && (t = "mode: " + t), t;
}
function we(e) {
  let t = kt.map((o) => o(e)).filter(Boolean).join(", ").toLocaleLowerCase();
  return t !== "" && (t = "format: " + t), t;
}
function It(e) {
  let t = e.getTarget();
  return t != null && (t = "target: " + t), t;
}
function Bt(e) {
  let t = e.getRel();
  return t != null && (t = "rel: " + t), t;
}
function Dt(e) {
  let t = e.getTitle();
  return t != null && (t = "title: " + t), t;
}
function $e(e, t) {
  const o = new Array(1 + t++).join("  "), h = new Array(t - 1).join("  ");
  let u;
  for (let f = 0; f < e.children.length; f++) u = document.createTextNode(`
` + o), e.insertBefore(u, e.children[f]), $e(e.children[f], t), e.lastElementChild === e.children[f] && (u = document.createTextNode(`
` + h), e.appendChild(u));
  return e;
}
const _t = Pe(function({ treeTypeButtonClassName: e, timeTravelButtonClassName: t, timeTravelPanelSliderClassName: o, timeTravelPanelButtonClassName: h, viewClassName: u, timeTravelPanelClassName: f, editorState: c, setEditorState: w, setEditorReadOnly: z, generateContent: S }, B) {
  const [x, l] = _([]), [a, N] = _(""), [k, L] = _(!1), [$, v] = _(!1), b = K(0), j = K(null), [D, r] = _(!1), [n, s] = _(!1), [m, E] = _(!1), p = K(), y = K(0), F = Z((R) => {
    const I = ++y.current;
    S(R).then((T) => {
      I === y.current && N(T);
    }).catch((T) => {
      I === y.current && N(`Error rendering tree: ${T.message}

Stack:
${T.stack}`);
    });
  }, [S]);
  U(() => {
    !m && c._nodeMap.size > 1e3 && (s(!0), !m) || p.current !== c && (p.current = c, F($), k || l((R) => [...R, [Date.now(), c]]));
  }, [c, F, $, m, k]);
  const O = x.length;
  return U(() => {
    if (D) {
      let R;
      const I = () => {
        const T = b.current;
        if (T === O - 1) return void r(!1);
        const V = x[T][0], Q = x[T + 1][0];
        R = setTimeout(() => {
          b.current++;
          const q = b.current, M = j.current;
          M !== null && (M.value = String(q)), w(x[q][1]), I();
        }, Q - V);
      };
      return I(), () => {
        clearTimeout(R);
      };
    }
  }, [x, D, O, w]), Y("div", { className: u, children: [!m && n ? Y("div", { style: { padding: 20 }, children: [i("span", { style: { marginRight: 20 }, children: "Detected large EditorState, this can impact debugging performance." }), i("button", { onClick: () => {
    E(!0);
  }, style: { background: "transparent", border: "1px solid white", color: "white", cursor: "pointer", padding: 5 }, children: "Show full tree" })] }) : null, m ? null : i("button", { onClick: () => (F(!$), void v(!$)), className: e, type: "button", children: $ ? "Tree" : "Export DOM" }), !k && (m || !n) && O > 2 && i("button", { onClick: () => {
    z(!0), b.current = O - 1, L(!0);
  }, className: t, type: "button", children: "Time Travel" }), (m || !n) && i("pre", { ref: B, children: a }), k && (m || !n) && Y("div", { className: f, children: [i("button", { className: h, onClick: () => {
    b.current === O - 1 && (b.current = 1), r(!D);
  }, type: "button", children: D ? "Pause" : "Play" }), i("input", { className: o, ref: j, onChange: (R) => {
    const I = Number(R.target.value), T = x[I];
    T && (b.current = I, w(T[1]));
  }, type: "range", min: "1", max: O - 1 }), i("button", { className: h, onClick: () => {
    z(!1);
    const R = x.length - 1, I = x[R];
    w(I[1]);
    const T = j.current;
    T !== null && (T.value = String(R)), L(!1), r(!1);
  }, type: "button", children: "Exit" })] })] });
});
function Mt(e, t) {
  const o = /* @__PURE__ */ new Set();
  let h = 0;
  for (const [u] of e._commands) o.add(e.registerCommand(u, (f) => (t((c) => {
    h += 1;
    const w = [...c];
    return w.push({ index: h, payload: f, type: u.type ? u.type : "UNKNOWN" }), w.length > 10 && w.shift(), w;
  }), !1), Ue));
  return () => o.forEach((u) => u());
}
function Ft(e) {
  const [t, o] = _([]);
  return U(() => Mt(e, o), [e]), ze(() => t, [t]);
}
function Ot({ treeTypeButtonClassName: e, timeTravelButtonClassName: t, timeTravelPanelSliderClassName: o, timeTravelPanelButtonClassName: h, viewClassName: u, timeTravelPanelClassName: f, editor: c, customPrintNode: w }) {
  const z = je.createRef(), [S, B] = _(c.getEditorState()), x = Ft(c);
  return U(() => xe(c.registerUpdateListener(({ editorState: l }) => {
    B(l);
  }), c.registerEditableListener(() => {
    B(c.getEditorState());
  })), [c]), U(() => {
    const l = z.current;
    if (l !== null) return l.__lexicalEditor = c, () => {
      l.__lexicalEditor = null;
    };
  }, [c, z]), i(_t, { treeTypeButtonClassName: e, timeTravelButtonClassName: t, timeTravelPanelSliderClassName: o, timeTravelPanelButtonClassName: h, viewClassName: u, timeTravelPanelClassName: f, setEditorReadOnly: (l) => {
    const a = c.getRootElement();
    a != null && (a.contentEditable = l ? "false" : "true");
  }, editorState: S, setEditorState: (l) => c.setEditorState(l), generateContent: async function(l) {
    return zt(c, x, l, w);
  }, ref: z });
}
function Ht() {
  const [e] = se();
  return /* @__PURE__ */ i(
    Ot,
    {
      viewClassName: "tree-view-output",
      treeTypeButtonClassName: "debug-treetype-button",
      timeTravelPanelClassName: "debug-timetravel-panel",
      timeTravelButtonClassName: "debug-timetravel-button",
      timeTravelPanelSliderClassName: "debug-timetravel-panel-slider",
      timeTravelPanelButtonClassName: "debug-timetravel-panel-button",
      editor: e
    }
  );
}
function ce(e, t, o) {
  return Math.min(Math.max(e, t), o);
}
const C = {
  east: 1,
  north: 8,
  south: 2,
  west: 4
};
function At({
  onResizeStart: e,
  onResizeEnd: t,
  buttonRef: o,
  imageRef: h,
  maxWidth: u,
  editor: f,
  showCaption: c,
  setShowCaption: w,
  captionsEnabled: z
}) {
  const S = K(null), B = K({
    priority: "",
    value: "default"
  }), x = K({
    currentHeight: 0,
    currentWidth: 0,
    direction: 0,
    isResizing: !1,
    ratio: 0,
    startHeight: 0,
    startWidth: 0,
    startX: 0,
    startY: 0
  }), l = f.getRootElement(), a = u || (l !== null ? l.getBoundingClientRect().width - 20 : 100), N = l !== null ? l.getBoundingClientRect().height - 20 : 100, k = 100, L = 100, $ = (r) => {
    const n = r === C.east || r === C.west, s = r === C.north || r === C.south, m = r & C.north && r & C.west || r & C.south && r & C.east, E = n ? "ew" : s ? "ns" : m ? "nwse" : "nesw";
    l !== null && l.style.setProperty("cursor", `${E}-resize`, "important"), document.body !== null && (document.body.style.setProperty("cursor", `${E}-resize`, "important"), B.current.value = document.body.style.getPropertyValue("-webkit-user-select"), B.current.priority = document.body.style.getPropertyPriority("-webkit-user-select"), document.body.style.setProperty("-webkit-user-select", "none", "important"));
  }, v = () => {
    l !== null && l.style.setProperty("cursor", "text"), document.body !== null && (document.body.style.setProperty("cursor", "default"), document.body.style.setProperty(
      "-webkit-user-select",
      B.current.value,
      B.current.priority
    ));
  }, b = (r, n) => {
    if (!f.isEditable())
      return;
    const s = h.current, m = S.current;
    if (s !== null && m !== null) {
      r.preventDefault();
      const { width: E, height: p } = s.getBoundingClientRect(), y = x.current;
      y.startWidth = E, y.startHeight = p, y.ratio = E / p, y.currentWidth = E, y.currentHeight = p, y.startX = r.clientX, y.startY = r.clientY, y.isResizing = !0, y.direction = n, $(n), e(), m.classList.add("image-control-wrapper--resizing"), s.style.height = `${p}px`, s.style.width = `${E}px`, document.addEventListener("pointermove", j), document.addEventListener("pointerup", D);
    }
  }, j = (r) => {
    const n = h.current, s = x.current, m = s.direction & (C.east | C.west), E = s.direction & (C.south | C.north);
    if (n !== null && s.isResizing)
      if (m && E) {
        let p = Math.floor(s.startX - r.clientX);
        p = s.direction & C.east ? -p : p;
        const y = ce(s.startWidth + p, k, a), F = y / s.ratio;
        n.style.width = `${y}px`, n.style.height = `${F}px`, s.currentHeight = F, s.currentWidth = y;
      } else if (E) {
        let p = Math.floor(s.startY - r.clientY);
        p = s.direction & C.south ? -p : p;
        const y = ce(s.startHeight + p, L, N);
        n.style.height = `${y}px`, s.currentHeight = y;
      } else {
        let p = Math.floor(s.startX - r.clientX);
        p = s.direction & C.east ? -p : p;
        const y = ce(s.startWidth + p, k, a);
        n.style.width = `${y}px`, s.currentWidth = y;
      }
  }, D = () => {
    const r = h.current, n = x.current, s = S.current;
    if (r !== null && s !== null && n.isResizing) {
      const m = n.currentWidth, E = n.currentHeight;
      n.startWidth = 0, n.startHeight = 0, n.ratio = 0, n.startX = 0, n.startY = 0, n.currentWidth = 0, n.currentHeight = 0, n.isResizing = !1, s.classList.remove("image-control-wrapper--resizing"), v(), t(m, E), document.removeEventListener("pointermove", j), document.removeEventListener("pointerup", D);
    }
  };
  return /* @__PURE__ */ Y("div", { ref: S, children: [
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-n",
        onPointerDown: (r) => {
          b(r, C.north);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-ne",
        onPointerDown: (r) => {
          b(r, C.north | C.east);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-e",
        onPointerDown: (r) => {
          b(r, C.east);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-se",
        onPointerDown: (r) => {
          b(r, C.south | C.east);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-s",
        onPointerDown: (r) => {
          b(r, C.south);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-sw",
        onPointerDown: (r) => {
          b(r, C.south | C.west);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-w",
        onPointerDown: (r) => {
          b(r, C.west);
        }
      }
    ),
    /* @__PURE__ */ i(
      "div",
      {
        className: "image-resizer image-resizer-nw",
        onPointerDown: (r) => {
          b(r, C.north | C.west);
        }
      }
    )
  ] });
}
const Ne = ft(), Ee = (e, t, o) => {
  if (!o) {
    t();
    return;
  }
  o(e, t);
};
function Wt({
  altText: e,
  className: t,
  imageRef: o,
  src: h,
  width: u,
  height: f,
  maxWidth: c,
  id: w
}) {
  return /* @__PURE__ */ i(
    "img",
    {
      className: t || void 0,
      src: h,
      alt: e,
      ref: o,
      style: {
        height: f,
        maxWidth: c,
        width: u
      },
      draggable: "false",
      "data-id": w
    }
  );
}
function Zt({
  src: e,
  altText: t,
  nodeKey: o,
  width: h,
  height: u,
  maxWidth: f,
  resizable: c,
  showCaption: w,
  caption: z,
  captionsEnabled: S,
  id: B
}) {
  const x = K(null), l = K(null), [a, N, k] = Xe(o), [L, $] = _(!1), [v, b] = _(!0), [j, D] = _(!1), { isCollabActive: r } = Ge(), [n] = se(), [s, m] = _(null), E = K(null), { fetchUploadImage: p, fetchDeleteImage: y } = Le(Ye), F = Z(
    (d) => {
      if (a && ie(oe())) {
        d.preventDefault();
        const P = ne(o);
        re(P) && Ee(
          P.__id,
          () => {
            n.update(() => {
              P.remove();
            });
          },
          y
        );
      }
      return !1;
    },
    [a, o]
  ), O = Z(
    (d) => {
      const g = oe(), P = l.current;
      if (a && ie(g) && g.getNodes().length === 1) {
        if (w)
          return fe(null), d.preventDefault(), z.focus(), !0;
        if (P !== null && P !== document.activeElement)
          return d.preventDefault(), P.focus(), !0;
      }
      return !1;
    },
    [z, a, w]
  ), R = Z(
    (d) => E.current === z || l.current === d.target ? (fe(null), n.update(() => {
      N(!0);
      const g = n.getRootElement();
      g !== null && g.focus();
    }), !0) : !1,
    [z, n, N]
  ), I = Z(
    (d) => {
      const g = d;
      return L ? !0 : g.target === x.current ? (g.shiftKey ? N(!a) : (k(), N(!0)), !0) : !1;
    },
    [L, a, N, k]
  ), T = Z(
    (d) => {
      n.getEditorState().read(() => {
        const g = oe();
        d.target.tagName === "IMG" && ue(g) && g.getNodes().length === 1 && n.dispatchCommand(Ne, d);
      });
    },
    [n]
  );
  U(() => {
    if (!e || e.startsWith("data:image/")) return;
    const d = new Image();
    d.src = e, d.onload = () => b(!1), d.onerror = () => {
      b(!1), D(!0);
    };
  }, [e]), U(() => {
    let d = !0;
    const g = n.getRootElement(), P = xe(
      n.registerUpdateListener(({ editorState: H }) => {
        d && m(H.read(() => oe()));
      }),
      n.registerCommand(
        et,
        (H, G) => (E.current = G, !1),
        J
      ),
      n.registerCommand(Qe, I, J),
      n.registerCommand(Ne, I, J),
      n.registerCommand(Je, F, J),
      n.registerCommand(qe, F, J),
      n.registerCommand(Ze, O, J),
      n.registerCommand(Ve, R, J)
    );
    return g == null || g.addEventListener("contextmenu", T), () => {
      d = !1, P(), g == null || g.removeEventListener("contextmenu", T);
    };
  }, [
    k,
    n,
    L,
    a,
    o,
    F,
    O,
    R,
    I,
    T,
    N
  ]);
  const V = () => {
    n.update(() => {
      const d = ne(o);
      re(d) && d.setShowCaption(!0);
    });
  }, Q = (d, g) => {
    setTimeout(() => {
      $(!1);
    }, 200), n.update(() => {
      const P = ne(o);
      re(P) && P.setWidthAndHeight(d, g);
    });
  }, q = () => {
    $(!0);
  }, { historyState: M } = tt(), {
    settings: { showNestedEditorTreeView: A }
  } = nt(), ee = a || L, [te, X] = _(!1);
  return U(() => {
    X(t === "new-image");
  }, [t]), e ? /* @__PURE__ */ Y(de, { children: [
    /* @__PURE__ */ Y(
      "div",
      {
        style: {
          display: "inline-block",
          position: "relative"
        },
        children: [
          /* @__PURE__ */ i(
            he,
            {
              visible: v,
              zIndex: 1e3,
              overlayProps: { backgroundOpacity: 0.5 },
              loaderProps: { size: 24, color: "black" }
            }
          ),
          /* @__PURE__ */ i(
            he,
            {
              visible: j,
              zIndex: 1e3,
              overlayProps: { backgroundOpacity: 0.5 },
              loaderProps: {
                children: /* @__PURE__ */ i(yt, { bg: "white", maw: 300, justify: "center", children: /* @__PURE__ */ i(vt, { variant: "light", color: "red", title: "Ошибка загрузки", icon: /* @__PURE__ */ i(Ct, {}), children: "Попробуйте загрузить заново." }) })
              }
            }
          ),
          a && /* @__PURE__ */ Y(de, { children: [
            /* @__PURE__ */ i(pe, { label: "Превью", children: /* @__PURE__ */ i("a", { className: "image-show-icon", href: e, target: "_blank", rel: "noopener noreferrer", children: /* @__PURE__ */ i(ye, { variant: "default", color: "gray", "aria-label": "Settings", children: /* @__PURE__ */ i(le, { name: "photo-check" }) }) }) }),
            /* @__PURE__ */ i(pe, { label: "Удалить", children: /* @__PURE__ */ i(
              ye,
              {
                color: "gray",
                "aria-label": "Settings",
                className: "image-delete-icon",
                onClick: (d) => {
                  d.stopPropagation(), Ee(
                    B,
                    () => {
                      n.update(() => {
                        if (oe()) {
                          const g = ne(o);
                          re(g) && g.remove();
                        }
                        return !1;
                      });
                    },
                    B !== "0" ? y : void 0
                  );
                },
                variant: "default",
                children: /* @__PURE__ */ i(le, { name: "trash" })
              }
            ) })
          ] }),
          c && ie(s) && ee && /* @__PURE__ */ i(
            At,
            {
              showCaption: w,
              setShowCaption: V,
              editor: n,
              buttonRef: l,
              imageRef: x,
              maxWidth: f,
              onResizeStart: q,
              onResizeEnd: Q,
              captionsEnabled: S
            }
          ),
          /* @__PURE__ */ i(
            Wt,
            {
              className: ee ? `focused ${ie(s) ? "draggable" : ""}` : null,
              src: e,
              altText: t,
              imageRef: x,
              width: h,
              height: u,
              maxWidth: f || "auto",
              id: B
            }
          )
        ]
      }
    ),
    w && /* @__PURE__ */ i("div", { className: "image-caption-container", children: /* @__PURE__ */ Y(ht, { initialEditor: z, children: [
      /* @__PURE__ */ i(it, {}),
      /* @__PURE__ */ i(st, {}),
      /* @__PURE__ */ i(St, {}),
      /* @__PURE__ */ i(at, {}),
      /* @__PURE__ */ i(Tt, {}),
      r ? /* @__PURE__ */ i(
        lt,
        {
          id: z.getKey(),
          providerFactory: bt,
          shouldBootstrap: !0
        }
      ) : /* @__PURE__ */ i(ct, { externalHistoryState: M }),
      /* @__PURE__ */ i(
        ut,
        {
          contentEditable: /* @__PURE__ */ i(dt, { className: "ImageNode__contentEditable" }),
          placeholder: /* @__PURE__ */ i(mt, { className: "ImageNode__placeholder", children: "Enter a caption..." }),
          ErrorBoundary: gt
        }
      ),
      A === !0 ? /* @__PURE__ */ i(Ht, {}) : null
    ] }) })
  ] }) : /* @__PURE__ */ i(
    rt,
    {
      uploading: !1,
      onUpload: (d) => {
        !p || !d.length || d.forEach((g, P) => {
          p(g, (H, G) => {
            P === 0 ? n.update(() => {
              const ae = ne(o);
              re(ae) && (ae.setSrc(H), ae.setId(G));
            }) : n.dispatchCommand(ot, {
              altText: "",
              src: H,
              id: G
            });
          });
        });
      },
      popoverProps: { opened: te, position: "bottom", onChange: X },
      onChange: (d) => {
        n.update(() => {
          const g = ne(o);
          re(g) && (g.setSrc(d), g.setAlt("chosen-image"));
        });
      },
      children: /* @__PURE__ */ Y(
        pt,
        {
          className: "image-node-picker-button",
          styles: {
            root: {
              width: "100%",
              display: "flex",
              alignItems: "center",
              gap: "var(--mantine-spacing-sm)",
              padding: "var(--mantine-spacing-md)",
              background: "var(--mantine-primary-color-light)",
              color: "var(--mantine-color-text)",
              borderRadius: "var(--mantine-radius-default)",
              opacity: 0.75
            }
          },
          onClick: () => X(!te),
          children: [
            /* @__PURE__ */ i(le, { name: "photo" }),
            "Добавить картинку"
          ]
        }
      )
    }
  );
}
export {
  Ne as RIGHT_CLICK_IMAGE_COMMAND,
  Zt as default
};
