@react-email/editor 0.0.0-canary.49

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 (80) hide show
  1. package/dist/columns-D1gzbJr5.cjs +404 -0
  2. package/dist/columns-TFI4L-IC.mjs +277 -0
  3. package/dist/columns-TFI4L-IC.mjs.map +1 -0
  4. package/dist/core/index.cjs +9 -0
  5. package/dist/core/index.d.cts +2 -0
  6. package/dist/core/index.d.mts +2 -0
  7. package/dist/core/index.mjs +4 -0
  8. package/dist/core-Dp3tVCOZ.mjs +156 -0
  9. package/dist/core-Dp3tVCOZ.mjs.map +1 -0
  10. package/dist/core-NV1Aun-R.cjs +173 -0
  11. package/dist/event-bus-BxVEXi1L.mjs +88 -0
  12. package/dist/event-bus-BxVEXi1L.mjs.map +1 -0
  13. package/dist/event-bus-WI0H5tIM.cjs +105 -0
  14. package/dist/extension-CfIsm0_p.cjs +1504 -0
  15. package/dist/extension-n2yYIR7e.mjs +1403 -0
  16. package/dist/extension-n2yYIR7e.mjs.map +1 -0
  17. package/dist/extensions/index.cjs +51 -0
  18. package/dist/extensions/index.d.cts +401 -0
  19. package/dist/extensions/index.d.cts.map +1 -0
  20. package/dist/extensions/index.d.mts +401 -0
  21. package/dist/extensions/index.d.mts.map +1 -0
  22. package/dist/extensions/index.mjs +5 -0
  23. package/dist/extensions-BsDsFFkk.mjs +1785 -0
  24. package/dist/extensions-BsDsFFkk.mjs.map +1 -0
  25. package/dist/extensions-D9BbHnEV.cjs +2029 -0
  26. package/dist/global-content-CaNsyaPw.mjs +78 -0
  27. package/dist/global-content-CaNsyaPw.mjs.map +1 -0
  28. package/dist/global-content-CxV8qpMp.cjs +89 -0
  29. package/dist/index-BMsf5s28.d.mts +194 -0
  30. package/dist/index-BMsf5s28.d.mts.map +1 -0
  31. package/dist/index-DNriNUPU.d.cts +194 -0
  32. package/dist/index-DNriNUPU.d.cts.map +1 -0
  33. package/dist/index.cjs +199 -0
  34. package/dist/index.css +1171 -0
  35. package/dist/index.css.map +1 -0
  36. package/dist/index.d.cts +43 -0
  37. package/dist/index.d.cts.map +1 -0
  38. package/dist/index.d.mts +43 -0
  39. package/dist/index.d.mts.map +1 -0
  40. package/dist/index.mjs +199 -0
  41. package/dist/index.mjs.map +1 -0
  42. package/dist/plugins/index.cjs +19 -0
  43. package/dist/plugins/index.d.cts +73 -0
  44. package/dist/plugins/index.d.cts.map +1 -0
  45. package/dist/plugins/index.d.mts +73 -0
  46. package/dist/plugins/index.d.mts.map +1 -0
  47. package/dist/plugins/index.mjs +3 -0
  48. package/dist/root-BWiLr5WO.mjs +2363 -0
  49. package/dist/root-BWiLr5WO.mjs.map +1 -0
  50. package/dist/root-Bm_YBU0n.cjs +2873 -0
  51. package/dist/set-text-alignment-BDkB4Vfh.mjs +19 -0
  52. package/dist/set-text-alignment-BDkB4Vfh.mjs.map +1 -0
  53. package/dist/set-text-alignment-BlyZq1GA.cjs +24 -0
  54. package/dist/styles-BBXVfEv-.mjs +223 -0
  55. package/dist/styles-BBXVfEv-.mjs.map +1 -0
  56. package/dist/styles-D5jB7Yx-.cjs +252 -0
  57. package/dist/types-B-hiUAR9.d.cts +47 -0
  58. package/dist/types-B-hiUAR9.d.cts.map +1 -0
  59. package/dist/types-J7sLqbPy.d.mts +47 -0
  60. package/dist/types-J7sLqbPy.d.mts.map +1 -0
  61. package/dist/ui/bubble-menu/bubble-menu.css +285 -0
  62. package/dist/ui/index.cjs +3052 -0
  63. package/dist/ui/index.d.cts +1220 -0
  64. package/dist/ui/index.d.cts.map +1 -0
  65. package/dist/ui/index.d.mts +1220 -0
  66. package/dist/ui/index.d.mts.map +1 -0
  67. package/dist/ui/index.mjs +2942 -0
  68. package/dist/ui/index.mjs.map +1 -0
  69. package/dist/ui/inspector/inspector.css +338 -0
  70. package/dist/ui/slash-command/slash-command.css +44 -0
  71. package/dist/ui/themes/default.css +1169 -0
  72. package/dist/utils/index.cjs +3 -0
  73. package/dist/utils/index.d.cts +7 -0
  74. package/dist/utils/index.d.cts.map +1 -0
  75. package/dist/utils/index.d.mts +7 -0
  76. package/dist/utils/index.d.mts.map +1 -0
  77. package/dist/utils/index.mjs +3 -0
  78. package/license.md +7 -0
  79. package/package.json +159 -0
  80. package/readme.md +69 -0
