@layers-app/editor 0.5.4-optimization → 0.5.6-optimization

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +19 -0
  2. package/dist/index.cjs +2 -0
  3. package/dist/index.js +12 -10
  4. package/dist/layers.7jmq6tBR.js +2227 -0
  5. package/dist/layers.B90YwJga.js +4 -0
  6. package/dist/layers.C03OvlLb.js +6 -0
  7. package/dist/layers.CJiIq6YQ.js +1 -0
  8. package/dist/layers.CXffIp2y.js +864 -0
  9. package/dist/layers.CZPeYQ9g.js +3 -0
  10. package/dist/layers.CZ_Lt7IL.js +7 -0
  11. package/dist/layers.Ci1-qkbn.js +341 -0
  12. package/dist/layers.Cnm-pECN.js +2 -0
  13. package/dist/layers.D6d62qQ_.js +6774 -0
  14. package/dist/layers.DNCgFYS7.js +27 -0
  15. package/dist/layers.Dev6Yrwi.js +530 -0
  16. package/dist/layers.Dgok89qX.js +1 -0
  17. package/dist/layers.Dq3o7sh3.js +7723 -0
  18. package/dist/layers.Duy8YzsH.js +2511 -0
  19. package/dist/layers.QjAkD17S.js +3677 -0
  20. package/package.json +73 -17
  21. package/dist/layers.0EAb8Ajx.js +0 -65
  22. package/dist/layers.1Mvzm38Y.js +0 -501
  23. package/dist/layers.2wIERhxO.js +0 -41
  24. package/dist/layers.694DrE1_.js +0 -931
  25. package/dist/layers.7JqFgE4-.js +0 -15
  26. package/dist/layers.B-5aeeDH.js +0 -1359
  27. package/dist/layers.B0winug5.js +0 -59
  28. package/dist/layers.B1S8ufDn.js +0 -40
  29. package/dist/layers.B3JNY9Km.js +0 -42
  30. package/dist/layers.B6W2tqC0.js +0 -40
  31. package/dist/layers.B7Olyhe8.js +0 -1089
  32. package/dist/layers.BCuuRSaf.js +0 -37
  33. package/dist/layers.BESPlBGC.js +0 -32
  34. package/dist/layers.BJDrjORS.js +0 -244
  35. package/dist/layers.BJTh7mUo.js +0 -1265
  36. package/dist/layers.BLL-019k.js +0 -39
  37. package/dist/layers.BNJiP8Pw.js +0 -2966
  38. package/dist/layers.BNvAl5dS.js +0 -14
  39. package/dist/layers.BThP74aw.js +0 -32
  40. package/dist/layers.BZ4laUeR.js +0 -40
  41. package/dist/layers.BZByPNdY.js +0 -37
  42. package/dist/layers.B_5zMrI3.js +0 -38
  43. package/dist/layers.B_7N5yjX.js +0 -32
  44. package/dist/layers.BbCfEXyj.js +0 -55
  45. package/dist/layers.BdvfoI4U.js +0 -44
  46. package/dist/layers.BiJ8hfRt.js +0 -1510
  47. package/dist/layers.BiJBOHr0.js +0 -84
  48. package/dist/layers.Bk3_8qR9.js +0 -48146
  49. package/dist/layers.BkPPOKBy.js +0 -32
  50. package/dist/layers.BnZcjRLr.js +0 -32
  51. package/dist/layers.BpilXLfW.js +0 -6
  52. package/dist/layers.BqpcWKH6.js +0 -2479
  53. package/dist/layers.Br7D0wMN.js +0 -39
  54. package/dist/layers.BsAu1GXs.js +0 -42
  55. package/dist/layers.Bv5sK47C.js +0 -769
  56. package/dist/layers.BxEdkUpI.js +0 -1088
  57. package/dist/layers.BxUBbVsO.js +0 -41
  58. package/dist/layers.Bzalhqz_.js +0 -39
  59. package/dist/layers.C-dS7ntQ.js +0 -41
  60. package/dist/layers.C0Lgw_Sx.js +0 -11688
  61. package/dist/layers.C5BFsvzI.js +0 -803
  62. package/dist/layers.C5WLg9ed.js +0 -21763
  63. package/dist/layers.C6lAFlKZ.js +0 -186
  64. package/dist/layers.C8_lu5UH.js +0 -23
  65. package/dist/layers.CGwNL7dH.js +0 -791
  66. package/dist/layers.CI739wqN.js +0 -39
  67. package/dist/layers.CKaj4dG4.js +0 -41
  68. package/dist/layers.CLRiSwgi.js +0 -904
  69. package/dist/layers.CN1QkD6D.js +0 -38
  70. package/dist/layers.CPY6U3g-.js +0 -1034
  71. package/dist/layers.CRSjdIG6.js +0 -1619
  72. package/dist/layers.CUHkTCid.js +0 -6
  73. package/dist/layers.CUPMw0sy.js +0 -40
  74. package/dist/layers.CWb6LiAY.js +0 -40
  75. package/dist/layers.C_XsSNQo.js +0 -42
  76. package/dist/layers.CbmlFoXt.js +0 -33
  77. package/dist/layers.CfGeHh-g.js +0 -36
  78. package/dist/layers.CiJxVu9b.js +0 -36
  79. package/dist/layers.Cj4ezyVr.js +0 -33
  80. package/dist/layers.Cpb-MRZn.js +0 -960
  81. package/dist/layers.CqVTtuYm.js +0 -6
  82. package/dist/layers.CskURloi.js +0 -39
  83. package/dist/layers.CtTD47i4.js +0 -41
  84. package/dist/layers.CxcvEfKe.js +0 -36
  85. package/dist/layers.D-U9uIsP.js +0 -40
  86. package/dist/layers.D10WeKck.js +0 -2235
  87. package/dist/layers.D4T8fTcj.js +0 -1223
  88. package/dist/layers.D4jK2Tet.js +0 -39
  89. package/dist/layers.D7jGxypv.js +0 -8
  90. package/dist/layers.DBosqi2D.js +0 -19
  91. package/dist/layers.DGtETOVJ.js +0 -304
  92. package/dist/layers.DKENAsMv.js +0 -220
  93. package/dist/layers.DLwuMfdd.js +0 -84
  94. package/dist/layers.DN9HoVxI.js +0 -18
  95. package/dist/layers.DOBSfaUM.js +0 -35
  96. package/dist/layers.DOKLQ6A3.js +0 -373
  97. package/dist/layers.DPuVWH3L.js +0 -40
  98. package/dist/layers.DQVXh43C.js +0 -42
  99. package/dist/layers.DSTh89J8.js +0 -42
  100. package/dist/layers.DUsIfvNt.js +0 -46859
  101. package/dist/layers.DVfpGIrv.js +0 -41
  102. package/dist/layers.DWSkLlGf.js +0 -41
  103. package/dist/layers.DX1RI3m3.js +0 -32
  104. package/dist/layers.DdMwmP4m.js +0 -37
  105. package/dist/layers.DhkyREpW.js +0 -793
  106. package/dist/layers.Dj-f1_6N.js +0 -34
  107. package/dist/layers.DjUOC4st.js +0 -16
  108. package/dist/layers.DjhJT1nZ.js +0 -21938
  109. package/dist/layers.Djl9Gz6s.js +0 -282
  110. package/dist/layers.Dn2AP7iE.js +0 -1283
  111. package/dist/layers.Dqbek_0L.js +0 -40
  112. package/dist/layers.DsDjOLHs.js +0 -437
  113. package/dist/layers.DsOaqGXW.js +0 -8
  114. package/dist/layers.DuE1l7lR.js +0 -41
  115. package/dist/layers.DxA6ocdw.js +0 -70
  116. package/dist/layers.DxHlP7Pb.js +0 -39
  117. package/dist/layers.Dy1naDTQ.js +0 -14
  118. package/dist/layers.DyZ5R-vS.js +0 -37
  119. package/dist/layers.H2Kl_PC2.js +0 -40
  120. package/dist/layers.IW4NBP9k.js +0 -39
  121. package/dist/layers.LGx1jmqd.js +0 -40
  122. package/dist/layers.NABwYdw5.js +0 -35
  123. package/dist/layers.NtwvbkGN.js +0 -1580
  124. package/dist/layers.O-bFTk-n.js +0 -268
  125. package/dist/layers.R_udKe_N.js +0 -38
  126. package/dist/layers.TdTDbIzb.js +0 -1126
  127. package/dist/layers.WLeJl9el.js +0 -202
  128. package/dist/layers.b0h5ZBmD.js +0 -61
  129. package/dist/layers.dEHKcy8J.js +0 -320
  130. package/dist/layers.eTredPK_.js +0 -36
  131. package/dist/layers.gIdzfQAa.js +0 -5
  132. package/dist/layers.huV95Ipe.js +0 -295
  133. package/dist/layers.jU4W5PG5.js +0 -9166
  134. package/dist/layers.lCpg7dOn.js +0 -21
  135. package/dist/layers.mQcENPPW.js +0 -802
  136. package/dist/layers.nPQCmYXI.js +0 -423
  137. package/dist/layers.ntC1foLT.js +0 -39
  138. package/dist/layers.uHy1yMbq.js +0 -6
