@react-email/editor 0.0.0-experimental.3 → 0.0.0-experimental.31

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 (63) hide show
  1. package/dist/columns-BXN-NNd4.cjs +450 -0
  2. package/dist/columns-Cos2lqfu.mjs +329 -0
  3. package/dist/columns-Cos2lqfu.mjs.map +1 -0
  4. package/dist/core/index.cjs +8 -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-DVox_fis.cjs +2159 -0
  9. package/dist/core-mUMTkab3.mjs +1914 -0
  10. package/dist/core-mUMTkab3.mjs.map +1 -0
  11. package/dist/extensions/index.cjs +48 -0
  12. package/dist/extensions/index.d.cts +395 -0
  13. package/dist/extensions/index.d.cts.map +1 -0
  14. package/dist/extensions/index.d.mts +395 -0
  15. package/dist/extensions/index.d.mts.map +1 -0
  16. package/dist/extensions/index.mjs +5 -0
  17. package/dist/global-content-BRvA4PRG.cjs +89 -0
  18. package/dist/global-content-kdUzYcsA.mjs +78 -0
  19. package/dist/global-content-kdUzYcsA.mjs.map +1 -0
  20. package/dist/index-BrSAA0dn.d.mts +131 -0
  21. package/dist/index-BrSAA0dn.d.mts.map +1 -0
  22. package/dist/index-CVRlPqX_.d.cts +131 -0
  23. package/dist/index-CVRlPqX_.d.cts.map +1 -0
  24. package/dist/plugins/index.cjs +747 -0
  25. package/dist/plugins/index.d.cts +79 -0
  26. package/dist/plugins/index.d.cts.map +1 -0
  27. package/dist/plugins/index.d.mts +79 -0
  28. package/dist/plugins/index.d.mts.map +1 -0
  29. package/dist/plugins/index.mjs +742 -0
  30. package/dist/plugins/index.mjs.map +1 -0
  31. package/dist/set-text-alignment-BO24ieeE.mjs +19 -0
  32. package/dist/set-text-alignment-BO24ieeE.mjs.map +1 -0
  33. package/dist/set-text-alignment-CbECklB4.cjs +24 -0
  34. package/dist/styles-C-cCyJCn.cjs +211 -0
  35. package/dist/styles-DLviD0JK.mjs +194 -0
  36. package/dist/styles-DLviD0JK.mjs.map +1 -0
  37. package/dist/ui/bubble-menu/bubble-menu.css +146 -0
  38. package/dist/ui/button-bubble-menu/button-bubble-menu.css +63 -0
  39. package/dist/ui/image-bubble-menu/image-bubble-menu.css +29 -0
  40. package/dist/ui/index.cjs +2559 -0
  41. package/dist/ui/index.d.cts +1028 -0
  42. package/dist/ui/index.d.cts.map +1 -0
  43. package/dist/ui/index.d.mts +1028 -0
  44. package/dist/ui/index.d.mts.map +1 -0
  45. package/dist/ui/index.mjs +2464 -0
  46. package/dist/ui/index.mjs.map +1 -0
  47. package/dist/ui/link-bubble-menu/link-bubble-menu.css +68 -0
  48. package/dist/ui/slash-command/slash-command.css +44 -0
  49. package/dist/ui/themes/default.css +857 -0
  50. package/dist/utils/index.cjs +3 -0
  51. package/dist/utils/index.d.cts +7 -0
  52. package/dist/utils/index.d.cts.map +1 -0
  53. package/dist/utils/index.d.mts +7 -0
  54. package/dist/utils/index.d.mts.map +1 -0
  55. package/dist/utils/index.mjs +3 -0
  56. package/package.json +95 -23
  57. package/dist/index.d.mts +0 -273
  58. package/dist/index.d.mts.map +0 -1
  59. package/dist/index.d.ts +0 -273
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/index.js +0 -1394
  62. package/dist/index.mjs +0 -1346
  63. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,2464 @@