@@ -0,0 +1,2363 @@
1
+ import { t as editorEventBus } from "./event-bus-BxVEXi1L.mjs";
2
+ import { i as MAX_COLUMNS_DEPTH, s as getColumnsDepth } from "./columns-TFI4L-IC.mjs";
3
+ import { t as setTextAlignment } from "./set-text-alignment-BDkB4Vfh.mjs";
4
+ import { useCurrentEditor, useEditorState } from "@tiptap/react";
5
+ import * as React$1 from "react";
6
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ import { PluginKey } from "@tiptap/pm/state";
9
+ import { BubbleMenu } from "@tiptap/react/menus";
10
+ import * as Popover from "@radix-ui/react-popover";
11
+ import { autoUpdate, flip, offset, shift, useFloating } from "@floating-ui/react-dom";
12
+ import Suggestion from "@tiptap/suggestion";
13
+ import { createPortal } from "react-dom";
14
+
15
+ //#region src/ui/icons/align-center.tsx
16
+ function AlignCenterIcon({ size, width, height, ...props }) {
17
+ return /* @__PURE__ */ jsxs("svg", {
18
+ xmlns: "http://www.w3.org/2000/svg",
19
+ width: size ?? width ?? 24,
20
+ height: size ?? height ?? 24,
21
+ viewBox: "0 0 24 24",
22
+ fill: "none",
23
+ stroke: "currentColor",
24
+ strokeWidth: 2,
25
+ strokeLinecap: "round",
26
+ strokeLinejoin: "round",
27
+ "aria-hidden": "true",
28
+ ...props,
29
+ children: [
30
+ /* @__PURE__ */ jsx("path", { d: "M21 5H3" }),
31
+ /* @__PURE__ */ jsx("path", { d: "M17 12H7" }),
32
+ /* @__PURE__ */ jsx("path", { d: "M19 19H5" })
33
+ ]
34
+ });
35
+ }
36
+
37
+ //#endregion
38
+ //#region src/ui/icons/align-left.tsx
39
+ function AlignLeftIcon({ size, width, height, ...props }) {
40
+ return /* @__PURE__ */ jsxs("svg", {
41
+ xmlns: "http://www.w3.org/2000/svg",
42
+ width: size ?? width ?? 24,
43
+ height: size ?? height ?? 24,
44
+ viewBox: "0 0 24 24",
45
+ fill: "none",
46
+ stroke: "currentColor",
47
+ strokeWidth: 2,
48
+ strokeLinecap: "round",
49
+ strokeLinejoin: "round",
50
+ "aria-hidden": "true",
51
+ ...props,
52
+ children: [
53
+ /* @__PURE__ */ jsx("path", { d: "M21 5H3" }),
54
+ /* @__PURE__ */ jsx("path", { d: "M15 12H3" }),
55
+ /* @__PURE__ */ jsx("path", { d: "M17 19H3" })
56
+ ]
57
+ });
58
+ }
59
+
60
+ //#endregion
61
+ //#region src/ui/icons/align-right.tsx
62
+ function AlignRightIcon({ size, width, height, ...props }) {
63
+ return /* @__PURE__ */ jsxs("svg", {
64
+ xmlns: "http://www.w3.org/2000/svg",
65
+ width: size ?? width ?? 24,
66
+ height: size ?? height ?? 24,
67
+ viewBox: "0 0 24 24",
68
+ fill: "none",
69
+ stroke: "currentColor",
70
+ strokeWidth: 2,
71
+ strokeLinecap: "round",
72
+ strokeLinejoin: "round",
73
+ "aria-hidden": "true",
74
+ ...props,
75
+ children: [
76
+ /* @__PURE__ */ jsx("path", { d: "M21 5H3" }),
77
+ /* @__PURE__ */ jsx("path", { d: "M21 12H9" }),
78
+ /* @__PURE__ */ jsx("path", { d: "M21 19H7" })
79
+ ]
80
+ });
81
+ }
82
+
83
+ //#endregion
84
+ //#region src/ui/icons/bold.tsx
85
+ function BoldIcon({ size, width, height, ...props }) {
86
+ return /* @__PURE__ */ jsx("svg", {
87
+ xmlns: "http://www.w3.org/2000/svg",
88
+ width: size ?? width ?? 24,
89
+ height: size ?? height ?? 24,
90
+ viewBox: "0 0 24 24",
91
+ fill: "none",
92
+ stroke: "currentColor",
93
+ strokeWidth: 2,
94
+ strokeLinecap: "round",
95
+ strokeLinejoin: "round",
96
+ "aria-hidden": "true",
97
+ ...props,
98
+ children: /* @__PURE__ */ jsx("path", { d: "M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8" })
99
+ });
100
+ }
101
+
102
+ //#endregion
103
+ //#region src/ui/icons/case-upper.tsx
104
+ function CaseUpperIcon({ size, width, height, ...props }) {
105
+ return /* @__PURE__ */ jsxs("svg", {
106
+ xmlns: "http://www.w3.org/2000/svg",
107
+ width: size ?? width ?? 24,
108
+ height: size ?? height ?? 24,
109
+ viewBox: "0 0 24 24",
110
+ fill: "none",
111
+ stroke: "currentColor",
112
+ strokeWidth: 2,
113
+ strokeLinecap: "round",
114
+ strokeLinejoin: "round",
115
+ "aria-hidden": "true",
116
+ ...props,
117
+ children: [
118
+ /* @__PURE__ */ jsx("path", { d: "M15 11h4.5a1 1 0 0 1 0 5h-4a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h3a1 1 0 0 1 0 5" }),
119
+ /* @__PURE__ */ jsx("path", { d: "m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16" }),
120
+ /* @__PURE__ */ jsx("path", { d: "M3.304 13h6.392" })
121
+ ]
122
+ });
123
+ }
124
+
125
+ //#endregion
126
+ //#region src/ui/icons/check.tsx
127
+ function CheckIcon({ size, width, height, ...props }) {
128
+ return /* @__PURE__ */ jsx("svg", {
129
+ xmlns: "http://www.w3.org/2000/svg",
130
+ width: size ?? width ?? 24,
131
+ height: size ?? height ?? 24,
132
+ viewBox: "0 0 24 24",
133
+ fill: "none",
134
+ stroke: "currentColor",
135
+ strokeWidth: 2,
136
+ strokeLinecap: "round",
137
+ strokeLinejoin: "round",
138
+ "aria-hidden": "true",
139
+ ...props,
140
+ children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
141
+ });
142
+ }
143
+
144
+ //#endregion
145
+ //#region src/ui/icons/chevron-down.tsx
146
+ function ChevronDownIcon({ size, width, height, ...props }) {
147
+ return /* @__PURE__ */ jsx("svg", {
148
+ xmlns: "http://www.w3.org/2000/svg",
149
+ width: size ?? width ?? 24,
150
+ height: size ?? height ?? 24,
151
+ viewBox: "0 0 24 24",
152
+ fill: "none",
153
+ stroke: "currentColor",
154
+ strokeWidth: 2,
155
+ strokeLinecap: "round",
156
+ strokeLinejoin: "round",
157
+ "aria-hidden": "true",
158
+ ...props,
159
+ children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
160
+ });
161
+ }
162
+
163
+ //#endregion
164
+ //#region src/ui/icons/code.tsx
165
+ function CodeIcon({ size, width, height, ...props }) {
166
+ return /* @__PURE__ */ jsxs("svg", {
167
+ xmlns: "http://www.w3.org/2000/svg",
168
+ width: size ?? width ?? 24,
169
+ height: size ?? height ?? 24,
170
+ viewBox: "0 0 24 24",
171
+ fill: "none",
172
+ stroke: "currentColor",
173
+ strokeWidth: 2,
174
+ strokeLinecap: "round",
175
+ strokeLinejoin: "round",
176
+ "aria-hidden": "true",
177
+ ...props,
178
+ children: [/* @__PURE__ */ jsx("path", { d: "m16 18 6-6-6-6" }), /* @__PURE__ */ jsx("path", { d: "m8 6-6 6 6 6" })]
179
+ });
180
+ }
181
+
182
+ //#endregion
183
+ //#region src/ui/icons/columns-2.tsx
184
+ function Columns2Icon({ size, width, height, ...props }) {
185
+ return /* @__PURE__ */ jsxs("svg", {
186
+ xmlns: "http://www.w3.org/2000/svg",
187
+ width: size ?? width ?? 24,
188
+ height: size ?? height ?? 24,
189
+ viewBox: "0 0 24 24",
190
+ fill: "none",
191
+ stroke: "currentColor",
192
+ strokeWidth: 2,
193
+ strokeLinecap: "round",
194
+ strokeLinejoin: "round",
195
+ "aria-hidden": "true",
196
+ ...props,
197
+ children: [/* @__PURE__ */ jsx("rect", {
198
+ width: "18",
199
+ height: "18",
200
+ x: "3",
201
+ y: "3",
202
+ rx: "2"
203
+ }), /* @__PURE__ */ jsx("path", { d: "M12 3v18" })]
204
+ });
205
+ }
206
+
207
+ //#endregion
208
+ //#region src/ui/icons/columns-3.tsx
209
+ function Columns3Icon({ size, width, height, ...props }) {
210
+ return /* @__PURE__ */ jsxs("svg", {
211
+ xmlns: "http://www.w3.org/2000/svg",
212
+ width: size ?? width ?? 24,
213
+ height: size ?? height ?? 24,
214
+ viewBox: "0 0 24 24",
215
+ fill: "none",
216
+ stroke: "currentColor",
217
+ strokeWidth: 2,
218
+ strokeLinecap: "round",
219
+ strokeLinejoin: "round",
220
+ "aria-hidden": "true",
221
+ ...props,
222
+ children: [
223
+ /* @__PURE__ */ jsx("rect", {
224
+ width: "18",
225
+ height: "18",
226
+ x: "3",
227
+ y: "3",
228
+ rx: "2"
229
+ }),
230
+ /* @__PURE__ */ jsx("path", { d: "M9 3v18" }),
231
+ /* @__PURE__ */ jsx("path", { d: "M15 3v18" })
232
+ ]
233
+ });
234
+ }
235
+
236
+ //#endregion
237
+ //#region src/ui/icons/columns-4.tsx
238
+ function Columns4Icon({ size, width, height, ...props }) {
239
+ return /* @__PURE__ */ jsxs("svg", {
240
+ xmlns: "http://www.w3.org/2000/svg",
241
+ width: size ?? width ?? 24,
242
+ height: size ?? height ?? 24,
243
+ viewBox: "0 0 24 24",
244
+ fill: "none",
245
+ stroke: "currentColor",
246
+ strokeWidth: 2,
247
+ strokeLinecap: "round",
248
+ strokeLinejoin: "round",
249
+ "aria-hidden": "true",
250
+ ...props,
251
+ children: [
252
+ /* @__PURE__ */ jsx("rect", {
253
+ width: "18",
254
+ height: "18",
255
+ x: "3",
256
+ y: "3",
257
+ rx: "2"
258
+ }),
259
+ /* @__PURE__ */ jsx("path", { d: "M7.5 3v18" }),
260
+ /* @__PURE__ */ jsx("path", { d: "M12 3v18" }),
261
+ /* @__PURE__ */ jsx("path", { d: "M16.5 3v18" })
262
+ ]
263
+ });
264
+ }
265
+
266
+ //#endregion
267
+ //#region src/ui/icons/external-link.tsx
268
+ function ExternalLinkIcon({ size, width, height, ...props }) {
269
+ return /* @__PURE__ */ jsxs("svg", {
270
+ xmlns: "http://www.w3.org/2000/svg",
271
+ width: size ?? width ?? 24,
272
+ height: size ?? height ?? 24,
273
+ viewBox: "0 0 24 24",
274
+ fill: "none",
275
+ stroke: "currentColor",
276
+ strokeWidth: 2,
277
+ strokeLinecap: "round",
278
+ strokeLinejoin: "round",
279
+ "aria-hidden": "true",
280
+ ...props,
281
+ children: [
282
+ /* @__PURE__ */ jsx("path", { d: "M15 3h6v6" }),
283
+ /* @__PURE__ */ jsx("path", { d: "M10 14 21 3" }),
284
+ /* @__PURE__ */ jsx("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" })
285
+ ]
286
+ });
287
+ }
288
+
289
+ //#endregion
290
+ //#region src/ui/icons/heading-1.tsx
291
+ function Heading1Icon({ size, width, height, ...props }) {
292
+ return /* @__PURE__ */ jsxs("svg", {
293
+ xmlns: "http://www.w3.org/2000/svg",
294
+ width: size ?? width ?? 24,
295
+ height: size ?? height ?? 24,
296
+ viewBox: "0 0 24 24",
297
+ fill: "none",
298
+ stroke: "currentColor",
299
+ strokeWidth: 2,
300
+ strokeLinecap: "round",
301
+ strokeLinejoin: "round",
302
+ "aria-hidden": "true",
303
+ ...props,
304
+ children: [
305
+ /* @__PURE__ */ jsx("path", { d: "M4 12h8" }),
306
+ /* @__PURE__ */ jsx("path", { d: "M4 18V6" }),
307
+ /* @__PURE__ */ jsx("path", { d: "M12 18V6" }),
308
+ /* @__PURE__ */ jsx("path", { d: "m17 12 3-2v8" })
309
+ ]
310
+ });
311
+ }
312
+
313
+ //#endregion
314
+ //#region src/ui/icons/heading-2.tsx
315
+ function Heading2Icon({ size, width, height, ...props }) {
316
+ return /* @__PURE__ */ jsxs("svg", {
317
+ xmlns: "http://www.w3.org/2000/svg",
318
+ width: size ?? width ?? 24,
319
+ height: size ?? height ?? 24,
320
+ viewBox: "0 0 24 24",
321
+ fill: "none",
322
+ stroke: "currentColor",
323
+ strokeWidth: 2,
324
+ strokeLinecap: "round",
325
+ strokeLinejoin: "round",
326
+ "aria-hidden": "true",
327
+ ...props,
328
+ children: [
329
+ /* @__PURE__ */ jsx("path", { d: "M4 12h8" }),
330
+ /* @__PURE__ */ jsx("path", { d: "M4 18V6" }),
331
+ /* @__PURE__ */ jsx("path", { d: "M12 18V6" }),
332
+ /* @__PURE__ */ jsx("path", { d: "M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1" })
333
+ ]
334
+ });
335
+ }
336
+
337
+ //#endregion
338
+ //#region src/ui/icons/heading-3.tsx
339
+ function Heading3Icon({ size, width, height, ...props }) {
340
+ return /* @__PURE__ */ jsxs("svg", {
341
+ xmlns: "http://www.w3.org/2000/svg",
342
+ width: size ?? width ?? 24,
343
+ height: size ?? height ?? 24,
344
+ viewBox: "0 0 24 24",
345
+ fill: "none",
346
+ stroke: "currentColor",
347
+ strokeWidth: 2,
348
+ strokeLinecap: "round",
349
+ strokeLinejoin: "round",
350
+ "aria-hidden": "true",
351
+ ...props,
352
+ children: [
353
+ /* @__PURE__ */ jsx("path", { d: "M4 12h8" }),
354
+ /* @__PURE__ */ jsx("path", { d: "M4 18V6" }),
355
+ /* @__PURE__ */ jsx("path", { d: "M12 18V6" }),
356
+ /* @__PURE__ */ jsx("path", { d: "M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2" }),
357
+ /* @__PURE__ */ jsx("path", { d: "M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2" })
358
+ ]
359
+ });
360
+ }
361
+
362
+ //#endregion
363
+ //#region src/ui/icons/italic.tsx
364
+ function ItalicIcon({ size, width, height, ...props }) {
365
+ return /* @__PURE__ */ jsxs("svg", {
366
+ xmlns: "http://www.w3.org/2000/svg",
367
+ width: size ?? width ?? 24,
368
+ height: size ?? height ?? 24,
369
+ viewBox: "0 0 24 24",
370
+ fill: "none",
371
+ stroke: "currentColor",
372
+ strokeWidth: 2,
373
+ strokeLinecap: "round",
374
+ strokeLinejoin: "round",
375
+ "aria-hidden": "true",
376
+ ...props,
377
+ children: [
378
+ /* @__PURE__ */ jsx("line", {
379
+ x1: "19",
380
+ x2: "10",
381
+ y1: "4",
382
+ y2: "4"
383
+ }),
384
+ /* @__PURE__ */ jsx("line", {
385
+ x1: "14",
386
+ x2: "5",
387
+ y1: "20",
388
+ y2: "20"
389
+ }),
390
+ /* @__PURE__ */ jsx("line", {
391
+ x1: "15",
392
+ x2: "9",
393
+ y1: "4",
394
+ y2: "20"
395
+ })
396
+ ]
397
+ });
398
+ }
399
+
400
+ //#endregion
401
+ //#region src/ui/icons/link.tsx
402
+ function LinkIcon({ size, width, height, ...props }) {
403
+ return /* @__PURE__ */ jsxs("svg", {
404
+ xmlns: "http://www.w3.org/2000/svg",
405
+ width: size ?? width ?? 24,
406
+ height: size ?? height ?? 24,
407
+ viewBox: "0 0 24 24",
408
+ fill: "none",
409
+ stroke: "currentColor",
410
+ strokeWidth: 2,
411
+ strokeLinecap: "round",
412
+ strokeLinejoin: "round",
413
+ "aria-hidden": "true",
414
+ ...props,
415
+ children: [/* @__PURE__ */ jsx("path", { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" }), /* @__PURE__ */ jsx("path", { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" })]
416
+ });
417
+ }
418
+
419
+ //#endregion
420
+ //#region src/ui/icons/list.tsx
421
+ function ListIcon({ size, width, height, ...props }) {
422
+ return /* @__PURE__ */ jsxs("svg", {
423
+ xmlns: "http://www.w3.org/2000/svg",
424
+ width: size ?? width ?? 24,
425
+ height: size ?? height ?? 24,
426
+ viewBox: "0 0 24 24",
427
+ fill: "none",
428
+ stroke: "currentColor",
429
+ strokeWidth: 2,
430
+ strokeLinecap: "round",
431
+ strokeLinejoin: "round",
432
+ "aria-hidden": "true",
433
+ ...props,
434
+ children: [
435
+ /* @__PURE__ */ jsx("path", { d: "M3 5h.01" }),
436
+ /* @__PURE__ */ jsx("path", { d: "M3 12h.01" }),
437
+ /* @__PURE__ */ jsx("path", { d: "M3 19h.01" }),
438
+ /* @__PURE__ */ jsx("path", { d: "M8 5h13" }),
439
+ /* @__PURE__ */ jsx("path", { d: "M8 12h13" }),
440
+ /* @__PURE__ */ jsx("path", { d: "M8 19h13" })
441
+ ]
442
+ });
443
+ }
444
+
445
+ //#endregion
446
+ //#region src/ui/icons/list-ordered.tsx
447
+ function ListOrderedIcon({ size, width, height, ...props }) {
448
+ return /* @__PURE__ */ jsxs("svg", {
449
+ xmlns: "http://www.w3.org/2000/svg",
450
+ width: size ?? width ?? 24,
451
+ height: size ?? height ?? 24,
452
+ viewBox: "0 0 24 24",
453
+ fill: "none",
454
+ stroke: "currentColor",
455
+ strokeWidth: 2,
456
+ strokeLinecap: "round",
457
+ strokeLinejoin: "round",
458
+ "aria-hidden": "true",
459
+ ...props,
460
+ children: [
461
+ /* @__PURE__ */ jsx("path", { d: "M11 5h10" }),
462
+ /* @__PURE__ */ jsx("path", { d: "M11 12h10" }),
463
+ /* @__PURE__ */ jsx("path", { d: "M11 19h10" }),
464
+ /* @__PURE__ */ jsx("path", { d: "M4 4h1v5" }),
465
+ /* @__PURE__ */ jsx("path", { d: "M4 9h2" }),
466
+ /* @__PURE__ */ jsx("path", { d: "M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02" })
467
+ ]
468
+ });
469
+ }
470
+
471
+ //#endregion
472
+ //#region src/ui/icons/mouse-pointer.tsx
473
+ function MousePointerIcon({ size, width, height, ...props }) {
474
+ return /* @__PURE__ */ jsxs("svg", {
475
+ xmlns: "http://www.w3.org/2000/svg",
476
+ width: size ?? width ?? 24,
477
+ height: size ?? height ?? 24,
478
+ viewBox: "0 0 24 24",
479
+ fill: "none",
480
+ stroke: "currentColor",
481
+ strokeWidth: 2,
482
+ strokeLinecap: "round",
483
+ strokeLinejoin: "round",
484
+ "aria-hidden": "true",
485
+ ...props,
486
+ children: [/* @__PURE__ */ jsx("path", { d: "M12.586 12.586 19 19" }), /* @__PURE__ */ jsx("path", { d: "M3.688 3.037a.497.497 0 0 0-.651.651l6.5 15.999a.501.501 0 0 0 .947-.062l1.569-6.083a2 2 0 0 1 1.448-1.479l6.124-1.579a.5.5 0 0 0 .063-.947z" })]
487
+ });
488
+ }
489
+
490
+ //#endregion
491
+ //#region src/ui/icons/pencil.tsx
492
+ function PencilIcon({ size, width, height, ...props }) {
493
+ return /* @__PURE__ */ jsxs("svg", {
494
+ xmlns: "http://www.w3.org/2000/svg",
495
+ width: size ?? width ?? 24,
496
+ height: size ?? height ?? 24,
497
+ viewBox: "0 0 24 24",
498
+ fill: "none",
499
+ stroke: "currentColor",
500
+ strokeWidth: 2,
501
+ strokeLinecap: "round",
502
+ strokeLinejoin: "round",
503
+ "aria-hidden": "true",
504
+ ...props,
505
+ children: [/* @__PURE__ */ jsx("path", { d: "M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" }), /* @__PURE__ */ jsx("path", { d: "m15 5 4 4" })]
506
+ });
507
+ }
508
+
509
+ //#endregion
510
+ //#region src/ui/icons/rows-2.tsx
511
+ function Rows2Icon({ size, width, height, ...props }) {
512
+ return /* @__PURE__ */ jsxs("svg", {
513
+ xmlns: "http://www.w3.org/2000/svg",
514
+ width: size ?? width ?? 24,
515
+ height: size ?? height ?? 24,
516
+ viewBox: "0 0 24 24",
517
+ fill: "none",
518
+ stroke: "currentColor",
519
+ strokeWidth: 2,
520
+ strokeLinecap: "round",
521
+ strokeLinejoin: "round",
522
+ "aria-hidden": "true",
523
+ ...props,
524
+ children: [/* @__PURE__ */ jsx("rect", {
525
+ width: "18",
526
+ height: "18",
527
+ x: "3",
528
+ y: "3",
529
+ rx: "2"
530
+ }), /* @__PURE__ */ jsx("path", { d: "M3 12h18" })]
531
+ });
532
+ }
533
+
534
+ //#endregion
535
+ //#region src/ui/icons/split-square-vertical.tsx
536
+ function SplitSquareVerticalIcon({ size, width, height, ...props }) {
537
+ return /* @__PURE__ */ jsxs("svg", {
538
+ xmlns: "http://www.w3.org/2000/svg",
539
+ width: size ?? width ?? 24,
540
+ height: size ?? height ?? 24,
541
+ viewBox: "0 0 24 24",
542
+ fill: "none",
543
+ stroke: "currentColor",
544
+ strokeWidth: 2,
545
+ strokeLinecap: "round",
546
+ strokeLinejoin: "round",
547
+ "aria-hidden": "true",
548
+ ...props,
549
+ children: [
550
+ /* @__PURE__ */ jsx("path", { d: "M5 8V5c0-1 1-2 2-2h10c1 0 2 1 2 2v3" }),
551
+ /* @__PURE__ */ jsx("path", { d: "M19 16v3c0 1-1 2-2 2H7c-1 0-2-1-2-2v-3" }),
552
+ /* @__PURE__ */ jsx("line", {
553
+ x1: "4",
554
+ x2: "20",
555
+ y1: "12",
556
+ y2: "12"
557
+ })
558
+ ]
559
+ });
560
+ }
561
+
562
+ //#endregion
563
+ //#region src/ui/icons/square-code.tsx
564
+ function SquareCodeIcon({ size, width, height, ...props }) {
565
+ return /* @__PURE__ */ jsxs("svg", {
566
+ xmlns: "http://www.w3.org/2000/svg",
567
+ width: size ?? width ?? 24,
568
+ height: size ?? height ?? 24,
569
+ viewBox: "0 0 24 24",
570
+ fill: "none",
571
+ stroke: "currentColor",
572
+ strokeWidth: 2,
573
+ strokeLinecap: "round",
574
+ strokeLinejoin: "round",
575
+ "aria-hidden": "true",
576
+ ...props,
577
+ children: [
578
+ /* @__PURE__ */ jsx("path", { d: "m10 9-3 3 3 3" }),
579
+ /* @__PURE__ */ jsx("path", { d: "m14 15 3-3-3-3" }),
580
+ /* @__PURE__ */ jsx("rect", {
581
+ x: "3",
582
+ y: "3",
583
+ width: "18",
584
+ height: "18",
585
+ rx: "2"
586
+ })
587
+ ]
588
+ });
589
+ }
590
+
591
+ //#endregion
592
+ //#region src/ui/icons/strikethrough.tsx
593
+ function StrikethroughIcon({ size, width, height, ...props }) {
594
+ return /* @__PURE__ */ jsxs("svg", {
595
+ xmlns: "http://www.w3.org/2000/svg",
596
+ width: size ?? width ?? 24,
597
+ height: size ?? height ?? 24,
598
+ viewBox: "0 0 24 24",
599
+ fill: "none",
600
+ stroke: "currentColor",
601
+ strokeWidth: 2,
602
+ strokeLinecap: "round",
603
+ strokeLinejoin: "round",
604
+ "aria-hidden": "true",
605
+ ...props,
606
+ children: [
607
+ /* @__PURE__ */ jsx("path", { d: "M16 4H9a3 3 0 0 0-2.83 4" }),
608
+ /* @__PURE__ */ jsx("path", { d: "M14 12a4 4 0 0 1 0 8H6" }),
609
+ /* @__PURE__ */ jsx("line", {
610
+ x1: "4",
611
+ x2: "20",
612
+ y1: "12",
613
+ y2: "12"
614
+ })
615
+ ]
616
+ });
617
+ }
618
+
619
+ //#endregion
620
+ //#region src/ui/icons/text.tsx
621
+ function TextIcon({ size, width, height, ...props }) {
622
+ return /* @__PURE__ */ jsxs("svg", {
623
+ xmlns: "http://www.w3.org/2000/svg",
624
+ width: size ?? width ?? 24,
625
+ height: size ?? height ?? 24,
626
+ viewBox: "0 0 24 24",
627
+ fill: "none",
628
+ stroke: "currentColor",
629
+ strokeWidth: 2,
630
+ strokeLinecap: "round",
631
+ strokeLinejoin: "round",
632
+ "aria-hidden": "true",
633
+ ...props,
634
+ children: [
635
+ /* @__PURE__ */ jsx("path", { d: "M21 5H3" }),
636
+ /* @__PURE__ */ jsx("path", { d: "M15 12H3" }),
637
+ /* @__PURE__ */ jsx("path", { d: "M17 19H3" })
638
+ ]
639
+ });
640
+ }
641
+
642
+ //#endregion
643
+ //#region src/ui/icons/text-quote.tsx
644
+ function TextQuoteIcon({ size, width, height, ...props }) {
645
+ return /* @__PURE__ */ jsxs("svg", {
646
+ xmlns: "http://www.w3.org/2000/svg",
647
+ width: size ?? width ?? 24,
648
+ height: size ?? height ?? 24,
649
+ viewBox: "0 0 24 24",
650
+ fill: "none",
651
+ stroke: "currentColor",
652
+ strokeWidth: 2,
653
+ strokeLinecap: "round",
654
+ strokeLinejoin: "round",
655
+ "aria-hidden": "true",
656
+ ...props,
657
+ children: [
658
+ /* @__PURE__ */ jsx("path", { d: "M17 5H3" }),
659
+ /* @__PURE__ */ jsx("path", { d: "M21 12H8" }),
660
+ /* @__PURE__ */ jsx("path", { d: "M21 19H8" }),
661
+ /* @__PURE__ */ jsx("path", { d: "M3 12v7" })
662
+ ]
663
+ });
664
+ }
665
+
666
+ //#endregion
667
+ //#region src/ui/icons/underline.tsx
668
+ function UnderlineIcon({ size, width, height, ...props }) {
669
+ return /* @__PURE__ */ jsxs("svg", {
670
+ xmlns: "http://www.w3.org/2000/svg",
671
+ width: size ?? width ?? 24,
672
+ height: size ?? height ?? 24,
673
+ viewBox: "0 0 24 24",
674
+ fill: "none",
675
+ stroke: "currentColor",
676
+ strokeWidth: 2,
677
+ strokeLinecap: "round",
678
+ strokeLinejoin: "round",
679
+ "aria-hidden": "true",
680
+ ...props,
681
+ children: [/* @__PURE__ */ jsx("path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }), /* @__PURE__ */ jsx("line", {
682
+ x1: "4",
683
+ x2: "20",
684
+ y1: "20",
685
+ y2: "20"
686
+ })]
687
+ });
688
+ }
689
+
690
+ //#endregion
691
+ //#region src/ui/icons/unlink.tsx
692
+ function UnlinkIcon({ size, width, height, ...props }) {
693
+ return /* @__PURE__ */ jsxs("svg", {
694
+ xmlns: "http://www.w3.org/2000/svg",
695
+ width: size ?? width ?? 24,
696
+ height: size ?? height ?? 24,
697
+ viewBox: "0 0 24 24",
698
+ fill: "none",
699
+ stroke: "currentColor",
700
+ strokeWidth: 2,
701
+ strokeLinecap: "round",
702
+ strokeLinejoin: "round",
703
+ "aria-hidden": "true",
704
+ ...props,
705
+ children: [
706
+ /* @__PURE__ */ jsx("path", { d: "m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71" }),
707
+ /* @__PURE__ */ jsx("path", { d: "m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71" }),
708
+ /* @__PURE__ */ jsx("line", {
709
+ x1: "8",
710
+ x2: "8",
711
+ y1: "2",
712
+ y2: "5"
713
+ }),
714
+ /* @__PURE__ */ jsx("line", {
715
+ x1: "2",
716
+ x2: "5",
717
+ y1: "8",
718
+ y2: "8"
719
+ }),
720
+ /* @__PURE__ */ jsx("line", {
721
+ x1: "16",
722
+ x2: "16",
723
+ y1: "19",
724
+ y2: "22"
725
+ }),
726
+ /* @__PURE__ */ jsx("line", {
727
+ x1: "19",
728
+ x2: "22",
729
+ y1: "16",
730
+ y2: "16"
731
+ })
732
+ ]
733
+ });
734
+ }
735
+
736
+ //#endregion
737
+ //#region src/ui/bubble-menu/context.tsx
738
+ const BubbleMenuContext = React$1.createContext(null);
739
+ function useBubbleMenuContext() {
740
+ const context = React$1.useContext(BubbleMenuContext);
741
+ if (!context) throw new Error("BubbleMenu compound components must be used within <BubbleMenu>");
742
+ return context;
743
+ }
744
+
745
+ //#endregion
746
+ //#region src/ui/bubble-menu/item.tsx
747
+ function BubbleMenuItem({ name, isActive, onCommand, className, children, ...rest }) {
748
+ return /* @__PURE__ */ jsx("button", {
749
+ type: "button",
750
+ "aria-label": name,
751
+ "aria-pressed": isActive,
752
+ className,
753
+ "data-re-bubble-menu-item": "",
754
+ "data-item": name,
755
+ ...isActive ? { "data-active": "" } : {},
756
+ onMouseDown: (e) => e.preventDefault(),
757
+ onClick: onCommand,
758
+ ...rest,
759
+ children
760
+ });
761
+ }
762
+
763
+ //#endregion
764
+ //#region src/ui/bubble-menu/align-center.tsx
765
+ function BubbleMenuAlignCenter({ className, children }) {
766
+ const { editor } = useBubbleMenuContext();
767
+ return /* @__PURE__ */ jsx(BubbleMenuItem, {
768
+ name: "align-center",
769
+ isActive: useEditorState({
770
+ editor,
771
+ selector: ({ editor: editor$1 }) => editor$1?.isActive({ alignment: "center" }) ?? false
772
+ }),
773
+ onCommand: () => setTextAlignment(editor, "center"),
774
+ className,
775
+ children: children ?? /* @__PURE__ */ jsx(AlignCenterIcon, {})
776
+ });
777
+ }
778
+
779
+ //#endregion
780
+ //#region src/ui/bubble-menu/align-left.tsx
781
+ function BubbleMenuAlignLeft({ className, children }) {
782
+ const { editor } = useBubbleMenuContext();
783
+ return /* @__PURE__ */ jsx(BubbleMenuItem, {
784
+ name: "align-left",
785
+ isActive: useEditorState({
786
+ editor,
787
+ selector: ({ editor: editor$1 }) => editor$1?.isActive({ alignment: "left" }) ?? false
788
+ }),
789
+ onCommand: () => setTextAlignment(editor, "left"),
790
+ className,
791
+ children: children ?? /* @__PURE__ */ jsx(AlignLeftIcon, {})
792
+ });
793
+ }
794
+
795
+ //#endregion
796
+ //#region src/ui/bubble-menu/align-right.tsx
797
+ function BubbleMenuAlignRight({ className, children }) {
798
+ const { editor } = useBubbleMenuContext();
799
+ return /* @__PURE__ */ jsx(BubbleMenuItem, {
800
+ name: "align-right",
801
+ isActive: useEditorState({
802
+ editor,
803
+ selector: ({ editor: editor$1 }) => editor$1?.isActive({ alignment: "right" }) ?? false
804
+ }),
805
+ onCommand: () => setTextAlignment(editor, "right"),
806
+ className,
807
+ children: children ?? /* @__PURE__ */ jsx(AlignRightIcon, {})
808
+ });
809
+ }
810
+
811
+ //#endregion
812
+ //#region src/ui/bubble-menu/create-mark-bubble-item.tsx
813
+ function createMarkBubbleItem(config) {
814
+ function MarkBubbleItem({ className, children }) {
815
+ const { editor } = useBubbleMenuContext();
816
+ const isActive = useEditorState({
817
+ editor,
818
+ selector: ({ editor: editor$1 }) => {
819
+ if (config.activeParams) return editor$1?.isActive(config.activeName, config.activeParams) ?? false;
820
+ return editor$1?.isActive(config.activeName) ?? false;
821
+ }
822
+ });
823
+ const handleCommand = () => {
824
+ const chain = editor.chain().focus();
825
+ const method = chain[config.command];
826
+ if (method) method.call(chain).run();
827
+ };
828
+ return /* @__PURE__ */ jsx(BubbleMenuItem, {
829
+ name: config.name,
830
+ isActive,
831
+ onCommand: handleCommand,
832
+ className,
833
+ children: children ?? config.icon
834
+ });
835
+ }
836
+ MarkBubbleItem.displayName = `BubbleMenu${config.name.charAt(0).toUpperCase() + config.name.slice(1)}`;
837
+ return MarkBubbleItem;
838
+ }
839
+
840
+ //#endregion
841
+ //#region src/ui/bubble-menu/bold.tsx
842
+ const BubbleMenuBold = createMarkBubbleItem({
843
+ name: "bold",
844
+ activeName: "bold",
845
+ command: "toggleBold",
846
+ icon: /* @__PURE__ */ jsx(BoldIcon, {})
847
+ });
848
+
849
+ //#endregion
850
+ //#region src/ui/bubble-menu/button-edit-link.tsx
851
+ function BubbleMenuButtonEditLink({ className, children, onClick, onMouseDown, ...rest }) {
852
+ const { setIsEditing } = useBubbleMenuContext();
853
+ return /* @__PURE__ */ jsx("button", {
854
+ ...rest,
855
+ type: "button",
856
+ "aria-label": "Edit link",
857
+ "data-re-btn-bm-item": "",
858
+ "data-item": "edit-link",
859
+ className,
860
+ onMouseDown: (e) => {
861
+ e.preventDefault();
862
+ onMouseDown?.(e);
863
+ },
864
+ onClick: (e) => {
865
+ onClick?.(e);
866
+ setIsEditing(true);
867
+ },
868
+ children: children ?? /* @__PURE__ */ jsx(PencilIcon, {})
869
+ });
870
+ }
871
+
872
+ //#endregion
873
+ //#region src/ui/bubble-menu/utils.ts
874
+ const SAFE_PROTOCOLS = new Set([
875
+ "http:",
876
+ "https:",
877
+ "mailto:",
878
+ "tel:"
879
+ ]);
880
+ /**
881
+ * Basic URL validation and auto-prefixing.
882
+ * Rejects dangerous schemes (javascript:, data:, vbscript:, etc.).
883
+ * Returns the valid URL string or null.
884
+ */
885
+ function getUrlFromString(str) {
886
+ if (str === "#") return str;
887
+ try {
888
+ const url = new URL(str);
889
+ if (SAFE_PROTOCOLS.has(url.protocol)) return str;
890
+ return null;
891
+ } catch {}
892
+ try {
893
+ if (str.includes(".") && !str.includes(" ")) return new URL(`https://${str}`).toString();
894
+ } catch {}
895
+ return null;
896
+ }
897
+ function setLinkHref(editor, href) {
898
+ if (href.length === 0) {
899
+ editor.chain().unsetLink().run();
900
+ return;
901
+ }
902
+ const { from, to } = editor.state.selection;
903
+ if (from === to) {
904
+ editor.chain().extendMarkRange("link").setLink({ href }).setTextSelection({
905
+ from,
906
+ to
907
+ }).run();
908
+ return;
909
+ }
910
+ editor.chain().setLink({ href }).run();
911
+ }
912
+ function focusEditor(editor) {
913
+ setTimeout(() => {
914
+ editor.commands.focus();
915
+ }, 0);
916
+ }
917
+
918
+ //#endregion
919
+ //#region src/ui/bubble-menu/button-form.tsx
920
+ function BubbleMenuButtonForm({ className, validateUrl, onLinkApply, onLinkRemove }) {
921
+ const { editor, isEditing, setIsEditing } = useBubbleMenuContext();
922
+ const inputRef = React$1.useRef(null);
923
+ const formRef = React$1.useRef(null);
924
+ const buttonHref = editor.getAttributes("button").href ?? "";
925
+ const displayHref = buttonHref === "#" ? "" : buttonHref;
926
+ const [inputValue, setInputValue] = React$1.useState(displayHref);
927
+ React$1.useEffect(() => {
928
+ if (!isEditing) return;
929
+ const currentHref = editor.getAttributes("button").href ?? "";
930
+ setInputValue(currentHref === "#" ? "" : currentHref);
931
+ const timeoutId = setTimeout(() => {
932
+ inputRef.current?.focus();
933
+ }, 0);
934
+ return () => clearTimeout(timeoutId);
935
+ }, [isEditing, editor]);
936
+ React$1.useEffect(() => {
937
+ if (!isEditing) return;
938
+ const handleKeyDown = (event) => {
939
+ if (event.key === "Escape") setIsEditing(false);
940
+ };
941
+ const handleClickOutside = (event) => {
942
+ if (formRef.current && !formRef.current.contains(event.target)) {
943
+ const form = formRef.current;
944
+ const submitEvent = new Event("submit", {
945
+ bubbles: true,
946
+ cancelable: true
947
+ });
948
+ form.dispatchEvent(submitEvent);
949
+ setIsEditing(false);
950
+ }
951
+ };
952
+ document.addEventListener("mousedown", handleClickOutside);
953
+ window.addEventListener("keydown", handleKeyDown);
954
+ return () => {
955
+ window.removeEventListener("keydown", handleKeyDown);
956
+ document.removeEventListener("mousedown", handleClickOutside);
957
+ };
958
+ }, [isEditing, setIsEditing]);
959
+ if (!isEditing) return null;
960
+ function handleSubmit(e) {
961
+ e.preventDefault();
962
+ const value = inputValue.trim();
963
+ if (value === "") {
964
+ editor.commands.updateButton({ href: "#" });
965
+ setIsEditing(false);
966
+ focusEditor(editor);
967
+ onLinkRemove?.();
968
+ return;
969
+ }
970
+ const finalValue = (validateUrl ?? getUrlFromString)(value);
971
+ if (!finalValue) {
972
+ editor.commands.updateButton({ href: "#" });
973
+ setIsEditing(false);
974
+ focusEditor(editor);
975
+ onLinkRemove?.();
976
+ return;
977
+ }
978
+ editor.commands.updateButton({ href: finalValue });
979
+ setIsEditing(false);
980
+ focusEditor(editor);
981
+ onLinkApply?.(finalValue);
982
+ }
983
+ function handleUnlink(e) {
984
+ e.stopPropagation();
985
+ editor.commands.updateButton({ href: "#" });
986
+ setIsEditing(false);
987
+ focusEditor(editor);
988
+ onLinkRemove?.();
989
+ }
990
+ return /* @__PURE__ */ jsxs("form", {
991
+ ref: formRef,
992
+ "data-re-btn-bm-form": "",
993
+ className,
994
+ onMouseDown: (e) => e.stopPropagation(),
995
+ onClick: (e) => e.stopPropagation(),
996
+ onKeyDown: (e) => e.stopPropagation(),
997
+ onSubmit: handleSubmit,
998
+ children: [/* @__PURE__ */ jsx("input", {
999
+ ref: inputRef,
1000
+ "data-re-btn-bm-input": "",
1001
+ value: inputValue,
1002
+ onFocus: (e) => e.stopPropagation(),
1003
+ onChange: (e) => setInputValue(e.target.value),
1004
+ placeholder: "Paste a link",
1005
+ type: "text"
1006
+ }), displayHref ? /* @__PURE__ */ jsx("button", {
1007
+ type: "button",
1008
+ "aria-label": "Remove link",
1009
+ "data-re-btn-bm-unlink": "",
1010
+ onClick: handleUnlink,
1011
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
1012
+ }) : /* @__PURE__ */ jsx("button", {
1013
+ type: "submit",
1014
+ "aria-label": "Apply link",
1015
+ "data-re-btn-bm-apply": "",
1016
+ onMouseDown: (e) => e.stopPropagation(),
1017
+ children: /* @__PURE__ */ jsx(CheckIcon, {})
1018
+ })]
1019
+ });
1020
+ }
1021
+
1022
+ //#endregion
1023
+ //#region src/ui/bubble-menu/button-toolbar.tsx
1024
+ function BubbleMenuButtonToolbar({ children, ...rest }) {
1025
+ const { isEditing } = useBubbleMenuContext();
1026
+ if (isEditing) return null;
1027
+ return /* @__PURE__ */ jsx("div", {
1028
+ "data-re-btn-bm-toolbar": "",
1029
+ ...rest,
1030
+ children
1031
+ });
1032
+ }
1033
+
1034
+ //#endregion
1035
+ //#region src/ui/bubble-menu/button-unlink.tsx
1036
+ function BubbleMenuButtonUnlink({ className, children, onClick, onMouseDown, onLinkRemove, ...rest }) {
1037
+ const { editor } = useBubbleMenuContext();
1038
+ return /* @__PURE__ */ jsx("button", {
1039
+ ...rest,
1040
+ type: "button",
1041
+ "aria-label": "Remove link",
1042
+ "data-re-btn-bm-item": "",
1043
+ "data-item": "unlink",
1044
+ className,
1045
+ onMouseDown: (e) => {
1046
+ e.preventDefault();
1047
+ onMouseDown?.(e);
1048
+ },
1049
+ onClick: (e) => {
1050
+ onClick?.(e);
1051
+ editor.commands.updateButton({ href: "#" });
1052
+ focusEditor(editor);
1053
+ onLinkRemove?.();
1054
+ },
1055
+ children: children ?? /* @__PURE__ */ jsx(UnlinkIcon, {})
1056
+ });
1057
+ }
1058
+
1059
+ //#endregion
1060
+ //#region src/ui/bubble-menu/code.tsx
1061
+ const BubbleMenuCode = createMarkBubbleItem({
1062
+ name: "code",
1063
+ activeName: "code",
1064
+ command: "toggleCode",
1065
+ icon: /* @__PURE__ */ jsx(CodeIcon, {})
1066
+ });
1067
+
1068
+ //#endregion
1069
+ //#region src/ui/bubble-menu/group.tsx
1070
+ function BubbleMenuItemGroup({ className, children }) {
1071
+ return /* @__PURE__ */ jsx("fieldset", {
1072
+ className,
1073
+ "data-re-bubble-menu-group": "",
1074
+ children
1075
+ });
1076
+ }
1077
+
1078
+ //#endregion
1079
+ //#region src/ui/bubble-menu/italic.tsx
1080
+ const BubbleMenuItalic = createMarkBubbleItem({
1081
+ name: "italic",
1082
+ activeName: "italic",
1083
+ command: "toggleItalic",
1084
+ icon: /* @__PURE__ */ jsx(ItalicIcon, {})
1085
+ });
1086
+
1087
+ //#endregion
1088
+ //#region src/ui/bubble-menu/link-selector.tsx
1089
+ function BubbleMenuLinkSelector({ className, showToggle = true, validateUrl, onLinkApply, onLinkRemove, children, open: controlledOpen, onOpenChange }) {
1090
+ const { editor } = useBubbleMenuContext();
1091
+ const [uncontrolledOpen, setUncontrolledOpen] = React$1.useState(false);
1092
+ const isControlled = controlledOpen !== void 0;
1093
+ const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
1094
+ const setIsOpen = React$1.useCallback((value) => {
1095
+ if (!isControlled) setUncontrolledOpen(value);
1096
+ onOpenChange?.(value);
1097
+ }, [isControlled, onOpenChange]);
1098
+ const editorState = useEditorState({
1099
+ editor,
1100
+ selector: ({ editor: editor$1 }) => ({
1101
+ isLinkActive: editor$1?.isActive("link") ?? false,
1102
+ hasLink: Boolean(editor$1?.getAttributes("link").href),
1103
+ currentHref: editor$1?.getAttributes("link").href || ""
1104
+ })
1105
+ });
1106
+ const setIsOpenRef = React$1.useRef(setIsOpen);
1107
+ setIsOpenRef.current = setIsOpen;
1108
+ React$1.useEffect(() => {
1109
+ const subscription = editorEventBus.on("bubble-menu:add-link", () => {
1110
+ setIsOpenRef.current(true);
1111
+ });
1112
+ return () => {
1113
+ setIsOpenRef.current(false);
1114
+ subscription.unsubscribe();
1115
+ };
1116
+ }, []);
1117
+ if (!editorState) return null;
1118
+ const handleOpenLink = () => {
1119
+ setIsOpen(!isOpen);
1120
+ };
1121
+ return /* @__PURE__ */ jsxs("div", {
1122
+ "data-re-link-selector": "",
1123
+ ...isOpen ? { "data-open": "" } : {},
1124
+ ...editorState.hasLink ? { "data-has-link": "" } : {},
1125
+ className,
1126
+ children: [showToggle && /* @__PURE__ */ jsx("button", {
1127
+ type: "button",
1128
+ "aria-expanded": isOpen,
1129
+ "aria-haspopup": "true",
1130
+ "aria-label": "Add link",
1131
+ "aria-pressed": editorState.isLinkActive && editorState.hasLink,
1132
+ "data-re-link-selector-trigger": "",
1133
+ onClick: handleOpenLink,
1134
+ children: /* @__PURE__ */ jsx(LinkIcon, {})
1135
+ }), isOpen && /* @__PURE__ */ jsx(LinkForm, {
1136
+ editor,
1137
+ currentHref: editorState.currentHref,
1138
+ validateUrl,
1139
+ onLinkApply,
1140
+ onLinkRemove,
1141
+ setIsOpen,
1142
+ children
1143
+ })]
1144
+ });
1145
+ }
1146
+ function LinkForm({ editor, currentHref, validateUrl, onLinkApply, onLinkRemove, setIsOpen, children }) {
1147
+ const inputRef = React$1.useRef(null);
1148
+ const formRef = React$1.useRef(null);
1149
+ const displayHref = currentHref === "#" ? "" : currentHref;
1150
+ const [inputValue, setInputValue] = React$1.useState(displayHref);
1151
+ React$1.useEffect(() => {
1152
+ const timeoutId = setTimeout(() => {
1153
+ inputRef.current?.focus();
1154
+ }, 0);
1155
+ return () => clearTimeout(timeoutId);
1156
+ }, []);
1157
+ React$1.useEffect(() => {
1158
+ const handleKeyDown = (event) => {
1159
+ if (event.key === "Escape") {
1160
+ if (editor.getAttributes("link").href === "#") editor.chain().unsetLink().run();
1161
+ setIsOpen(false);
1162
+ }
1163
+ };
1164
+ const handleClickOutside = (event) => {
1165
+ if (formRef.current && !formRef.current.contains(event.target)) {
1166
+ const form = formRef.current;
1167
+ const submitEvent = new Event("submit", {
1168
+ bubbles: true,
1169
+ cancelable: true
1170
+ });
1171
+ form.dispatchEvent(submitEvent);
1172
+ setIsOpen(false);
1173
+ }
1174
+ };
1175
+ document.addEventListener("mousedown", handleClickOutside);
1176
+ window.addEventListener("keydown", handleKeyDown);
1177
+ return () => {
1178
+ window.removeEventListener("keydown", handleKeyDown);
1179
+ document.removeEventListener("mousedown", handleClickOutside);
1180
+ };
1181
+ }, [editor, setIsOpen]);
1182
+ function handleSubmit(e) {
1183
+ e.preventDefault();
1184
+ const value = inputValue.trim();
1185
+ if (value === "") {
1186
+ setLinkHref(editor, "");
1187
+ setIsOpen(false);
1188
+ focusEditor(editor);
1189
+ onLinkRemove?.();
1190
+ return;
1191
+ }
1192
+ const finalValue = (validateUrl ?? getUrlFromString)(value);
1193
+ if (!finalValue) {
1194
+ setLinkHref(editor, "");
1195
+ setIsOpen(false);
1196
+ focusEditor(editor);
1197
+ onLinkRemove?.();
1198
+ return;
1199
+ }
1200
+ setLinkHref(editor, finalValue);
1201
+ setIsOpen(false);
1202
+ focusEditor(editor);
1203
+ onLinkApply?.(finalValue);
1204
+ }
1205
+ function handleUnlink(e) {
1206
+ e.stopPropagation();
1207
+ setLinkHref(editor, "");
1208
+ setIsOpen(false);
1209
+ focusEditor(editor);
1210
+ onLinkRemove?.();
1211
+ }
1212
+ return /* @__PURE__ */ jsxs("form", {
1213
+ ref: formRef,
1214
+ "data-re-link-selector-form": "",
1215
+ onMouseDown: (e) => e.stopPropagation(),
1216
+ onClick: (e) => e.stopPropagation(),
1217
+ onKeyDown: (e) => e.stopPropagation(),
1218
+ onSubmit: handleSubmit,
1219
+ children: [
1220
+ /* @__PURE__ */ jsx("input", {
1221
+ ref: inputRef,
1222
+ "data-re-link-selector-input": "",
1223
+ value: inputValue,
1224
+ onFocus: (e) => e.stopPropagation(),
1225
+ onChange: (e) => setInputValue(e.target.value),
1226
+ placeholder: "Paste a link",
1227
+ type: "text"
1228
+ }),
1229
+ children,
1230
+ displayHref ? /* @__PURE__ */ jsx("button", {
1231
+ type: "button",
1232
+ "aria-label": "Remove link",
1233
+ "data-re-link-selector-unlink": "",
1234
+ onClick: handleUnlink,
1235
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
1236
+ }) : /* @__PURE__ */ jsx("button", {
1237
+ type: "submit",
1238
+ "aria-label": "Apply link",
1239
+ "data-re-link-selector-apply": "",
1240
+ onMouseDown: (e) => e.stopPropagation(),
1241
+ children: /* @__PURE__ */ jsx(CheckIcon, {})
1242
+ })
1243
+ ]
1244
+ });
1245
+ }
1246
+
1247
+ //#endregion
1248
+ //#region src/ui/bubble-menu/node-selector.tsx
1249
+ const NodeSelectorContext = React$1.createContext(null);
1250
+ function useNodeSelectorContext() {
1251
+ const context = React$1.useContext(NodeSelectorContext);
1252
+ if (!context) throw new Error("NodeSelector compound components must be used within <NodeSelector.Root>");
1253
+ return context;
1254
+ }
1255
+ function NodeSelectorRoot({ omit = [], open: controlledOpen, onOpenChange, className, children }) {
1256
+ const { editor } = useBubbleMenuContext();
1257
+ const [uncontrolledOpen, setUncontrolledOpen] = React$1.useState(false);
1258
+ const isControlled = controlledOpen !== void 0;
1259
+ const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
1260
+ const setIsOpen = React$1.useCallback((value) => {
1261
+ if (!isControlled) setUncontrolledOpen(value);
1262
+ onOpenChange?.(value);
1263
+ }, [isControlled, onOpenChange]);
1264
+ const editorState = useEditorState({
1265
+ editor,
1266
+ selector: ({ editor: editor$1 }) => ({
1267
+ isParagraphActive: (editor$1?.isActive("paragraph") ?? false) && !editor$1?.isActive("bulletList") && !editor$1?.isActive("orderedList"),
1268
+ isHeading1Active: editor$1?.isActive("heading", { level: 1 }) ?? false,
1269
+ isHeading2Active: editor$1?.isActive("heading", { level: 2 }) ?? false,
1270
+ isHeading3Active: editor$1?.isActive("heading", { level: 3 }) ?? false,
1271
+ isBulletListActive: editor$1?.isActive("bulletList") ?? false,
1272
+ isOrderedListActive: editor$1?.isActive("orderedList") ?? false,
1273
+ isBlockquoteActive: editor$1?.isActive("blockquote") ?? false,
1274
+ isCodeBlockActive: editor$1?.isActive("codeBlock") ?? false
1275
+ })
1276
+ });
1277
+ const allItems = React$1.useMemo(() => [
1278
+ {
1279
+ name: "Text",
1280
+ icon: TextIcon,
1281
+ command: () => editor.chain().focus().clearNodes().toggleNode("paragraph", "paragraph").run(),
1282
+ isActive: editorState?.isParagraphActive ?? false
1283
+ },
1284
+ {
1285
+ name: "Title",
1286
+ icon: Heading1Icon,
1287
+ command: () => editor.chain().focus().clearNodes().toggleHeading({ level: 1 }).run(),
1288
+ isActive: editorState?.isHeading1Active ?? false
1289
+ },
1290
+ {
1291
+ name: "Subtitle",
1292
+ icon: Heading2Icon,
1293
+ command: () => editor.chain().focus().clearNodes().toggleHeading({ level: 2 }).run(),
1294
+ isActive: editorState?.isHeading2Active ?? false
1295
+ },
1296
+ {
1297
+ name: "Heading",
1298
+ icon: Heading3Icon,
1299
+ command: () => editor.chain().focus().clearNodes().toggleHeading({ level: 3 }).run(),
1300
+ isActive: editorState?.isHeading3Active ?? false
1301
+ },
1302
+ {
1303
+ name: "Bullet List",
1304
+ icon: ListIcon,
1305
+ command: () => editor.chain().focus().clearNodes().toggleBulletList().run(),
1306
+ isActive: editorState?.isBulletListActive ?? false
1307
+ },
1308
+ {
1309
+ name: "Numbered List",
1310
+ icon: ListOrderedIcon,
1311
+ command: () => editor.chain().focus().clearNodes().toggleOrderedList().run(),
1312
+ isActive: editorState?.isOrderedListActive ?? false
1313
+ },
1314
+ {
1315
+ name: "Quote",
1316
+ icon: TextQuoteIcon,
1317
+ command: () => editor.chain().focus().clearNodes().toggleNode("paragraph", "paragraph").toggleBlockquote().run(),
1318
+ isActive: editorState?.isBlockquoteActive ?? false
1319
+ },
1320
+ {
1321
+ name: "Code",
1322
+ icon: CodeIcon,
1323
+ command: () => editor.chain().focus().clearNodes().toggleCodeBlock().run(),
1324
+ isActive: editorState?.isCodeBlockActive ?? false
1325
+ }
1326
+ ], [editor, editorState]);
1327
+ const items = React$1.useMemo(() => allItems.filter((item) => !omit.includes(item.name)), [allItems, omit]);
1328
+ const activeItem = React$1.useMemo(() => items.find((item) => item.isActive) ?? { name: "Multiple" }, [items]);
1329
+ const contextValue = React$1.useMemo(() => ({
1330
+ items,
1331
+ activeItem,
1332
+ isOpen,
1333
+ setIsOpen
1334
+ }), [
1335
+ items,
1336
+ activeItem,
1337
+ isOpen,
1338
+ setIsOpen
1339
+ ]);
1340
+ if (!editorState || items.length === 0) return null;
1341
+ return /* @__PURE__ */ jsx(NodeSelectorContext.Provider, {
1342
+ value: contextValue,
1343
+ children: /* @__PURE__ */ jsx(Popover.Root, {
1344
+ open: isOpen,
1345
+ onOpenChange: setIsOpen,
1346
+ children: /* @__PURE__ */ jsx("div", {
1347
+ "data-re-node-selector": "",
1348
+ ...isOpen ? { "data-open": "" } : {},
1349
+ className,
1350
+ children
1351
+ })
1352
+ })
1353
+ });
1354
+ }
1355
+ function NodeSelectorTrigger({ className, children }) {
1356
+ const { activeItem, isOpen, setIsOpen } = useNodeSelectorContext();
1357
+ return /* @__PURE__ */ jsx(Popover.Trigger, {
1358
+ "data-re-node-selector-trigger": "",
1359
+ className,
1360
+ onClick: () => setIsOpen(!isOpen),
1361
+ children: children ?? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", { children: activeItem.name }), /* @__PURE__ */ jsx(ChevronDownIcon, {})] })
1362
+ });
1363
+ }
1364
+ function NodeSelectorContent({ className, align = "start", children }) {
1365
+ const { items, setIsOpen } = useNodeSelectorContext();
1366
+ return /* @__PURE__ */ jsx(Popover.Content, {
1367
+ align,
1368
+ "data-re-node-selector-content": "",
1369
+ className,
1370
+ children: children ? children(items, () => setIsOpen(false)) : items.map((item) => {
1371
+ const Icon = item.icon;
1372
+ return /* @__PURE__ */ jsxs("button", {
1373
+ type: "button",
1374
+ "data-re-node-selector-item": "",
1375
+ ...item.isActive ? { "data-active": "" } : {},
1376
+ onClick: () => {
1377
+ item.command();
1378
+ setIsOpen(false);
1379
+ },
1380
+ children: [
1381
+ /* @__PURE__ */ jsx(Icon, {}),
1382
+ /* @__PURE__ */ jsx("span", { children: item.name }),
1383
+ item.isActive && /* @__PURE__ */ jsx(CheckIcon, {})
1384
+ ]
1385
+ }, item.name);
1386
+ })
1387
+ });
1388
+ }
1389
+ function BubbleMenuNodeSelector({ omit = [], className, triggerContent, open, onOpenChange }) {
1390
+ return /* @__PURE__ */ jsxs(NodeSelectorRoot, {
1391
+ omit,
1392
+ open,
1393
+ onOpenChange,
1394
+ className,
1395
+ children: [/* @__PURE__ */ jsx(NodeSelectorTrigger, { children: triggerContent }), /* @__PURE__ */ jsx(NodeSelectorContent, {})]
1396
+ });
1397
+ }
1398
+
1399
+ //#endregion
1400
+ //#region src/ui/bubble-menu/strike.tsx
1401
+ const BubbleMenuStrike = createMarkBubbleItem({
1402
+ name: "strike",
1403
+ activeName: "strike",
1404
+ command: "toggleStrike",
1405
+ icon: /* @__PURE__ */ jsx(StrikethroughIcon, {})
1406
+ });
1407
+
1408
+ //#endregion
1409
+ //#region src/ui/bubble-menu/triggers.ts
1410
+ const bubbleMenuTriggers = {
1411
+ textSelection(hideWhenActiveNodes = [], hideWhenActiveMarks = []) {
1412
+ return ({ editor, state }) => {
1413
+ for (const node of hideWhenActiveNodes) {
1414
+ if (editor.isActive(node)) return false;
1415
+ const { $from } = state.selection;
1416
+ for (let d = $from.depth; d > 0; d--) if ($from.node(d).type.name === node) return false;
1417
+ }
1418
+ for (const mark of hideWhenActiveMarks) if (editor.isActive(mark)) return false;
1419
+ return editor.view.state.selection.content().size > 0;
1420
+ };
1421
+ },
1422
+ node(name) {
1423
+ return ({ editor }) => editor.isActive(name);
1424
+ },
1425
+ nodeWithoutSelection(name) {
1426
+ return ({ editor }) => editor.isActive(name) && editor.view.state.selection.content().size === 0;
1427
+ }
1428
+ };
1429
+
1430
+ //#endregion
1431
+ //#region src/ui/bubble-menu/underline.tsx
1432
+ const BubbleMenuUnderline = createMarkBubbleItem({
1433
+ name: "underline",
1434
+ activeName: "underline",
1435
+ command: "toggleUnderline",
1436
+ icon: /* @__PURE__ */ jsx(UnderlineIcon, {})
1437
+ });
1438
+
1439
+ //#endregion
1440
+ //#region src/ui/bubble-menu/uppercase.tsx
1441
+ const BubbleMenuUppercase = createMarkBubbleItem({
1442
+ name: "uppercase",
1443
+ activeName: "uppercase",
1444
+ command: "toggleUppercase",
1445
+ icon: /* @__PURE__ */ jsx(CaseUpperIcon, {})
1446
+ });
1447
+
1448
+ //#endregion
1449
+ //#region src/ui/bubble-menu/root.tsx
1450
+ const defaultPluginKey = new PluginKey("bubbleMenu");
1451
+ function Root({ trigger, pluginKey: pluginKey$1 = defaultPluginKey, hideWhenActiveNodes = [], hideWhenActiveMarks = [], placement = "bottom", offset: offset$1 = 8, onHide, className, children, ...rest }) {
1452
+ const { editor } = useCurrentEditor();
1453
+ const [isEditing, setIsEditing] = React$1.useState(false);
1454
+ const resolvedTrigger = trigger ?? bubbleMenuTriggers.textSelection(hideWhenActiveNodes, hideWhenActiveMarks);
1455
+ if (!editor) return null;
1456
+ return /* @__PURE__ */ jsx(BubbleMenu, {
1457
+ editor,
1458
+ pluginKey: pluginKey$1,
1459
+ "data-re-bubble-menu": "",
1460
+ shouldShow: resolvedTrigger,
1461
+ options: {
1462
+ placement,
1463
+ offset: offset$1,
1464
+ onHide: () => {
1465
+ setIsEditing(false);
1466
+ onHide?.();
1467
+ }
1468
+ },
1469
+ className,
1470
+ ...rest,
1471
+ children: /* @__PURE__ */ jsx(BubbleMenuContext.Provider, {
1472
+ value: {
1473
+ editor,
1474
+ isEditing,
1475
+ setIsEditing
1476
+ },
1477
+ children
1478
+ })
1479
+ });
1480
+ }
1481
+ const textPluginKey = new PluginKey("textBubbleMenu");
1482
+ function Default({ hideWhenActiveNodes, hideWhenActiveMarks, placement, offset: offset$1, onHide, className, ...rest }) {
1483
+ const [isNodeSelectorOpen, setIsNodeSelectorOpen] = React$1.useState(false);
1484
+ const [isLinkSelectorOpen, setIsLinkSelectorOpen] = React$1.useState(false);
1485
+ const handleNodeSelectorOpenChange = React$1.useCallback((open) => {
1486
+ setIsNodeSelectorOpen(open);
1487
+ if (open) setIsLinkSelectorOpen(false);
1488
+ }, []);
1489
+ const handleLinkSelectorOpenChange = React$1.useCallback((open) => {
1490
+ setIsLinkSelectorOpen(open);
1491
+ if (open) setIsNodeSelectorOpen(false);
1492
+ }, []);
1493
+ return /* @__PURE__ */ jsxs(Root, {
1494
+ pluginKey: textPluginKey,
1495
+ hideWhenActiveNodes,
1496
+ hideWhenActiveMarks,
1497
+ placement,
1498
+ offset: offset$1,
1499
+ onHide: React$1.useCallback(() => {
1500
+ setIsNodeSelectorOpen(false);
1501
+ setIsLinkSelectorOpen(false);
1502
+ onHide?.();
1503
+ }, [onHide]),
1504
+ className,
1505
+ ...rest,
1506
+ children: [
1507
+ /* @__PURE__ */ jsx(BubbleMenuNodeSelector, {
1508
+ open: isNodeSelectorOpen,
1509
+ onOpenChange: handleNodeSelectorOpenChange
1510
+ }),
1511
+ /* @__PURE__ */ jsx(BubbleMenuLinkSelector, {
1512
+ open: isLinkSelectorOpen,
1513
+ onOpenChange: handleLinkSelectorOpenChange
1514
+ }),
1515
+ /* @__PURE__ */ jsxs(BubbleMenuItemGroup, { children: [
1516
+ /* @__PURE__ */ jsx(BubbleMenuBold, {}),
1517
+ /* @__PURE__ */ jsx(BubbleMenuItalic, {}),
1518
+ /* @__PURE__ */ jsx(BubbleMenuUnderline, {}),
1519
+ /* @__PURE__ */ jsx(BubbleMenuStrike, {}),
1520
+ /* @__PURE__ */ jsx(BubbleMenuCode, {}),
1521
+ /* @__PURE__ */ jsx(BubbleMenuUppercase, {})
1522
+ ] }),
1523
+ /* @__PURE__ */ jsxs(BubbleMenuItemGroup, { children: [
1524
+ /* @__PURE__ */ jsx(BubbleMenuAlignLeft, {}),
1525
+ /* @__PURE__ */ jsx(BubbleMenuAlignCenter, {}),
1526
+ /* @__PURE__ */ jsx(BubbleMenuAlignRight, {})
1527
+ ] })
1528
+ ]
1529
+ });
1530
+ }
1531
+ function RootWithDefault({ children, ...rest }) {
1532
+ if (children) return /* @__PURE__ */ jsx(Root, {
1533
+ ...rest,
1534
+ children
1535
+ });
1536
+ return /* @__PURE__ */ jsx(Default, { ...rest });
1537
+ }
1538
+
1539
+ //#endregion
1540
+ //#region src/ui/bubble-menu/button-default.tsx
1541
+ const buttonPluginKey = new PluginKey("buttonBubbleMenu");
1542
+ function BubbleMenuButtonDefaultInner({ validateUrl, onLinkApply, onLinkRemove }) {
1543
+ const { editor } = useBubbleMenuContext();
1544
+ const buttonHref = useEditorState({
1545
+ editor,
1546
+ selector: ({ editor: e }) => e?.getAttributes("button").href ?? ""
1547
+ });
1548
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(BubbleMenuButtonToolbar, { children: [/* @__PURE__ */ jsx(BubbleMenuButtonEditLink, {}), (buttonHref ?? "") !== "" && buttonHref !== "#" && /* @__PURE__ */ jsx(BubbleMenuButtonUnlink, { onLinkRemove })] }), /* @__PURE__ */ jsx(BubbleMenuButtonForm, {
1549
+ validateUrl,
1550
+ onLinkApply,
1551
+ onLinkRemove
1552
+ })] });
1553
+ }
1554
+ function BubbleMenuButtonDefault({ placement = "top", offset: offset$1, onHide, className, validateUrl, onLinkApply, onLinkRemove, ...rest }) {
1555
+ return /* @__PURE__ */ jsx(RootWithDefault, {
1556
+ trigger: bubbleMenuTriggers.node("button"),
1557
+ pluginKey: buttonPluginKey,
1558
+ placement,
1559
+ offset: offset$1,
1560
+ onHide,
1561
+ className,
1562
+ ...rest,
1563
+ children: /* @__PURE__ */ jsx(BubbleMenuButtonDefaultInner, {
1564
+ validateUrl,
1565
+ onLinkApply,
1566
+ onLinkRemove
1567
+ })
1568
+ });
1569
+ }
1570
+
1571
+ //#endregion
1572
+ //#region src/ui/bubble-menu/image-edit-link.tsx
1573
+ function BubbleMenuImageEditLink({ className, children, onClick, onMouseDown, ...rest }) {
1574
+ const { setIsEditing } = useBubbleMenuContext();
1575
+ return /* @__PURE__ */ jsx("button", {
1576
+ ...rest,
1577
+ type: "button",
1578
+ "aria-label": "Edit link",
1579
+ "data-re-img-bm-item": "",
1580
+ "data-item": "edit-link",
1581
+ className,
1582
+ onMouseDown: (e) => {
1583
+ e.preventDefault();
1584
+ onMouseDown?.(e);
1585
+ },
1586
+ onClick: (e) => {
1587
+ onClick?.(e);
1588
+ setIsEditing(true);
1589
+ },
1590
+ children: children ?? /* @__PURE__ */ jsx(LinkIcon, {})
1591
+ });
1592
+ }
1593
+
1594
+ //#endregion
1595
+ //#region src/ui/bubble-menu/image-toolbar.tsx
1596
+ function BubbleMenuImageToolbar({ children, ...rest }) {
1597
+ const { isEditing } = useBubbleMenuContext();
1598
+ if (isEditing) return null;
1599
+ return /* @__PURE__ */ jsx("div", {
1600
+ "data-re-img-bm-toolbar": "",
1601
+ ...rest,
1602
+ children
1603
+ });
1604
+ }
1605
+
1606
+ //#endregion
1607
+ //#region src/ui/bubble-menu/image-default.tsx
1608
+ const imagePluginKey = new PluginKey("imageBubbleMenu");
1609
+ function BubbleMenuImageDefault({ excludeItems = [], placement = "top", offset: offset$1, onHide, className, ...rest }) {
1610
+ const hasEditLink = !excludeItems.includes("edit-link");
1611
+ return /* @__PURE__ */ jsx(RootWithDefault, {
1612
+ trigger: bubbleMenuTriggers.node("image"),
1613
+ pluginKey: imagePluginKey,
1614
+ placement,
1615
+ offset: offset$1,
1616
+ onHide,
1617
+ className,
1618
+ ...rest,
1619
+ children: hasEditLink && /* @__PURE__ */ jsx(BubbleMenuImageToolbar, { children: /* @__PURE__ */ jsx(BubbleMenuImageEditLink, {}) })
1620
+ });
1621
+ }
1622
+
1623
+ //#endregion
1624
+ //#region src/ui/bubble-menu/link-edit-link.tsx
1625
+ function BubbleMenuLinkEditLink({ className, children, onClick, onMouseDown, ...rest }) {
1626
+ const { setIsEditing } = useBubbleMenuContext();
1627
+ return /* @__PURE__ */ jsx("button", {
1628
+ type: "button",
1629
+ "aria-label": "Edit link",
1630
+ "data-re-link-bm-item": "",
1631
+ "data-item": "edit-link",
1632
+ className,
1633
+ onMouseDown: (e) => {
1634
+ e.preventDefault();
1635
+ onMouseDown?.(e);
1636
+ },
1637
+ onClick: (e) => {
1638
+ onClick?.(e);
1639
+ setIsEditing(true);
1640
+ },
1641
+ ...rest,
1642
+ children: children ?? /* @__PURE__ */ jsx(PencilIcon, {})
1643
+ });
1644
+ }
1645
+
1646
+ //#endregion
1647
+ //#region src/ui/bubble-menu/link-form.tsx
1648
+ function BubbleMenuLinkForm({ className, validateUrl, onLinkApply, onLinkRemove, children }) {
1649
+ const { editor, isEditing, setIsEditing } = useBubbleMenuContext();
1650
+ const inputRef = React$1.useRef(null);
1651
+ const formRef = React$1.useRef(null);
1652
+ const linkHref = useEditorState({
1653
+ editor,
1654
+ selector: ({ editor: e }) => e?.getAttributes("link").href ?? ""
1655
+ });
1656
+ const displayHref = (linkHref ?? "") === "#" ? "" : linkHref ?? "";
1657
+ const [inputValue, setInputValue] = React$1.useState(displayHref);
1658
+ React$1.useEffect(() => {
1659
+ if (!isEditing) return;
1660
+ setInputValue(displayHref);
1661
+ const timeoutId = setTimeout(() => {
1662
+ inputRef.current?.focus();
1663
+ }, 0);
1664
+ return () => clearTimeout(timeoutId);
1665
+ }, [isEditing, displayHref]);
1666
+ React$1.useEffect(() => {
1667
+ if (!isEditing) return;
1668
+ const handleKeyDown = (event) => {
1669
+ if (event.key === "Escape") setIsEditing(false);
1670
+ };
1671
+ const handleClickOutside = (event) => {
1672
+ if (formRef.current && !formRef.current.contains(event.target)) {
1673
+ const form = formRef.current;
1674
+ const submitEvent = new Event("submit", {
1675
+ bubbles: true,
1676
+ cancelable: true
1677
+ });
1678
+ form.dispatchEvent(submitEvent);
1679
+ setIsEditing(false);
1680
+ }
1681
+ };
1682
+ document.addEventListener("mousedown", handleClickOutside);
1683
+ window.addEventListener("keydown", handleKeyDown);
1684
+ return () => {
1685
+ window.removeEventListener("keydown", handleKeyDown);
1686
+ document.removeEventListener("mousedown", handleClickOutside);
1687
+ };
1688
+ }, [isEditing, setIsEditing]);
1689
+ if (!isEditing) return null;
1690
+ function handleSubmit(e) {
1691
+ e.preventDefault();
1692
+ const value = inputValue.trim();
1693
+ if (value === "") {
1694
+ setLinkHref(editor, "");
1695
+ setIsEditing(false);
1696
+ focusEditor(editor);
1697
+ onLinkRemove?.();
1698
+ return;
1699
+ }
1700
+ const finalValue = (validateUrl ?? getUrlFromString)(value);
1701
+ if (!finalValue) {
1702
+ setLinkHref(editor, "");
1703
+ setIsEditing(false);
1704
+ focusEditor(editor);
1705
+ onLinkRemove?.();
1706
+ return;
1707
+ }
1708
+ setLinkHref(editor, finalValue);
1709
+ setIsEditing(false);
1710
+ focusEditor(editor);
1711
+ onLinkApply?.(finalValue);
1712
+ }
1713
+ function handleUnlink(e) {
1714
+ e.stopPropagation();
1715
+ setLinkHref(editor, "");
1716
+ setIsEditing(false);
1717
+ focusEditor(editor);
1718
+ onLinkRemove?.();
1719
+ }
1720
+ return /* @__PURE__ */ jsxs("form", {
1721
+ ref: formRef,
1722
+ "data-re-link-bm-form": "",
1723
+ className,
1724
+ onMouseDown: (e) => e.stopPropagation(),
1725
+ onClick: (e) => e.stopPropagation(),
1726
+ onKeyDown: (e) => e.stopPropagation(),
1727
+ onSubmit: handleSubmit,
1728
+ children: [
1729
+ /* @__PURE__ */ jsx("input", {
1730
+ ref: inputRef,
1731
+ "data-re-link-bm-input": "",
1732
+ value: inputValue,
1733
+ onFocus: (e) => e.stopPropagation(),
1734
+ onChange: (e) => setInputValue(e.target.value),
1735
+ placeholder: "Paste a link",
1736
+ type: "text"
1737
+ }),
1738
+ children,
1739
+ displayHref ? /* @__PURE__ */ jsx("button", {
1740
+ type: "button",
1741
+ "aria-label": "Remove link",
1742
+ "data-re-link-bm-unlink": "",
1743
+ onClick: handleUnlink,
1744
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
1745
+ }) : /* @__PURE__ */ jsx("button", {
1746
+ type: "submit",
1747
+ "aria-label": "Apply link",
1748
+ "data-re-link-bm-apply": "",
1749
+ onMouseDown: (e) => e.stopPropagation(),
1750
+ children: /* @__PURE__ */ jsx(CheckIcon, {})
1751
+ })
1752
+ ]
1753
+ });
1754
+ }
1755
+
1756
+ //#endregion
1757
+ //#region src/ui/bubble-menu/link-open-link.tsx
1758
+ function BubbleMenuLinkOpenLink({ className, children, ...rest }) {
1759
+ const { editor } = useBubbleMenuContext();
1760
+ const linkHref = useEditorState({
1761
+ editor,
1762
+ selector: ({ editor: e }) => e?.getAttributes("link").href ?? ""
1763
+ });
1764
+ return /* @__PURE__ */ jsx("a", {
1765
+ ...rest,
1766
+ href: linkHref ?? "",
1767
+ target: "_blank",
1768
+ rel: "noopener noreferrer",
1769
+ "aria-label": "Open link",
1770
+ "data-re-link-bm-item": "",
1771
+ "data-item": "open-link",
1772
+ className,
1773
+ children: children ?? /* @__PURE__ */ jsx(ExternalLinkIcon, {})
1774
+ });
1775
+ }
1776
+
1777
+ //#endregion
1778
+ //#region src/ui/bubble-menu/link-toolbar.tsx
1779
+ function BubbleMenuLinkToolbar({ children, ...rest }) {
1780
+ const { isEditing } = useBubbleMenuContext();
1781
+ if (isEditing) return null;
1782
+ return /* @__PURE__ */ jsx("div", {
1783
+ "data-re-link-bm-toolbar": "",
1784
+ ...rest,
1785
+ children
1786
+ });
1787
+ }
1788
+
1789
+ //#endregion
1790
+ //#region src/ui/bubble-menu/link-unlink.tsx
1791
+ function BubbleMenuLinkUnlink({ className, children, onClick, onMouseDown, ...rest }) {
1792
+ const { editor } = useBubbleMenuContext();
1793
+ return /* @__PURE__ */ jsx("button", {
1794
+ type: "button",
1795
+ "aria-label": "Remove link",
1796
+ "data-re-link-bm-item": "",
1797
+ "data-item": "unlink",
1798
+ className,
1799
+ onMouseDown: (e) => {
1800
+ e.preventDefault();
1801
+ onMouseDown?.(e);
1802
+ },
1803
+ onClick: (e) => {
1804
+ onClick?.(e);
1805
+ editor.chain().focus().unsetLink().run();
1806
+ },
1807
+ ...rest,
1808
+ children: children ?? /* @__PURE__ */ jsx(UnlinkIcon, {})
1809
+ });
1810
+ }
1811
+
1812
+ //#endregion
1813
+ //#region src/ui/bubble-menu/link-default.tsx
1814
+ const linkPluginKey = new PluginKey("linkBubbleMenu");
1815
+ function BubbleMenuLinkDefault({ excludeItems = [], placement = "top", offset: offset$1, onHide, className, validateUrl, onLinkApply, onLinkRemove, ...rest }) {
1816
+ const has = (item) => !excludeItems.includes(item);
1817
+ const hasToolbarItems = has("edit-link") || has("open-link") || has("unlink");
1818
+ return /* @__PURE__ */ jsxs(RootWithDefault, {
1819
+ trigger: bubbleMenuTriggers.nodeWithoutSelection("link"),
1820
+ pluginKey: linkPluginKey,
1821
+ placement,
1822
+ offset: offset$1,
1823
+ onHide,
1824
+ className,
1825
+ ...rest,
1826
+ children: [hasToolbarItems && /* @__PURE__ */ jsxs(BubbleMenuLinkToolbar, { children: [
1827
+ has("edit-link") && /* @__PURE__ */ jsx(BubbleMenuLinkEditLink, {}),
1828
+ has("open-link") && /* @__PURE__ */ jsx(BubbleMenuLinkOpenLink, {}),
1829
+ has("unlink") && /* @__PURE__ */ jsx(BubbleMenuLinkUnlink, {})
1830
+ ] }), /* @__PURE__ */ jsx(BubbleMenuLinkForm, {
1831
+ validateUrl,
1832
+ onLinkApply,
1833
+ onLinkRemove
1834
+ })]
1835
+ });
1836
+ }
1837
+
1838
+ //#endregion
1839
+ //#region src/ui/bubble-menu/separator.tsx
1840
+ function BubbleMenuSeparator({ className }) {
1841
+ return /* @__PURE__ */ jsx("hr", {
1842
+ className,
1843
+ "data-re-bubble-menu-separator": ""
1844
+ });
1845
+ }
1846
+
1847
+ //#endregion
1848
+ //#region src/ui/bubble-menu/index.ts
1849
+ const BubbleMenu$1 = Object.assign(RootWithDefault, {
1850
+ Root: RootWithDefault,
1851
+ ItemGroup: BubbleMenuItemGroup,
1852
+ Separator: BubbleMenuSeparator,
1853
+ Item: BubbleMenuItem,
1854
+ Bold: BubbleMenuBold,
1855
+ Italic: BubbleMenuItalic,
1856
+ Underline: BubbleMenuUnderline,
1857
+ Strike: BubbleMenuStrike,
1858
+ Code: BubbleMenuCode,
1859
+ Uppercase: BubbleMenuUppercase,
1860
+ AlignLeft: BubbleMenuAlignLeft,
1861
+ AlignCenter: BubbleMenuAlignCenter,
1862
+ AlignRight: BubbleMenuAlignRight,
1863
+ NodeSelector: Object.assign(BubbleMenuNodeSelector, {
1864
+ Root: NodeSelectorRoot,
1865
+ Trigger: NodeSelectorTrigger,
1866
+ Content: NodeSelectorContent
1867
+ }),
1868
+ LinkSelector: BubbleMenuLinkSelector,
1869
+ ButtonToolbar: BubbleMenuButtonToolbar,
1870
+ ButtonEditLink: BubbleMenuButtonEditLink,
1871
+ ButtonUnlink: BubbleMenuButtonUnlink,
1872
+ ButtonForm: BubbleMenuButtonForm,
1873
+ ButtonDefault: BubbleMenuButtonDefault,
1874
+ LinkToolbar: BubbleMenuLinkToolbar,
1875
+ LinkEditLink: BubbleMenuLinkEditLink,
1876
+ LinkUnlink: BubbleMenuLinkUnlink,
1877
+ LinkOpenLink: BubbleMenuLinkOpenLink,
1878
+ LinkForm: BubbleMenuLinkForm,
1879
+ LinkDefault: BubbleMenuLinkDefault,
1880
+ ImageToolbar: BubbleMenuImageToolbar,
1881
+ ImageEditLink: BubbleMenuImageEditLink,
1882
+ ImageDefault: BubbleMenuImageDefault
1883
+ });
1884
+
1885
+ //#endregion
1886
+ //#region src/ui/slash-command/utils.ts
1887
+ function isInsideNode(editor, type) {
1888
+ const { $from } = editor.state.selection;
1889
+ for (let d = $from.depth; d > 0; d--) if ($from.node(d).type.name === type) return true;
1890
+ return false;
1891
+ }
1892
+ function isAtMaxColumnsDepth(editor) {
1893
+ const { from } = editor.state.selection;
1894
+ return getColumnsDepth(editor.state.doc, from) >= MAX_COLUMNS_DEPTH;
1895
+ }
1896
+ function updateScrollView(container, item) {
1897
+ const containerRect = container.getBoundingClientRect();
1898
+ const itemRect = item.getBoundingClientRect();
1899
+ if (itemRect.top < containerRect.top) container.scrollTop -= containerRect.top - itemRect.top;
1900
+ else if (itemRect.bottom > containerRect.bottom) container.scrollTop += itemRect.bottom - containerRect.bottom;
1901
+ }
1902
+
1903
+ //#endregion
1904
+ //#region src/ui/slash-command/command-list.tsx
1905
+ const CATEGORY_ORDER = [
1906
+ "Text",
1907
+ "Media",
1908
+ "Layout",
1909
+ "Utility"
1910
+ ];
1911
+ function groupByCategory(items) {
1912
+ const seen = /* @__PURE__ */ new Map();
1913
+ for (const item of items) {
1914
+ const existing = seen.get(item.category);
1915
+ if (existing) existing.push(item);
1916
+ else seen.set(item.category, [item]);
1917
+ }
1918
+ const ordered = [];
1919
+ for (const cat of CATEGORY_ORDER) {
1920
+ const group = seen.get(cat);
1921
+ if (group) {
1922
+ ordered.push({
1923
+ category: cat,
1924
+ items: group
1925
+ });
1926
+ seen.delete(cat);
1927
+ }
1928
+ }
1929
+ for (const [category, group] of seen) ordered.push({
1930
+ category,
1931
+ items: group
1932
+ });
1933
+ return ordered;
1934
+ }
1935
+ function CommandItem({ item, selected, onSelect }) {
1936
+ return /* @__PURE__ */ jsxs("button", {
1937
+ "data-re-slash-command-item": "",
1938
+ "data-selected": selected || void 0,
1939
+ onClick: onSelect,
1940
+ type: "button",
1941
+ children: [item.icon, /* @__PURE__ */ jsx("span", { children: item.title })]
1942
+ });
1943
+ }
1944
+ function CommandList({ items, query, selectedIndex, onSelect }) {
1945
+ const containerRef = useRef(null);
1946
+ useLayoutEffect(() => {
1947
+ const container = containerRef.current;
1948
+ if (!container) return;
1949
+ const selected = container.querySelector("[data-selected]");
1950
+ if (selected) updateScrollView(container, selected);
1951
+ }, [selectedIndex]);
1952
+ if (items.length === 0) return /* @__PURE__ */ jsx("div", {
1953
+ "data-re-slash-command": "",
1954
+ children: /* @__PURE__ */ jsx("div", {
1955
+ "data-re-slash-command-empty": "",
1956
+ children: "No results"
1957
+ })
1958
+ });
1959
+ if (query.trim().length > 0) return /* @__PURE__ */ jsx("div", {
1960
+ "data-re-slash-command": "",
1961
+ ref: containerRef,
1962
+ children: items.map((item, index) => /* @__PURE__ */ jsx(CommandItem, {
1963
+ item,
1964
+ onSelect: () => onSelect(index),
1965
+ selected: index === selectedIndex
1966
+ }, item.title))
1967
+ });
1968
+ const groups = groupByCategory(items);
1969
+ let flatIndex = 0;
1970
+ return /* @__PURE__ */ jsx("div", {
1971
+ "data-re-slash-command": "",
1972
+ ref: containerRef,
1973
+ children: groups.map((group) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
1974
+ "data-re-slash-command-category": "",
1975
+ children: group.category
1976
+ }), group.items.map((item) => {
1977
+ const currentIndex = flatIndex++;
1978
+ return /* @__PURE__ */ jsx(CommandItem, {
1979
+ item,
1980
+ onSelect: () => onSelect(currentIndex),
1981
+ selected: currentIndex === selectedIndex
1982
+ }, item.title);
1983
+ })] }, group.category))
1984
+ });
1985
+ }
1986
+
1987
+ //#endregion
1988
+ //#region src/ui/slash-command/commands.tsx
1989
+ const TEXT = {
1990
+ title: "Text",
1991
+ description: "Plain text block",
1992
+ icon: /* @__PURE__ */ jsx(TextIcon, { size: 20 }),
1993
+ category: "Text",
1994
+ searchTerms: ["p", "paragraph"],
1995
+ command: ({ editor, range }) => {
1996
+ editor.chain().focus().deleteRange(range).toggleNode("paragraph", "paragraph").run();
1997
+ }
1998
+ };
1999
+ const H1 = {
2000
+ title: "Title",
2001
+ description: "Large heading",
2002
+ icon: /* @__PURE__ */ jsx(Heading1Icon, { size: 20 }),
2003
+ category: "Text",
2004
+ searchTerms: [
2005
+ "title",
2006
+ "big",
2007
+ "large",
2008
+ "h1"
2009
+ ],
2010
+ command: ({ editor, range }) => {
2011
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 1 }).run();
2012
+ }
2013
+ };
2014
+ const H2 = {
2015
+ title: "Subtitle",
2016
+ description: "Medium heading",
2017
+ icon: /* @__PURE__ */ jsx(Heading2Icon, { size: 20 }),
2018
+ category: "Text",
2019
+ searchTerms: [
2020
+ "subtitle",
2021
+ "medium",
2022
+ "h2"
2023
+ ],
2024
+ command: ({ editor, range }) => {
2025
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 2 }).run();
2026
+ }
2027
+ };
2028
+ const H3 = {
2029
+ title: "Heading",
2030
+ description: "Small heading",
2031
+ icon: /* @__PURE__ */ jsx(Heading3Icon, { size: 20 }),
2032
+ category: "Text",
2033
+ searchTerms: [
2034
+ "subtitle",
2035
+ "small",
2036
+ "h3"
2037
+ ],
2038
+ command: ({ editor, range }) => {
2039
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 3 }).run();
2040
+ }
2041
+ };
2042
+ const BULLET_LIST = {
2043
+ title: "Bullet list",
2044
+ description: "Unordered list",
2045
+ icon: /* @__PURE__ */ jsx(ListIcon, { size: 20 }),
2046
+ category: "Text",
2047
+ searchTerms: ["unordered", "point"],
2048
+ command: ({ editor, range }) => {
2049
+ editor.chain().focus().deleteRange(range).toggleBulletList().run();
2050
+ }
2051
+ };
2052
+ const NUMBERED_LIST = {
2053
+ title: "Numbered list",
2054
+ description: "Ordered list",
2055
+ icon: /* @__PURE__ */ jsx(ListOrderedIcon, { size: 20 }),
2056
+ category: "Text",
2057
+ searchTerms: ["ordered"],
2058
+ command: ({ editor, range }) => {
2059
+ editor.chain().focus().deleteRange(range).toggleOrderedList().run();
2060
+ }
2061
+ };
2062
+ const QUOTE = {
2063
+ title: "Quote",
2064
+ description: "Block quote",
2065
+ icon: /* @__PURE__ */ jsx(TextQuoteIcon, { size: 20 }),
2066
+ category: "Text",
2067
+ searchTerms: ["blockquote"],
2068
+ command: ({ editor, range }) => {
2069
+ editor.chain().focus().deleteRange(range).toggleNode("paragraph", "paragraph").toggleBlockquote().run();
2070
+ }
2071
+ };
2072
+ const CODE = {
2073
+ title: "Code block",
2074
+ description: "Code snippet",
2075
+ icon: /* @__PURE__ */ jsx(SquareCodeIcon, { size: 20 }),
2076
+ category: "Text",
2077
+ searchTerms: ["codeblock"],
2078
+ command: ({ editor, range }) => {
2079
+ editor.chain().focus().deleteRange(range).toggleCodeBlock().run();
2080
+ }
2081
+ };
2082
+ const BUTTON = {
2083
+ title: "Button",
2084
+ description: "Clickable button",
2085
+ icon: /* @__PURE__ */ jsx(MousePointerIcon, { size: 20 }),
2086
+ category: "Layout",
2087
+ searchTerms: ["button"],
2088
+ command: ({ editor, range }) => {
2089
+ editor.chain().focus().deleteRange(range).setButton().run();
2090
+ }
2091
+ };
2092
+ const DIVIDER = {
2093
+ title: "Divider",
2094
+ description: "Horizontal separator",
2095
+ icon: /* @__PURE__ */ jsx(SplitSquareVerticalIcon, { size: 20 }),
2096
+ category: "Layout",
2097
+ searchTerms: [
2098
+ "hr",
2099
+ "divider",
2100
+ "separator"
2101
+ ],
2102
+ command: ({ editor, range }) => {
2103
+ editor.chain().focus().deleteRange(range).setHorizontalRule().run();
2104
+ }
2105
+ };
2106
+ const SECTION = {
2107
+ title: "Section",
2108
+ description: "Content section",
2109
+ icon: /* @__PURE__ */ jsx(Rows2Icon, { size: 20 }),
2110
+ category: "Layout",
2111
+ searchTerms: [
2112
+ "section",
2113
+ "row",
2114
+ "container"
2115
+ ],
2116
+ command: ({ editor, range }) => {
2117
+ editor.chain().focus().deleteRange(range).insertSection().run();
2118
+ }
2119
+ };
2120
+ const TWO_COLUMNS = {
2121
+ title: "2 columns",
2122
+ description: "Two column layout",
2123
+ icon: /* @__PURE__ */ jsx(Columns2Icon, { size: 20 }),
2124
+ category: "Layout",
2125
+ searchTerms: [
2126
+ "columns",
2127
+ "column",
2128
+ "layout",
2129
+ "grid",
2130
+ "split",
2131
+ "side-by-side",
2132
+ "multi-column",
2133
+ "row",
2134
+ "two",
2135
+ "2"
2136
+ ],
2137
+ command: ({ editor, range }) => {
2138
+ editor.chain().focus().deleteRange(range).insertColumns(2).run();
2139
+ }
2140
+ };
2141
+ const THREE_COLUMNS = {
2142
+ title: "3 columns",
2143
+ description: "Three column layout",
2144
+ icon: /* @__PURE__ */ jsx(Columns3Icon, { size: 20 }),
2145
+ category: "Layout",
2146
+ searchTerms: [
2147
+ "columns",
2148
+ "column",
2149
+ "layout",
2150
+ "grid",
2151
+ "split",
2152
+ "multi-column",
2153
+ "row",
2154
+ "three",
2155
+ "3"
2156
+ ],
2157
+ command: ({ editor, range }) => {
2158
+ editor.chain().focus().deleteRange(range).insertColumns(3).run();
2159
+ }
2160
+ };
2161
+ const FOUR_COLUMNS = {
2162
+ title: "4 columns",
2163
+ description: "Four column layout",
2164
+ icon: /* @__PURE__ */ jsx(Columns4Icon, { size: 20 }),
2165
+ category: "Layout",
2166
+ searchTerms: [
2167
+ "columns",
2168
+ "column",
2169
+ "layout",
2170
+ "grid",
2171
+ "split",
2172
+ "multi-column",
2173
+ "row",
2174
+ "four",
2175
+ "4"
2176
+ ],
2177
+ command: ({ editor, range }) => {
2178
+ editor.chain().focus().deleteRange(range).insertColumns(4).run();
2179
+ }
2180
+ };
2181
+ const defaultSlashCommands = [
2182
+ TEXT,
2183
+ H1,
2184
+ H2,
2185
+ H3,
2186
+ BULLET_LIST,
2187
+ NUMBERED_LIST,
2188
+ QUOTE,
2189
+ CODE,
2190
+ BUTTON,
2191
+ DIVIDER,
2192
+ SECTION,
2193
+ TWO_COLUMNS,
2194
+ THREE_COLUMNS,
2195
+ FOUR_COLUMNS
2196
+ ];
2197
+
2198
+ //#endregion
2199
+ //#region src/ui/slash-command/search.ts
2200
+ function scoreItem(item, query) {
2201
+ if (!query) return 100;
2202
+ const q = query.toLowerCase();
2203
+ const title = item.title.toLowerCase();
2204
+ const description = item.description.toLowerCase();
2205
+ const terms = item.searchTerms?.map((t) => t.toLowerCase()) ?? [];
2206
+ if (title === q) return 100;
2207
+ if (title.startsWith(q)) return 90;
2208
+ if (title.split(/\s+/).some((w) => w.startsWith(q))) return 80;
2209
+ if (terms.some((t) => t === q)) return 70;
2210
+ if (terms.some((t) => t.startsWith(q))) return 60;
2211
+ if (title.includes(q)) return 40;
2212
+ if (terms.some((t) => t.includes(q))) return 30;
2213
+ if (description.includes(q)) return 20;
2214
+ return 0;
2215
+ }
2216
+ function filterAndRankItems(items, query) {
2217
+ const trimmed = query.trim();
2218
+ if (!trimmed) return items;
2219
+ const scored = items.map((item) => ({
2220
+ item,
2221
+ score: scoreItem(item, trimmed)
2222
+ })).filter(({ score }) => score > 0);
2223
+ scored.sort((a, b) => b.score - a.score);
2224
+ return scored.map(({ item }) => item);
2225
+ }
2226
+
2227
+ //#endregion
2228
+ //#region src/ui/slash-command/root.tsx
2229
+ const pluginKey = new PluginKey("slash-command");
2230
+ const INITIAL_STATE = {
2231
+ active: false,
2232
+ query: "",
2233
+ items: [],
2234
+ clientRect: null
2235
+ };
2236
+ function defaultFilterItems(items, query, editor) {
2237
+ return filterAndRankItems(isAtMaxColumnsDepth(editor) ? items.filter((item) => item.category !== "Layout" || !item.title.includes("column")) : items, query);
2238
+ }
2239
+ function SlashCommandRoot({ items: itemsProp, filterItems: filterItemsProp, char = "/", allow: allowProp, children }) {
2240
+ const { editor } = useCurrentEditor();
2241
+ const [state, setState] = useState(INITIAL_STATE);
2242
+ const [selectedIndex, setSelectedIndex] = useState(0);
2243
+ const itemsRef = useRef(itemsProp ?? defaultSlashCommands);
2244
+ const filterRef = useRef(filterItemsProp ?? defaultFilterItems);
2245
+ const allowRef = useRef(allowProp ?? (({ editor: e }) => !e.isActive("codeBlock")));
2246
+ itemsRef.current = itemsProp ?? defaultSlashCommands;
2247
+ filterRef.current = filterItemsProp ?? defaultFilterItems;
2248
+ allowRef.current = allowProp ?? (({ editor: e }) => !e.isActive("codeBlock"));
2249
+ const commandRef = useRef(null);
2250
+ const suggestionItemsRef = useRef([]);
2251
+ const selectedIndexRef = useRef(0);
2252
+ suggestionItemsRef.current = state.items;
2253
+ selectedIndexRef.current = selectedIndex;
2254
+ const { refs, floatingStyles } = useFloating({
2255
+ open: state.active,
2256
+ placement: "bottom-start",
2257
+ middleware: [
2258
+ offset(8),
2259
+ flip(),
2260
+ shift({ padding: 8 })
2261
+ ],
2262
+ whileElementsMounted: autoUpdate
2263
+ });
2264
+ useEffect(() => {
2265
+ if (!state.clientRect) return;
2266
+ const clientRect = state.clientRect;
2267
+ refs.setReference({ getBoundingClientRect: () => clientRect() });
2268
+ }, [state.clientRect, refs]);
2269
+ useEffect(() => {
2270
+ setSelectedIndex(0);
2271
+ }, [state.items]);
2272
+ const onSelect = useCallback((index) => {
2273
+ const item = suggestionItemsRef.current[index];
2274
+ if (item && commandRef.current) commandRef.current(item);
2275
+ }, []);
2276
+ useEffect(() => {
2277
+ if (!editor) return;
2278
+ const plugin = Suggestion({
2279
+ pluginKey,
2280
+ editor,
2281
+ char,
2282
+ allow: ({ editor: e }) => allowRef.current({ editor: e }),
2283
+ command: ({ editor: e, range, props }) => {
2284
+ props.command({
2285
+ editor: e,
2286
+ range
2287
+ });
2288
+ },
2289
+ items: ({ query, editor: e }) => filterRef.current(itemsRef.current, query, e),
2290
+ render: () => ({
2291
+ onStart: (props) => {
2292
+ commandRef.current = props.command;
2293
+ setState({
2294
+ active: true,
2295
+ query: props.query,
2296
+ items: props.items,
2297
+ clientRect: props.clientRect ?? null
2298
+ });
2299
+ },
2300
+ onUpdate: (props) => {
2301
+ commandRef.current = props.command;
2302
+ setState({
2303
+ active: true,
2304
+ query: props.query,
2305
+ items: props.items,
2306
+ clientRect: props.clientRect ?? null
2307
+ });
2308
+ },
2309
+ onKeyDown: ({ event }) => {
2310
+ if (event.key === "Escape") {
2311
+ setState(INITIAL_STATE);
2312
+ return true;
2313
+ }
2314
+ const items = suggestionItemsRef.current;
2315
+ if (items.length === 0) return false;
2316
+ if (event.key === "ArrowUp") {
2317
+ setSelectedIndex((i) => (i + items.length - 1) % items.length);
2318
+ return true;
2319
+ }
2320
+ if (event.key === "ArrowDown") {
2321
+ setSelectedIndex((i) => (i + 1) % items.length);
2322
+ return true;
2323
+ }
2324
+ if (event.key === "Enter") {
2325
+ const item = items[selectedIndexRef.current];
2326
+ if (item && commandRef.current) commandRef.current(item);
2327
+ return true;
2328
+ }
2329
+ return false;
2330
+ },
2331
+ onExit: () => {
2332
+ setState(INITIAL_STATE);
2333
+ requestAnimationFrame(() => {
2334
+ commandRef.current = null;
2335
+ });
2336
+ }
2337
+ })
2338
+ });
2339
+ editor.registerPlugin(plugin, (newPlugin, plugins) => [newPlugin, ...plugins]);
2340
+ return () => {
2341
+ editor.unregisterPlugin(pluginKey);
2342
+ };
2343
+ }, [editor, char]);
2344
+ if (!editor || !state.active) return null;
2345
+ const renderProps = {
2346
+ items: state.items,
2347
+ query: state.query,
2348
+ selectedIndex,
2349
+ onSelect
2350
+ };
2351
+ let content;
2352
+ if (children) content = children(renderProps);
2353
+ else content = /* @__PURE__ */ jsx(CommandList, { ...renderProps });
2354
+ return createPortal(/* @__PURE__ */ jsx("div", {
2355
+ ref: refs.setFloating,
2356
+ style: floatingStyles,
2357
+ children: content
2358
+ }), document.body);
2359
+ }
2360
+
2361
+ //#endregion
2362
+ export { BubbleMenuAlignLeft as $, BubbleMenuImageDefault as A, AlignLeftIcon as At, NodeSelectorContent as B, BubbleMenuSeparator as C, Columns2Icon as Ct, BubbleMenuLinkOpenLink as D, CaseUpperIcon as Dt, BubbleMenuLinkToolbar as E, CheckIcon as Et, BubbleMenuUppercase as F, BubbleMenuItemGroup as G, NodeSelectorTrigger as H, BubbleMenuUnderline as I, BubbleMenuButtonToolbar as J, BubbleMenuCode as K, bubbleMenuTriggers as L, BubbleMenuImageEditLink as M, BubbleMenuButtonDefault as N, BubbleMenuLinkForm as O, BoldIcon as Ot, RootWithDefault as P, BubbleMenuAlignRight as Q, BubbleMenuStrike as R, BubbleMenu$1 as S, Columns3Icon as St, BubbleMenuLinkUnlink as T, ChevronDownIcon as Tt, BubbleMenuLinkSelector as U, NodeSelectorRoot as V, BubbleMenuItalic as W, BubbleMenuButtonEditLink as X, BubbleMenuButtonForm as Y, BubbleMenuBold as Z, TWO_COLUMNS as _, Heading3Icon as _t, BUTTON as a, TextQuoteIcon as at, isAtMaxColumnsDepth as b, ExternalLinkIcon as bt, FOUR_COLUMNS as c, SquareCodeIcon as ct, H3 as d, PencilIcon as dt, BubbleMenuAlignCenter as et, NUMBERED_LIST as f, MousePointerIcon as ft, THREE_COLUMNS as g, ItalicIcon as gt, TEXT as h, LinkIcon as ht, BULLET_LIST as i, UnderlineIcon as it, BubbleMenuImageToolbar as j, AlignCenterIcon as jt, BubbleMenuLinkEditLink as k, AlignRightIcon as kt, H1 as l, SplitSquareVerticalIcon as lt, SECTION as m, ListIcon as mt, filterAndRankItems as n, useBubbleMenuContext as nt, CODE as o, TextIcon as ot, QUOTE as p, ListOrderedIcon as pt, BubbleMenuButtonUnlink as q, scoreItem as r, UnlinkIcon as rt, DIVIDER as s, StrikethroughIcon as st, SlashCommandRoot as t, BubbleMenuItem as tt, H2 as u, Rows2Icon as ut, defaultSlashCommands as v, Heading2Icon as vt, BubbleMenuLinkDefault as w, CodeIcon as wt, isInsideNode as x, Columns4Icon as xt, CommandList as y, Heading1Icon as yt, BubbleMenuNodeSelector as z };
2363
+ //# sourceMappingURL=root-BWiLr5WO.mjs.map