@@ -0,0 +1,341 @@
1
+ import { useContext as c, useEffect as m, useMemo as S } from "react";
2
+ import { useTranslation as l } from "react-i18next";
3
+ import { useLexicalComposerContext as h } from "@lexical/react/LexicalComposerContext";
4
+ import { createCommand as d, COMMAND_PRIORITY_LOW as p, $isRootNode as x, $isElementNode as A, $getRoot as E, ParagraphNode as O } from "lexical";
5
+ import { showMessageNotification as g, showErrorNotification as M, FilePicker as D } from "@layers-app/shared";
6
+ import { C as u } from "./layers.7jmq6tBR.js";
7
+ import { h as T, i as w, V as P, j as y, I as L, k as U, l as z, L as V, m as $, n as R, F as W, o as G } from "./layers.Dq3o7sh3.js";
8
+ import "@lexical/code";
9
+ import "@lexical/hashtag";
10
+ import "@lexical/link";
11
+ import "@lexical/mark";
12
+ import "@lexical/overflow";
13
+ import "@lexical/react/LexicalHorizontalRuleNode";
14
+ import "@lexical/rich-text";
15
+ import { i as Z } from "./layers.Dev6Yrwi.js";
16
+ import { jsx as j } from "react/jsx-runtime";
17
+ const v = d(
18
+ "INSERT_MUSIC_COMMAND"
19
+ ), Y = d("UPLOAD_MUSIC_COMMAND");
20
+ function pe() {
21
+ const [e] = h(), { t } = l(), { imperativeHandleRef: o, maxFileSize: n } = c(u);
22
+ return m(() => {
23
+ if (!e.hasNodes([T]))
24
+ throw new Error("MusicPlugin: MusicNode not registered on editor");
25
+ const i = (r) => {
26
+ const a = r.filter((s) => s.type.includes("Music/"));
27
+ if (r.length > 1) {
28
+ g({
29
+ message: t("editor.validation.doNotUploadMoreThanSingleFile")
30
+ });
31
+ return;
32
+ }
33
+ if (a[0].size > n * 1024 * 1024) {
34
+ M({
35
+ message: t("editor.validation.shouldNotExceed", {
36
+ maxSize: n
37
+ })
38
+ });
39
+ return;
40
+ }
41
+ e.dispatchCommand(v, "upload"), setTimeout(() => {
42
+ e.dispatchCommand(Y, r);
43
+ });
44
+ };
45
+ return o != null && o.current && (o.current.insertMusics = i), e.registerCommand(
46
+ v,
47
+ (r) => {
48
+ const s = w(r === "upload" ? "" : r, r !== "upload");
49
+ return f(s), !1;
50
+ },
51
+ p
52
+ );
53
+ }, [e]), null;
54
+ }
55
+ function ge(e, t = !1) {
56
+ const o = e.match(
57
+ /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/
58
+ );
59
+ if (o && o[2].length === 11)
60
+ return { platform: "youtube", id: o[2] };
61
+ const n = e.match(
62
+ /vk\.com\/video(?:_ext\.php\?oid=-?(\d+)&id=(\d+)|-(\d+)_(\d+))/
63
+ );
64
+ if (n) {
65
+ const a = n[1] || n[3], s = n[2] || n[4];
66
+ return { platform: "vk", id: `${a}-${s}` };
67
+ }
68
+ const i = e.match(
69
+ /rutube\.ru\/(?:play\/embed|video)\/([a-zA-Z0-9]+)/
70
+ );
71
+ if (i)
72
+ return { platform: "rutube", id: i[1] };
73
+ if (e === "upload")
74
+ return {
75
+ platform: "upload",
76
+ id: null
77
+ };
78
+ if (t)
79
+ return {
80
+ platform: "link",
81
+ id: e
82
+ };
83
+ const r = e.split("/").pop();
84
+ return r ? { platform: "download", id: r } : { platform: "unknown", id: null };
85
+ }
86
+ function q(e, t) {
87
+ let o = "";
88
+ switch (e) {
89
+ case "youtube":
90
+ o = `https://www.youtube-nocookie.com/embed/${t}`;
91
+ break;
92
+ case "download":
93
+ o = `${t}`;
94
+ break;
95
+ case "vk":
96
+ const n = t.split("-");
97
+ o = `https://vk.com/video_ext.php?oid=-${n[0]}&id=${n[1]}`;
98
+ break;
99
+ case "link":
100
+ o = t;
101
+ break;
102
+ case "rutube":
103
+ o = `https://rutube.ru/play/embed/${t}`;
104
+ break;
105
+ }
106
+ return o;
107
+ }
108
+ function Me(e, t) {
109
+ const o = q(e, t);
110
+ return o.startsWith("http://") || o.startsWith("https://") ? { src: o } : { attachmentId: o };
111
+ }
112
+ function fe(e) {
113
+ const t = e.match(
114
+ /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/
115
+ );
116
+ return !!(t && t[2].length === 11 || e.match(
117
+ /vk\.com\/video(?:_ext\.php\?oid=-?(\d+)&id=(\d+)|-(\d+)_(\d+))/
118
+ ) || e.match(
119
+ /rutube\.ru\/(?:play\/embed|video)\/([a-zA-Z0-9]+)/
120
+ ) || e.match(/\.(mp4|webm|ogg|mov|avi|mkv)(\?.*)?$/i));
121
+ }
122
+ const k = d(
123
+ "INSERT_VIDEO_COMMAND"
124
+ ), B = d("UPLOAD_VIDEO_COMMAND");
125
+ function Ce() {
126
+ const [e] = h(), { t } = l(), { imperativeHandleRef: o, maxFileSize: n } = c(u);
127
+ return m(() => {
128
+ if (!e.hasNodes([P]))
129
+ throw new Error("VideoPlugin: VideoNode not registered on editor");
130
+ const i = (r) => {
131
+ const a = r.filter((s) => s.type.includes("video/"));
132
+ if (r.length > 1) {
133
+ g({
134
+ message: t("editor.validation.doNotUploadMoreThanSingleFile")
135
+ });
136
+ return;
137
+ }
138
+ if (a[0].size > n * 1024 * 1024) {
139
+ M({
140
+ message: t("editor.validation.shouldNotExceed", {
141
+ maxSize: n
142
+ })
143
+ });
144
+ return;
145
+ }
146
+ e.dispatchCommand(k, "upload"), setTimeout(() => {
147
+ e.dispatchCommand(B, r);
148
+ });
149
+ };
150
+ return o != null && o.current && (o.current.insertVideos = i), e.registerCommand(
151
+ k,
152
+ (r) => {
153
+ const a = y(
154
+ r,
155
+ "100%",
156
+ "100%",
157
+ "left",
158
+ r !== "upload"
159
+ );
160
+ return f(a), !1;
161
+ },
162
+ p
163
+ );
164
+ }, [e]), null;
165
+ }
166
+ const I = d("INSERT_IMAGE_COMMAND"), J = d("UPLOAD_IMAGE_COMMAND");
167
+ function Ne() {
168
+ const [e] = h(), { t } = l(), { imperativeHandleRef: o } = c(u), { maxFileSize: n } = c(u);
169
+ return m(() => {
170
+ if (!e.hasNodes([L]))
171
+ throw new Error("ImageOlugin: FileNode not registered on editor");
172
+ const i = (r) => {
173
+ if (r.length > 1) {
174
+ g({
175
+ message: t("editor.validation.doNotUploadMoreThanSingleFile")
176
+ });
177
+ return;
178
+ }
179
+ if (r[0].size > n * 1024 * 1024) {
180
+ M({
181
+ message: t("editor.validation.shouldNotExceed", {
182
+ maxSize: n
183
+ })
184
+ });
185
+ return;
186
+ }
187
+ e.dispatchCommand(I, {
188
+ src: "upload",
189
+ create: !1,
190
+ altText: ""
191
+ }), setTimeout(() => {
192
+ e.dispatchCommand(J, r);
193
+ }, 100);
194
+ };
195
+ return o != null && o.current && (o.current.insertImages = i), e.registerCommand(
196
+ I,
197
+ (r) => {
198
+ const a = U(r);
199
+ return f(a), !1;
200
+ },
201
+ p
202
+ );
203
+ }, [e]), null;
204
+ }
205
+ const f = (e) => {
206
+ var a;
207
+ const t = Z();
208
+ if (x(t))
209
+ return t.append(e), !0;
210
+ let o = t == null ? void 0 : t.getParent();
211
+ const n = o instanceof O || o instanceof $ || o instanceof R, i = t instanceof z && !!t.__text, r = A(t) && (t == null ? void 0 : t.getChildrenSize()) > 0;
212
+ if (r && (o = t), n && i || n || r)
213
+ return o.insertAfter(e), !0;
214
+ if (t && o)
215
+ return t instanceof V ? ((a = t.getPreviousSibling()) == null || a.replace(e), !0) : (t == null || t.replace(e), !0);
216
+ if (!t)
217
+ return E().append(e), !0;
218
+ }, b = d(
219
+ "INSERT_FILE_COMMAND"
220
+ ), K = d("UPLOAD_FILE_COMMAND");
221
+ function ve() {
222
+ const [e] = h(), { t } = l(), { imperativeHandleRef: o, maxFileSize: n } = c(u);
223
+ return m(() => {
224
+ if (!e.hasNodes([W]))
225
+ throw new Error("FilePlugin: FileNode not registered on editor");
226
+ const i = (r) => {
227
+ if (r.length > 1) {
228
+ g({
229
+ message: t("editor.validation.doNotUploadMoreThanSingleFile")
230
+ });
231
+ return;
232
+ }
233
+ if (r[0].size > n * 1024 * 1024) {
234
+ M({
235
+ message: t("editor.validation.shouldNotExceed", {
236
+ maxSize: n
237
+ })
238
+ });
239
+ return;
240
+ }
241
+ e.dispatchCommand(b, "upload"), setTimeout(() => {
242
+ e.dispatchCommand(K, r);
243
+ });
244
+ };
245
+ return o != null && o.current && (o.current.insertFiles = i), e.registerCommand(
246
+ b,
247
+ (r) => {
248
+ const a = G(
249
+ r,
250
+ "100%",
251
+ "100%",
252
+ "left",
253
+ r !== "upload"
254
+ );
255
+ return f(a), !1;
256
+ },
257
+ p
258
+ );
259
+ }, [e]), null;
260
+ }
261
+ const ke = ({
262
+ children: e,
263
+ ...t
264
+ }) => {
265
+ const { imagePickerSettings: o, maxFileSize: n } = c(u), { t: i } = l("ui"), { giphyToken: r, unsplashClientId: a, link: s, download: N, maxUploadFiles: _ } = o, F = S(() => [
266
+ { key: "gallery", enabled: !0 },
267
+ { key: "giphy", enabled: r },
268
+ {
269
+ key: "unsplash",
270
+ enabled: a
271
+ },
272
+ {
273
+ key: "link",
274
+ enabled: s === void 0 ? !0 : s
275
+ },
276
+ {
277
+ key: "upload",
278
+ enabled: N === void 0 ? !0 : N
279
+ }
280
+ ].filter((C) => C.enabled).map((C) => C.key), [o]);
281
+ return /* @__PURE__ */ j(
282
+ D,
283
+ {
284
+ showTabs: F,
285
+ dropZoneProps: {
286
+ maxFiles: _ || 1,
287
+ maxSize: n * 1024 * 1024
288
+ },
289
+ giphyToken: r,
290
+ unsplashClientId: a,
291
+ locales: {
292
+ gallery: i("changeCover.gallery"),
293
+ link: i("changeCover.link"),
294
+ search: i("changeCover.searchImage"),
295
+ upload: i("changeCover.upload"),
296
+ uploadFile: i("changeCover.uploadFile"),
297
+ change: i("changeCover.change"),
298
+ remove: i("remove"),
299
+ error: i("errorMessage"),
300
+ dragOrClickToChoose: i("changeCover.dragOrClickToChoose"),
301
+ // loadMore: t('changeCover.loadMore'),
302
+ maxFileSize: i("changeCover.maxFileSize", { maxSize: n }),
303
+ pasteLink: i("changeCover.pasteLink"),
304
+ submitLink: i("changeCover.submitLink"),
305
+ worksWithAnyImage: i("changeCover.worksWithAnyImage"),
306
+ noImages: i("changeCover.noResult"),
307
+ errors: {
308
+ typeIsNotAllowed: "This file type is not supported",
309
+ shouldNotExceed: i("changeCover.maxFileSize", {
310
+ maxSize: n
311
+ }),
312
+ doNotUploadMoreThanSingleFile: i(
313
+ "dropZone.errors.doNotUploadMoreThanSingleFile"
314
+ ),
315
+ invalidLink: i("changeCover.invalidLink")
316
+ }
317
+ },
318
+ ...t,
319
+ children: e
320
+ }
321
+ );
322
+ };
323
+ export {
324
+ ve as F,
325
+ ke as I,
326
+ pe as M,
327
+ Y as U,
328
+ Ce as V,
329
+ Ne as a,
330
+ B as b,
331
+ q as c,
332
+ K as d,
333
+ J as e,
334
+ I as f,
335
+ Me as g,
336
+ k as h,
337
+ fe as i,
338
+ v as j,
339
+ b as k,
340
+ ge as p
341
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";const Oe=require("@lexical/react/LexicalComposerContext"),n=require("react/jsx-runtime"),l=require("react"),Be=require("react-dom"),Ee=require("react-i18next"),xe=require("@lexical/rich-text"),de=require("@lexical/utils"),u=require("@mantine/core"),$=require("@tabler/icons-react"),c=require("lexical"),Ce=require("./layers.CZPeYQ9g.js"),rt=require("@lexical/code");require("@lexical/hashtag");const Me=require("@lexical/link");require("@lexical/mark");require("@lexical/overflow");require("@lexical/react/LexicalHorizontalRuleNode");const C=require("./layers.B90YwJga.js"),ee=require("./layers.CZ_Lt7IL.js"),T=require("./layers.Dgok89qX.js"),Ne=require("@lexical/selection"),Pe=require("@layers-app/shared"),V=require("./layers.C03OvlLb.js"),lt=require("./layers.DNCgFYS7.js"),at=require("@lexical/react/LexicalDecoratorBlockNode"),He=require("@mantine/hooks"),Ke=require("./layers.CJiIq6YQ.js"),ct=4,ut=2,dt="draggable-block-menu",ft=16,ze="application/x-lexical-drag-block",De=e=>e?e.match(/(\d*\.?\d+)%/g):[],Ze=e=>e<0?0:e>100?100:e,Je=(e,t,o)=>{let i=0,s=[];e.update(()=>{if(e&&t){const f=e.getElementByKey(t.getKey());if(f){const p=f.style;s=De(p.getPropertyValue("grid-template-columns")).map(m=>m.slice(0,-1)),i=s?s.length:0}}const a=100/(i+1),r=[...s];r.splice(o,0,`${a}%`);let d=a/i;for(let f=0;f<r.length;f++)if(o!==f){const p=Number(r[f])-d;r[f]=`minmax(100px,${Ze(p)}%)`}else r[f]=`minmax(100px,${r[f]})`;t.setTemplateColumns(r.join(" "))})},Re=(e,t,o,i)=>{e.update(()=>{const s=e.getElementByKey(t.getKey());if(!s)return;let a=i;o<i&&(a=i-1);const d=s.style.getPropertyValue("grid-template-columns").match(/minmax\([^)]*\)|\S+/g)||[],f=d.splice(o,1)[0];d.splice(a,0,f),t.setTemplateColumns(d.join(" "))})},Ie=(e,t)=>(e!=null&&e.children?Array.from(e.children):[]).indexOf(t);function mt(e,t,o,i){var f;let s=e.getAttribute("data-direction")==="left",a=e.getAttribute("data-direction")==="right",r=e.getAttribute("data-index"),d=e.getAttribute("data-index-start");if(s||a||r){let p=(f=o.getParent())==null?void 0:f.getParent();if(o instanceof C.LayoutContainerNode&&(p=o),o instanceof C.LayoutDividerNode||o instanceof C.LayoutContainerNode){const m=p==null?void 0:p.getChildren();let N=i instanceof C.LayoutDividerNode;if((m==null?void 0:m.length)>=4&&!N)return!0;t.update(()=>{var _;let g=0;s?g=0:a?g=((_=p==null?void 0:p.getChildren())==null?void 0:_.length)-1:g=Number(r),N?Re(t,p,Number(d),g):Je(t,p,g);let A=null;g!==void 0&&t.update(()=>{if(A=p.getChildren()[g],N)o instanceof C.LayoutContainerNode?A.insertAfter(i.getParent()):A.insertBefore(i.getParent());else if(a)A.insertAfter(C.$createLayoutItemNode().append(i).append(C.$createLayoutDividerNode()));else{const j=i.getParent(),L=j==null?void 0:j.getParent();C.$isLayoutItemNode(j)&&(j==null?void 0:j.getChildrenSize())===2&&C.$isLayoutItemNode(j)&&C.$isLayoutContainerNode(L)&&T.removeNodeKeepContent(t,j,L),A.insertBefore(C.$createLayoutItemNode().append(i).append(C.$createLayoutDividerNode()))}})})}else t.update(()=>{const m=C.$createLayoutContainerNode(ee.GRID_TWO_COL_WITH_GAP);let N;if(C.$isCalloutWrapperNode(o)||ee.$isCollapsibleContainerNode(o)){const g=i.getParent(),A=g==null?void 0:g.getParent();if(C.$isLayoutItemNode(g)&&(g==null?void 0:g.getChildrenSize())===2&&C.$isLayoutContainerNode(A)){const j=A.getParent(),L=j==null?void 0:j.getParent(),F=A.getChildren(),v=F.findIndex(B=>B===g)===0?1:0,P=F[v];if(C.$isLayoutItemNode(P)){const B=P.getChildren()[0];C.$isCalloutWrapperNode(L)&&(L.append(B),A.remove(),N=T.$copyNodeDeep(L))}}else N=T.$copyNodeDeep(o,i)}else N=T.$copyNodeDeep(o);N&&(s?(m.append(C.$createLayoutItemNode().append(i).append(C.$createLayoutDividerNode())),m.append(C.$createLayoutItemNode().append(N).append(C.$createLayoutDividerNode()))):(m.append(C.$createLayoutItemNode().append(N).append(C.$createLayoutDividerNode())),m.append(C.$createLayoutItemNode().append(i).append(C.$createLayoutDividerNode()))),o.insertAfter(m),o.remove(),N.selectStart())});return!0}return!1}function pt(e,t,o="right",i=!1){e.update(()=>{const s=c.$getNearestNodeFromDOMNode(t),a=s==null?void 0:s.getParent();if(a){if(De(a.__templateColumns).length===4)return;let d=Ie(t.parentElement,t);o==="right"&&(d=d+1),Je(e,a,d)}const r=C.$createLayoutItemNode().append(c.$createParagraphNode()).append(C.$createLayoutDividerNode());s&&(o==="right"?i?(s.insertBefore(T.$copyNodeDeep(s)),s.selectStart()):(s.insertAfter(r),r==null||r.selectStart()):(s.insertBefore(r),r.selectStart()))})}const et=(e,t)=>{const o=t==null?void 0:t.getParent();let i=De(o==null?void 0:o.getTemplateColumns());const s=o==null?void 0:o.getChildren();let a=0;if(s&&t){for(let m=0;m<s.length;m++)if(s[m].__key===t.__key){a=m;break}}i.splice(a,1);const r=i.map(m=>parseFloat(m)),d=r.reduce((m,N)=>m+N,0),p=r.map(m=>m/d*100).map(m=>`minmax(50px,${m.toFixed(2)}%)`);o==null||o.setTemplateColumns(p.join(" "))},gt=e=>e.className.includes("editor-image")||e.className.includes("video-container")?e:e.className.includes("editor-excalidraw")?e.firstChild:null,tt=(e,t)=>t!=null&&t.__key&&e!==t.__key?tt(e,t==null?void 0:t.getParent()):e===(t==null?void 0:t.__key),qe=(e,t,o)=>{e.update(()=>{var r,d,f;const i=(r=t==null?void 0:t.getParent())==null?void 0:r.getParent(),s=t==null?void 0:t.getParent(),a=o==="right"?(d=t==null?void 0:t.getParent())==null?void 0:d.getNextSibling():(f=t==null?void 0:t.getParent())==null?void 0:f.getPreviousSibling();if(s&&a&&i instanceof C.LayoutContainerNode){const p=e.getElementByKey(s.getKey()),m=e.getElementByKey(i.getKey()),N=Ie(m,p);s&&i&&a&&(o==="right"&&(Re(e,i,N+1,N),a.insertAfter(s)),o==="left"&&(Re(e,i,N,N+1),a.insertBefore(s)))}})};function ht(e){e&&(e.style.display="none")}function We({blockElement:e,editor:t,isTop:o,isClickedBlockRef:i,setDraggableBlockElem:s}){e&&(i.current=!0,t.update(()=>{const a=c.$getNearestNodeFromDOMNode(e);if(a){const r=c.$createParagraphNode();o?(a.insertBefore(r),setTimeout(()=>{s(t.getElementByKey(r.__key)),t.update(()=>{r.selectStart()})})):(a.insertAfter(r),setTimeout(()=>{s(t.getElementByKey(r.__key)),t.update(()=>{r.selectEnd()})}))}}))}function xt(e){const t=(f,p)=>f?parseFloat(window.getComputedStyle(f)[p]):0,{marginTop:o,marginBottom:i}=window.getComputedStyle(e),s=t(e.previousElementSibling,"marginBottom"),a=t(e.nextElementSibling,"marginTop"),r=Math.max(parseFloat(o),s);return{marginBottom:Math.max(parseFloat(i),a),marginTop:r}}function Ct(e){return!!e.closest(`.${dt}`)}function Ue(e,t,o,i){if(!e){t.style.opacity="0";return}t.style.display="block";let s=null;const a=gt(e);a&&a.style.justifyContent!=="left"&&a.firstChild instanceof HTMLElement?s=a.firstChild.getBoundingClientRect():s=e.getBoundingClientRect();let r=null,d=0,f=!0,p=0;if(s){let F=e.firstChild instanceof HTMLElement&&(e.firstChild.hasAttribute("data-lexical-text")||e.firstChild.tagName==="LI"||e.firstChild.tagName==="A")?e.firstChild:null;if(F&&!F.className.includes("editor-image")&&e.tagName!=="CODE"){const M=window.getComputedStyle(F),v=parseFloat(M.lineHeight),P=parseFloat(M.fontSize);p=Math.ceil(P+(v-P)/2),r=F.getBoundingClientRect()}else if(e.firstChild instanceof HTMLElement&&e.firstChild.tagName==="BR"&&e.tagName!=="CODE"){const M=window.getComputedStyle(e,"::before");p=parseFloat(M.height)||30}else e&&(e.tagName==="HR"||e.matches(":has(audio)")||e.classList.contains("file-container"))?p=e.clientHeight:e.firstChild instanceof HTMLElement&&e.firstChild.tagName==="SUMMARY"?p=e.firstChild.clientHeight:(r=s,f=!1)}const m=o.getBoundingClientRect(),N=(r==null?void 0:r.top)||s.top,g=p||d,A=t.clientHeight,_=g-A;let j=!f||!g?s.top+7-m.top:N+_/2-m.top,L=s.left-m.left-A*2-3;e.tagName==="LI"&&e.getAttribute("role")!=="checkbox"&&(L=L-26,j=j-1),a&&(j=N-m.top+7,(a.style.justifyContent==="center"||a.style.justifyContent==="right")&&(L=L+10)),e.matches(":has(.resizable-container__handle)")&&!e.matches(":has(.hide-padding)")&&(j=N-m.top+27),s.top<0&&(j=j+-s.top),e.className==="dsd__theme__layoutDivider"&&(t.style.display="none",s.top-t.clientHeight<0?e.style.setProperty("--height-column",`${e.clientHeight+s.top-t.clientHeight-7}px`):e.style.setProperty("--height-column",`${e.clientHeight}px`)),t.style.opacity="1",!i&&L>-40&&(t.style.transform=`translate(${L}px, ${j}px)`)}function Ye(e,t){const{transform:o}=t.style;t.style.transform="translateZ(0)",e.setDragImage(t,0,0),setTimeout(()=>{t.style.transform=o})}function yt(e,t){const o=document.createElement("div");o.style.position="absolute",o.style.top="-9999px",o.style.left="-9999px",t.forEach(i=>{const s=i.cloneNode(!0);s.style.position="relative",o.appendChild(s)}),document.body.appendChild(o),e.setDragImage(o,0,0),setTimeout(()=>document.body.removeChild(o),0)}function bt(e,t,o,i,s,a,r){var x;const{top:d,height:f,width:p,left:m}=t.getBoundingClientRect(),{top:N,left:g,width:A}=s==null?void 0:s.getBoundingClientRect(),{marginTop:_,marginBottom:j}=xt(t);let L=d;o>=d?(r.current.isBottom=!0,L+=f+j/2):(r.current.isBottom=!1,L-=_/2);const F=L-N-ut,M=ft-ct,P=a.target.closest(".dsd__theme__layoutDivider");e.setAttribute("data-index",""),e.style.background="deepskyblue";const B=m-g-M;if(i<=m&&!P){if(t.closest(".dsd__theme__layoutItem"))return;e.style.transform=`translate(${B}px, ${d-N}px)`,e.style.width="4px",e.style.height=`${f}px`,e.style.opacity=".4",e.setAttribute("data-direction","left")}else if(i>=A-B&&!P&&!t.closest(".dsd__theme__layoutItem"))t.classList.contains("dsd__theme__layoutContainer")&&!e.getAttribute("data-index-start")&&t&&t.children.length>=4&&(e.style.background="red"),e.style.transform=`translate(${A-B}px, ${d-N}px)`,e.style.width="4px",e.style.height=`${f}px`,e.style.opacity=".4",e.setAttribute("data-direction","right");else if(P){a.preventDefault();const S=(x=P.parentNode)==null?void 0:x.parentNode;(S==null?void 0:S.children.length)===4&&(e.style.background="red");const k=P.parentNode,O=Ie(S,k),R=O?P.getBoundingClientRect().left-g:B+30;e.style.transform=`translate(${R}px, ${d-N}px)`,e.style.width="4px",e.style.height=`${f}px`,e.style.opacity=".4",e.setAttribute("data-index",`${O}`)}else e.style.transform=`translate(${B}px, ${F}px)`,e.style.width=`${p+M}px`,e.style.opacity=".4",e.style.height="4px",e.setAttribute("data-direction","")}function Ge(e){e&&(e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)")}const Tt=({hoveredButton:e,insertNewParagraph:t,currentDraggableBlockRef:o,setHoveredButton:i,isClickedBlockRef:s,setDraggableBlockElem:a,editor:r,t:d})=>n.jsx("div",{className:`icon add-block-menu ${e?"active":""}`,onClick:()=>{t({blockElement:o.current.htmlElement,editor:r,isTop:!1,isClickedBlockRef:s,setDraggableBlockElem:a}),i("both")},onMouseEnter:()=>{i("bottom")},onMouseLeave:()=>{i("both")},children:n.jsx(u.Tooltip,{openDelay:300,label:d("editor.hoverOptions.addNewBlockAbove"),position:"bottom",disabled:s.current||!e,children:n.jsx(u.ActionIcon,{radius:"sm",color:"gray",size:"xs",variant:"subtle","aria-label":"Settings",children:e==="bottom"?n.jsx($.IconPlus,{}):n.jsx($.IconMinus,{})})})}),Mt=({hoveredButton:e,insertNewParagraph:t,currentDraggableBlockRef:o,setHoveredButton:i,isClickedBlockRef:s,setDraggableBlockElem:a,editor:r,t:d})=>n.jsx("div",{className:`icon add-block-menu add-block-menu_top ${e?"active":""}`,onClick:()=>{t({blockElement:o.current.htmlElement,editor:r,isTop:!0,isClickedBlockRef:s,setDraggableBlockElem:a}),i("both")},onMouseEnter:()=>{i("top")},onMouseLeave:()=>{i("both")},children:n.jsx(u.Tooltip,{disabled:s.current||!e,openDelay:300,label:d("editor.hoverOptions.addNewBlockBelow"),position:"top",children:n.jsx(u.ActionIcon,{radius:"sm",color:"gray",size:"xs",variant:"subtle","aria-label":"Settings",children:e==="top"?n.jsx($.IconPlus,{}):n.jsx($.IconMinus,{})})})});function nt(e,t){var a,r;const o=(a=t.exportDOM)==null?void 0:a.call(t,e),i=(o==null?void 0:o.element)??null;if(c.$isElementNode(t)){const d=i??document.createElement("div"),f=((r=t.getChildren)==null?void 0:r.call(t))??[];for(const p of f){const m=nt(e,p);if(m)d.appendChild(m);else{const N=typeof p.getTextContent=="function"?p.getTextContent():"";N&&d.appendChild(document.createTextNode(N))}}return typeof(o==null?void 0:o.after)=="function"&&o.after(d),d}if(i)return typeof(o==null?void 0:o.after)=="function"&&o.after(i),i;const s=typeof t.getTextContent=="function"?t.getTextContent():"";return s?document.createTextNode(s):null}async function Xe(e,t){const o=e.getRootElement(),i=Array.from(o.querySelectorAll(".selected-block"));if(!i.length)return;let s="",a="";e.getEditorState().read(()=>{e.update(()=>{let r=i.map(f=>c.$getNearestNodeFromDOMNode(f)).filter(f=>!!f);s=r.map(f=>typeof f.getTextContent=="function"?f.getTextContent():"").filter(Boolean).join(`
2
+ `);const d=document.createElement("div");r.forEach(f=>{const p=nt(e,f);t==="cut"&&f.remove(),p&&d.appendChild(p)}),a=d.innerHTML})}),(s||a)&&await Nt(s,a)}async function Nt(e,t){if(navigator.clipboard&&"write"in navigator.clipboard&&window.ClipboardItem){const o=new ClipboardItem({"text/plain":new Blob([e],{type:"text/plain"}),...t?{"text/html":new Blob([t],{type:"text/html"})}:{}});await navigator.clipboard.write([o])}}const Ve=(e,t,o,i)=>{if(o)if(i==="layout"){const s=o.getParent(),a=s.getParent();T.removeNodeKeepContent(e,s,a),t("delete")}else{const s=o==null?void 0:o.getParent();if(s instanceof C.LayoutItemNode&&s.getChildren().length===2){const a=s,r=s.getParent();if(o.__type==="image"){a.append(c.$createParagraphNode());return}T.removeNodeKeepContent(e,a,r)}T.deleteNode(e,o),t("delete")}},Qe=e=>{const t=e._rootElement;return Array.from(t.querySelectorAll(".selected-block"))},Fe=(e,t,o,i=!1)=>{t&&e.update(()=>{const s=e.getElementByKey(t.getParent().getKey());pt(e,s,o,i)})},_t=(e,t,o,i)=>{if(i==="layout")Fe(e,o,"right",!0);else{const s=e._rootElement,a=Array.from(s.querySelectorAll(".selected-block")).reverse();a.length&&(e.update(()=>{const r=c.$getNearestNodeFromDOMNode(a[0]);a.forEach(d=>{let f=c.$getNearestNodeFromDOMNode(d);f&&(r==null||r.insertAfter(T.$copyNodeDeep(f))),ee.$removeSelectedHTMLElement(d)})}),t())}},St=({editor:e,onChange:t,currentEditorNode:o,textBlock:i,t:s,isDisabledAddColumnButton:a,disabledMoveColumnButtons:r})=>{const{fetchUploadMedia:d,excludeNodes:f}=l.useContext(Ce.Context),[p,m]=l.useState("inherit"),[N,g]=l.useState("inherit"),[A,_]=l.useState("inherit"),[j,L]=l.useState("");l.useEffect(()=>{const x=o==null?void 0:o.__type;e.read(()=>{var S;((S=o==null?void 0:o.getParent())==null?void 0:S.__type)==="layout-item"?L("layout"):L(x==="callout-wrapper"?x:"block")})},[o==null?void 0:o.__key]);const F=x=>x.split(";").filter(Boolean).reduce((S,k)=>{const[O,R]=k.split(":").map(U=>U.trim());return O&&R&&(S[O]=R),S},{}),M=x=>Object.entries(x).map(([S,k])=>`${S}: ${k}`).join("; "),v=l.useCallback(x=>{e.update(()=>{const S=Qe(e).map(O=>c.$getNearestNodeFromDOMNode(O)).filter(Boolean),k=O=>{if(typeof O.getStyle=="function"&&typeof O.setStyle=="function"){const R=F(O.getStyle());R.color=x.color,R["background-color"]=x.bgColor,O.setStyle(M(R)),m(x.bgColor),_(x.color)}};S.forEach(O=>{if(O instanceof C.ListNode){O.getChildren().forEach(R=>{const U=R.getFirstChild();U instanceof C.ExtendedTextNode&&k(U)});return}if(O instanceof c.ElementNode){const R=O.getFirstChild();R instanceof C.ExtendedTextNode&&k(R)}})})},[m,_]),P=(x,S)=>{const k=S||j;k==="callout-wrapper"&&o instanceof C.CalloutWrapperNode?e.update(()=>{const O=ee.isCalloutValue(x);o.setType(O?x.meta.type:void 0),o.setBackgroundColor(x.value)}):k==="layout-color"?e.update(()=>{const O=o==null?void 0:o.getParent(),R=x.value===N?"inherit":x.value;O instanceof C.LayoutItemNode&&O.setLayoutBackground(R)}):v({color:A,bgColor:p,[x.mode==="background"?"bgColor":x.mode]:x.value})},B=x=>{const S=Qe(e);S.length?S.forEach(k=>{e.update(()=>{let O=c.$getNearestNodeFromDOMNode(k);O&&Ve(e,t,O,x)})}):e.update(()=>{let k=c.$getNearestNodeFromDOMNode(S[0]);Ve(e,t,k,x)})};return l.useEffect(()=>{setTimeout(()=>{e.read(()=>{if(j==="callout-wrapper"&&o instanceof C.CalloutWrapperNode){m(o.__backgroundColor);return}const x=o==null?void 0:o.getParent();x instanceof C.LayoutItemNode&&g(x.__backgroundColor);const S=c.$getSelection();c.$isRangeSelection(S)&&(_(Ne.$getSelectionStyleValueForProperty(S,"color","inherit")),m(Ne.$getSelectionStyleValueForProperty(S,"background-color","inherit")))})})},[]),n.jsxs(n.Fragment,{children:[n.jsx(u.Menu.Item,{onMouseDown:x=>{x.preventDefault(),Xe(e,"copy"),t("copy")},leftSection:n.jsx($.IconClipboard,{style:{width:u.rem(14),height:u.rem(14)}}),children:s("editor.link.copy")}),n.jsx(u.Menu.Item,{onMouseDown:x=>{x.preventDefault(),Xe(e,"cut"),t("cut")},leftSection:n.jsx($.IconCut,{style:{width:u.rem(14),height:u.rem(14)}}),children:s("editor.contextMenu.cut")}),n.jsx(u.Menu.Item,{onClick:()=>B(""),leftSection:n.jsx($.IconTrash,{style:{width:u.rem(14),height:u.rem(14)}}),children:s("editor.contextMenu.delete")}),n.jsx(u.Menu.Item,{disabled:j==="layout"&&a,onClick:()=>_t(e,t,o,j),leftSection:n.jsx($.IconCopy,{style:{width:u.rem(14),height:u.rem(14)}}),children:s("editor.contextMenu.duplicate")}),i==="text"&&j!=="callout-wrapper"&&n.jsxs(n.Fragment,{children:[n.jsx(u.Menu.Divider,{}),n.jsx(ee.BlockFormatMenu,{disabled:!1,blockType:"paragraph",rootType:"root",editor:e,mode:"editor",fetchUploadMedia:d,excludeNodes:f,onChange:t,menuProps:{trigger:"hover",position:"right-start",offset:{mainAxis:0,alignmentAxis:0}},children:n.jsx("div",{children:n.jsx(V.CustomMenuItem,{label:s("editor.toolbar.turnInto"),icon:n.jsx($.IconArrowsRightLeft,{style:{width:u.rem(14),height:u.rem(14)}})})})})]}),(i==="text"||j=="callout-wrapper")&&n.jsxs(n.Fragment,{children:[n.jsx(u.Menu.Divider,{}),n.jsx(Pe.NewColorPicker,{data:{callout:{label:s("editor.colors.theme"),filled:!0,palette:ee.calloutData.map(x=>({label:s(`editor.colors.callout.${x.name}`),value:u.alpha(x.color,.19),icon:x.icon,meta:{type:x.name,emoji:x.emoji}}))}},modes:j==="callout-wrapper"?["callout","background"]:["color","background"],value:{color:A,background:p,callout:p},onChange:x=>{P(x),t(),T.resetSelection(e)},hideInherit:!0,target:n.jsx("div",{children:n.jsx(V.CustomMenuItem,{label:s(j==="callout-wrapper"?"editor.contextMenu.appearance":"editor.toolbar.color"),icon:n.jsx($.IconPaint,{size:14})})}),menuProps:{trigger:"hover",position:"right-start",offset:{mainAxis:0,alignmentAxis:0}}})]}),j==="layout"&&n.jsxs(n.Fragment,{children:[n.jsx(u.Menu.Divider,{}),n.jsx(Pe.NewColorPicker,{modes:["background"],value:{background:N},onChange:x=>{P(x,"layout-color"),t(),T.resetSelection(e)},hideInherit:!0,target:n.jsx("div",{children:n.jsx(V.CustomMenuItem,{label:s("editor.column.changeColor"),icon:n.jsx($.IconPaint,{size:14})})}),menuProps:{trigger:"hover",position:"right-start",offset:{mainAxis:0,alignmentAxis:0}}}),n.jsx(u.Menu.Item,{disabled:a,onClick:()=>{Fe(e,o,"left")},leftSection:n.jsx($.IconColumnInsertLeft,{style:{width:u.rem(14),height:u.rem(14)}}),children:s("editor.column.addLeft")}),n.jsx(u.Menu.Item,{disabled:a,onClick:()=>{Fe(e,o,"right")},leftSection:n.jsx($.IconColumnInsertRight,{style:{width:u.rem(14),height:u.rem(14)}}),children:s("editor.column.addRight")}),n.jsx(u.Menu.Item,{disabled:r.left,onClick:()=>{qe(e,o,"left"),T.resetSelection(e)},leftSection:n.jsx($.IconColumnInsertRight,{style:{width:u.rem(14),height:u.rem(14)}}),children:s("editor.column.moveLeft")}),n.jsx(u.Menu.Item,{disabled:r.right,onClick:()=>{qe(e,o,"right"),T.resetSelection(e)},leftSection:n.jsx($.IconColumnInsertRight,{style:{width:u.rem(14),height:u.rem(14)}}),children:s("editor.column.moveRight")}),n.jsx(u.Menu.Item,{onClick:()=>B("layout"),leftSection:n.jsx($.IconTrash,{style:{width:u.rem(14),height:u.rem(14)}}),children:s("editor.column.deleteColumn")})]})]})};function It(e){if(!e)return window;let t=e;for(;t;){if(t===document.body||t===document.documentElement)return window;const i=getComputedStyle(t).overflowY;if((i==="auto"||i==="scroll"||i==="overlay")&&t.scrollHeight>t.clientHeight)return t;t=t.parentElement}return window}function jt(e,t){let o=150;const{clientY:i}=e;if(t===window){const s=window.innerHeight;i<o?window.scrollBy(0,Math.max(-15,(i-o)/15)):i>s-o&&window.scrollBy(0,Math.min(15,(i-(s-o))/15))}else{o=100;const s=t.getBoundingClientRect();i<s.top+o?t.scrollTop-=5:i>s.bottom-o&&(t.scrollTop+=5)}}const $t=lt.lodashExports.throttle((e,t)=>{e.preventDefault(),jt(e,t)},16);let ve=null;function kt(e){return e?e.classList.contains("dsd__theme__table-scrollable-wrapper")?e.firstElementChild:e:null}function vt(e,t,o){const i=l.useRef(null),s=l.useRef(null),a=l.useRef(!1),r=l.useRef(!1),d=l.useRef({htmlElement:null,lexicalNode:null,isBottom:!1}),f=l.useRef(null),[p,m]=l.useState(null),{disable:N}=l.useContext(Ce.Context),[g,A]=l.useState(!1),[_,j]=l.useState({opened:!1}),[L,F]=l.useState(""),[M,v]=l.useState(null),[P,B]=l.useState(!1),[x,S]=l.useState({left:!1,right:!1}),[k,O]=l.useState(null),{t:R}=Ee.useTranslation(),U=ee.useDebounce(y=>{const h=y.target;r.current||T.isHTMLElement(h)&&(Ct(h)||e.read(()=>{var X;const w=h.className.includes("content-editable-wrapper"),G=w?c.$getRoot():c.$getNearestNodeFromDOMNode(h),{htmlElement:W,lexicalNode:D}=T.$getBlockNode(G,e,{root:!0,"layout-container":!0,"layout-item":!0,callout:!0,"collapsible-content":!0},y);if((D==null?void 0:D.__type)==="callout"||(D==null?void 0:D.__type)==="callout-image"||((X=D==null?void 0:D.getParent())==null?void 0:X.__type)==="callout"&&(D==null?void 0:D.getPreviousSibling())===null){m(null);return}if(!(w&&D instanceof C.LayoutDividerNode||w&&!D)&&D!=null&&D.__key){if(D.__type==="layout-container"||D.__type==="layout-item"||D.__type==="collapsible-content"){m(null);return}W&&(d.current.htmlElement=W,d.current.lexicalNode=D),(D==null?void 0:D.__type)==="collapsible-title"&&(d.current.htmlElement=(W==null?void 0:W.parentElement)||W,d.current.lexicalNode=D.getParent()),v(null),m(d.current.htmlElement)}}))},20,50);l.useEffect(()=>()=>{ve=null},[]),l.useEffect(()=>{function y(){r.current||m(null)}function h(G){if(!a.current)return!1;const[W]=xe.eventFiles(G);if(W)return!1;const{target:D,dataTransfer:X}=G,te=(X==null?void 0:X.getData(ze))||"";e.update(()=>{var ge;let b=c.$getNodeByKey(te);if(!b||!(T.isHTMLElement(D)||D.closest(".resizable-container")))return!1;const{htmlElement:H,lexicalNode:ie,isBottom:K}=d.current;let z=ie,pe=null;if(z!=null&&z.__key&&(pe=H),!pe||!z)return!1;if(z===b)return!0;if(s.current&&mt(s.current,e,z,b))return!1;if(b.__type==="layout-divider"){if(b=b.getParent(),ie&&(b!=null&&b.isParentOf(ie)))return!1;et(e,b)}if(b.getParent()instanceof C.LayoutItemNode&&((ge=b.getParent())==null?void 0:ge.getChildren().length)===2){const he=b.getParent(),Te=he.getParent();T.removeNodeKeepContent(e,he,Te)}if(H!=null&&H.classList.contains("selected-block"))return;let be;const re=e._rootElement;K?be=Array.from(re.querySelectorAll(".selected-block")).reverse():be=Array.from(re.querySelectorAll(".selected-block")),be.length?be.forEach(he=>{let Te=c.$getNearestNodeFromDOMNode(he);K?z==null||z.insertAfter(Te):z==null||z.insertBefore(Te)}):K?z.insertAfter(b):z.insertBefore(b),m(null)})}function w(G){const{target:W}=G;T.isHTMLElement(W)&&W.className==="ContentEditable__root"&&Ge(s.current)}return t==null||t.addEventListener("mousemove",U),t==null||t.addEventListener("drop",h),t==null||t.addEventListener("mouseleave",y),t==null||t.addEventListener("dragleave",w),()=>{t==null||t.removeEventListener("mousemove",U),t==null||t.addEventListener("drop",h),t==null||t.removeEventListener("mouseleave",y),t==null||t.removeEventListener("dragleave",w)}},[t,e]),l.useEffect(()=>{if(i.current){if(r.current||_.opened)return;Ue(p,i.current,t,_.opened)}},[t,p,r.current,_.opened]),l.useEffect(()=>{function y(h){var K,z;const{clientY:w,target:G,pageX:W}=h;if(!a.current)return!1;const[D]=xe.eventFiles(h);if(D||!T.isHTMLElement(G))return!1;const X=c.$getNearestNodeFromDOMNode(G)||c.$getRoot(),{htmlElement:te,lexicalNode:b}=T.$getBlockNode(X,e,{root:!0,"layout-container":!0,"layout-item":!0,"callout-wrapper":!0,callout:!0,"collapsible-content":!0,"collapsible-container":!0},h);if(h.preventDefault(),(b==null?void 0:b.__type)==="callout"||(b==null?void 0:b.__type)==="collapsible-content"||tt(f.current,b==null?void 0:b.getParent())||(b==null?void 0:b.__type)==="layout-item"&&X.__type!=="root")return!1;te&&(d.current.htmlElement=te,d.current.lexicalNode=b);let H=null;H=d.current.htmlElement||te,H!=null&&H.closest(".dsd__theme__layoutContainer")&&X.__type==="root"&&b&&((b==null?void 0:b.__type)==="layout-item"&&X.__type==="root"?(H=H==null?void 0:H.parentElement,d.current.htmlElement=H,d.current.lexicalNode=b==null?void 0:b.getParent()):(H=(K=H.parentElement)==null?void 0:K.parentElement,d.current.htmlElement=H,d.current.lexicalNode=(z=b.getParent())==null?void 0:z.getParent()));const ie=s.current;return!H&&ie?(ie.style.background="transparent",!1):H===null||ie===null||H!=null&&H.classList.contains("selected-block")?!1:(bt(ie,H,w,W,t,h,d),!0)}return de.mergeRegister(e.registerCommand(T.ON_CHANGE_COMMAND,h=>h==="hide_menu"?(ht(i.current),setTimeout(()=>{r.current=!0},0),!1):h==="show_menu"?(r.current=!1,!1):(h===!0&&!r.current&&m(null),r.current=!1,!1),c.COMMAND_PRIORITY_LOW),e.registerCommand(T.RIGHT_CLICK_COMMAND,h=>((h==null?void 0:h.target)instanceof HTMLElement&&i.current instanceof HTMLElement&&(Z(h),Ue(h.target,i.current,t,_.opened)),!1),c.COMMAND_PRIORITY_LOW),e.registerCommand(c.DRAGOVER_COMMAND,h=>(ve||(ve=It(h.target)),$t(h,ve),y(h)),c.COMMAND_PRIORITY_LOW),e.registerCommand(c.KEY_ARROW_DOWN_COMMAND,()=>(e.dispatchCommand(T.ON_CHANGE_COMMAND,!0),!1),c.COMMAND_PRIORITY_LOW),e.registerCommand(c.KEY_ARROW_UP_COMMAND,()=>(e.dispatchCommand(T.ON_CHANGE_COMMAND,!0),!1),c.COMMAND_PRIORITY_LOW))},[t,e]);function ae(y){var D;const h=y.dataTransfer;(D=s.current)==null||D.setAttribute("data-index-start","");const w=p||d.current.htmlElement;if(!h||!w)return;const G=e._rootElement;if(w!=null&&w.classList.contains("selected-block")){const X=e._rootElement,te=Array.from(X.querySelectorAll(".selected-block"));yt(y.dataTransfer,te)}else ee.$removeSelectedHTMLElements(G),w.className.includes("_layoutDivider")&&w.parentElement?Ye(h,w.parentElement):Ye(h,w);let W="";e.read(()=>{var te,b;const X=c.$getNearestNodeFromDOMNode(w);if(X&&(W=X.getKey()),X instanceof C.LayoutDividerNode){const H=Ie((te=w.parentElement)==null?void 0:te.parentElement,w.parentElement);(b=s.current)==null||b.setAttribute("data-index-start",H.toString())}}),i.current&&(A(!0),i.current.style.opacity="0"),a.current=!0,f.current=W,h.setData(ze,W)}function Y(){a.current=!1,Ge(s.current),A(!1)}if(N)return n.jsx("div",{});function E(){var w;const y=d.current.htmlElement,h=(w=y==null?void 0:y.parentElement)==null?void 0:w.parentElement;if(h!=null&&h.classList.contains("dsd__theme__layoutContainer")&&(h.children.length===4?B(!0):B(!1),y!=null&&y.parentElement)){const G=Ie(h,y==null?void 0:y.parentElement);G?G===h.children.length-1?S({left:!1,right:!0}):S({left:!1,right:!1}):S({left:!0,right:!1})}}function Z(y){r.current=!0;const h=kt((y==null?void 0:y.target)??d.current.htmlElement);if(!h)return;const w=e._rootElement;E(),h.classList.contains("selected-block")||ee.$removeSelectedHTMLElements(w),e.update(()=>{const W=c.$getSelection(),X=((W==null?void 0:W.getNodes())??[]).filter(K=>!c.$isTextNode(K)&&!C.$isListNode(K)&&K.__parent==="root"),te=X.map(K=>{const z=e.getElementByKey(K.getKey());return K.getType()==="table"?z==null?void 0:z.firstElementChild:z}).filter(K=>K!==null),b=X.length&&te.includes(h)?te:[h];if(b.length===1){const K=c.$getNearestNodeFromDOMNode(h);if(!K)return;K.selectStart(),O(K)}else O(null);b.forEach(K=>{ee.$getSelectedHTMLElements(e,{block:K,isCreateEventListener:!1})});const H=Array.from(document.querySelectorAll(".selected-block")).reduce((K,z)=>{const pe=c.$getNearestNodeFromDOMNode(z);return pe&&K.push(pe),K},[]),ie=H.length>0&&H.every(K=>C.$isCalloutWrapperNode(K)||C.$isTableNode(K)||ee.$isCollapsibleContainerNode(K)?!1:c.$isElementNode(K)||c.$isTextNode(K));F(ie?"text":"block")}),T.blockScroll();const G=Number(y==null?void 0:y.y)+240>window.innerHeight?Number(y==null?void 0:y.y)-200:y==null?void 0:y.y;j({opened:!0,x:(y==null?void 0:y.x)??0,y:G??0}),e.dispatchCommand(T.ON_OPEN_KEBAB_MENU,!0)}const oe=()=>{e.update(()=>{const y=T.getCurrentElement();if(r.current=!1,j(h=>({opened:!1,x:h.x,y:h.y})),(y==null?void 0:y.__key)==="root"){const h=c.$createParagraphNode();y.append(h)}})},ce=o?"hide-add-button":"",me=_.x!==0?{position:"fixed",top:0,left:0,transform:`translate(${_.x}px, ${_.y}px)`}:{},_e=()=>{oe(),T.unblockScroll(),ee.onSelectEnd(e),ee.$removeSelectedHTMLElements(e._rootElement)},je=(y=!1)=>{y?e.update(()=>{const h=c.$getSelection();let w=null;c.$isRangeSelection(h)&&(w=h.anchor.getNode().getParent()),_e(),setTimeout(()=>{e.update(()=>{w==null||w.selectEnd()})},100)}):_e()},ye=l.useCallback(y=>{const h=document.querySelector(".draggable-menu");if(!_&&y.button!==2)return;const w=y.target;if(w.closest(".mantine-Menu-dropdown"))return;!((h==null?void 0:h.contains(w))&&w.closest("div.custom-menu-item"))&&y.button!==2&&_.opened&&(y.stopPropagation(),y.preventDefault())},[e,_]);return l.useEffect(()=>(_.opened?document.addEventListener("mousedown",ye):document.removeEventListener("mousedown",ye),()=>{document.removeEventListener("mousedown",ye)}),[_.opened,ye]),Be.createPortal(n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`draggable-block-container ${ce} ${p?"visible":""}`,ref:i,onMouseEnter:()=>{var y;_||v("both"),(y=i.current)!=null&&y.style&&(i.current.style.opacity="1")},onMouseLeave:()=>{v(null)},children:[n.jsx(Mt,{hoveredButton:M,insertNewParagraph:We,currentDraggableBlockRef:d,setHoveredButton:v,isClickedBlockRef:r,setDraggableBlockElem:m,editor:e,t:R}),n.jsxs(u.Menu,{onOpen:Z,opened:_.opened,styles:{dropdown:me},position:"left-start",width:320,shadow:"md",withinPortal:!0,onClose:()=>{je()},transitionProps:C.animationMenu,children:[n.jsx(u.Menu.Target,{children:n.jsx("div",{className:"icon draggable-block-menu",draggable:!0,onDragStart:ae,onDragEnd:Y,children:n.jsx(u.Tooltip,{openDelay:300,multiline:!0,disabled:g||r.current,label:n.jsxs(n.Fragment,{children:[n.jsxs("span",{children:[n.jsx("strong",{children:R("editor.hoverOptions.drag")}),","," ",R("editor.hoverOptions.dragAction")]}),n.jsx("br",{}),n.jsxs("span",{children:[n.jsx("strong",{children:R("editor.hoverOptions.click")}),","," ",R("editor.hoverOptions.clickAction")]})]}),position:"bottom-start",children:n.jsx(u.ActionIcon,{radius:"sm",color:"gray",size:"sm",variant:"subtle","aria-label":"Settings",children:n.jsx($.IconGripVertical,{size:20})})})})}),n.jsx(Tt,{hoveredButton:M,insertNewParagraph:We,currentDraggableBlockRef:d,setHoveredButton:v,isClickedBlockRef:r,setDraggableBlockElem:m,editor:e,t:R}),n.jsx(u.Menu.Dropdown,{className:"draggable-menu",children:n.jsx(St,{onChange:()=>{je(!0),T.resetSelection(e)},t:R,textBlock:L,currentEditorNode:k,editor:e,isDisabledAddColumnButton:P,disabledMoveColumnButtons:x})})]})]}),n.jsx("div",{className:"draggable-block-target-line",ref:s})]}),t)}function At({anchorElem:e=document.body,isShowAddButton:t=!1}){const[o]=Oe.useLexicalComposerContext();return vt(o,e,t)}function Ot({editor:e,anchorElem:t,isLink:o,isBold:i,isItalic:s,isUnderline:a,isCode:r,isStrikethrough:d,isSubscript:f,isSuperscript:p,component:m,isText:N}){const g=l.useRef(null),A=l.useRef(!1),_=l.useRef(null),j=l.useCallback(()=>{e.dispatchCommand(T.ON_SHOW_LINK_POPUP,"create")},[e,o]);function L(){var M,v;g.current&&(A.current=!0,T.setFloatingElemPosition(((M=_.current)==null?void 0:M.rect)||null,g==null?void 0:g.current,t,(v=_.current)==null?void 0:v.isLink))}l.useEffect(()=>{const M=T.getNativeSelectedText();if(!N&&!(M!=null&&M.length)){let v=function(S){return S instanceof HTMLElement};const P=g.current,B=window.getSelection();let x=!1;B!=null&&B.anchorNode&&v(B.anchorNode)&&B.anchorNode.className==="toolbar"&&(x=!0),P&&!x&&(_.current={rect:null,floatingElem:P,anchorElem:t,isLink:o},T.setFloatingElemPosition(null,P,t,o),A.current=!1)}},[N,e]),l.useEffect(()=>{if(g!=null&&g.current)return document.addEventListener("mouseup",L),()=>{document.removeEventListener("mouseup",L)}},[g]),l.useEffect(()=>{e.registerCommand(c.KEY_DOWN_COMMAND,M=>{var v;return(M.metaKey||M.ctrlKey)&&M.code==="KeyA"?(M.preventDefault(),T.selectCurrentNode(e),T.getCurrentElement(!0)&&(T.isWholeNodeSelected()&&(g!=null&&g.current)?(T.setFloatingElemPosition(null,g==null?void 0:g.current,t,(v=_.current)==null?void 0:v.isLink),c.$selectAll(),ee.$getSelectedHTMLElements(e)):setTimeout(()=>{L()})),!0):!1},c.COMMAND_PRIORITY_LOW),e.registerCommand(T.ON_OPEN_KEBAB_MENU,()=>(setTimeout(()=>{var M;g!=null&&g.current&&T.setFloatingElemPosition(null,g==null?void 0:g.current,t,(M=_.current)==null?void 0:M.isLink)},100),!1),c.COMMAND_PRIORITY_LOW)},[e]);const F=l.useCallback(()=>{const M=c.$getSelection(),v=g.current,P=window.getSelection();if(v===null)return;const B=e.getRootElement();let x=!1;const S=T.getNativeSelectedText();if(S&&S.length>0&&(x=!0),M!==null&&P!==null&&!P.isCollapsed&&B!==null&&B.contains(P.anchorNode)&&x){const k=T.getDOMRangeRect(P,B);if(_.current={rect:k,floatingElem:v,anchorElem:t,isLink:o},c.$isRangeSelection(M)){const R=T.getSelectedNode(M).getParent(),U=R==null?void 0:R.getFormatType();A.current&&U&&g&&e.registerCommand(T.ON_OPEN_KEBAB_MENU,ae=>(ae||setTimeout(()=>{var Y,E;T.setFloatingElemPosition(((Y=_.current)==null?void 0:Y.rect)||null,v,t,(E=_.current)==null?void 0:E.isLink)},100),!1),c.COMMAND_PRIORITY_LOW)}}else _.current={rect:null,floatingElem:v,anchorElem:t,isLink:o}},[e,t,o]);return l.useEffect(()=>{const M=t.parentElement,v=()=>{e.getEditorState().read(()=>{F()})};return window.addEventListener("resize",v),M&&M.addEventListener("scroll",v),()=>{window.removeEventListener("resize",v),M&&M.removeEventListener("scroll",v)}},[e,F,t]),l.useEffect(()=>(e.getEditorState().read(()=>{F()}),de.mergeRegister(e.registerUpdateListener(({editorState:M})=>{M.read(()=>{F()})}),e.registerCommand(c.SELECTION_CHANGE_COMMAND,()=>(F(),!1),c.COMMAND_PRIORITY_LOW))),[e,F]),n.jsx("div",{ref:g,className:`floating-text-format-popup doc-space-editor-wrapper ${N?"":"floating-text-format-popup-hidden"}`,children:n.jsx("div",{children:e.isEditable()&&(m||n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",onClick:()=>{e.dispatchCommand(c.FORMAT_TEXT_COMMAND,"bold")},className:"popup-item spaced "+(i?"active":""),children:n.jsx(V.Icon,{name:"bold",stroke:i?3:2})}),n.jsx("button",{type:"button",onClick:()=>{e.dispatchCommand(c.FORMAT_TEXT_COMMAND,"italic")},className:"popup-item spaced "+(s?"active":""),children:n.jsx(V.Icon,{name:"italic",stroke:s?3:2})}),n.jsx("button",{type:"button",onClick:()=>{e.dispatchCommand(c.FORMAT_TEXT_COMMAND,"underline")},className:"popup-item spaced "+(a?"active":""),children:n.jsx(V.Icon,{name:"underline",stroke:a?3:2})}),n.jsx("button",{type:"button",onClick:()=>{e.dispatchCommand(c.FORMAT_TEXT_COMMAND,"strikethrough")},className:"popup-item spaced "+(d?"active":""),"data-test-id":"toolbar-strikethrough",children:n.jsx(V.Icon,{name:"strikethrough",stroke:d?3:2})}),n.jsx("button",{type:"button",onClick:()=>{e.dispatchCommand(c.FORMAT_TEXT_COMMAND,"subscript")},className:"popup-item spaced "+(f?"active":""),children:n.jsx(V.Icon,{name:"subscript",stroke:f?3:2})}),n.jsx("button",{type:"button",onClick:()=>{e.dispatchCommand(c.FORMAT_TEXT_COMMAND,"superscript")},className:"popup-item spaced "+(p?"active":""),children:n.jsx(V.Icon,{name:"superscript",stroke:p?3:2})}),n.jsx("button",{type:"button",onClick:()=>{e.dispatchCommand(c.FORMAT_TEXT_COMMAND,"code")},className:"popup-item spaced "+(r?"active":""),children:n.jsx(V.Icon,{name:"code"})}),n.jsx("button",{type:"button",onClick:j,className:"popup-item spaced "+(o?"active":""),children:n.jsx(V.Icon,{name:"link"})})]}))})})}function Dt(e,t,o){const[i,s]=l.useState(!1),[a,r]=l.useState(!1),[d,f]=l.useState(!1),[p,m]=l.useState(!1),[N,g]=l.useState(!1),[A,_]=l.useState(!1),[j,L]=l.useState(!1),[F,M]=l.useState(!1),[v,P]=l.useState(!1),B=T.allEditorSelected(),{disable:x}=l.useContext(Ce.Context),S=l.useCallback(()=>{e.getEditorState().read(()=>{var oe,ce,me;if(e.isComposing())return;const k=c.$getSelection(),O=window.getSelection(),R=e.getRootElement();if(O!==null&&(!c.$isRangeSelection(k)||R===null||!R.contains(O.anchorNode))){s(!1);return}if(!c.$isRangeSelection(k))return;const U=T.getSelectedNode(k);f(k.hasFormat("bold")),m(k.hasFormat("italic")),g(k.hasFormat("underline")),_(k.hasFormat("strikethrough")),L(k.hasFormat("subscript")),M(k.hasFormat("superscript")),P(k.hasFormat("code"));const ae=U.getParent();Me.$isLinkNode(ae)||Me.$isLinkNode(U)?r(!0):r(!1);const Y=rt.$isCodeHighlightNode(k.anchor.getNode()),E=(me=(ce=(oe=e.getElementByKey(U.__key))==null?void 0:oe.parentElement)==null?void 0:ce.parentElement)==null?void 0:me.classList.contains("Collapsible__title");!Y&&k.getTextContent()!==""&&!E?s(C.$isExtendedTextNode(U)||c.$isParagraphNode(U)||xe.$isHeadingNode(U)||xe.$isQuoteNode(U)||C.$isListItemNode(U)):s(!1);const Z=k.getTextContent().replace(/\n/g,"");if(!k.isCollapsed()&&Z===""){s(!1);return}})},[e]);return l.useEffect(()=>(document.addEventListener("selectionchange",S),()=>{document.removeEventListener("selectionchange",S)}),[S]),l.useEffect(()=>de.mergeRegister(e.registerUpdateListener(()=>{S()}),e.registerRootListener(()=>{e.getRootElement()===null&&s(!1)})),[e,S]),x?null:Be.createPortal(n.jsx(Ot,{editor:e,anchorElem:t,isLink:a,isBold:d,isItalic:p,isStrikethrough:A,isSubscript:j,isSuperscript:F,isUnderline:N,isCode:v,component:o,isText:i&&!B}),document.body)}function wt({anchorElem:e=document.body,component:t}){const[o]=Oe.useLexicalComposerContext();return Dt(o,e,t)}const Lt=(e,t,o,i)=>{e.update(()=>{if(c.$isRangeSelection(o)){const s=c.$createTextNode(t);o.insertNodes([s]),i()}})},Pt=(e,t,o,i)=>{e.update(()=>{if(c.$isRangeSelection(o)){const s=c.$createTextNode(t);o.insertNodes([]);const a=s.getParent()??o.focus.getNode().getParent();if(a){const r=o.focus.getNode().getNextSibling();r?r.insertBefore(s):a.append(s),i()}}})},Rt=(e,t="",o,i)=>{e.update(()=>{if(!c.$isRangeSelection(o))return;const a=o.anchor.getNode().getTopLevelElementOrThrow(),r=c.$createParagraphNode();t&&r.append(c.$createTextNode(t)),a.insertAfter(r),i()})},Ft=(e,t)=>{e.update(()=>{const o=c.$getSelection();if(c.$isRangeSelection(o)){const i=o.getTextContent();t(i)}})},Bt=({editor:e,response:t,onSubmit:o,setTypeMenu:i,onClose:s,t:a,selection:r})=>n.jsxs(n.Fragment,{children:[n.jsx(u.Menu.Item,{leftSection:n.jsx($.IconArrowNarrowLeft,{size:14}),onClick:()=>i("main"),children:a("editor.ai.back")}),n.jsx(u.Menu.Item,{onClick:()=>{Lt(e,t,r,s)},leftSection:n.jsx($.IconReplace,{size:14}),children:a("editor.ai.menu.answer.replaceSelection")}),n.jsx(u.Menu.Item,{onClick:()=>{Pt(e,` ${t}`,r,s)},leftSection:n.jsx($.IconTextPlus,{size:14}),children:a("editor.ai.menu.answer.addTextInline")}),n.jsx(u.Menu.Item,{onClick:()=>{Rt(e,t,r,s),s()},leftSection:n.jsx($.IconIndentIncrease,{size:14}),children:a("editor.ai.menu.answer.addBelowParagraph")}),n.jsx(u.Menu.Divider,{}),n.jsx(u.Menu.Label,{children:a("editor.ai.menu.answer.modifyFurther")}),n.jsx(u.Menu.Item,{onClick:()=>{o(`Start with this text and continue. Output this text at the start: "${t}"`,!1)},leftSection:n.jsx($.IconPlayerPlay,{size:14}),children:a("editor.ai.menu.answer.continueWriting")}),n.jsx(u.Menu.Item,{onClick:()=>{o("Regenerate this text with another way: ")},leftSection:n.jsx($.IconReload,{size:14}),children:a("editor.ai.menu.answer.regenerate")}),n.jsx(u.Menu.Item,{onClick:s,leftSection:n.jsx($.IconTrash,{size:14}),children:a("editor.ai.menu.answer.discard")})]}),Et=["arabic","bengali","chinese","dutch","english","french","german","hindi","japanese","korean","nepali","portuguese","spanish"],Ht=["professional","straightforward","friendly","poetic","passiveAggressive","pirate"],Kt=[{title:"modifySelection",options:[{title:"improveWriting",prompt:"Improve the quality of the text",icon:n.jsx($.IconWand,{size:14})},{title:"fixMistakes",prompt:"Fix any typos or general errors in the text",icon:n.jsx($.IconTextSpellcheck,{size:14})},{title:"simplify",prompt:"Shorten the text, simplifying it",icon:n.jsx($.IconSortAscending,{size:14})},{title:"addMoreDetail",prompt:"Lengthen the text, going into more detail",icon:n.jsx($.IconSortDescending,{size:14})}]},{title:"generate",options:[{title:"summarise",prompt:"Summarise the text",icon:n.jsx($.IconNotes,{size:14})},{title:"translate",icon:n.jsx($.IconLanguage,{size:14}),type:"language"},{title:"changeStyle",icon:n.jsx($.IconScript,{size:14}),type:"style"},{title:"explain",prompt:"Explain what the text is about",icon:n.jsx($.IconHelpOctagon,{size:14})}]}],zt=({setTypeMenu:e,onSubmit:t,t:o})=>n.jsxs(n.Fragment,{children:[n.jsx(u.Menu.Item,{leftSection:n.jsx($.IconArrowNarrowLeft,{size:14}),onClick:()=>e("main"),children:o("editor.ai.back")}),Et.map(i=>n.jsx(u.Menu.Item,{onClick:()=>{t(`Translate text into the ${i} language`)},children:o(`editor.ai.menu.languages.${i}`)},i))]}),qt=({setTypeMenu:e,onSubmit:t,t:o})=>n.jsx(n.Fragment,{children:Kt.map(i=>n.jsxs("div",{children:[n.jsx(u.Menu.Label,{children:o(`editor.ai.menu.main.${i.title}`)}),i.options.map(s=>n.jsx(u.Menu.Item,{onClick:()=>{if(s.type){e(s.type);return}t(s.prompt||"")},leftSection:s.icon,children:o(`editor.ai.menu.main.${s.title}`)},s.title))]},i.title))}),Wt=({setTypeMenu:e,onSubmit:t,t:o})=>n.jsxs(n.Fragment,{children:[n.jsx(u.Menu.Item,{leftSection:n.jsx($.IconArrowNarrowLeft,{size:14}),onClick:()=>e("main"),children:o("editor.ai.back")}),Ht.map(i=>n.jsx(u.Menu.Item,{onClick:()=>{t(`Change text into ${i} style`)},children:o(`editor.ai.menu.style.${i}`)},i))]}),Ut=({keyType:e,setTypeMenu:t,editor:o,onSubmit:i,response:s,onClose:a,t:r,selection:d})=>{switch(e){case"main":return n.jsx(qt,{t:r,setTypeMenu:t,onSubmit:i});case"answer":return n.jsx(Bt,{t:r,onSubmit:i,editor:o,response:s,setTypeMenu:t,onClose:a,selection:d});case"language":return n.jsx(zt,{t:r,onSubmit:i,setTypeMenu:t});case"style":return n.jsx(Wt,{t:r,onSubmit:i,setTypeMenu:t});default:return null}};function Yt(e,t=40){const[o,i]=l.useState(""),s=l.useRef(0),a=l.useRef(null),r=l.useRef(null);return l.useEffect(()=>{if(a.current&&clearInterval(a.current),i(""),s.current=0,!!e)return a.current=setInterval(()=>{i(d=>{const f=e[s.current];return s.current+=1,s.current>=e.length&&clearInterval(a.current),d+(f||"")})},t),()=>{a.current&&clearInterval(a.current)}},[e,t]),l.useEffect(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},[o]),{displayedText:o,containerRef:r}}const Gt=()=>{var ae;const[e,t]=l.useState({top:"0px",bottom:"auto"}),[o,i]=l.useState(!1),[s,a]=l.useState(!1),[r]=Oe.useLexicalComposerContext(),[d,f]=l.useState("main"),[p,m]=l.useState(""),[N,g]=l.useState(""),[A,_]=l.useState(""),[j,L]=l.useState(null),[F,M]=l.useState(!1),{fetchPromptResult:v}=l.useContext(Ce.Context),{t:P}=Ee.useTranslation(),[B,x]=He.useResizeObserver(),S=()=>{i(!1),a(!1),_(""),f("main"),setTimeout(()=>{t({top:"0px",bottom:"auto"})},200)},k=He.useClickOutside(()=>{S()});l.useEffect(()=>{o?(Ft(r,g),document.documentElement.style.overflow="hidden",r.update(()=>{const Y=c.$getSelection();Y&&L(Y)})):(f("main"),document.documentElement.style.overflow="auto",_(""))},[o]);const{displayedText:O,containerRef:R}=Yt(A,10),U=(Y,E=!0)=>{const Z=Y+` "${E?N:""}"Only return the modified text. Do not include any explanations, introductions, or formatting.`;M(!0),v&&v(Z,oe=>{_(oe),M(!1),f("answer"),m("")},()=>{M(!1)})};return l.useEffect(()=>{var E,Z,oe;const{bottom:Y}=((E=B.current)==null?void 0:E.getBoundingClientRect())||{bottom:0};if(Y>window.innerHeight){const ce=(((oe=(Z=r._rootElement)==null?void 0:Z.getBoundingClientRect())==null?void 0:oe.bottom)||0)-window.innerHeight;t({...e,top:"auto",bottom:`${ce}px`})}},[x.height,o,B.current]),(ae=r._rootElement)!=null&&ae.parentElement?n.jsxs(n.Fragment,{children:[e.top?Be.createPortal(n.jsx(u.Transition,{mounted:!!o,transition:"scale-x",duration:300,timingFunction:"ease",children:Y=>n.jsx(u.Box,{ref:k,style:{position:"absolute",...e,...Y},className:"ai-editor-menu",children:n.jsxs(u.Menu,{opened:!!s,closeOnItemClick:!1,position:"bottom-start",zIndex:99,transitionProps:{transition:"fade",duration:300},styles:{dropdown:{overflow:"auto"}},offset:8,middlewares:{flip:!0,size:{apply({availableHeight:E,elements:Z}){requestAnimationFrame(()=>{Object.assign(Z.floating.style,{maxHeight:`${E>=425?425:E}px`})})}}},disabled:F,children:[n.jsx(u.Menu.Target,{children:n.jsxs(u.Paper,{withBorder:!0,ref:B,shadow:"lg",radius:"md",p:"0",px:"xs",children:[A&&n.jsxs(n.Fragment,{children:[n.jsxs(u.Group,{gap:3,align:"flex-start",style:{overflowY:"auto"},mah:120,ref:R,children:[n.jsx(u.Box,{style:{flex:1},w:"auto",py:"xs",children:O}),n.jsx(u.Box,{w:"auto",mt:"xs",children:n.jsx(u.CopyButton,{value:A,timeout:2e3,children:({copied:E,copy:Z})=>n.jsx(u.Tooltip,{label:E?"Copied":"Copy",withArrow:!0,position:"right",children:n.jsx(u.ActionIcon,{color:E?"teal":"gray",variant:"subtle",onClick:Z,children:E?n.jsx($.IconCheck,{size:16}):n.jsx($.IconCopy,{size:16})})})})})]}),n.jsx(u.Divider,{my:"0"})]}),n.jsx(u.Box,{children:n.jsx(u.Input,{size:"md",placeholder:P("editor.ai.placeholder"),rightSectionPointerEvents:"all",variant:"unstyled",value:p,onKeyDown:E=>{if(E.key==="Enter"){if(F)return;U(p)}},onChange:E=>{m(E.target.value)},rightSection:n.jsx(n.Fragment,{children:F?n.jsx(u.Loader,{color:"violet",size:"16",mr:"xs"}):n.jsx(u.ActionIcon,{color:"violet",disabled:!p,variant:"subtle",onClick:()=>{U(p)},children:n.jsx($.IconSparkles,{size:16})})})})})]})}),n.jsx(u.Menu.Dropdown,{className:"menu-dropdown-ai",onMouseDown:E=>{E.stopPropagation()},children:n.jsx(Ut,{keyType:d,setTypeMenu:f,editor:r,onSubmit:U,response:A,onClose:S,t:P,selection:j})})]})})}),r._rootElement.parentElement):null,n.jsxs("button",{disabled:!1,className:"toolbar-item spaced alignment","aria-label":"Formatting options for text alignment",type:"button",onClick:()=>{const Y=document.querySelector(".floating-text-format-popup");if(Y.style.opacity="0",Y.style.transform="translate(-10000px, -10000px)",Y!=null&&Y.style){const E=window.getSelection();if((E==null?void 0:E.rangeCount)===0)return null;if(E){const oe=E.getRangeAt(0).getBoundingClientRect(),ce=document.querySelector(".content-editable-wrapper"),me=ce.getBoundingClientRect(),_e=oe.top-me.top+ce.scrollTop+oe.height+"px";t({top:_e,bottom:"auto"}),setTimeout(()=>{i(!0)},0),setTimeout(()=>{a(!0)},100)}}},children:[n.jsx($.IconSparkles,{color:"#7950f2",size:18}),n.jsx($.IconAi,{size:21,color:"#7950f2"})]})]}):null},Xt=({editor:e,isEditable:t,t:o})=>{const{fetchUploadMedia:i,imperativeHandleRef:s}=l.useContext(Ce.Context),[a,r]=l.useState(!1);return i?n.jsx(Ke.ImagePicker,{popoverProps:{opened:a,position:"bottom",onChange:r},onUpload:d=>{var f,p;!i||!d.length||(r(!1),(f=s==null?void 0:s.current)!=null&&f.insertImages&&((p=s.current)==null||p.insertImages(d)))},onChange:d=>{e.dispatchCommand(Ke.INSERT_IMAGE_COMMAND,{altText:"",src:d}),r(!1)},children:n.jsx(u.Tooltip,{label:o("editor.image.add_photo"),children:n.jsx("button",{disabled:!t,type:"button",onClick:()=>r(d=>!d),className:"toolbar-item spaced",children:n.jsx(V.Icon,{name:"photo"})})})}):null},Vt={bullet:"Маркированный список",check:"Чек-лист",code:"Кодовый блок",h1:"Заголовок 1",h2:"Заголовок 2",h3:"Заголовок 3",h4:"Заголовок 4",h5:"Заголовок 5",h6:"Заголовок 6",number:"Нумерованный список",paragraph:"Параграф",quote:"Цитата"};function Ae(){return n.jsx("div",{className:"divider"})}function Qt({mode:e,isFloating:t}){const[o]=Oe.useLexicalComposerContext(),[i,s]=l.useState(o),[a,r]=l.useState("paragraph"),[d,f]=l.useState("root"),[p,m]=l.useState(null),[N,g]=l.useState("#000"),[A,_]=l.useState("#fff"),[j,L]=l.useState("left"),[F,M]=l.useState(!1),[v,P]=l.useState(!1),[B,x]=l.useState(!1),[S,k]=l.useState(!1),[O,R]=l.useState(!1),[U,ae]=l.useState(!1),[Y,E]=l.useState(!1),[Z,oe]=l.useState(!1),[ce,me]=l.useState(!1),[_e,je]=l.useState(!1),[ye]=C.useModal(),[y,h]=l.useState(!1),[w,G]=l.useState(!0),[W,D]=l.useState(!0),[X,te]=l.useState(0),[b,H]=l.useState(()=>o.isEditable()),ie=e||"default",{excludeNodes:K,fetchUploadMedia:z,fetchPromptResult:pe,commentOptions:be}=l.useContext(Ce.Context),{t:re}=Ee.useTranslation(),ge=l.useCallback(()=>{const I=c.$getSelection();if(c.$isRangeSelection(I)){const q=I.anchor.getNode(),se=I.focus.getNode(),ne=c.$isRootNode(q)?null:q.getTopLevelElementOrThrow(),fe=c.$isRootNode(se)?null:se.getTopLevelElementOrThrow();let Q=q.getKey()==="root"?q:de.$findMatchingParent(q,ue=>{const ke=ue.getParent();return ke!==null&&c.$isRootOrShadowRoot(ke)});I.getNodes().length===1?G(!0):G(!1),Q===null&&(Q=q.getTopLevelElementOrThrow());const J=Q.getKey(),$e=i.getElementByKey(J);o.update(()=>{P(I.hasFormat("bold")),x(I.hasFormat("italic")),k(I.hasFormat("underline")),R(I.hasFormat("strikethrough")),ae(I.hasFormat("subscript")),E(I.hasFormat("superscript")),oe(I.hasFormat("code"))});const le=T.getSelectedNode(I),Se=le.getParent();Me.$isLinkNode(Se)||Me.$isLinkNode(le)?M(!0):M(!1),g(Ne.$getSelectionStyleValueForProperty(I,"color","inherit")),_(Ne.$getSelectionStyleValueForProperty(I,"background-color","inherit"));let Le;Me.$isLinkNode(Se)&&(Le=de.$findMatchingParent(le,ue=>c.$isElementNode(ue)&&!ue.isInline())),L(c.$isElementNode(Le)?Le.getFormatType():c.$isElementNode(le)?le.getFormatType():(Se==null?void 0:Se.getFormatType())||"left");const it=de.$findMatchingParent(le,C.$isTableNode);if(C.$isTableNode(it)?f("table"):f("root"),$e!==null&&(ne==null?void 0:ne.getKey())===(fe==null?void 0:fe.getKey()))if(m(J),C.$isListNode(Q)){const ue=de.$getNearestNodeOfType(q,C.ListNode),ke=ue?ue.getListType():Q.getListType();r(ke)}else{const ue=xe.$isHeadingNode(Q)?Q.getTag():Q.getType();ue in Vt&&r(ue)}else r("")}},[i,G]);l.useEffect(()=>o.registerCommand(c.SELECTION_CHANGE_COMMAND,(I,q)=>(ge(),s(q),!1),c.COMMAND_PRIORITY_CRITICAL),[o,ge]),l.useEffect(()=>de.mergeRegister(o.registerEditableListener(I=>{H(I)}),i.registerUpdateListener(({editorState:I})=>{I.read(()=>{ge()})}),i.registerCommand(c.CAN_UNDO_COMMAND,I=>(me(I),!1),c.COMMAND_PRIORITY_CRITICAL),i.registerCommand(c.CAN_REDO_COMMAND,I=>(je(I),!1),c.COMMAND_PRIORITY_CRITICAL)),[ge,i,o]),l.useEffect(()=>de.mergeRegister(i.registerCommand(c.KEY_MODIFIER_COMMAND,I=>{const q=I,{code:se,metaKey:ne}=q;if(se==="KeyK"&&ne){q.preventDefault();let fe;return F?fe=null:fe=T.sanitizeUrl("https://"),i.dispatchCommand(Me.TOGGLE_LINK_COMMAND,fe)}return!1},c.COMMAND_PRIORITY_NORMAL),i.registerCommand(c.CLICK_COMMAND,()=>{const I=c.$getSelection();if(c.$isRangeSelection(I)){const q=I.getNodes(),se=q.length>0&&q.every(ne=>C.$isCalloutWrapperNode(ne)||C.$isTableNode(ne)||ee.$isCollapsibleContainerNode(ne)?!1:c.$isElementNode(ne)||c.$isTextNode(ne));D(!se)}return!1},c.COMMAND_PRIORITY_NORMAL)),[i,F]),l.useCallback((I,q)=>{i.update(()=>{const se=c.$getSelection();se!==null&&Ne.$patchStyleText(se,I)},q?{tag:"historic"}:{})},[i]);const he=l.useCallback(()=>{setTimeout(()=>{i.dispatchCommand(c.FORMAT_TEXT_COMMAND,"")}),i.update(()=>{const I=c.$getSelection();if(c.$isRangeSelection(I)){const q=I.anchor,se=I.focus,ne=I.getNodes(),fe=I.extract();if(q.key===se.key&&q.offset===se.offset)return;ne.forEach((Q,we)=>{if(C.$isExtendedTextNode(Q)){let J=Q;we===0&&q.offset!==0&&(J=J.splitText(q.offset)[1]||J),we===ne.length-1&&(J=J.splitText(se.offset)[0]||J);const $e=fe[0];ne.length===1&&C.$isExtendedTextNode($e)&&(J=$e),J.__style!==""&&J.setStyle(""),J.__format!==0&&J.setFormat(0);const le=de.$getNearestBlockElementAncestorOrThrow(J);le.__format!==0&&le.setFormat(""),le.__indent!==0&&le.setIndent(0),Q=J}else xe.$isHeadingNode(Q)||xe.$isQuoteNode(Q)?Q.replace(c.$createParagraphNode(),!0):at.$isDecoratorBlockNode(Q)&&Q.setFormat("")})}})},[i]),Te=I=>{g(I.color),_(I["background-color"]),i.update(()=>{const q=c.$getSelection();q!==null&&Ne.$patchStyleText(q,I)})},ot=l.useCallback(()=>{o.dispatchCommand(T.ON_SHOW_LINK_POPUP,"create"),setTimeout(()=>{H(!0)},1e3)},[o]),st=()=>{o.dispatchCommand(Ce.INSERT_INLINE_COMMAND,void 0),te(I=>I+1)};return n.jsx("div",{className:"toolbar-wrapper",tabIndex:-1,children:n.jsxs("div",{className:"toolbar",children:[n.jsxs(n.Fragment,{children:[n.jsx(ee.BlockFormatMenu,{disabled:W,blockType:a,rootType:d,editor:o,mode:ie,fetchUploadMedia:z,excludeNodes:K}),n.jsx(Ae,{})]}),e==="editor"&&!0&&pe&&n.jsxs(n.Fragment,{children:[n.jsx(l.Suspense,{fallback:null,children:n.jsx(Gt,{})}),n.jsx(Ae,{})]}),n.jsxs(n.Fragment,{children:[n.jsx(u.Tooltip,{label:re("editor.toolbar.bold"),children:n.jsx("button",{disabled:!b,onClick:()=>{i.dispatchCommand(c.FORMAT_TEXT_COMMAND,"bold")},className:"toolbar-item spaced "+(v?"active":""),type:"button","data-test-id":"toolbar-bold",children:n.jsx(V.Icon,{name:"bold"})})}),n.jsx(u.Tooltip,{label:re("editor.toolbar.italic"),children:n.jsx("button",{disabled:!b,onClick:()=>{i.dispatchCommand(c.FORMAT_TEXT_COMMAND,"italic")},className:"toolbar-item spaced "+(B?"active":""),type:"button","data-test-id":"toolbar-italic",children:n.jsx(V.Icon,{name:"italic"})})}),n.jsx(u.Tooltip,{label:re("editor.toolbar.underline"),children:n.jsx("button",{disabled:!b,"data-test-id":"toolbar-underline",onClick:()=>{i.dispatchCommand(c.FORMAT_TEXT_COMMAND,"underline")},className:"toolbar-item spaced "+(S?"active":""),type:"button",children:n.jsx(V.Icon,{name:"underline"})})}),n.jsx(u.Tooltip,{label:re("editor.toolbar.strike"),children:n.jsx("button",{disabled:!b,className:"toolbar-item spaced "+(O?"active":""),"data-test-id":"toolbar-strikethrough",onClick:()=>{i.dispatchCommand(c.FORMAT_TEXT_COMMAND,"strikethrough")},children:n.jsx(V.Icon,{name:"strikethrough"})})}),n.jsx(u.Tooltip,{label:re("editor.toolbar.code"),children:n.jsx("button",{disabled:!b,onClick:()=>{i.dispatchCommand(c.FORMAT_TEXT_COMMAND,"code")},className:"toolbar-item spaced "+(Z?"active":""),type:"button","data-test-id":"toolbar-code",children:n.jsx(V.Icon,{name:"code"})})}),n.jsx(u.Tooltip,{label:re("editor.toolbar.clear"),children:n.jsx("button",{disabled:!b,className:"toolbar-item",onClick:he,"data-test-id":"toolbar-clear-format",children:n.jsx(V.Icon,{name:"сlear-format"})})}),n.jsx(u.Tooltip,{disabled:!b,label:re("editor.toolbar.link"),children:n.jsx("button",{onClick:ot,className:"toolbar-item spaced "+(F?"active":""),onMouseDown:()=>{H(!1)},type:"button","data-test-id":"toolbar-link",children:n.jsx(V.Icon,{name:"link"})})}),be&&e==="editor"&&n.jsx(u.Tooltip,{label:re("editor.toolbar.comment"),children:n.jsx("button",{onClick:st,className:"toolbar-item spaced "+(F?"active":""),type:"button","data-test-id":"toolbar-comment",children:n.jsx(V.Icon,{name:"message"})})},X),n.jsx(Pe.NewColorPicker,{value:{color:N,background:A},menuProps:{closeOnItemClick:!0},onChange:I=>{Te({color:N,"background-color":A,[I.mode==="color"?"color":"background-color"]:I.value})},disabled:!b,modes:["color","background"]})]}),n.jsx(Ae,{}),n.jsx(V.AlignMenu,{disabled:!b,value:j,editor:o,isRTL:y,setElementFormat:L}),e==="default"&&n.jsxs(n.Fragment,{children:[n.jsx(Ae,{}),n.jsx(Xt,{editor:o,t:re,isEditable:b})]}),ye]})})}exports.DraggableBlockPlugin=At;exports.FloatingTextFormatToolbarPlugin=wt;exports.ToolbarPlugin=Qt;exports.getTemplateColumns=De;exports.maxWidthPercent=Ze;exports.setTemplateColumnsAfterDelete=et;