1
+ import { h as editorEventBus, i as MAX_COLUMNS_DEPTH, s as getColumnsDepth } from "../columns-Cos2lqfu.mjs";
2
+ import { t as setTextAlignment } from "../set-text-alignment-BO24ieeE.mjs";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { useCurrentEditor, useEditorState } from "@tiptap/react";
5
+ import * as React from "react";
6
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
7
+ import { PluginKey } from "@tiptap/pm/state";
8
+ import * as Popover from "@radix-ui/react-popover";
9
+ import { BubbleMenu as BubbleMenu$1 } from "@tiptap/react/menus";
10
+ import { autoUpdate, flip, offset, shift, useFloating } from "@floating-ui/react-dom";
11
+ import Suggestion from "@tiptap/suggestion";
12
+ import { createPortal } from "react-dom";
13
+
14
+ //#region src/ui/icons/align-center.tsx
15
+ function AlignCenterIcon({ size, width, height, ...props }) {
16
+ return /* @__PURE__ */ jsxs("svg", {
17
+ xmlns: "http://www.w3.org/2000/svg",
18
+ width: size ?? width ?? 24,
19
+ height: size ?? height ?? 24,
20
+ viewBox: "0 0 24 24",
21
+ fill: "none",
22
+ stroke: "currentColor",
23
+ strokeWidth: 2,
24
+ strokeLinecap: "round",
25
+ strokeLinejoin: "round",
26
+ "aria-hidden": "true",
27
+ ...props,
28
+ children: [
29
+ /* @__PURE__ */ jsx("path", { d: "M21 5H3" }),
30
+ /* @__PURE__ */ jsx("path", { d: "M17 12H7" }),
31
+ /* @__PURE__ */ jsx("path", { d: "M19 19H5" })
32
+ ]
33
+ });
34
+ }
35
+
36
+ //#endregion
37
+ //#region src/ui/icons/align-left.tsx
38
+ function AlignLeftIcon({ size, width, height, ...props }) {
39
+ return /* @__PURE__ */ jsxs("svg", {
40
+ xmlns: "http://www.w3.org/2000/svg",
41
+ width: size ?? width ?? 24,
42
+ height: size ?? height ?? 24,
43
+ viewBox: "0 0 24 24",
44
+ fill: "none",
45
+ stroke: "currentColor",
46
+ strokeWidth: 2,
47
+ strokeLinecap: "round",
48
+ strokeLinejoin: "round",
49
+ "aria-hidden": "true",
50
+ ...props,
51
+ children: [
52
+ /* @__PURE__ */ jsx("path", { d: "M21 5H3" }),
53
+ /* @__PURE__ */ jsx("path", { d: "M15 12H3" }),
54
+ /* @__PURE__ */ jsx("path", { d: "M17 19H3" })
55
+ ]
56
+ });
57
+ }
58
+
59
+ //#endregion
60
+ //#region src/ui/icons/align-right.tsx
61
+ function AlignRightIcon({ size, width, height, ...props }) {
62
+ return /* @__PURE__ */ jsxs("svg", {
63
+ xmlns: "http://www.w3.org/2000/svg",
64
+ width: size ?? width ?? 24,
65
+ height: size ?? height ?? 24,
66
+ viewBox: "0 0 24 24",
67
+ fill: "none",
68
+ stroke: "currentColor",
69
+ strokeWidth: 2,
70
+ strokeLinecap: "round",
71
+ strokeLinejoin: "round",
72
+ "aria-hidden": "true",
73
+ ...props,
74
+ children: [
75
+ /* @__PURE__ */ jsx("path", { d: "M21 5H3" }),
76
+ /* @__PURE__ */ jsx("path", { d: "M21 12H9" }),
77
+ /* @__PURE__ */ jsx("path", { d: "M21 19H7" })
78
+ ]
79
+ });
80
+ }
81
+
82
+ //#endregion
83
+ //#region src/ui/icons/bold.tsx
84
+ function BoldIcon({ size, width, height, ...props }) {
85
+ return /* @__PURE__ */ jsx("svg", {
86
+ xmlns: "http://www.w3.org/2000/svg",
87
+ width: size ?? width ?? 24,
88
+ height: size ?? height ?? 24,
89
+ viewBox: "0 0 24 24",
90
+ fill: "none",
91
+ stroke: "currentColor",
92
+ strokeWidth: 2,
93
+ strokeLinecap: "round",
94
+ strokeLinejoin: "round",
95
+ "aria-hidden": "true",
96
+ ...props,
97
+ 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" })
98
+ });
99
+ }
100
+
101
+ //#endregion
102
+ //#region src/ui/icons/case-upper.tsx
103
+ function CaseUpperIcon({ size, width, height, ...props }) {
104
+ return /* @__PURE__ */ jsxs("svg", {
105
+ xmlns: "http://www.w3.org/2000/svg",
106
+ width: size ?? width ?? 24,
107
+ height: size ?? height ?? 24,
108
+ viewBox: "0 0 24 24",
109
+ fill: "none",
110
+ stroke: "currentColor",
111
+ strokeWidth: 2,
112
+ strokeLinecap: "round",
113
+ strokeLinejoin: "round",
114
+ "aria-hidden": "true",
115
+ ...props,
116
+ children: [
117
+ /* @__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" }),
118
+ /* @__PURE__ */ jsx("path", { d: "m2 16 4.039-9.69a.5.5 0 0 1 .923 0L11 16" }),
119
+ /* @__PURE__ */ jsx("path", { d: "M3.304 13h6.392" })
120
+ ]
121
+ });
122
+ }
123
+
124
+ //#endregion
125
+ //#region src/ui/icons/check.tsx
126
+ function Check({ size, width, height, ...props }) {
127
+ return /* @__PURE__ */ jsx("svg", {
128
+ xmlns: "http://www.w3.org/2000/svg",
129
+ width: size ?? width ?? 24,
130
+ height: size ?? height ?? 24,
131
+ viewBox: "0 0 24 24",
132
+ fill: "none",
133
+ stroke: "currentColor",
134
+ strokeWidth: 2,
135
+ strokeLinecap: "round",
136
+ strokeLinejoin: "round",
137
+ "aria-hidden": "true",
138
+ ...props,
139
+ children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
140
+ });
141
+ }
142
+
143
+ //#endregion
144
+ //#region src/ui/icons/chevron-down.tsx
145
+ function ChevronDown({ size, width, height, ...props }) {
146
+ return /* @__PURE__ */ jsx("svg", {
147
+ xmlns: "http://www.w3.org/2000/svg",
148
+ width: size ?? width ?? 24,
149
+ height: size ?? height ?? 24,
150
+ viewBox: "0 0 24 24",
151
+ fill: "none",
152
+ stroke: "currentColor",
153
+ strokeWidth: 2,
154
+ strokeLinecap: "round",
155
+ strokeLinejoin: "round",
156
+ "aria-hidden": "true",
157
+ ...props,
158
+ children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
159
+ });
160
+ }
161
+
162
+ //#endregion
163
+ //#region src/ui/icons/code.tsx
164
+ function CodeIcon({ size, width, height, ...props }) {
165
+ return /* @__PURE__ */ jsxs("svg", {
166
+ xmlns: "http://www.w3.org/2000/svg",
167
+ width: size ?? width ?? 24,
168
+ height: size ?? height ?? 24,
169
+ viewBox: "0 0 24 24",
170
+ fill: "none",
171
+ stroke: "currentColor",
172
+ strokeWidth: 2,
173
+ strokeLinecap: "round",
174
+ strokeLinejoin: "round",
175
+ "aria-hidden": "true",
176
+ ...props,
177
+ children: [/* @__PURE__ */ jsx("path", { d: "m16 18 6-6-6-6" }), /* @__PURE__ */ jsx("path", { d: "m8 6-6 6 6 6" })]
178
+ });
179
+ }
180
+ const Code = CodeIcon;
181
+
182
+ //#endregion
183
+ //#region src/ui/icons/columns-2.tsx
184
+ function Columns2({ 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 Columns3({ 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 Columns4({ 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 Heading1({ 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 Heading2({ 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 Heading3({ 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 List({ 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 ListOrdered({ 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 MousePointer({ 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 Rows2({ 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 SplitSquareVertical({ 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 SquareCode({ 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
+ const Text = TextIcon;
642
+
643
+ //#endregion
644
+ //#region src/ui/icons/text-quote.tsx
645
+ function TextQuote({ size, width, height, ...props }) {
646
+ return /* @__PURE__ */ jsxs("svg", {
647
+ xmlns: "http://www.w3.org/2000/svg",
648
+ width: size ?? width ?? 24,
649
+ height: size ?? height ?? 24,
650
+ viewBox: "0 0 24 24",
651
+ fill: "none",
652
+ stroke: "currentColor",
653
+ strokeWidth: 2,
654
+ strokeLinecap: "round",
655
+ strokeLinejoin: "round",
656
+ "aria-hidden": "true",
657
+ ...props,
658
+ children: [
659
+ /* @__PURE__ */ jsx("path", { d: "M17 5H3" }),
660
+ /* @__PURE__ */ jsx("path", { d: "M21 12H8" }),
661
+ /* @__PURE__ */ jsx("path", { d: "M21 19H8" }),
662
+ /* @__PURE__ */ jsx("path", { d: "M3 12v7" })
663
+ ]
664
+ });
665
+ }
666
+
667
+ //#endregion
668
+ //#region src/ui/icons/underline.tsx
669
+ function UnderlineIcon({ size, width, height, ...props }) {
670
+ return /* @__PURE__ */ jsxs("svg", {
671
+ xmlns: "http://www.w3.org/2000/svg",
672
+ width: size ?? width ?? 24,
673
+ height: size ?? height ?? 24,
674
+ viewBox: "0 0 24 24",
675
+ fill: "none",
676
+ stroke: "currentColor",
677
+ strokeWidth: 2,
678
+ strokeLinecap: "round",
679
+ strokeLinejoin: "round",
680
+ "aria-hidden": "true",
681
+ ...props,
682
+ children: [/* @__PURE__ */ jsx("path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }), /* @__PURE__ */ jsx("line", {
683
+ x1: "4",
684
+ x2: "20",
685
+ y1: "20",
686
+ y2: "20"
687
+ })]
688
+ });
689
+ }
690
+
691
+ //#endregion
692
+ //#region src/ui/icons/unlink.tsx
693
+ function UnlinkIcon({ size, width, height, ...props }) {
694
+ return /* @__PURE__ */ jsxs("svg", {
695
+ xmlns: "http://www.w3.org/2000/svg",
696
+ width: size ?? width ?? 24,
697
+ height: size ?? height ?? 24,
698
+ viewBox: "0 0 24 24",
699
+ fill: "none",
700
+ stroke: "currentColor",
701
+ strokeWidth: 2,
702
+ strokeLinecap: "round",
703
+ strokeLinejoin: "round",
704
+ "aria-hidden": "true",
705
+ ...props,
706
+ children: [
707
+ /* @__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" }),
708
+ /* @__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" }),
709
+ /* @__PURE__ */ jsx("line", {
710
+ x1: "8",
711
+ x2: "8",
712
+ y1: "2",
713
+ y2: "5"
714
+ }),
715
+ /* @__PURE__ */ jsx("line", {
716
+ x1: "2",
717
+ x2: "5",
718
+ y1: "8",
719
+ y2: "8"
720
+ }),
721
+ /* @__PURE__ */ jsx("line", {
722
+ x1: "16",
723
+ x2: "16",
724
+ y1: "19",
725
+ y2: "22"
726
+ }),
727
+ /* @__PURE__ */ jsx("line", {
728
+ x1: "19",
729
+ x2: "22",
730
+ y1: "16",
731
+ y2: "16"
732
+ })
733
+ ]
734
+ });
735
+ }
736
+
737
+ //#endregion
738
+ //#region src/ui/bubble-menu/context.tsx
739
+ const BubbleMenuContext = React.createContext(null);
740
+ function useBubbleMenuContext() {
741
+ const context = React.useContext(BubbleMenuContext);
742
+ if (!context) throw new Error("BubbleMenu compound components must be used within <BubbleMenu.Root>");
743
+ return context;
744
+ }
745
+
746
+ //#endregion
747
+ //#region src/ui/bubble-menu/item.tsx
748
+ function BubbleMenuItem({ name, isActive, onCommand, className, children, ...rest }) {
749
+ return /* @__PURE__ */ jsx("button", {
750
+ type: "button",
751
+ "aria-label": name,
752
+ "aria-pressed": isActive,
753
+ className,
754
+ "data-re-bubble-menu-item": "",
755
+ "data-item": name,
756
+ ...isActive ? { "data-active": "" } : {},
757
+ onMouseDown: (e) => e.preventDefault(),
758
+ onClick: onCommand,
759
+ ...rest,
760
+ children
761
+ });
762
+ }
763
+
764
+ //#endregion
765
+ //#region src/ui/bubble-menu/align-center.tsx
766
+ function BubbleMenuAlignCenter({ className, children }) {
767
+ const { editor } = useBubbleMenuContext();
768
+ return /* @__PURE__ */ jsx(BubbleMenuItem, {
769
+ name: "align-center",
770
+ isActive: useEditorState({
771
+ editor,
772
+ selector: ({ editor: editor$1 }) => editor$1?.isActive({ alignment: "center" }) ?? false
773
+ }),
774
+ onCommand: () => setTextAlignment(editor, "center"),
775
+ className,
776
+ children: children ?? /* @__PURE__ */ jsx(AlignCenterIcon, {})
777
+ });
778
+ }
779
+
780
+ //#endregion
781
+ //#region src/ui/bubble-menu/align-left.tsx
782
+ function BubbleMenuAlignLeft({ className, children }) {
783
+ const { editor } = useBubbleMenuContext();
784
+ return /* @__PURE__ */ jsx(BubbleMenuItem, {
785
+ name: "align-left",
786
+ isActive: useEditorState({
787
+ editor,
788
+ selector: ({ editor: editor$1 }) => editor$1?.isActive({ alignment: "left" }) ?? false
789
+ }),
790
+ onCommand: () => setTextAlignment(editor, "left"),
791
+ className,
792
+ children: children ?? /* @__PURE__ */ jsx(AlignLeftIcon, {})
793
+ });
794
+ }
795
+
796
+ //#endregion
797
+ //#region src/ui/bubble-menu/align-right.tsx
798
+ function BubbleMenuAlignRight({ className, children }) {
799
+ const { editor } = useBubbleMenuContext();
800
+ return /* @__PURE__ */ jsx(BubbleMenuItem, {
801
+ name: "align-right",
802
+ isActive: useEditorState({
803
+ editor,
804
+ selector: ({ editor: editor$1 }) => editor$1?.isActive({ alignment: "right" }) ?? false
805
+ }),
806
+ onCommand: () => setTextAlignment(editor, "right"),
807
+ className,
808
+ children: children ?? /* @__PURE__ */ jsx(AlignRightIcon, {})
809
+ });
810
+ }
811
+
812
+ //#endregion
813
+ //#region src/ui/bubble-menu/create-mark-bubble-item.tsx
814
+ function createMarkBubbleItem(config) {
815
+ function MarkBubbleItem({ className, children }) {
816
+ const { editor } = useBubbleMenuContext();
817
+ const isActive = useEditorState({
818
+ editor,
819
+ selector: ({ editor: editor$1 }) => {
820
+ if (config.activeParams) return editor$1?.isActive(config.activeName, config.activeParams) ?? false;
821
+ return editor$1?.isActive(config.activeName) ?? false;
822
+ }
823
+ });
824
+ const handleCommand = () => {
825
+ const chain = editor.chain().focus();
826
+ const method = chain[config.command];
827
+ if (method) method.call(chain).run();
828
+ };
829
+ return /* @__PURE__ */ jsx(BubbleMenuItem, {
830
+ name: config.name,
831
+ isActive,
832
+ onCommand: handleCommand,
833
+ className,
834
+ children: children ?? config.icon
835
+ });
836
+ }
837
+ MarkBubbleItem.displayName = `BubbleMenu${config.name.charAt(0).toUpperCase() + config.name.slice(1)}`;
838
+ return MarkBubbleItem;
839
+ }
840
+
841
+ //#endregion
842
+ //#region src/ui/bubble-menu/bold.tsx
843
+ const BubbleMenuBold = createMarkBubbleItem({
844
+ name: "bold",
845
+ activeName: "bold",
846
+ command: "toggleBold",
847
+ icon: /* @__PURE__ */ jsx(BoldIcon, {})
848
+ });
849
+
850
+ //#endregion
851
+ //#region src/ui/bubble-menu/code.tsx
852
+ const BubbleMenuCode = createMarkBubbleItem({
853
+ name: "code",
854
+ activeName: "code",
855
+ command: "toggleCode",
856
+ icon: /* @__PURE__ */ jsx(CodeIcon, {})
857
+ });
858
+
859
+ //#endregion
860
+ //#region src/ui/bubble-menu/group.tsx
861
+ function BubbleMenuItemGroup({ className, children }) {
862
+ return /* @__PURE__ */ jsx("fieldset", {
863
+ className,
864
+ "data-re-bubble-menu-group": "",
865
+ children
866
+ });
867
+ }
868
+
869
+ //#endregion
870
+ //#region src/ui/bubble-menu/italic.tsx
871
+ const BubbleMenuItalic = createMarkBubbleItem({
872
+ name: "italic",
873
+ activeName: "italic",
874
+ command: "toggleItalic",
875
+ icon: /* @__PURE__ */ jsx(ItalicIcon, {})
876
+ });
877
+
878
+ //#endregion
879
+ //#region src/ui/bubble-menu/utils.ts
880
+ const SAFE_PROTOCOLS = new Set([
881
+ "http:",
882
+ "https:",
883
+ "mailto:",
884
+ "tel:"
885
+ ]);
886
+ /**
887
+ * Basic URL validation and auto-prefixing.
888
+ * Rejects dangerous schemes (javascript:, data:, vbscript:, etc.).
889
+ * Returns the valid URL string or null.
890
+ */
891
+ function getUrlFromString(str) {
892
+ if (str === "#") return str;
893
+ try {
894
+ const url = new URL(str);
895
+ if (SAFE_PROTOCOLS.has(url.protocol)) return str;
896
+ return null;
897
+ } catch {}
898
+ try {
899
+ if (str.includes(".") && !str.includes(" ")) return new URL(`https://${str}`).toString();
900
+ } catch {}
901
+ return null;
902
+ }
903
+ function setLinkHref(editor, href) {
904
+ if (href.length === 0) {
905
+ editor.chain().unsetLink().run();
906
+ return;
907
+ }
908
+ const { from, to } = editor.state.selection;
909
+ if (from === to) {
910
+ editor.chain().extendMarkRange("link").setLink({ href }).setTextSelection({
911
+ from,
912
+ to
913
+ }).run();
914
+ return;
915
+ }
916
+ editor.chain().setLink({ href }).run();
917
+ }
918
+ function focusEditor(editor) {
919
+ setTimeout(() => {
920
+ editor.commands.focus();
921
+ }, 0);
922
+ }
923
+
924
+ //#endregion
925
+ //#region src/ui/bubble-menu/link-selector.tsx
926
+ function BubbleMenuLinkSelector({ className, showToggle = true, validateUrl, onLinkApply, onLinkRemove, children, open: controlledOpen, onOpenChange }) {
927
+ const { editor } = useBubbleMenuContext();
928
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
929
+ const isControlled = controlledOpen !== void 0;
930
+ const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
931
+ const setIsOpen = React.useCallback((value) => {
932
+ if (!isControlled) setUncontrolledOpen(value);
933
+ onOpenChange?.(value);
934
+ }, [isControlled, onOpenChange]);
935
+ const editorState = useEditorState({
936
+ editor,
937
+ selector: ({ editor: editor$1 }) => ({
938
+ isLinkActive: editor$1?.isActive("link") ?? false,
939
+ hasLink: Boolean(editor$1?.getAttributes("link").href),
940
+ currentHref: editor$1?.getAttributes("link").href || ""
941
+ })
942
+ });
943
+ const setIsOpenRef = React.useRef(setIsOpen);
944
+ setIsOpenRef.current = setIsOpen;
945
+ React.useEffect(() => {
946
+ const subscription = editorEventBus.on("bubble-menu:add-link", () => {
947
+ setIsOpenRef.current(true);
948
+ });
949
+ return () => {
950
+ setIsOpenRef.current(false);
951
+ subscription.unsubscribe();
952
+ };
953
+ }, []);
954
+ if (!editorState) return null;
955
+ const handleOpenLink = () => {
956
+ setIsOpen(!isOpen);
957
+ };
958
+ return /* @__PURE__ */ jsxs("div", {
959
+ "data-re-link-selector": "",
960
+ ...isOpen ? { "data-open": "" } : {},
961
+ ...editorState.hasLink ? { "data-has-link": "" } : {},
962
+ className,
963
+ children: [showToggle && /* @__PURE__ */ jsx("button", {
964
+ type: "button",
965
+ "aria-expanded": isOpen,
966
+ "aria-haspopup": "true",
967
+ "aria-label": "Add link",
968
+ "aria-pressed": editorState.isLinkActive && editorState.hasLink,
969
+ "data-re-link-selector-trigger": "",
970
+ onClick: handleOpenLink,
971
+ children: /* @__PURE__ */ jsx(LinkIcon, {})
972
+ }), isOpen && /* @__PURE__ */ jsx(LinkForm, {
973
+ editor,
974
+ currentHref: editorState.currentHref,
975
+ validateUrl,
976
+ onLinkApply,
977
+ onLinkRemove,
978
+ setIsOpen,
979
+ children
980
+ })]
981
+ });
982
+ }
983
+ function LinkForm({ editor, currentHref, validateUrl, onLinkApply, onLinkRemove, setIsOpen, children }) {
984
+ const inputRef = React.useRef(null);
985
+ const formRef = React.useRef(null);
986
+ const displayHref = currentHref === "#" ? "" : currentHref;
987
+ const [inputValue, setInputValue] = React.useState(displayHref);
988
+ React.useEffect(() => {
989
+ const timeoutId = setTimeout(() => {
990
+ inputRef.current?.focus();
991
+ }, 0);
992
+ return () => clearTimeout(timeoutId);
993
+ }, []);
994
+ React.useEffect(() => {
995
+ const handleKeyDown = (event) => {
996
+ if (event.key === "Escape") {
997
+ if (editor.getAttributes("link").href === "#") editor.chain().unsetLink().run();
998
+ setIsOpen(false);
999
+ }
1000
+ };
1001
+ const handleClickOutside = (event) => {
1002
+ if (formRef.current && !formRef.current.contains(event.target)) {
1003
+ const form = formRef.current;
1004
+ const submitEvent = new Event("submit", {
1005
+ bubbles: true,
1006
+ cancelable: true
1007
+ });
1008
+ form.dispatchEvent(submitEvent);
1009
+ setIsOpen(false);
1010
+ }
1011
+ };
1012
+ document.addEventListener("mousedown", handleClickOutside);
1013
+ window.addEventListener("keydown", handleKeyDown);
1014
+ return () => {
1015
+ window.removeEventListener("keydown", handleKeyDown);
1016
+ document.removeEventListener("mousedown", handleClickOutside);
1017
+ };
1018
+ }, [editor, setIsOpen]);
1019
+ function handleSubmit(e) {
1020
+ e.preventDefault();
1021
+ const value = inputValue.trim();
1022
+ if (value === "") {
1023
+ setLinkHref(editor, "");
1024
+ setIsOpen(false);
1025
+ focusEditor(editor);
1026
+ onLinkRemove?.();
1027
+ return;
1028
+ }
1029
+ const finalValue = (validateUrl ?? getUrlFromString)(value);
1030
+ if (!finalValue) {
1031
+ setLinkHref(editor, "");
1032
+ setIsOpen(false);
1033
+ focusEditor(editor);
1034
+ onLinkRemove?.();
1035
+ return;
1036
+ }
1037
+ setLinkHref(editor, finalValue);
1038
+ setIsOpen(false);
1039
+ focusEditor(editor);
1040
+ onLinkApply?.(finalValue);
1041
+ }
1042
+ function handleUnlink(e) {
1043
+ e.stopPropagation();
1044
+ setLinkHref(editor, "");
1045
+ setIsOpen(false);
1046
+ focusEditor(editor);
1047
+ onLinkRemove?.();
1048
+ }
1049
+ return /* @__PURE__ */ jsxs("form", {
1050
+ ref: formRef,
1051
+ "data-re-link-selector-form": "",
1052
+ onMouseDown: (e) => e.stopPropagation(),
1053
+ onClick: (e) => e.stopPropagation(),
1054
+ onKeyDown: (e) => e.stopPropagation(),
1055
+ onSubmit: handleSubmit,
1056
+ children: [
1057
+ /* @__PURE__ */ jsx("input", {
1058
+ ref: inputRef,
1059
+ "data-re-link-selector-input": "",
1060
+ value: inputValue,
1061
+ onFocus: (e) => e.stopPropagation(),
1062
+ onChange: (e) => setInputValue(e.target.value),
1063
+ placeholder: "Paste a link",
1064
+ type: "text"
1065
+ }),
1066
+ children,
1067
+ displayHref ? /* @__PURE__ */ jsx("button", {
1068
+ type: "button",
1069
+ "aria-label": "Remove link",
1070
+ "data-re-link-selector-unlink": "",
1071
+ onClick: handleUnlink,
1072
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
1073
+ }) : /* @__PURE__ */ jsx("button", {
1074
+ type: "submit",
1075
+ "aria-label": "Apply link",
1076
+ "data-re-link-selector-apply": "",
1077
+ onMouseDown: (e) => e.stopPropagation(),
1078
+ children: /* @__PURE__ */ jsx(Check, {})
1079
+ })
1080
+ ]
1081
+ });
1082
+ }
1083
+
1084
+ //#endregion
1085
+ //#region src/ui/bubble-menu/node-selector.tsx
1086
+ const NodeSelectorContext = React.createContext(null);
1087
+ function useNodeSelectorContext() {
1088
+ const context = React.useContext(NodeSelectorContext);
1089
+ if (!context) throw new Error("NodeSelector compound components must be used within <NodeSelector.Root>");
1090
+ return context;
1091
+ }
1092
+ function NodeSelectorRoot({ omit = [], open: controlledOpen, onOpenChange, className, children }) {
1093
+ const { editor } = useBubbleMenuContext();
1094
+ const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
1095
+ const isControlled = controlledOpen !== void 0;
1096
+ const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
1097
+ const setIsOpen = React.useCallback((value) => {
1098
+ if (!isControlled) setUncontrolledOpen(value);
1099
+ onOpenChange?.(value);
1100
+ }, [isControlled, onOpenChange]);
1101
+ const editorState = useEditorState({
1102
+ editor,
1103
+ selector: ({ editor: editor$1 }) => ({
1104
+ isParagraphActive: (editor$1?.isActive("paragraph") ?? false) && !editor$1?.isActive("bulletList") && !editor$1?.isActive("orderedList"),
1105
+ isHeading1Active: editor$1?.isActive("heading", { level: 1 }) ?? false,
1106
+ isHeading2Active: editor$1?.isActive("heading", { level: 2 }) ?? false,
1107
+ isHeading3Active: editor$1?.isActive("heading", { level: 3 }) ?? false,
1108
+ isBulletListActive: editor$1?.isActive("bulletList") ?? false,
1109
+ isOrderedListActive: editor$1?.isActive("orderedList") ?? false,
1110
+ isBlockquoteActive: editor$1?.isActive("blockquote") ?? false,
1111
+ isCodeBlockActive: editor$1?.isActive("codeBlock") ?? false
1112
+ })
1113
+ });
1114
+ const allItems = React.useMemo(() => [
1115
+ {
1116
+ name: "Text",
1117
+ icon: TextIcon,
1118
+ command: () => editor.chain().focus().clearNodes().toggleNode("paragraph", "paragraph").run(),
1119
+ isActive: editorState?.isParagraphActive ?? false
1120
+ },
1121
+ {
1122
+ name: "Title",
1123
+ icon: Heading1,
1124
+ command: () => editor.chain().focus().clearNodes().toggleHeading({ level: 1 }).run(),
1125
+ isActive: editorState?.isHeading1Active ?? false
1126
+ },
1127
+ {
1128
+ name: "Subtitle",
1129
+ icon: Heading2,
1130
+ command: () => editor.chain().focus().clearNodes().toggleHeading({ level: 2 }).run(),
1131
+ isActive: editorState?.isHeading2Active ?? false
1132
+ },
1133
+ {
1134
+ name: "Heading",
1135
+ icon: Heading3,
1136
+ command: () => editor.chain().focus().clearNodes().toggleHeading({ level: 3 }).run(),
1137
+ isActive: editorState?.isHeading3Active ?? false
1138
+ },
1139
+ {
1140
+ name: "Bullet List",
1141
+ icon: List,
1142
+ command: () => editor.chain().focus().clearNodes().toggleBulletList().run(),
1143
+ isActive: editorState?.isBulletListActive ?? false
1144
+ },
1145
+ {
1146
+ name: "Numbered List",
1147
+ icon: ListOrdered,
1148
+ command: () => editor.chain().focus().clearNodes().toggleOrderedList().run(),
1149
+ isActive: editorState?.isOrderedListActive ?? false
1150
+ },
1151
+ {
1152
+ name: "Quote",
1153
+ icon: TextQuote,
1154
+ command: () => editor.chain().focus().clearNodes().toggleNode("paragraph", "paragraph").toggleBlockquote().run(),
1155
+ isActive: editorState?.isBlockquoteActive ?? false
1156
+ },
1157
+ {
1158
+ name: "Code",
1159
+ icon: Code,
1160
+ command: () => editor.chain().focus().clearNodes().toggleCodeBlock().run(),
1161
+ isActive: editorState?.isCodeBlockActive ?? false
1162
+ }
1163
+ ], [editor, editorState]);
1164
+ const items = React.useMemo(() => allItems.filter((item) => !omit.includes(item.name)), [allItems, omit]);
1165
+ const activeItem = React.useMemo(() => items.find((item) => item.isActive) ?? { name: "Multiple" }, [items]);
1166
+ const contextValue = React.useMemo(() => ({
1167
+ items,
1168
+ activeItem,
1169
+ isOpen,
1170
+ setIsOpen
1171
+ }), [
1172
+ items,
1173
+ activeItem,
1174
+ isOpen,
1175
+ setIsOpen
1176
+ ]);
1177
+ if (!editorState || items.length === 0) return null;
1178
+ return /* @__PURE__ */ jsx(NodeSelectorContext.Provider, {
1179
+ value: contextValue,
1180
+ children: /* @__PURE__ */ jsx(Popover.Root, {
1181
+ open: isOpen,
1182
+ onOpenChange: setIsOpen,
1183
+ children: /* @__PURE__ */ jsx("div", {
1184
+ "data-re-node-selector": "",
1185
+ ...isOpen ? { "data-open": "" } : {},
1186
+ className,
1187
+ children
1188
+ })
1189
+ })
1190
+ });
1191
+ }
1192
+ function NodeSelectorTrigger({ className, children }) {
1193
+ const { activeItem, isOpen, setIsOpen } = useNodeSelectorContext();
1194
+ return /* @__PURE__ */ jsx(Popover.Trigger, {
1195
+ "data-re-node-selector-trigger": "",
1196
+ className,
1197
+ onClick: () => setIsOpen(!isOpen),
1198
+ children: children ?? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", { children: activeItem.name }), /* @__PURE__ */ jsx(ChevronDown, {})] })
1199
+ });
1200
+ }
1201
+ function NodeSelectorContent({ className, align = "start", children }) {
1202
+ const { items, setIsOpen } = useNodeSelectorContext();
1203
+ return /* @__PURE__ */ jsx(Popover.Content, {
1204
+ align,
1205
+ "data-re-node-selector-content": "",
1206
+ className,
1207
+ children: children ? children(items, () => setIsOpen(false)) : items.map((item) => {
1208
+ const Icon = item.icon;
1209
+ return /* @__PURE__ */ jsxs("button", {
1210
+ type: "button",
1211
+ "data-re-node-selector-item": "",
1212
+ ...item.isActive ? { "data-active": "" } : {},
1213
+ onClick: () => {
1214
+ item.command();
1215
+ setIsOpen(false);
1216
+ },
1217
+ children: [
1218
+ /* @__PURE__ */ jsx(Icon, {}),
1219
+ /* @__PURE__ */ jsx("span", { children: item.name }),
1220
+ item.isActive && /* @__PURE__ */ jsx(Check, {})
1221
+ ]
1222
+ }, item.name);
1223
+ })
1224
+ });
1225
+ }
1226
+ function BubbleMenuNodeSelector({ omit = [], className, triggerContent, open, onOpenChange }) {
1227
+ return /* @__PURE__ */ jsxs(NodeSelectorRoot, {
1228
+ omit,
1229
+ open,
1230
+ onOpenChange,
1231
+ className,
1232
+ children: [/* @__PURE__ */ jsx(NodeSelectorTrigger, { children: triggerContent }), /* @__PURE__ */ jsx(NodeSelectorContent, {})]
1233
+ });
1234
+ }
1235
+
1236
+ //#endregion
1237
+ //#region src/ui/bubble-menu/root.tsx
1238
+ function BubbleMenuRoot({ excludeNodes = [], excludeMarks = [], placement = "bottom", offset: offset$1 = 8, onHide, className, children }) {
1239
+ const { editor } = useCurrentEditor();
1240
+ if (!editor) return null;
1241
+ return /* @__PURE__ */ jsx(BubbleMenu$1, {
1242
+ editor,
1243
+ pluginKey: "textBubbleMenu",
1244
+ "data-re-bubble-menu": "",
1245
+ shouldShow: ({ editor: editor$1, view, state }) => {
1246
+ for (const node of excludeNodes) {
1247
+ if (editor$1.isActive(node)) return false;
1248
+ const { $from } = state.selection;
1249
+ for (let d = $from.depth; d > 0; d--) if ($from.node(d).type.name === node) return false;
1250
+ }
1251
+ for (const mark of excludeMarks) if (editor$1.isActive(mark)) return false;
1252
+ if (view.dom.classList.contains("dragging")) return false;
1253
+ return editor$1.view.state.selection.content().size > 0;
1254
+ },
1255
+ options: {
1256
+ placement,
1257
+ offset: offset$1,
1258
+ onHide
1259
+ },
1260
+ className,
1261
+ children: /* @__PURE__ */ jsx(BubbleMenuContext.Provider, {
1262
+ value: { editor },
1263
+ children
1264
+ })
1265
+ });
1266
+ }
1267
+
1268
+ //#endregion
1269
+ //#region src/ui/bubble-menu/strike.tsx
1270
+ const BubbleMenuStrike = createMarkBubbleItem({
1271
+ name: "strike",
1272
+ activeName: "strike",
1273
+ command: "toggleStrike",
1274
+ icon: /* @__PURE__ */ jsx(StrikethroughIcon, {})
1275
+ });
1276
+
1277
+ //#endregion
1278
+ //#region src/ui/bubble-menu/underline.tsx
1279
+ const BubbleMenuUnderline = createMarkBubbleItem({
1280
+ name: "underline",
1281
+ activeName: "underline",
1282
+ command: "toggleUnderline",
1283
+ icon: /* @__PURE__ */ jsx(UnderlineIcon, {})
1284
+ });
1285
+
1286
+ //#endregion
1287
+ //#region src/ui/bubble-menu/uppercase.tsx
1288
+ const BubbleMenuUppercase = createMarkBubbleItem({
1289
+ name: "uppercase",
1290
+ activeName: "uppercase",
1291
+ command: "toggleUppercase",
1292
+ icon: /* @__PURE__ */ jsx(CaseUpperIcon, {})
1293
+ });
1294
+
1295
+ //#endregion
1296
+ //#region src/ui/bubble-menu/default.tsx
1297
+ function BubbleMenuDefault({ excludeItems = [], excludeNodes, excludeMarks, placement, offset: offset$1, onHide, className }) {
1298
+ const [isNodeSelectorOpen, setIsNodeSelectorOpen] = React.useState(false);
1299
+ const [isLinkSelectorOpen, setIsLinkSelectorOpen] = React.useState(false);
1300
+ const has = (item) => !excludeItems.includes(item);
1301
+ const handleNodeSelectorOpenChange = React.useCallback((open) => {
1302
+ setIsNodeSelectorOpen(open);
1303
+ if (open) setIsLinkSelectorOpen(false);
1304
+ }, []);
1305
+ const handleLinkSelectorOpenChange = React.useCallback((open) => {
1306
+ setIsLinkSelectorOpen(open);
1307
+ if (open) setIsNodeSelectorOpen(false);
1308
+ }, []);
1309
+ const handleHide = React.useCallback(() => {
1310
+ setIsNodeSelectorOpen(false);
1311
+ setIsLinkSelectorOpen(false);
1312
+ onHide?.();
1313
+ }, [onHide]);
1314
+ const hasFormattingItems = has("bold") || has("italic") || has("underline") || has("strike") || has("code") || has("uppercase");
1315
+ const hasAlignmentItems = has("align-left") || has("align-center") || has("align-right");
1316
+ return /* @__PURE__ */ jsxs(BubbleMenuRoot, {
1317
+ excludeNodes,
1318
+ excludeMarks,
1319
+ placement,
1320
+ offset: offset$1,
1321
+ onHide: handleHide,
1322
+ className,
1323
+ children: [
1324
+ has("node-selector") && /* @__PURE__ */ jsx(BubbleMenuNodeSelector, {
1325
+ open: isNodeSelectorOpen,
1326
+ onOpenChange: handleNodeSelectorOpenChange
1327
+ }),
1328
+ has("link-selector") && /* @__PURE__ */ jsx(BubbleMenuLinkSelector, {
1329
+ open: isLinkSelectorOpen,
1330
+ onOpenChange: handleLinkSelectorOpenChange
1331
+ }),
1332
+ hasFormattingItems && /* @__PURE__ */ jsxs(BubbleMenuItemGroup, { children: [
1333
+ has("bold") && /* @__PURE__ */ jsx(BubbleMenuBold, {}),
1334
+ has("italic") && /* @__PURE__ */ jsx(BubbleMenuItalic, {}),
1335
+ has("underline") && /* @__PURE__ */ jsx(BubbleMenuUnderline, {}),
1336
+ has("strike") && /* @__PURE__ */ jsx(BubbleMenuStrike, {}),
1337
+ has("code") && /* @__PURE__ */ jsx(BubbleMenuCode, {}),
1338
+ has("uppercase") && /* @__PURE__ */ jsx(BubbleMenuUppercase, {})
1339
+ ] }),
1340
+ hasAlignmentItems && /* @__PURE__ */ jsxs(BubbleMenuItemGroup, { children: [
1341
+ has("align-left") && /* @__PURE__ */ jsx(BubbleMenuAlignLeft, {}),
1342
+ has("align-center") && /* @__PURE__ */ jsx(BubbleMenuAlignCenter, {}),
1343
+ has("align-right") && /* @__PURE__ */ jsx(BubbleMenuAlignRight, {})
1344
+ ] })
1345
+ ]
1346
+ });
1347
+ }
1348
+
1349
+ //#endregion
1350
+ //#region src/ui/bubble-menu/separator.tsx
1351
+ function BubbleMenuSeparator({ className }) {
1352
+ return /* @__PURE__ */ jsx("hr", {
1353
+ className,
1354
+ "data-re-bubble-menu-separator": ""
1355
+ });
1356
+ }
1357
+
1358
+ //#endregion
1359
+ //#region src/ui/bubble-menu/index.ts
1360
+ const BubbleMenu = {
1361
+ Root: BubbleMenuRoot,
1362
+ ItemGroup: BubbleMenuItemGroup,
1363
+ Separator: BubbleMenuSeparator,
1364
+ Item: BubbleMenuItem,
1365
+ Bold: BubbleMenuBold,
1366
+ Italic: BubbleMenuItalic,
1367
+ Underline: BubbleMenuUnderline,
1368
+ Strike: BubbleMenuStrike,
1369
+ Code: BubbleMenuCode,
1370
+ Uppercase: BubbleMenuUppercase,
1371
+ AlignLeft: BubbleMenuAlignLeft,
1372
+ AlignCenter: BubbleMenuAlignCenter,
1373
+ AlignRight: BubbleMenuAlignRight,
1374
+ NodeSelector: Object.assign(BubbleMenuNodeSelector, {
1375
+ Root: NodeSelectorRoot,
1376
+ Trigger: NodeSelectorTrigger,
1377
+ Content: NodeSelectorContent
1378
+ }),
1379
+ LinkSelector: BubbleMenuLinkSelector,
1380
+ Default: BubbleMenuDefault
1381
+ };
1382
+
1383
+ //#endregion
1384
+ //#region src/ui/button-bubble-menu/context.tsx
1385
+ const ButtonBubbleMenuContext = React.createContext(null);
1386
+ function useButtonBubbleMenuContext() {
1387
+ const context = React.useContext(ButtonBubbleMenuContext);
1388
+ if (!context) throw new Error("ButtonBubbleMenu compound components must be used within <ButtonBubbleMenu.Root>");
1389
+ return context;
1390
+ }
1391
+
1392
+ //#endregion
1393
+ //#region src/ui/button-bubble-menu/edit-link.tsx
1394
+ function ButtonBubbleMenuEditLink({ className, children, onClick, onMouseDown, ...rest }) {
1395
+ const { setIsEditing } = useButtonBubbleMenuContext();
1396
+ return /* @__PURE__ */ jsx("button", {
1397
+ ...rest,
1398
+ type: "button",
1399
+ "aria-label": "Edit link",
1400
+ "data-re-btn-bm-item": "",
1401
+ "data-item": "edit-link",
1402
+ className,
1403
+ onMouseDown: (e) => {
1404
+ e.preventDefault();
1405
+ onMouseDown?.(e);
1406
+ },
1407
+ onClick: (e) => {
1408
+ onClick?.(e);
1409
+ setIsEditing(true);
1410
+ },
1411
+ children: children ?? /* @__PURE__ */ jsx(PencilIcon, {})
1412
+ });
1413
+ }
1414
+
1415
+ //#endregion
1416
+ //#region src/ui/button-bubble-menu/form.tsx
1417
+ function ButtonBubbleMenuForm({ className, validateUrl, onLinkApply, onLinkRemove }) {
1418
+ const { editor, buttonHref, isEditing, setIsEditing } = useButtonBubbleMenuContext();
1419
+ const inputRef = React.useRef(null);
1420
+ const formRef = React.useRef(null);
1421
+ const displayHref = buttonHref === "#" ? "" : buttonHref;
1422
+ const [inputValue, setInputValue] = React.useState(displayHref);
1423
+ React.useEffect(() => {
1424
+ if (!isEditing) return;
1425
+ setInputValue(displayHref);
1426
+ const timeoutId = setTimeout(() => {
1427
+ inputRef.current?.focus();
1428
+ }, 0);
1429
+ return () => clearTimeout(timeoutId);
1430
+ }, [isEditing, displayHref]);
1431
+ React.useEffect(() => {
1432
+ if (!isEditing) return;
1433
+ const handleKeyDown = (event) => {
1434
+ if (event.key === "Escape") setIsEditing(false);
1435
+ };
1436
+ const handleClickOutside = (event) => {
1437
+ if (formRef.current && !formRef.current.contains(event.target)) {
1438
+ const form = formRef.current;
1439
+ const submitEvent = new Event("submit", {
1440
+ bubbles: true,
1441
+ cancelable: true
1442
+ });
1443
+ form.dispatchEvent(submitEvent);
1444
+ setIsEditing(false);
1445
+ }
1446
+ };
1447
+ document.addEventListener("mousedown", handleClickOutside);
1448
+ window.addEventListener("keydown", handleKeyDown);
1449
+ return () => {
1450
+ window.removeEventListener("keydown", handleKeyDown);
1451
+ document.removeEventListener("mousedown", handleClickOutside);
1452
+ };
1453
+ }, [isEditing, setIsEditing]);
1454
+ if (!isEditing) return null;
1455
+ function handleSubmit(e) {
1456
+ e.preventDefault();
1457
+ const value = inputValue.trim();
1458
+ if (value === "") {
1459
+ editor.commands.updateButton({ href: "#" });
1460
+ setIsEditing(false);
1461
+ focusEditor(editor);
1462
+ onLinkRemove?.();
1463
+ return;
1464
+ }
1465
+ const finalValue = (validateUrl ?? getUrlFromString)(value);
1466
+ if (!finalValue) {
1467
+ editor.commands.updateButton({ href: "#" });
1468
+ setIsEditing(false);
1469
+ focusEditor(editor);
1470
+ onLinkRemove?.();
1471
+ return;
1472
+ }
1473
+ editor.commands.updateButton({ href: finalValue });
1474
+ setIsEditing(false);
1475
+ focusEditor(editor);
1476
+ onLinkApply?.(finalValue);
1477
+ }
1478
+ function handleUnlink(e) {
1479
+ e.stopPropagation();
1480
+ editor.commands.updateButton({ href: "#" });
1481
+ setIsEditing(false);
1482
+ focusEditor(editor);
1483
+ onLinkRemove?.();
1484
+ }
1485
+ return /* @__PURE__ */ jsxs("form", {
1486
+ ref: formRef,
1487
+ "data-re-btn-bm-form": "",
1488
+ className,
1489
+ onMouseDown: (e) => e.stopPropagation(),
1490
+ onClick: (e) => e.stopPropagation(),
1491
+ onKeyDown: (e) => e.stopPropagation(),
1492
+ onSubmit: handleSubmit,
1493
+ children: [/* @__PURE__ */ jsx("input", {
1494
+ ref: inputRef,
1495
+ "data-re-btn-bm-input": "",
1496
+ value: inputValue,
1497
+ onFocus: (e) => e.stopPropagation(),
1498
+ onChange: (e) => setInputValue(e.target.value),
1499
+ placeholder: "Paste a link",
1500
+ type: "text"
1501
+ }), displayHref ? /* @__PURE__ */ jsx("button", {
1502
+ type: "button",
1503
+ "aria-label": "Remove link",
1504
+ "data-re-btn-bm-unlink": "",
1505
+ onClick: handleUnlink,
1506
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
1507
+ }) : /* @__PURE__ */ jsx("button", {
1508
+ type: "submit",
1509
+ "aria-label": "Apply link",
1510
+ "data-re-btn-bm-apply": "",
1511
+ onMouseDown: (e) => e.stopPropagation(),
1512
+ children: /* @__PURE__ */ jsx(Check, {})
1513
+ })]
1514
+ });
1515
+ }
1516
+
1517
+ //#endregion
1518
+ //#region src/ui/button-bubble-menu/root.tsx
1519
+ function ButtonBubbleMenuRoot({ onHide, placement = "top", offset: offset$1 = 8, className, children }) {
1520
+ const { editor } = useCurrentEditor();
1521
+ const [isEditing, setIsEditing] = React.useState(false);
1522
+ const buttonHref = useEditorState({
1523
+ editor,
1524
+ selector: ({ editor: e }) => e?.getAttributes("button").href ?? ""
1525
+ });
1526
+ if (!editor) return null;
1527
+ return /* @__PURE__ */ jsx(BubbleMenu$1, {
1528
+ editor,
1529
+ pluginKey: "buttonBubbleMenu",
1530
+ "data-re-btn-bm": "",
1531
+ shouldShow: ({ editor: e, view }) => e.isActive("button") && !view.dom.classList.contains("dragging"),
1532
+ options: {
1533
+ placement,
1534
+ offset: offset$1,
1535
+ onHide: () => {
1536
+ setIsEditing(false);
1537
+ onHide?.();
1538
+ }
1539
+ },
1540
+ className,
1541
+ children: /* @__PURE__ */ jsx(ButtonBubbleMenuContext.Provider, {
1542
+ value: {
1543
+ editor,
1544
+ buttonHref: buttonHref ?? "",
1545
+ isEditing,
1546
+ setIsEditing
1547
+ },
1548
+ children
1549
+ })
1550
+ });
1551
+ }
1552
+
1553
+ //#endregion
1554
+ //#region src/ui/button-bubble-menu/toolbar.tsx
1555
+ function ButtonBubbleMenuToolbar({ children, ...rest }) {
1556
+ const { isEditing } = useButtonBubbleMenuContext();
1557
+ if (isEditing) return null;
1558
+ return /* @__PURE__ */ jsx("div", {
1559
+ "data-re-btn-bm-toolbar": "",
1560
+ ...rest,
1561
+ children
1562
+ });
1563
+ }
1564
+
1565
+ //#endregion
1566
+ //#region src/ui/button-bubble-menu/unlink.tsx
1567
+ function ButtonBubbleMenuUnlink({ className, children, onClick, onMouseDown, onLinkRemove, ...rest }) {
1568
+ const { editor } = useButtonBubbleMenuContext();
1569
+ return /* @__PURE__ */ jsx("button", {
1570
+ ...rest,
1571
+ type: "button",
1572
+ "aria-label": "Remove link",
1573
+ "data-re-btn-bm-item": "",
1574
+ "data-item": "unlink",
1575
+ className,
1576
+ onMouseDown: (e) => {
1577
+ e.preventDefault();
1578
+ onMouseDown?.(e);
1579
+ },
1580
+ onClick: (e) => {
1581
+ onClick?.(e);
1582
+ editor.commands.updateButton({ href: "#" });
1583
+ focusEditor(editor);
1584
+ onLinkRemove?.();
1585
+ },
1586
+ children: children ?? /* @__PURE__ */ jsx(UnlinkIcon, {})
1587
+ });
1588
+ }
1589
+
1590
+ //#endregion
1591
+ //#region src/ui/button-bubble-menu/default.tsx
1592
+ function ButtonBubbleMenuDefaultInner({ validateUrl, onLinkApply, onLinkRemove }) {
1593
+ const { buttonHref } = useButtonBubbleMenuContext();
1594
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(ButtonBubbleMenuToolbar, { children: [/* @__PURE__ */ jsx(ButtonBubbleMenuEditLink, {}), buttonHref !== "" && buttonHref !== "#" && /* @__PURE__ */ jsx(ButtonBubbleMenuUnlink, { onLinkRemove })] }), /* @__PURE__ */ jsx(ButtonBubbleMenuForm, {
1595
+ validateUrl,
1596
+ onLinkApply,
1597
+ onLinkRemove
1598
+ })] });
1599
+ }
1600
+ function ButtonBubbleMenuDefault({ placement, offset: offset$1, onHide, className, validateUrl, onLinkApply, onLinkRemove }) {
1601
+ return /* @__PURE__ */ jsx(ButtonBubbleMenuRoot, {
1602
+ placement,
1603
+ offset: offset$1,
1604
+ onHide,
1605
+ className,
1606
+ children: /* @__PURE__ */ jsx(ButtonBubbleMenuDefaultInner, {
1607
+ validateUrl,
1608
+ onLinkApply,
1609
+ onLinkRemove
1610
+ })
1611
+ });
1612
+ }
1613
+
1614
+ //#endregion
1615
+ //#region src/ui/button-bubble-menu/index.ts
1616
+ const ButtonBubbleMenu = {
1617
+ Root: ButtonBubbleMenuRoot,
1618
+ Toolbar: ButtonBubbleMenuToolbar,
1619
+ EditLink: ButtonBubbleMenuEditLink,
1620
+ Unlink: ButtonBubbleMenuUnlink,
1621
+ Form: ButtonBubbleMenuForm,
1622
+ Default: ButtonBubbleMenuDefault
1623
+ };
1624
+
1625
+ //#endregion
1626
+ //#region src/ui/image-bubble-menu/context.tsx
1627
+ const ImageBubbleMenuContext = React.createContext(null);
1628
+ function useImageBubbleMenuContext() {
1629
+ const context = React.useContext(ImageBubbleMenuContext);
1630
+ if (!context) throw new Error("ImageBubbleMenu compound components must be used within <ImageBubbleMenu.Root>");
1631
+ return context;
1632
+ }
1633
+
1634
+ //#endregion
1635
+ //#region src/ui/image-bubble-menu/edit-link.tsx
1636
+ function ImageBubbleMenuEditLink({ className, children, onClick, onMouseDown, ...rest }) {
1637
+ const { setIsEditing } = useImageBubbleMenuContext();
1638
+ return /* @__PURE__ */ jsx("button", {
1639
+ ...rest,
1640
+ type: "button",
1641
+ "aria-label": "Edit link",
1642
+ "data-re-img-bm-item": "",
1643
+ "data-item": "edit-link",
1644
+ className,
1645
+ onMouseDown: (e) => {
1646
+ e.preventDefault();
1647
+ onMouseDown?.(e);
1648
+ },
1649
+ onClick: (e) => {
1650
+ onClick?.(e);
1651
+ setIsEditing(true);
1652
+ },
1653
+ children: children ?? /* @__PURE__ */ jsx(LinkIcon, {})
1654
+ });
1655
+ }
1656
+
1657
+ //#endregion
1658
+ //#region src/ui/image-bubble-menu/root.tsx
1659
+ function ImageBubbleMenuRoot({ onHide, placement = "top", offset: offset$1 = 8, className, children }) {
1660
+ const { editor } = useCurrentEditor();
1661
+ const [isEditing, setIsEditing] = React.useState(false);
1662
+ if (!editor) return null;
1663
+ return /* @__PURE__ */ jsx(BubbleMenu$1, {
1664
+ editor,
1665
+ pluginKey: "imageBubbleMenu",
1666
+ "data-re-img-bm": "",
1667
+ shouldShow: ({ editor: e, view }) => e.isActive("image") && !view.dom.classList.contains("dragging"),
1668
+ options: {
1669
+ placement,
1670
+ offset: offset$1,
1671
+ onHide: () => {
1672
+ setIsEditing(false);
1673
+ onHide?.();
1674
+ }
1675
+ },
1676
+ className,
1677
+ children: /* @__PURE__ */ jsx(ImageBubbleMenuContext.Provider, {
1678
+ value: {
1679
+ editor,
1680
+ isEditing,
1681
+ setIsEditing
1682
+ },
1683
+ children
1684
+ })
1685
+ });
1686
+ }
1687
+
1688
+ //#endregion
1689
+ //#region src/ui/image-bubble-menu/toolbar.tsx
1690
+ function ImageBubbleMenuToolbar({ children, ...rest }) {
1691
+ const { isEditing } = useImageBubbleMenuContext();
1692
+ if (isEditing) return null;
1693
+ return /* @__PURE__ */ jsx("div", {
1694
+ "data-re-img-bm-toolbar": "",
1695
+ ...rest,
1696
+ children
1697
+ });
1698
+ }
1699
+
1700
+ //#endregion
1701
+ //#region src/ui/image-bubble-menu/default.tsx
1702
+ function ImageBubbleMenuDefault({ excludeItems = [], placement, offset: offset$1, onHide, className }) {
1703
+ return /* @__PURE__ */ jsx(ImageBubbleMenuRoot, {
1704
+ placement,
1705
+ offset: offset$1,
1706
+ onHide,
1707
+ className,
1708
+ children: !excludeItems.includes("edit-link") && /* @__PURE__ */ jsx(ImageBubbleMenuToolbar, { children: /* @__PURE__ */ jsx(ImageBubbleMenuEditLink, {}) })
1709
+ });
1710
+ }
1711
+
1712
+ //#endregion
1713
+ //#region src/ui/image-bubble-menu/index.ts
1714
+ const ImageBubbleMenu = {
1715
+ Root: ImageBubbleMenuRoot,
1716
+ Toolbar: ImageBubbleMenuToolbar,
1717
+ EditLink: ImageBubbleMenuEditLink,
1718
+ Default: ImageBubbleMenuDefault
1719
+ };
1720
+
1721
+ //#endregion
1722
+ //#region src/ui/link-bubble-menu/context.tsx
1723
+ const LinkBubbleMenuContext = React.createContext(null);
1724
+ function useLinkBubbleMenuContext() {
1725
+ const context = React.useContext(LinkBubbleMenuContext);
1726
+ if (!context) throw new Error("LinkBubbleMenu compound components must be used within <LinkBubbleMenu.Root>");
1727
+ return context;
1728
+ }
1729
+
1730
+ //#endregion
1731
+ //#region src/ui/link-bubble-menu/edit-link.tsx
1732
+ function LinkBubbleMenuEditLink({ className, children, onClick, onMouseDown, ...rest }) {
1733
+ const { setIsEditing } = useLinkBubbleMenuContext();
1734
+ return /* @__PURE__ */ jsx("button", {
1735
+ type: "button",
1736
+ "aria-label": "Edit link",
1737
+ "data-re-link-bm-item": "",
1738
+ "data-item": "edit-link",
1739
+ className,
1740
+ onMouseDown: (e) => {
1741
+ e.preventDefault();
1742
+ onMouseDown?.(e);
1743
+ },
1744
+ onClick: (e) => {
1745
+ onClick?.(e);
1746
+ setIsEditing(true);
1747
+ },
1748
+ ...rest,
1749
+ children: children ?? /* @__PURE__ */ jsx(PencilIcon, {})
1750
+ });
1751
+ }
1752
+
1753
+ //#endregion
1754
+ //#region src/ui/link-bubble-menu/form.tsx
1755
+ function LinkBubbleMenuForm({ className, validateUrl, onLinkApply, onLinkRemove, children }) {
1756
+ const { editor, linkHref, isEditing, setIsEditing } = useLinkBubbleMenuContext();
1757
+ const inputRef = React.useRef(null);
1758
+ const formRef = React.useRef(null);
1759
+ const displayHref = linkHref === "#" ? "" : linkHref;
1760
+ const [inputValue, setInputValue] = React.useState(displayHref);
1761
+ React.useEffect(() => {
1762
+ if (!isEditing) return;
1763
+ setInputValue(displayHref);
1764
+ const timeoutId = setTimeout(() => {
1765
+ inputRef.current?.focus();
1766
+ }, 0);
1767
+ return () => clearTimeout(timeoutId);
1768
+ }, [isEditing, displayHref]);
1769
+ React.useEffect(() => {
1770
+ if (!isEditing) return;
1771
+ const handleKeyDown = (event) => {
1772
+ if (event.key === "Escape") setIsEditing(false);
1773
+ };
1774
+ const handleClickOutside = (event) => {
1775
+ if (formRef.current && !formRef.current.contains(event.target)) {
1776
+ const form = formRef.current;
1777
+ const submitEvent = new Event("submit", {
1778
+ bubbles: true,
1779
+ cancelable: true
1780
+ });
1781
+ form.dispatchEvent(submitEvent);
1782
+ setIsEditing(false);
1783
+ }
1784
+ };
1785
+ document.addEventListener("mousedown", handleClickOutside);
1786
+ window.addEventListener("keydown", handleKeyDown);
1787
+ return () => {
1788
+ window.removeEventListener("keydown", handleKeyDown);
1789
+ document.removeEventListener("mousedown", handleClickOutside);
1790
+ };
1791
+ }, [isEditing, setIsEditing]);
1792
+ if (!isEditing) return null;
1793
+ function handleSubmit(e) {
1794
+ e.preventDefault();
1795
+ const value = inputValue.trim();
1796
+ if (value === "") {
1797
+ setLinkHref(editor, "");
1798
+ setIsEditing(false);
1799
+ focusEditor(editor);
1800
+ onLinkRemove?.();
1801
+ return;
1802
+ }
1803
+ const finalValue = (validateUrl ?? getUrlFromString)(value);
1804
+ if (!finalValue) {
1805
+ setLinkHref(editor, "");
1806
+ setIsEditing(false);
1807
+ focusEditor(editor);
1808
+ onLinkRemove?.();
1809
+ return;
1810
+ }
1811
+ setLinkHref(editor, finalValue);
1812
+ setIsEditing(false);
1813
+ focusEditor(editor);
1814
+ onLinkApply?.(finalValue);
1815
+ }
1816
+ function handleUnlink(e) {
1817
+ e.stopPropagation();
1818
+ setLinkHref(editor, "");
1819
+ setIsEditing(false);
1820
+ focusEditor(editor);
1821
+ onLinkRemove?.();
1822
+ }
1823
+ return /* @__PURE__ */ jsxs("form", {
1824
+ ref: formRef,
1825
+ "data-re-link-bm-form": "",
1826
+ className,
1827
+ onMouseDown: (e) => e.stopPropagation(),
1828
+ onClick: (e) => e.stopPropagation(),
1829
+ onKeyDown: (e) => e.stopPropagation(),
1830
+ onSubmit: handleSubmit,
1831
+ children: [
1832
+ /* @__PURE__ */ jsx("input", {
1833
+ ref: inputRef,
1834
+ "data-re-link-bm-input": "",
1835
+ value: inputValue,
1836
+ onFocus: (e) => e.stopPropagation(),
1837
+ onChange: (e) => setInputValue(e.target.value),
1838
+ placeholder: "Paste a link",
1839
+ type: "text"
1840
+ }),
1841
+ children,
1842
+ displayHref ? /* @__PURE__ */ jsx("button", {
1843
+ type: "button",
1844
+ "aria-label": "Remove link",
1845
+ "data-re-link-bm-unlink": "",
1846
+ onClick: handleUnlink,
1847
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
1848
+ }) : /* @__PURE__ */ jsx("button", {
1849
+ type: "submit",
1850
+ "aria-label": "Apply link",
1851
+ "data-re-link-bm-apply": "",
1852
+ onMouseDown: (e) => e.stopPropagation(),
1853
+ children: /* @__PURE__ */ jsx(Check, {})
1854
+ })
1855
+ ]
1856
+ });
1857
+ }
1858
+
1859
+ //#endregion
1860
+ //#region src/ui/link-bubble-menu/open-link.tsx
1861
+ function LinkBubbleMenuOpenLink({ className, children, ...rest }) {
1862
+ const { linkHref } = useLinkBubbleMenuContext();
1863
+ return /* @__PURE__ */ jsx("a", {
1864
+ ...rest,
1865
+ href: linkHref,
1866
+ target: "_blank",
1867
+ rel: "noopener noreferrer",
1868
+ "aria-label": "Open link",
1869
+ "data-re-link-bm-item": "",
1870
+ "data-item": "open-link",
1871
+ className,
1872
+ children: children ?? /* @__PURE__ */ jsx(ExternalLinkIcon, {})
1873
+ });
1874
+ }
1875
+
1876
+ //#endregion
1877
+ //#region src/ui/link-bubble-menu/root.tsx
1878
+ function LinkBubbleMenuRoot({ onHide, placement = "top", offset: offset$1 = 8, className, children }) {
1879
+ const { editor } = useCurrentEditor();
1880
+ const [isEditing, setIsEditing] = React.useState(false);
1881
+ const linkHref = useEditorState({
1882
+ editor,
1883
+ selector: ({ editor: e }) => e?.getAttributes("link").href ?? ""
1884
+ });
1885
+ if (!editor) return null;
1886
+ return /* @__PURE__ */ jsx(BubbleMenu$1, {
1887
+ editor,
1888
+ pluginKey: "linkBubbleMenu",
1889
+ "data-re-link-bm": "",
1890
+ shouldShow: ({ editor: e }) => e.isActive("link") && e.view.state.selection.content().size === 0,
1891
+ options: {
1892
+ placement,
1893
+ offset: offset$1,
1894
+ onHide: () => {
1895
+ setIsEditing(false);
1896
+ onHide?.();
1897
+ }
1898
+ },
1899
+ className,
1900
+ children: /* @__PURE__ */ jsx(LinkBubbleMenuContext.Provider, {
1901
+ value: {
1902
+ editor,
1903
+ linkHref: linkHref ?? "",
1904
+ isEditing,
1905
+ setIsEditing
1906
+ },
1907
+ children
1908
+ })
1909
+ });
1910
+ }
1911
+
1912
+ //#endregion
1913
+ //#region src/ui/link-bubble-menu/toolbar.tsx
1914
+ function LinkBubbleMenuToolbar({ children, ...rest }) {
1915
+ const { isEditing } = useLinkBubbleMenuContext();
1916
+ if (isEditing) return null;
1917
+ return /* @__PURE__ */ jsx("div", {
1918
+ "data-re-link-bm-toolbar": "",
1919
+ ...rest,
1920
+ children
1921
+ });
1922
+ }
1923
+
1924
+ //#endregion
1925
+ //#region src/ui/link-bubble-menu/unlink.tsx
1926
+ function LinkBubbleMenuUnlink({ className, children, onClick, onMouseDown, ...rest }) {
1927
+ const { editor } = useLinkBubbleMenuContext();
1928
+ return /* @__PURE__ */ jsx("button", {
1929
+ type: "button",
1930
+ "aria-label": "Remove link",
1931
+ "data-re-link-bm-item": "",
1932
+ "data-item": "unlink",
1933
+ className,
1934
+ onMouseDown: (e) => {
1935
+ e.preventDefault();
1936
+ onMouseDown?.(e);
1937
+ },
1938
+ onClick: (e) => {
1939
+ onClick?.(e);
1940
+ editor.chain().focus().unsetLink().run();
1941
+ },
1942
+ ...rest,
1943
+ children: children ?? /* @__PURE__ */ jsx(UnlinkIcon, {})
1944
+ });
1945
+ }
1946
+
1947
+ //#endregion
1948
+ //#region src/ui/link-bubble-menu/default.tsx
1949
+ function LinkBubbleMenuDefault({ excludeItems = [], placement, offset: offset$1, onHide, className, validateUrl, onLinkApply, onLinkRemove }) {
1950
+ const has = (item) => !excludeItems.includes(item);
1951
+ return /* @__PURE__ */ jsxs(LinkBubbleMenuRoot, {
1952
+ placement,
1953
+ offset: offset$1,
1954
+ onHide,
1955
+ className,
1956
+ children: [(has("edit-link") || has("open-link") || has("unlink")) && /* @__PURE__ */ jsxs(LinkBubbleMenuToolbar, { children: [
1957
+ has("edit-link") && /* @__PURE__ */ jsx(LinkBubbleMenuEditLink, {}),
1958
+ has("open-link") && /* @__PURE__ */ jsx(LinkBubbleMenuOpenLink, {}),
1959
+ has("unlink") && /* @__PURE__ */ jsx(LinkBubbleMenuUnlink, {})
1960
+ ] }), /* @__PURE__ */ jsx(LinkBubbleMenuForm, {
1961
+ validateUrl,
1962
+ onLinkApply,
1963
+ onLinkRemove
1964
+ })]
1965
+ });
1966
+ }
1967
+
1968
+ //#endregion
1969
+ //#region src/ui/link-bubble-menu/index.ts
1970
+ const LinkBubbleMenu = {
1971
+ Root: LinkBubbleMenuRoot,
1972
+ Toolbar: LinkBubbleMenuToolbar,
1973
+ Form: LinkBubbleMenuForm,
1974
+ EditLink: LinkBubbleMenuEditLink,
1975
+ Unlink: LinkBubbleMenuUnlink,
1976
+ OpenLink: LinkBubbleMenuOpenLink,
1977
+ Default: LinkBubbleMenuDefault
1978
+ };
1979
+
1980
+ //#endregion
1981
+ //#region src/ui/slash-command/utils.ts
1982
+ function isInsideNode(editor, type) {
1983
+ const { $from } = editor.state.selection;
1984
+ for (let d = $from.depth; d > 0; d--) if ($from.node(d).type.name === type) return true;
1985
+ return false;
1986
+ }
1987
+ function isAtMaxColumnsDepth(editor) {
1988
+ const { from } = editor.state.selection;
1989
+ return getColumnsDepth(editor.state.doc, from) >= MAX_COLUMNS_DEPTH;
1990
+ }
1991
+ function updateScrollView(container, item) {
1992
+ const containerRect = container.getBoundingClientRect();
1993
+ const itemRect = item.getBoundingClientRect();
1994
+ if (itemRect.top < containerRect.top) container.scrollTop -= containerRect.top - itemRect.top;
1995
+ else if (itemRect.bottom > containerRect.bottom) container.scrollTop += itemRect.bottom - containerRect.bottom;
1996
+ }
1997
+
1998
+ //#endregion
1999
+ //#region src/ui/slash-command/command-list.tsx
2000
+ const CATEGORY_ORDER = [
2001
+ "Text",
2002
+ "Media",
2003
+ "Layout",
2004
+ "Utility"
2005
+ ];
2006
+ function groupByCategory(items) {
2007
+ const seen = /* @__PURE__ */ new Map();
2008
+ for (const item of items) {
2009
+ const existing = seen.get(item.category);
2010
+ if (existing) existing.push(item);
2011
+ else seen.set(item.category, [item]);
2012
+ }
2013
+ const ordered = [];
2014
+ for (const cat of CATEGORY_ORDER) {
2015
+ const group = seen.get(cat);
2016
+ if (group) {
2017
+ ordered.push({
2018
+ category: cat,
2019
+ items: group
2020
+ });
2021
+ seen.delete(cat);
2022
+ }
2023
+ }
2024
+ for (const [category, group] of seen) ordered.push({
2025
+ category,
2026
+ items: group
2027
+ });
2028
+ return ordered;
2029
+ }
2030
+ function CommandItem({ item, selected, onSelect }) {
2031
+ return /* @__PURE__ */ jsxs("button", {
2032
+ "data-re-slash-command-item": "",
2033
+ "data-selected": selected || void 0,
2034
+ onClick: onSelect,
2035
+ type: "button",
2036
+ children: [item.icon, /* @__PURE__ */ jsx("span", { children: item.title })]
2037
+ });
2038
+ }
2039
+ function CommandList({ items, query, selectedIndex, onSelect }) {
2040
+ const containerRef = useRef(null);
2041
+ useLayoutEffect(() => {
2042
+ const container = containerRef.current;
2043
+ if (!container) return;
2044
+ const selected = container.querySelector("[data-selected]");
2045
+ if (selected) updateScrollView(container, selected);
2046
+ }, [selectedIndex]);
2047
+ if (items.length === 0) return /* @__PURE__ */ jsx("div", {
2048
+ "data-re-slash-command": "",
2049
+ children: /* @__PURE__ */ jsx("div", {
2050
+ "data-re-slash-command-empty": "",
2051
+ children: "No results"
2052
+ })
2053
+ });
2054
+ if (query.trim().length > 0) return /* @__PURE__ */ jsx("div", {
2055
+ "data-re-slash-command": "",
2056
+ ref: containerRef,
2057
+ children: items.map((item, index) => /* @__PURE__ */ jsx(CommandItem, {
2058
+ item,
2059
+ onSelect: () => onSelect(index),
2060
+ selected: index === selectedIndex
2061
+ }, item.title))
2062
+ });
2063
+ const groups = groupByCategory(items);
2064
+ let flatIndex = 0;
2065
+ return /* @__PURE__ */ jsx("div", {
2066
+ "data-re-slash-command": "",
2067
+ ref: containerRef,
2068
+ children: groups.map((group) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
2069
+ "data-re-slash-command-category": "",
2070
+ children: group.category
2071
+ }), group.items.map((item) => {
2072
+ const currentIndex = flatIndex++;
2073
+ return /* @__PURE__ */ jsx(CommandItem, {
2074
+ item,
2075
+ onSelect: () => onSelect(currentIndex),
2076
+ selected: currentIndex === selectedIndex
2077
+ }, item.title);
2078
+ })] }, group.category))
2079
+ });
2080
+ }
2081
+
2082
+ //#endregion
2083
+ //#region src/ui/slash-command/commands.tsx
2084
+ const TEXT = {
2085
+ title: "Text",
2086
+ description: "Plain text block",
2087
+ icon: /* @__PURE__ */ jsx(Text, { size: 20 }),
2088
+ category: "Text",
2089
+ searchTerms: ["p", "paragraph"],
2090
+ command: ({ editor, range }) => {
2091
+ editor.chain().focus().deleteRange(range).toggleNode("paragraph", "paragraph").run();
2092
+ }
2093
+ };
2094
+ const H1 = {
2095
+ title: "Title",
2096
+ description: "Large heading",
2097
+ icon: /* @__PURE__ */ jsx(Heading1, { size: 20 }),
2098
+ category: "Text",
2099
+ searchTerms: [
2100
+ "title",
2101
+ "big",
2102
+ "large",
2103
+ "h1"
2104
+ ],
2105
+ command: ({ editor, range }) => {
2106
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 1 }).run();
2107
+ }
2108
+ };
2109
+ const H2 = {
2110
+ title: "Subtitle",
2111
+ description: "Medium heading",
2112
+ icon: /* @__PURE__ */ jsx(Heading2, { size: 20 }),
2113
+ category: "Text",
2114
+ searchTerms: [
2115
+ "subtitle",
2116
+ "medium",
2117
+ "h2"
2118
+ ],
2119
+ command: ({ editor, range }) => {
2120
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 2 }).run();
2121
+ }
2122
+ };
2123
+ const H3 = {
2124
+ title: "Heading",
2125
+ description: "Small heading",
2126
+ icon: /* @__PURE__ */ jsx(Heading3, { size: 20 }),
2127
+ category: "Text",
2128
+ searchTerms: [
2129
+ "subtitle",
2130
+ "small",
2131
+ "h3"
2132
+ ],
2133
+ command: ({ editor, range }) => {
2134
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 3 }).run();
2135
+ }
2136
+ };
2137
+ const BULLET_LIST = {
2138
+ title: "Bullet list",
2139
+ description: "Unordered list",
2140
+ icon: /* @__PURE__ */ jsx(List, { size: 20 }),
2141
+ category: "Text",
2142
+ searchTerms: ["unordered", "point"],
2143
+ command: ({ editor, range }) => {
2144
+ editor.chain().focus().deleteRange(range).toggleBulletList().run();
2145
+ }
2146
+ };
2147
+ const NUMBERED_LIST = {
2148
+ title: "Numbered list",
2149
+ description: "Ordered list",
2150
+ icon: /* @__PURE__ */ jsx(ListOrdered, { size: 20 }),
2151
+ category: "Text",
2152
+ searchTerms: ["ordered"],
2153
+ command: ({ editor, range }) => {
2154
+ editor.chain().focus().deleteRange(range).toggleOrderedList().run();
2155
+ }
2156
+ };
2157
+ const QUOTE = {
2158
+ title: "Quote",
2159
+ description: "Block quote",
2160
+ icon: /* @__PURE__ */ jsx(TextQuote, { size: 20 }),
2161
+ category: "Text",
2162
+ searchTerms: ["blockquote"],
2163
+ command: ({ editor, range }) => {
2164
+ editor.chain().focus().deleteRange(range).toggleNode("paragraph", "paragraph").toggleBlockquote().run();
2165
+ }
2166
+ };
2167
+ const CODE = {
2168
+ title: "Code block",
2169
+ description: "Code snippet",
2170
+ icon: /* @__PURE__ */ jsx(SquareCode, { size: 20 }),
2171
+ category: "Text",
2172
+ searchTerms: ["codeblock"],
2173
+ command: ({ editor, range }) => {
2174
+ editor.chain().focus().deleteRange(range).toggleCodeBlock().run();
2175
+ }
2176
+ };
2177
+ const BUTTON = {
2178
+ title: "Button",
2179
+ description: "Clickable button",
2180
+ icon: /* @__PURE__ */ jsx(MousePointer, { size: 20 }),
2181
+ category: "Layout",
2182
+ searchTerms: ["button"],
2183
+ command: ({ editor, range }) => {
2184
+ editor.chain().focus().deleteRange(range).setButton().run();
2185
+ }
2186
+ };
2187
+ const DIVIDER = {
2188
+ title: "Divider",
2189
+ description: "Horizontal separator",
2190
+ icon: /* @__PURE__ */ jsx(SplitSquareVertical, { size: 20 }),
2191
+ category: "Layout",
2192
+ searchTerms: [
2193
+ "hr",
2194
+ "divider",
2195
+ "separator"
2196
+ ],
2197
+ command: ({ editor, range }) => {
2198
+ editor.chain().focus().deleteRange(range).setHorizontalRule().run();
2199
+ }
2200
+ };
2201
+ const SECTION = {
2202
+ title: "Section",
2203
+ description: "Content section",
2204
+ icon: /* @__PURE__ */ jsx(Rows2, { size: 20 }),
2205
+ category: "Layout",
2206
+ searchTerms: [
2207
+ "section",
2208
+ "row",
2209
+ "container"
2210
+ ],
2211
+ command: ({ editor, range }) => {
2212
+ editor.chain().focus().deleteRange(range).insertSection().run();
2213
+ }
2214
+ };
2215
+ const TWO_COLUMNS = {
2216
+ title: "2 columns",
2217
+ description: "Two column layout",
2218
+ icon: /* @__PURE__ */ jsx(Columns2, { size: 20 }),
2219
+ category: "Layout",
2220
+ searchTerms: [
2221
+ "columns",
2222
+ "column",
2223
+ "layout",
2224
+ "grid",
2225
+ "split",
2226
+ "side-by-side",
2227
+ "multi-column",
2228
+ "row",
2229
+ "two",
2230
+ "2"
2231
+ ],
2232
+ command: ({ editor, range }) => {
2233
+ editor.chain().focus().deleteRange(range).insertColumns(2).run();
2234
+ }
2235
+ };
2236
+ const THREE_COLUMNS = {
2237
+ title: "3 columns",
2238
+ description: "Three column layout",
2239
+ icon: /* @__PURE__ */ jsx(Columns3, { size: 20 }),
2240
+ category: "Layout",
2241
+ searchTerms: [
2242
+ "columns",
2243
+ "column",
2244
+ "layout",
2245
+ "grid",
2246
+ "split",
2247
+ "multi-column",
2248
+ "row",
2249
+ "three",
2250
+ "3"
2251
+ ],
2252
+ command: ({ editor, range }) => {
2253
+ editor.chain().focus().deleteRange(range).insertColumns(3).run();
2254
+ }
2255
+ };
2256
+ const FOUR_COLUMNS = {
2257
+ title: "4 columns",
2258
+ description: "Four column layout",
2259
+ icon: /* @__PURE__ */ jsx(Columns4, { size: 20 }),
2260
+ category: "Layout",
2261
+ searchTerms: [
2262
+ "columns",
2263
+ "column",
2264
+ "layout",
2265
+ "grid",
2266
+ "split",
2267
+ "multi-column",
2268
+ "row",
2269
+ "four",
2270
+ "4"
2271
+ ],
2272
+ command: ({ editor, range }) => {
2273
+ editor.chain().focus().deleteRange(range).insertColumns(4).run();
2274
+ }
2275
+ };
2276
+ const defaultSlashCommands = [
2277
+ TEXT,
2278
+ H1,
2279
+ H2,
2280
+ H3,
2281
+ BULLET_LIST,
2282
+ NUMBERED_LIST,
2283
+ QUOTE,
2284
+ CODE,
2285
+ BUTTON,
2286
+ DIVIDER,
2287
+ SECTION,
2288
+ TWO_COLUMNS,
2289
+ THREE_COLUMNS,
2290
+ FOUR_COLUMNS
2291
+ ];
2292
+
2293
+ //#endregion
2294
+ //#region src/ui/slash-command/search.ts
2295
+ function scoreItem(item, query) {
2296
+ if (!query) return 100;
2297
+ const q = query.toLowerCase();
2298
+ const title = item.title.toLowerCase();
2299
+ const description = item.description.toLowerCase();
2300
+ const terms = item.searchTerms?.map((t) => t.toLowerCase()) ?? [];
2301
+ if (title === q) return 100;
2302
+ if (title.startsWith(q)) return 90;
2303
+ if (title.split(/\s+/).some((w) => w.startsWith(q))) return 80;
2304
+ if (terms.some((t) => t === q)) return 70;
2305
+ if (terms.some((t) => t.startsWith(q))) return 60;
2306
+ if (title.includes(q)) return 40;
2307
+ if (terms.some((t) => t.includes(q))) return 30;
2308
+ if (description.includes(q)) return 20;
2309
+ return 0;
2310
+ }
2311
+ function filterAndRankItems(items, query) {
2312
+ const trimmed = query.trim();
2313
+ if (!trimmed) return items;
2314
+ const scored = items.map((item) => ({
2315
+ item,
2316
+ score: scoreItem(item, trimmed)
2317
+ })).filter(({ score }) => score > 0);
2318
+ scored.sort((a, b) => b.score - a.score);
2319
+ return scored.map(({ item }) => item);
2320
+ }
2321
+
2322
+ //#endregion
2323
+ //#region src/ui/slash-command/root.tsx
2324
+ const pluginKey = new PluginKey("slash-command");
2325
+ const INITIAL_STATE = {
2326
+ active: false,
2327
+ query: "",
2328
+ items: [],
2329
+ clientRect: null
2330
+ };
2331
+ function defaultFilterItems(items, query, editor) {
2332
+ return filterAndRankItems(isAtMaxColumnsDepth(editor) ? items.filter((item) => item.category !== "Layout" || !item.title.includes("column")) : items, query);
2333
+ }
2334
+ function SlashCommandRoot({ items: itemsProp, filterItems: filterItemsProp, char = "/", allow: allowProp, children }) {
2335
+ const { editor } = useCurrentEditor();
2336
+ const [state, setState] = useState(INITIAL_STATE);
2337
+ const [selectedIndex, setSelectedIndex] = useState(0);
2338
+ const itemsRef = useRef(itemsProp ?? defaultSlashCommands);
2339
+ const filterRef = useRef(filterItemsProp ?? defaultFilterItems);
2340
+ const allowRef = useRef(allowProp ?? (({ editor: e }) => !e.isActive("codeBlock")));
2341
+ itemsRef.current = itemsProp ?? defaultSlashCommands;
2342
+ filterRef.current = filterItemsProp ?? defaultFilterItems;
2343
+ allowRef.current = allowProp ?? (({ editor: e }) => !e.isActive("codeBlock"));
2344
+ const commandRef = useRef(null);
2345
+ const suggestionItemsRef = useRef([]);
2346
+ const selectedIndexRef = useRef(0);
2347
+ suggestionItemsRef.current = state.items;
2348
+ selectedIndexRef.current = selectedIndex;
2349
+ const { refs, floatingStyles } = useFloating({
2350
+ open: state.active,
2351
+ placement: "bottom-start",
2352
+ middleware: [
2353
+ offset(8),
2354
+ flip(),
2355
+ shift({ padding: 8 })
2356
+ ],
2357
+ whileElementsMounted: autoUpdate
2358
+ });
2359
+ useEffect(() => {
2360
+ if (!state.clientRect) return;
2361
+ refs.setReference({ getBoundingClientRect: state.clientRect });
2362
+ }, [state.clientRect, refs]);
2363
+ useEffect(() => {
2364
+ setSelectedIndex(0);
2365
+ }, [state.items]);
2366
+ const onSelect = useCallback((index) => {
2367
+ const item = suggestionItemsRef.current[index];
2368
+ if (item && commandRef.current) commandRef.current(item);
2369
+ }, []);
2370
+ useEffect(() => {
2371
+ if (!editor) return;
2372
+ const plugin = Suggestion({
2373
+ pluginKey,
2374
+ editor,
2375
+ char,
2376
+ allow: ({ editor: e }) => allowRef.current({ editor: e }),
2377
+ command: ({ editor: e, range, props }) => {
2378
+ props.command({
2379
+ editor: e,
2380
+ range
2381
+ });
2382
+ },
2383
+ items: ({ query, editor: e }) => filterRef.current(itemsRef.current, query, e),
2384
+ render: () => ({
2385
+ onStart: (props) => {
2386
+ commandRef.current = props.command;
2387
+ setState({
2388
+ active: true,
2389
+ query: props.query,
2390
+ items: props.items,
2391
+ clientRect: props.clientRect ?? null
2392
+ });
2393
+ },
2394
+ onUpdate: (props) => {
2395
+ commandRef.current = props.command;
2396
+ setState({
2397
+ active: true,
2398
+ query: props.query,
2399
+ items: props.items,
2400
+ clientRect: props.clientRect ?? null
2401
+ });
2402
+ },
2403
+ onKeyDown: ({ event }) => {
2404
+ if (event.key === "Escape") {
2405
+ setState(INITIAL_STATE);
2406
+ return true;
2407
+ }
2408
+ const items = suggestionItemsRef.current;
2409
+ if (items.length === 0) return false;
2410
+ if (event.key === "ArrowUp") {
2411
+ setSelectedIndex((i) => (i + items.length - 1) % items.length);
2412
+ return true;
2413
+ }
2414
+ if (event.key === "ArrowDown") {
2415
+ setSelectedIndex((i) => (i + 1) % items.length);
2416
+ return true;
2417
+ }
2418
+ if (event.key === "Enter") {
2419
+ const item = items[selectedIndexRef.current];
2420
+ if (item && commandRef.current) commandRef.current(item);
2421
+ return true;
2422
+ }
2423
+ return false;
2424
+ },
2425
+ onExit: () => {
2426
+ setState(INITIAL_STATE);
2427
+ requestAnimationFrame(() => {
2428
+ commandRef.current = null;
2429
+ });
2430
+ }
2431
+ })
2432
+ });
2433
+ editor.registerPlugin(plugin, (newPlugin, plugins) => [newPlugin, ...plugins]);
2434
+ return () => {
2435
+ editor.unregisterPlugin(pluginKey);
2436
+ };
2437
+ }, [editor, char]);
2438
+ if (!editor || !state.active) return null;
2439
+ const renderProps = {
2440
+ items: state.items,
2441
+ query: state.query,
2442
+ selectedIndex,
2443
+ onSelect
2444
+ };
2445
+ let content;
2446
+ if (children) content = children(renderProps);
2447
+ else content = /* @__PURE__ */ jsx(CommandList, { ...renderProps });
2448
+ return createPortal(/* @__PURE__ */ jsx("div", {
2449
+ ref: refs.setFloating,
2450
+ style: floatingStyles,
2451
+ children: content
2452
+ }), document.body);
2453
+ }
2454
+
2455
+ //#endregion
2456
+ //#region src/ui/slash-command/index.ts
2457
+ const SlashCommand = {
2458
+ Root: SlashCommandRoot,
2459
+ CommandList
2460
+ };
2461
+
2462
+ //#endregion
2463
+ export { AlignCenterIcon, AlignLeftIcon, AlignRightIcon, BULLET_LIST, BUTTON, BoldIcon, BubbleMenu, BubbleMenuAlignCenter, BubbleMenuAlignLeft, BubbleMenuAlignRight, BubbleMenuBold, BubbleMenuCode, BubbleMenuDefault, BubbleMenuItalic, BubbleMenuItem, BubbleMenuItemGroup, BubbleMenuLinkSelector, BubbleMenuNodeSelector, BubbleMenuRoot, BubbleMenuSeparator, BubbleMenuStrike, BubbleMenuUnderline, BubbleMenuUppercase, ButtonBubbleMenu, ButtonBubbleMenuDefault, ButtonBubbleMenuEditLink, ButtonBubbleMenuForm, ButtonBubbleMenuRoot, ButtonBubbleMenuToolbar, ButtonBubbleMenuUnlink, CODE, CaseUpperIcon, Check, ChevronDown, Code, CodeIcon, Columns2, Columns3, Columns4, CommandList, DIVIDER, ExternalLinkIcon, FOUR_COLUMNS, H1, H2, H3, Heading1, Heading2, Heading3, ImageBubbleMenu, ImageBubbleMenuDefault, ImageBubbleMenuEditLink, ImageBubbleMenuRoot, ImageBubbleMenuToolbar, ItalicIcon, LinkBubbleMenu, LinkBubbleMenuDefault, LinkBubbleMenuEditLink, LinkBubbleMenuForm, LinkBubbleMenuOpenLink, LinkBubbleMenuRoot, LinkBubbleMenuToolbar, LinkBubbleMenuUnlink, LinkIcon, List, ListOrdered, MousePointer, NUMBERED_LIST, NodeSelectorContent, NodeSelectorRoot, NodeSelectorTrigger, PencilIcon, QUOTE, Rows2, SECTION, SlashCommand, SplitSquareVertical, SquareCode, StrikethroughIcon, TEXT, THREE_COLUMNS, TWO_COLUMNS, Text, TextIcon, TextQuote, UnderlineIcon, UnlinkIcon, defaultSlashCommands, filterAndRankItems, isAtMaxColumnsDepth, isInsideNode, scoreItem, useButtonBubbleMenuContext, useImageBubbleMenuContext, useLinkBubbleMenuContext };
2464
+ //# sourceMappingURL=index.mjs.map