@react-email/editor 0.0.0-experimental.35 → 0.0.0-experimental.38

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 (67) hide show
  1. package/dist/core/index.cjs +8 -7
  2. package/dist/core/index.d.cts +2 -2
  3. package/dist/core/index.d.mts +3 -2
  4. package/dist/core/index.mjs +3 -3
  5. package/dist/create-paste-handler-B8BtjBk3.d.cts +14 -0
  6. package/dist/create-paste-handler-B8BtjBk3.d.cts.map +1 -0
  7. package/dist/create-paste-handler-CGR738bC.d.mts +14 -0
  8. package/dist/create-paste-handler-CGR738bC.d.mts.map +1 -0
  9. package/dist/{columns-Cos2lqfu.mjs → event-bus-CHEzOS_O.mjs} +45 -45
  10. package/dist/event-bus-CHEzOS_O.mjs.map +1 -0
  11. package/dist/{columns-BXN-NNd4.cjs → event-bus-fb8U7hrl.cjs} +42 -42
  12. package/dist/extension-CnC8y63H.mjs +1119 -0
  13. package/dist/extension-CnC8y63H.mjs.map +1 -0
  14. package/dist/extension-dGpPpEvD.cjs +1244 -0
  15. package/dist/extensions/index.cjs +45 -45
  16. package/dist/extensions/index.d.cts +2 -41
  17. package/dist/extensions/index.d.cts.map +1 -1
  18. package/dist/extensions/index.d.mts +3 -41
  19. package/dist/extensions/index.d.mts.map +1 -1
  20. package/dist/extensions/index.mjs +3 -3
  21. package/dist/{core-mUMTkab3.mjs → extensions-DWsu9kwZ.mjs} +221 -221
  22. package/dist/extensions-DWsu9kwZ.mjs.map +1 -0
  23. package/dist/{core-DVox_fis.cjs → extensions-aMMnHcs9.cjs} +298 -280
  24. package/dist/{global-content-kdUzYcsA.mjs → global-content-5rAU84QT.mjs} +1 -1
  25. package/dist/{global-content-kdUzYcsA.mjs.map → global-content-5rAU84QT.mjs.map} +1 -1
  26. package/dist/{global-content-BRvA4PRG.cjs → global-content-62RO9uoQ.cjs} +1 -1
  27. package/dist/{index-CVRlPqX_.d.cts → index-C4KcMQ0R.d.cts} +43 -13
  28. package/dist/index-C4KcMQ0R.d.cts.map +1 -0
  29. package/dist/{index-BrSAA0dn.d.mts → index-CxX7W63O.d.mts} +43 -13
  30. package/dist/index-CxX7W63O.d.mts.map +1 -0
  31. package/dist/index.cjs +74 -0
  32. package/dist/index.css +859 -0
  33. package/dist/index.css.map +1 -0
  34. package/dist/index.d.cts +33 -0
  35. package/dist/index.d.cts.map +1 -0
  36. package/dist/index.d.mts +33 -0
  37. package/dist/index.d.mts.map +1 -0
  38. package/dist/index.mjs +74 -0
  39. package/dist/index.mjs.map +1 -0
  40. package/dist/plugins/index.cjs +22 -1138
  41. package/dist/plugins/index.d.cts.map +1 -1
  42. package/dist/plugins/index.d.mts +1 -1
  43. package/dist/plugins/index.d.mts.map +1 -1
  44. package/dist/plugins/index.mjs +2 -1118
  45. package/dist/root-BMxsq1NF.mjs +2401 -0
  46. package/dist/root-BMxsq1NF.mjs.map +1 -0
  47. package/dist/root-CNVO39XG.cjs +2941 -0
  48. package/dist/{set-text-alignment-BO24ieeE.mjs → set-text-alignment-GMXOPMlJ.mjs} +1 -1
  49. package/dist/{set-text-alignment-BO24ieeE.mjs.map → set-text-alignment-GMXOPMlJ.mjs.map} +1 -1
  50. package/dist/{styles-DLviD0JK.mjs → styles-_TMw3YxC.mjs} +1 -1
  51. package/dist/{styles-DLviD0JK.mjs.map → styles-_TMw3YxC.mjs.map} +1 -1
  52. package/dist/ui/index.cjs +128 -2515
  53. package/dist/ui/index.d.cts +97 -102
  54. package/dist/ui/index.d.cts.map +1 -1
  55. package/dist/ui/index.d.mts +98 -103
  56. package/dist/ui/index.d.mts.map +1 -1
  57. package/dist/ui/index.mjs +2 -2388
  58. package/dist/ui/index.mjs.map +1 -1
  59. package/dist/utils/index.cjs +1 -1
  60. package/dist/utils/index.mjs +1 -1
  61. package/package.json +12 -2
  62. package/dist/columns-Cos2lqfu.mjs.map +0 -1
  63. package/dist/core-mUMTkab3.mjs.map +0 -1
  64. package/dist/index-BrSAA0dn.d.mts.map +0 -1
  65. package/dist/index-CVRlPqX_.d.cts.map +0 -1
  66. package/dist/plugins/index.mjs.map +0 -1
  67. /package/dist/{set-text-alignment-CbECklB4.cjs → set-text-alignment-aNb7Ml9N.cjs} +0 -0
@@ -0,0 +1,2401 @@
1
+ import { a as MAX_COLUMNS_DEPTH, c as getColumnsDepth, t as editorEventBus } from "./event-bus-CHEzOS_O.mjs";
2
+ import { t as setTextAlignment } from "./set-text-alignment-GMXOPMlJ.mjs";
3
+ import { useCurrentEditor, useEditorState } from "@tiptap/react";
4
+ import * as React from "react";
5
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { PluginKey } from "@tiptap/pm/state";
8
+ import * as Popover from "@radix-ui/react-popover";
9
+ import { BubbleMenu } 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, ...rest }) {
1239
+ const { editor } = useCurrentEditor();
1240
+ if (!editor) return null;
1241
+ return /* @__PURE__ */ jsx(BubbleMenu, {
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
+ ...rest,
1262
+ children: /* @__PURE__ */ jsx(BubbleMenuContext.Provider, {
1263
+ value: { editor },
1264
+ children
1265
+ })
1266
+ });
1267
+ }
1268
+
1269
+ //#endregion
1270
+ //#region src/ui/bubble-menu/strike.tsx
1271
+ const BubbleMenuStrike = createMarkBubbleItem({
1272
+ name: "strike",
1273
+ activeName: "strike",
1274
+ command: "toggleStrike",
1275
+ icon: /* @__PURE__ */ jsx(StrikethroughIcon, {})
1276
+ });
1277
+
1278
+ //#endregion
1279
+ //#region src/ui/bubble-menu/underline.tsx
1280
+ const BubbleMenuUnderline = createMarkBubbleItem({
1281
+ name: "underline",
1282
+ activeName: "underline",
1283
+ command: "toggleUnderline",
1284
+ icon: /* @__PURE__ */ jsx(UnderlineIcon, {})
1285
+ });
1286
+
1287
+ //#endregion
1288
+ //#region src/ui/bubble-menu/uppercase.tsx
1289
+ const BubbleMenuUppercase = createMarkBubbleItem({
1290
+ name: "uppercase",
1291
+ activeName: "uppercase",
1292
+ command: "toggleUppercase",
1293
+ icon: /* @__PURE__ */ jsx(CaseUpperIcon, {})
1294
+ });
1295
+
1296
+ //#endregion
1297
+ //#region src/ui/bubble-menu/default.tsx
1298
+ function BubbleMenuDefault({ excludeItems = [], excludeNodes, excludeMarks, placement, offset: offset$1, onHide, className, ...rest }) {
1299
+ const [isNodeSelectorOpen, setIsNodeSelectorOpen] = React.useState(false);
1300
+ const [isLinkSelectorOpen, setIsLinkSelectorOpen] = React.useState(false);
1301
+ const has = (item) => !excludeItems.includes(item);
1302
+ const handleNodeSelectorOpenChange = React.useCallback((open) => {
1303
+ setIsNodeSelectorOpen(open);
1304
+ if (open) setIsLinkSelectorOpen(false);
1305
+ }, []);
1306
+ const handleLinkSelectorOpenChange = React.useCallback((open) => {
1307
+ setIsLinkSelectorOpen(open);
1308
+ if (open) setIsNodeSelectorOpen(false);
1309
+ }, []);
1310
+ const handleHide = React.useCallback(() => {
1311
+ setIsNodeSelectorOpen(false);
1312
+ setIsLinkSelectorOpen(false);
1313
+ onHide?.();
1314
+ }, [onHide]);
1315
+ const hasFormattingItems = has("bold") || has("italic") || has("underline") || has("strike") || has("code") || has("uppercase");
1316
+ const hasAlignmentItems = has("align-left") || has("align-center") || has("align-right");
1317
+ return /* @__PURE__ */ jsxs(BubbleMenuRoot, {
1318
+ excludeNodes,
1319
+ excludeMarks,
1320
+ placement,
1321
+ offset: offset$1,
1322
+ onHide: handleHide,
1323
+ className,
1324
+ ...rest,
1325
+ children: [
1326
+ has("node-selector") && /* @__PURE__ */ jsx(BubbleMenuNodeSelector, {
1327
+ open: isNodeSelectorOpen,
1328
+ onOpenChange: handleNodeSelectorOpenChange
1329
+ }),
1330
+ has("link-selector") && /* @__PURE__ */ jsx(BubbleMenuLinkSelector, {
1331
+ open: isLinkSelectorOpen,
1332
+ onOpenChange: handleLinkSelectorOpenChange
1333
+ }),
1334
+ hasFormattingItems && /* @__PURE__ */ jsxs(BubbleMenuItemGroup, { children: [
1335
+ has("bold") && /* @__PURE__ */ jsx(BubbleMenuBold, {}),
1336
+ has("italic") && /* @__PURE__ */ jsx(BubbleMenuItalic, {}),
1337
+ has("underline") && /* @__PURE__ */ jsx(BubbleMenuUnderline, {}),
1338
+ has("strike") && /* @__PURE__ */ jsx(BubbleMenuStrike, {}),
1339
+ has("code") && /* @__PURE__ */ jsx(BubbleMenuCode, {}),
1340
+ has("uppercase") && /* @__PURE__ */ jsx(BubbleMenuUppercase, {})
1341
+ ] }),
1342
+ hasAlignmentItems && /* @__PURE__ */ jsxs(BubbleMenuItemGroup, { children: [
1343
+ has("align-left") && /* @__PURE__ */ jsx(BubbleMenuAlignLeft, {}),
1344
+ has("align-center") && /* @__PURE__ */ jsx(BubbleMenuAlignCenter, {}),
1345
+ has("align-right") && /* @__PURE__ */ jsx(BubbleMenuAlignRight, {})
1346
+ ] })
1347
+ ]
1348
+ });
1349
+ }
1350
+
1351
+ //#endregion
1352
+ //#region src/ui/button-bubble-menu/context.tsx
1353
+ const ButtonBubbleMenuContext = React.createContext(null);
1354
+ function useButtonBubbleMenuContext() {
1355
+ const context = React.useContext(ButtonBubbleMenuContext);
1356
+ if (!context) throw new Error("ButtonBubbleMenu compound components must be used within <ButtonBubbleMenu.Root>");
1357
+ return context;
1358
+ }
1359
+
1360
+ //#endregion
1361
+ //#region src/ui/button-bubble-menu/edit-link.tsx
1362
+ function ButtonBubbleMenuEditLink({ className, children, onClick, onMouseDown, ...rest }) {
1363
+ const { setIsEditing } = useButtonBubbleMenuContext();
1364
+ return /* @__PURE__ */ jsx("button", {
1365
+ ...rest,
1366
+ type: "button",
1367
+ "aria-label": "Edit link",
1368
+ "data-re-btn-bm-item": "",
1369
+ "data-item": "edit-link",
1370
+ className,
1371
+ onMouseDown: (e) => {
1372
+ e.preventDefault();
1373
+ onMouseDown?.(e);
1374
+ },
1375
+ onClick: (e) => {
1376
+ onClick?.(e);
1377
+ setIsEditing(true);
1378
+ },
1379
+ children: children ?? /* @__PURE__ */ jsx(PencilIcon, {})
1380
+ });
1381
+ }
1382
+
1383
+ //#endregion
1384
+ //#region src/ui/button-bubble-menu/form.tsx
1385
+ function ButtonBubbleMenuForm({ className, validateUrl, onLinkApply, onLinkRemove }) {
1386
+ const { editor, buttonHref, isEditing, setIsEditing } = useButtonBubbleMenuContext();
1387
+ const inputRef = React.useRef(null);
1388
+ const formRef = React.useRef(null);
1389
+ const displayHref = buttonHref === "#" ? "" : buttonHref;
1390
+ const [inputValue, setInputValue] = React.useState(displayHref);
1391
+ React.useEffect(() => {
1392
+ if (!isEditing) return;
1393
+ setInputValue(displayHref);
1394
+ const timeoutId = setTimeout(() => {
1395
+ inputRef.current?.focus();
1396
+ }, 0);
1397
+ return () => clearTimeout(timeoutId);
1398
+ }, [isEditing, displayHref]);
1399
+ React.useEffect(() => {
1400
+ if (!isEditing) return;
1401
+ const handleKeyDown = (event) => {
1402
+ if (event.key === "Escape") setIsEditing(false);
1403
+ };
1404
+ const handleClickOutside = (event) => {
1405
+ if (formRef.current && !formRef.current.contains(event.target)) {
1406
+ const form = formRef.current;
1407
+ const submitEvent = new Event("submit", {
1408
+ bubbles: true,
1409
+ cancelable: true
1410
+ });
1411
+ form.dispatchEvent(submitEvent);
1412
+ setIsEditing(false);
1413
+ }
1414
+ };
1415
+ document.addEventListener("mousedown", handleClickOutside);
1416
+ window.addEventListener("keydown", handleKeyDown);
1417
+ return () => {
1418
+ window.removeEventListener("keydown", handleKeyDown);
1419
+ document.removeEventListener("mousedown", handleClickOutside);
1420
+ };
1421
+ }, [isEditing, setIsEditing]);
1422
+ if (!isEditing) return null;
1423
+ function handleSubmit(e) {
1424
+ e.preventDefault();
1425
+ const value = inputValue.trim();
1426
+ if (value === "") {
1427
+ editor.commands.updateButton({ href: "#" });
1428
+ setIsEditing(false);
1429
+ focusEditor(editor);
1430
+ onLinkRemove?.();
1431
+ return;
1432
+ }
1433
+ const finalValue = (validateUrl ?? getUrlFromString)(value);
1434
+ if (!finalValue) {
1435
+ editor.commands.updateButton({ href: "#" });
1436
+ setIsEditing(false);
1437
+ focusEditor(editor);
1438
+ onLinkRemove?.();
1439
+ return;
1440
+ }
1441
+ editor.commands.updateButton({ href: finalValue });
1442
+ setIsEditing(false);
1443
+ focusEditor(editor);
1444
+ onLinkApply?.(finalValue);
1445
+ }
1446
+ function handleUnlink(e) {
1447
+ e.stopPropagation();
1448
+ editor.commands.updateButton({ href: "#" });
1449
+ setIsEditing(false);
1450
+ focusEditor(editor);
1451
+ onLinkRemove?.();
1452
+ }
1453
+ return /* @__PURE__ */ jsxs("form", {
1454
+ ref: formRef,
1455
+ "data-re-btn-bm-form": "",
1456
+ className,
1457
+ onMouseDown: (e) => e.stopPropagation(),
1458
+ onClick: (e) => e.stopPropagation(),
1459
+ onKeyDown: (e) => e.stopPropagation(),
1460
+ onSubmit: handleSubmit,
1461
+ children: [/* @__PURE__ */ jsx("input", {
1462
+ ref: inputRef,
1463
+ "data-re-btn-bm-input": "",
1464
+ value: inputValue,
1465
+ onFocus: (e) => e.stopPropagation(),
1466
+ onChange: (e) => setInputValue(e.target.value),
1467
+ placeholder: "Paste a link",
1468
+ type: "text"
1469
+ }), displayHref ? /* @__PURE__ */ jsx("button", {
1470
+ type: "button",
1471
+ "aria-label": "Remove link",
1472
+ "data-re-btn-bm-unlink": "",
1473
+ onClick: handleUnlink,
1474
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
1475
+ }) : /* @__PURE__ */ jsx("button", {
1476
+ type: "submit",
1477
+ "aria-label": "Apply link",
1478
+ "data-re-btn-bm-apply": "",
1479
+ onMouseDown: (e) => e.stopPropagation(),
1480
+ children: /* @__PURE__ */ jsx(Check, {})
1481
+ })]
1482
+ });
1483
+ }
1484
+
1485
+ //#endregion
1486
+ //#region src/ui/button-bubble-menu/root.tsx
1487
+ function ButtonBubbleMenuRoot({ onHide, placement = "top", offset: offset$1 = 8, className, children, ...rest }) {
1488
+ const { editor } = useCurrentEditor();
1489
+ const [isEditing, setIsEditing] = React.useState(false);
1490
+ const buttonHref = useEditorState({
1491
+ editor,
1492
+ selector: ({ editor: e }) => e?.getAttributes("button").href ?? ""
1493
+ });
1494
+ if (!editor) return null;
1495
+ return /* @__PURE__ */ jsx(BubbleMenu, {
1496
+ editor,
1497
+ pluginKey: "buttonBubbleMenu",
1498
+ "data-re-btn-bm": "",
1499
+ shouldShow: ({ editor: e, view }) => e.isActive("button") && !view.dom.classList.contains("dragging"),
1500
+ options: {
1501
+ placement,
1502
+ offset: offset$1,
1503
+ onHide: () => {
1504
+ setIsEditing(false);
1505
+ onHide?.();
1506
+ }
1507
+ },
1508
+ className,
1509
+ ...rest,
1510
+ children: /* @__PURE__ */ jsx(ButtonBubbleMenuContext.Provider, {
1511
+ value: {
1512
+ editor,
1513
+ buttonHref: buttonHref ?? "",
1514
+ isEditing,
1515
+ setIsEditing
1516
+ },
1517
+ children
1518
+ })
1519
+ });
1520
+ }
1521
+
1522
+ //#endregion
1523
+ //#region src/ui/button-bubble-menu/toolbar.tsx
1524
+ function ButtonBubbleMenuToolbar({ children, ...rest }) {
1525
+ const { isEditing } = useButtonBubbleMenuContext();
1526
+ if (isEditing) return null;
1527
+ return /* @__PURE__ */ jsx("div", {
1528
+ "data-re-btn-bm-toolbar": "",
1529
+ ...rest,
1530
+ children
1531
+ });
1532
+ }
1533
+
1534
+ //#endregion
1535
+ //#region src/ui/button-bubble-menu/unlink.tsx
1536
+ function ButtonBubbleMenuUnlink({ className, children, onClick, onMouseDown, onLinkRemove, ...rest }) {
1537
+ const { editor } = useButtonBubbleMenuContext();
1538
+ return /* @__PURE__ */ jsx("button", {
1539
+ ...rest,
1540
+ type: "button",
1541
+ "aria-label": "Remove link",
1542
+ "data-re-btn-bm-item": "",
1543
+ "data-item": "unlink",
1544
+ className,
1545
+ onMouseDown: (e) => {
1546
+ e.preventDefault();
1547
+ onMouseDown?.(e);
1548
+ },
1549
+ onClick: (e) => {
1550
+ onClick?.(e);
1551
+ editor.commands.updateButton({ href: "#" });
1552
+ focusEditor(editor);
1553
+ onLinkRemove?.();
1554
+ },
1555
+ children: children ?? /* @__PURE__ */ jsx(UnlinkIcon, {})
1556
+ });
1557
+ }
1558
+
1559
+ //#endregion
1560
+ //#region src/ui/button-bubble-menu/default.tsx
1561
+ function ButtonBubbleMenuDefaultInner({ validateUrl, onLinkApply, onLinkRemove }) {
1562
+ const { buttonHref } = useButtonBubbleMenuContext();
1563
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(ButtonBubbleMenuToolbar, { children: [/* @__PURE__ */ jsx(ButtonBubbleMenuEditLink, {}), buttonHref !== "" && buttonHref !== "#" && /* @__PURE__ */ jsx(ButtonBubbleMenuUnlink, { onLinkRemove })] }), /* @__PURE__ */ jsx(ButtonBubbleMenuForm, {
1564
+ validateUrl,
1565
+ onLinkApply,
1566
+ onLinkRemove
1567
+ })] });
1568
+ }
1569
+ function ButtonBubbleMenuDefault({ placement, offset: offset$1, onHide, className, validateUrl, onLinkApply, onLinkRemove, ...rest }) {
1570
+ return /* @__PURE__ */ jsx(ButtonBubbleMenuRoot, {
1571
+ placement,
1572
+ offset: offset$1,
1573
+ onHide,
1574
+ className,
1575
+ ...rest,
1576
+ children: /* @__PURE__ */ jsx(ButtonBubbleMenuDefaultInner, {
1577
+ validateUrl,
1578
+ onLinkApply,
1579
+ onLinkRemove
1580
+ })
1581
+ });
1582
+ }
1583
+
1584
+ //#endregion
1585
+ //#region src/ui/image-bubble-menu/context.tsx
1586
+ const ImageBubbleMenuContext = React.createContext(null);
1587
+ function useImageBubbleMenuContext() {
1588
+ const context = React.useContext(ImageBubbleMenuContext);
1589
+ if (!context) throw new Error("ImageBubbleMenu compound components must be used within <ImageBubbleMenu.Root>");
1590
+ return context;
1591
+ }
1592
+
1593
+ //#endregion
1594
+ //#region src/ui/image-bubble-menu/edit-link.tsx
1595
+ function ImageBubbleMenuEditLink({ className, children, onClick, onMouseDown, ...rest }) {
1596
+ const { setIsEditing } = useImageBubbleMenuContext();
1597
+ return /* @__PURE__ */ jsx("button", {
1598
+ ...rest,
1599
+ type: "button",
1600
+ "aria-label": "Edit link",
1601
+ "data-re-img-bm-item": "",
1602
+ "data-item": "edit-link",
1603
+ className,
1604
+ onMouseDown: (e) => {
1605
+ e.preventDefault();
1606
+ onMouseDown?.(e);
1607
+ },
1608
+ onClick: (e) => {
1609
+ onClick?.(e);
1610
+ setIsEditing(true);
1611
+ },
1612
+ children: children ?? /* @__PURE__ */ jsx(LinkIcon, {})
1613
+ });
1614
+ }
1615
+
1616
+ //#endregion
1617
+ //#region src/ui/image-bubble-menu/root.tsx
1618
+ function ImageBubbleMenuRoot({ onHide, placement = "top", offset: offset$1 = 8, className, children, ...rest }) {
1619
+ const { editor } = useCurrentEditor();
1620
+ const [isEditing, setIsEditing] = React.useState(false);
1621
+ if (!editor) return null;
1622
+ return /* @__PURE__ */ jsx(BubbleMenu, {
1623
+ editor,
1624
+ pluginKey: "imageBubbleMenu",
1625
+ "data-re-img-bm": "",
1626
+ shouldShow: ({ editor: e, view }) => e.isActive("image") && !view.dom.classList.contains("dragging"),
1627
+ options: {
1628
+ placement,
1629
+ offset: offset$1,
1630
+ onHide: () => {
1631
+ setIsEditing(false);
1632
+ onHide?.();
1633
+ }
1634
+ },
1635
+ className,
1636
+ ...rest,
1637
+ children: /* @__PURE__ */ jsx(ImageBubbleMenuContext.Provider, {
1638
+ value: {
1639
+ editor,
1640
+ isEditing,
1641
+ setIsEditing
1642
+ },
1643
+ children
1644
+ })
1645
+ });
1646
+ }
1647
+
1648
+ //#endregion
1649
+ //#region src/ui/image-bubble-menu/toolbar.tsx
1650
+ function ImageBubbleMenuToolbar({ children, ...rest }) {
1651
+ const { isEditing } = useImageBubbleMenuContext();
1652
+ if (isEditing) return null;
1653
+ return /* @__PURE__ */ jsx("div", {
1654
+ "data-re-img-bm-toolbar": "",
1655
+ ...rest,
1656
+ children
1657
+ });
1658
+ }
1659
+
1660
+ //#endregion
1661
+ //#region src/ui/image-bubble-menu/default.tsx
1662
+ function ImageBubbleMenuDefault({ excludeItems = [], placement, offset: offset$1, onHide, className, ...rest }) {
1663
+ const hasEditLink = !excludeItems.includes("edit-link");
1664
+ return /* @__PURE__ */ jsx(ImageBubbleMenuRoot, {
1665
+ placement,
1666
+ offset: offset$1,
1667
+ onHide,
1668
+ className,
1669
+ ...rest,
1670
+ children: hasEditLink && /* @__PURE__ */ jsx(ImageBubbleMenuToolbar, { children: /* @__PURE__ */ jsx(ImageBubbleMenuEditLink, {}) })
1671
+ });
1672
+ }
1673
+
1674
+ //#endregion
1675
+ //#region src/ui/link-bubble-menu/context.tsx
1676
+ const LinkBubbleMenuContext = React.createContext(null);
1677
+ function useLinkBubbleMenuContext() {
1678
+ const context = React.useContext(LinkBubbleMenuContext);
1679
+ if (!context) throw new Error("LinkBubbleMenu compound components must be used within <LinkBubbleMenu.Root>");
1680
+ return context;
1681
+ }
1682
+
1683
+ //#endregion
1684
+ //#region src/ui/link-bubble-menu/edit-link.tsx
1685
+ function LinkBubbleMenuEditLink({ className, children, onClick, onMouseDown, ...rest }) {
1686
+ const { setIsEditing } = useLinkBubbleMenuContext();
1687
+ return /* @__PURE__ */ jsx("button", {
1688
+ type: "button",
1689
+ "aria-label": "Edit link",
1690
+ "data-re-link-bm-item": "",
1691
+ "data-item": "edit-link",
1692
+ className,
1693
+ onMouseDown: (e) => {
1694
+ e.preventDefault();
1695
+ onMouseDown?.(e);
1696
+ },
1697
+ onClick: (e) => {
1698
+ onClick?.(e);
1699
+ setIsEditing(true);
1700
+ },
1701
+ ...rest,
1702
+ children: children ?? /* @__PURE__ */ jsx(PencilIcon, {})
1703
+ });
1704
+ }
1705
+
1706
+ //#endregion
1707
+ //#region src/ui/link-bubble-menu/form.tsx
1708
+ function LinkBubbleMenuForm({ className, validateUrl, onLinkApply, onLinkRemove, children }) {
1709
+ const { editor, linkHref, isEditing, setIsEditing } = useLinkBubbleMenuContext();
1710
+ const inputRef = React.useRef(null);
1711
+ const formRef = React.useRef(null);
1712
+ const displayHref = linkHref === "#" ? "" : linkHref;
1713
+ const [inputValue, setInputValue] = React.useState(displayHref);
1714
+ React.useEffect(() => {
1715
+ if (!isEditing) return;
1716
+ setInputValue(displayHref);
1717
+ const timeoutId = setTimeout(() => {
1718
+ inputRef.current?.focus();
1719
+ }, 0);
1720
+ return () => clearTimeout(timeoutId);
1721
+ }, [isEditing, displayHref]);
1722
+ React.useEffect(() => {
1723
+ if (!isEditing) return;
1724
+ const handleKeyDown = (event) => {
1725
+ if (event.key === "Escape") setIsEditing(false);
1726
+ };
1727
+ const handleClickOutside = (event) => {
1728
+ if (formRef.current && !formRef.current.contains(event.target)) {
1729
+ const form = formRef.current;
1730
+ const submitEvent = new Event("submit", {
1731
+ bubbles: true,
1732
+ cancelable: true
1733
+ });
1734
+ form.dispatchEvent(submitEvent);
1735
+ setIsEditing(false);
1736
+ }
1737
+ };
1738
+ document.addEventListener("mousedown", handleClickOutside);
1739
+ window.addEventListener("keydown", handleKeyDown);
1740
+ return () => {
1741
+ window.removeEventListener("keydown", handleKeyDown);
1742
+ document.removeEventListener("mousedown", handleClickOutside);
1743
+ };
1744
+ }, [isEditing, setIsEditing]);
1745
+ if (!isEditing) return null;
1746
+ function handleSubmit(e) {
1747
+ e.preventDefault();
1748
+ const value = inputValue.trim();
1749
+ if (value === "") {
1750
+ setLinkHref(editor, "");
1751
+ setIsEditing(false);
1752
+ focusEditor(editor);
1753
+ onLinkRemove?.();
1754
+ return;
1755
+ }
1756
+ const finalValue = (validateUrl ?? getUrlFromString)(value);
1757
+ if (!finalValue) {
1758
+ setLinkHref(editor, "");
1759
+ setIsEditing(false);
1760
+ focusEditor(editor);
1761
+ onLinkRemove?.();
1762
+ return;
1763
+ }
1764
+ setLinkHref(editor, finalValue);
1765
+ setIsEditing(false);
1766
+ focusEditor(editor);
1767
+ onLinkApply?.(finalValue);
1768
+ }
1769
+ function handleUnlink(e) {
1770
+ e.stopPropagation();
1771
+ setLinkHref(editor, "");
1772
+ setIsEditing(false);
1773
+ focusEditor(editor);
1774
+ onLinkRemove?.();
1775
+ }
1776
+ return /* @__PURE__ */ jsxs("form", {
1777
+ ref: formRef,
1778
+ "data-re-link-bm-form": "",
1779
+ className,
1780
+ onMouseDown: (e) => e.stopPropagation(),
1781
+ onClick: (e) => e.stopPropagation(),
1782
+ onKeyDown: (e) => e.stopPropagation(),
1783
+ onSubmit: handleSubmit,
1784
+ children: [
1785
+ /* @__PURE__ */ jsx("input", {
1786
+ ref: inputRef,
1787
+ "data-re-link-bm-input": "",
1788
+ value: inputValue,
1789
+ onFocus: (e) => e.stopPropagation(),
1790
+ onChange: (e) => setInputValue(e.target.value),
1791
+ placeholder: "Paste a link",
1792
+ type: "text"
1793
+ }),
1794
+ children,
1795
+ displayHref ? /* @__PURE__ */ jsx("button", {
1796
+ type: "button",
1797
+ "aria-label": "Remove link",
1798
+ "data-re-link-bm-unlink": "",
1799
+ onClick: handleUnlink,
1800
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
1801
+ }) : /* @__PURE__ */ jsx("button", {
1802
+ type: "submit",
1803
+ "aria-label": "Apply link",
1804
+ "data-re-link-bm-apply": "",
1805
+ onMouseDown: (e) => e.stopPropagation(),
1806
+ children: /* @__PURE__ */ jsx(Check, {})
1807
+ })
1808
+ ]
1809
+ });
1810
+ }
1811
+
1812
+ //#endregion
1813
+ //#region src/ui/link-bubble-menu/open-link.tsx
1814
+ function LinkBubbleMenuOpenLink({ className, children, ...rest }) {
1815
+ const { linkHref } = useLinkBubbleMenuContext();
1816
+ return /* @__PURE__ */ jsx("a", {
1817
+ ...rest,
1818
+ href: linkHref,
1819
+ target: "_blank",
1820
+ rel: "noopener noreferrer",
1821
+ "aria-label": "Open link",
1822
+ "data-re-link-bm-item": "",
1823
+ "data-item": "open-link",
1824
+ className,
1825
+ children: children ?? /* @__PURE__ */ jsx(ExternalLinkIcon, {})
1826
+ });
1827
+ }
1828
+
1829
+ //#endregion
1830
+ //#region src/ui/link-bubble-menu/root.tsx
1831
+ function LinkBubbleMenuRoot({ onHide, placement = "top", offset: offset$1 = 8, className, children, ...rest }) {
1832
+ const { editor } = useCurrentEditor();
1833
+ const [isEditing, setIsEditing] = React.useState(false);
1834
+ const linkHref = useEditorState({
1835
+ editor,
1836
+ selector: ({ editor: e }) => e?.getAttributes("link").href ?? ""
1837
+ });
1838
+ if (!editor) return null;
1839
+ return /* @__PURE__ */ jsx(BubbleMenu, {
1840
+ editor,
1841
+ pluginKey: "linkBubbleMenu",
1842
+ "data-re-link-bm": "",
1843
+ shouldShow: ({ editor: e }) => e.isActive("link") && e.view.state.selection.content().size === 0,
1844
+ options: {
1845
+ placement,
1846
+ offset: offset$1,
1847
+ onHide: () => {
1848
+ setIsEditing(false);
1849
+ onHide?.();
1850
+ }
1851
+ },
1852
+ className,
1853
+ ...rest,
1854
+ children: /* @__PURE__ */ jsx(LinkBubbleMenuContext.Provider, {
1855
+ value: {
1856
+ editor,
1857
+ linkHref: linkHref ?? "",
1858
+ isEditing,
1859
+ setIsEditing
1860
+ },
1861
+ children
1862
+ })
1863
+ });
1864
+ }
1865
+
1866
+ //#endregion
1867
+ //#region src/ui/link-bubble-menu/toolbar.tsx
1868
+ function LinkBubbleMenuToolbar({ children, ...rest }) {
1869
+ const { isEditing } = useLinkBubbleMenuContext();
1870
+ if (isEditing) return null;
1871
+ return /* @__PURE__ */ jsx("div", {
1872
+ "data-re-link-bm-toolbar": "",
1873
+ ...rest,
1874
+ children
1875
+ });
1876
+ }
1877
+
1878
+ //#endregion
1879
+ //#region src/ui/link-bubble-menu/unlink.tsx
1880
+ function LinkBubbleMenuUnlink({ className, children, onClick, onMouseDown, ...rest }) {
1881
+ const { editor } = useLinkBubbleMenuContext();
1882
+ return /* @__PURE__ */ jsx("button", {
1883
+ type: "button",
1884
+ "aria-label": "Remove link",
1885
+ "data-re-link-bm-item": "",
1886
+ "data-item": "unlink",
1887
+ className,
1888
+ onMouseDown: (e) => {
1889
+ e.preventDefault();
1890
+ onMouseDown?.(e);
1891
+ },
1892
+ onClick: (e) => {
1893
+ onClick?.(e);
1894
+ editor.chain().focus().unsetLink().run();
1895
+ },
1896
+ ...rest,
1897
+ children: children ?? /* @__PURE__ */ jsx(UnlinkIcon, {})
1898
+ });
1899
+ }
1900
+
1901
+ //#endregion
1902
+ //#region src/ui/link-bubble-menu/default.tsx
1903
+ function LinkBubbleMenuDefault({ excludeItems = [], placement, offset: offset$1, onHide, className, validateUrl, onLinkApply, onLinkRemove, ...rest }) {
1904
+ const has = (item) => !excludeItems.includes(item);
1905
+ const hasToolbarItems = has("edit-link") || has("open-link") || has("unlink");
1906
+ return /* @__PURE__ */ jsxs(LinkBubbleMenuRoot, {
1907
+ placement,
1908
+ offset: offset$1,
1909
+ onHide,
1910
+ className,
1911
+ ...rest,
1912
+ children: [hasToolbarItems && /* @__PURE__ */ jsxs(LinkBubbleMenuToolbar, { children: [
1913
+ has("edit-link") && /* @__PURE__ */ jsx(LinkBubbleMenuEditLink, {}),
1914
+ has("open-link") && /* @__PURE__ */ jsx(LinkBubbleMenuOpenLink, {}),
1915
+ has("unlink") && /* @__PURE__ */ jsx(LinkBubbleMenuUnlink, {})
1916
+ ] }), /* @__PURE__ */ jsx(LinkBubbleMenuForm, {
1917
+ validateUrl,
1918
+ onLinkApply,
1919
+ onLinkRemove
1920
+ })]
1921
+ });
1922
+ }
1923
+
1924
+ //#endregion
1925
+ //#region src/ui/slash-command/utils.ts
1926
+ function isInsideNode(editor, type) {
1927
+ const { $from } = editor.state.selection;
1928
+ for (let d = $from.depth; d > 0; d--) if ($from.node(d).type.name === type) return true;
1929
+ return false;
1930
+ }
1931
+ function isAtMaxColumnsDepth(editor) {
1932
+ const { from } = editor.state.selection;
1933
+ return getColumnsDepth(editor.state.doc, from) >= MAX_COLUMNS_DEPTH;
1934
+ }
1935
+ function updateScrollView(container, item) {
1936
+ const containerRect = container.getBoundingClientRect();
1937
+ const itemRect = item.getBoundingClientRect();
1938
+ if (itemRect.top < containerRect.top) container.scrollTop -= containerRect.top - itemRect.top;
1939
+ else if (itemRect.bottom > containerRect.bottom) container.scrollTop += itemRect.bottom - containerRect.bottom;
1940
+ }
1941
+
1942
+ //#endregion
1943
+ //#region src/ui/slash-command/command-list.tsx
1944
+ const CATEGORY_ORDER = [
1945
+ "Text",
1946
+ "Media",
1947
+ "Layout",
1948
+ "Utility"
1949
+ ];
1950
+ function groupByCategory(items) {
1951
+ const seen = /* @__PURE__ */ new Map();
1952
+ for (const item of items) {
1953
+ const existing = seen.get(item.category);
1954
+ if (existing) existing.push(item);
1955
+ else seen.set(item.category, [item]);
1956
+ }
1957
+ const ordered = [];
1958
+ for (const cat of CATEGORY_ORDER) {
1959
+ const group = seen.get(cat);
1960
+ if (group) {
1961
+ ordered.push({
1962
+ category: cat,
1963
+ items: group
1964
+ });
1965
+ seen.delete(cat);
1966
+ }
1967
+ }
1968
+ for (const [category, group] of seen) ordered.push({
1969
+ category,
1970
+ items: group
1971
+ });
1972
+ return ordered;
1973
+ }
1974
+ function CommandItem({ item, selected, onSelect }) {
1975
+ return /* @__PURE__ */ jsxs("button", {
1976
+ "data-re-slash-command-item": "",
1977
+ "data-selected": selected || void 0,
1978
+ onClick: onSelect,
1979
+ type: "button",
1980
+ children: [item.icon, /* @__PURE__ */ jsx("span", { children: item.title })]
1981
+ });
1982
+ }
1983
+ function CommandList({ items, query, selectedIndex, onSelect }) {
1984
+ const containerRef = useRef(null);
1985
+ useLayoutEffect(() => {
1986
+ const container = containerRef.current;
1987
+ if (!container) return;
1988
+ const selected = container.querySelector("[data-selected]");
1989
+ if (selected) updateScrollView(container, selected);
1990
+ }, [selectedIndex]);
1991
+ if (items.length === 0) return /* @__PURE__ */ jsx("div", {
1992
+ "data-re-slash-command": "",
1993
+ children: /* @__PURE__ */ jsx("div", {
1994
+ "data-re-slash-command-empty": "",
1995
+ children: "No results"
1996
+ })
1997
+ });
1998
+ if (query.trim().length > 0) return /* @__PURE__ */ jsx("div", {
1999
+ "data-re-slash-command": "",
2000
+ ref: containerRef,
2001
+ children: items.map((item, index) => /* @__PURE__ */ jsx(CommandItem, {
2002
+ item,
2003
+ onSelect: () => onSelect(index),
2004
+ selected: index === selectedIndex
2005
+ }, item.title))
2006
+ });
2007
+ const groups = groupByCategory(items);
2008
+ let flatIndex = 0;
2009
+ return /* @__PURE__ */ jsx("div", {
2010
+ "data-re-slash-command": "",
2011
+ ref: containerRef,
2012
+ children: groups.map((group) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
2013
+ "data-re-slash-command-category": "",
2014
+ children: group.category
2015
+ }), group.items.map((item) => {
2016
+ const currentIndex = flatIndex++;
2017
+ return /* @__PURE__ */ jsx(CommandItem, {
2018
+ item,
2019
+ onSelect: () => onSelect(currentIndex),
2020
+ selected: currentIndex === selectedIndex
2021
+ }, item.title);
2022
+ })] }, group.category))
2023
+ });
2024
+ }
2025
+
2026
+ //#endregion
2027
+ //#region src/ui/slash-command/commands.tsx
2028
+ const TEXT = {
2029
+ title: "Text",
2030
+ description: "Plain text block",
2031
+ icon: /* @__PURE__ */ jsx(Text, { size: 20 }),
2032
+ category: "Text",
2033
+ searchTerms: ["p", "paragraph"],
2034
+ command: ({ editor, range }) => {
2035
+ editor.chain().focus().deleteRange(range).toggleNode("paragraph", "paragraph").run();
2036
+ }
2037
+ };
2038
+ const H1 = {
2039
+ title: "Title",
2040
+ description: "Large heading",
2041
+ icon: /* @__PURE__ */ jsx(Heading1, { size: 20 }),
2042
+ category: "Text",
2043
+ searchTerms: [
2044
+ "title",
2045
+ "big",
2046
+ "large",
2047
+ "h1"
2048
+ ],
2049
+ command: ({ editor, range }) => {
2050
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 1 }).run();
2051
+ }
2052
+ };
2053
+ const H2 = {
2054
+ title: "Subtitle",
2055
+ description: "Medium heading",
2056
+ icon: /* @__PURE__ */ jsx(Heading2, { size: 20 }),
2057
+ category: "Text",
2058
+ searchTerms: [
2059
+ "subtitle",
2060
+ "medium",
2061
+ "h2"
2062
+ ],
2063
+ command: ({ editor, range }) => {
2064
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 2 }).run();
2065
+ }
2066
+ };
2067
+ const H3 = {
2068
+ title: "Heading",
2069
+ description: "Small heading",
2070
+ icon: /* @__PURE__ */ jsx(Heading3, { size: 20 }),
2071
+ category: "Text",
2072
+ searchTerms: [
2073
+ "subtitle",
2074
+ "small",
2075
+ "h3"
2076
+ ],
2077
+ command: ({ editor, range }) => {
2078
+ editor.chain().focus().deleteRange(range).setNode("heading", { level: 3 }).run();
2079
+ }
2080
+ };
2081
+ const BULLET_LIST = {
2082
+ title: "Bullet list",
2083
+ description: "Unordered list",
2084
+ icon: /* @__PURE__ */ jsx(List, { size: 20 }),
2085
+ category: "Text",
2086
+ searchTerms: ["unordered", "point"],
2087
+ command: ({ editor, range }) => {
2088
+ editor.chain().focus().deleteRange(range).toggleBulletList().run();
2089
+ }
2090
+ };
2091
+ const NUMBERED_LIST = {
2092
+ title: "Numbered list",
2093
+ description: "Ordered list",
2094
+ icon: /* @__PURE__ */ jsx(ListOrdered, { size: 20 }),
2095
+ category: "Text",
2096
+ searchTerms: ["ordered"],
2097
+ command: ({ editor, range }) => {
2098
+ editor.chain().focus().deleteRange(range).toggleOrderedList().run();
2099
+ }
2100
+ };
2101
+ const QUOTE = {
2102
+ title: "Quote",
2103
+ description: "Block quote",
2104
+ icon: /* @__PURE__ */ jsx(TextQuote, { size: 20 }),
2105
+ category: "Text",
2106
+ searchTerms: ["blockquote"],
2107
+ command: ({ editor, range }) => {
2108
+ editor.chain().focus().deleteRange(range).toggleNode("paragraph", "paragraph").toggleBlockquote().run();
2109
+ }
2110
+ };
2111
+ const CODE = {
2112
+ title: "Code block",
2113
+ description: "Code snippet",
2114
+ icon: /* @__PURE__ */ jsx(SquareCode, { size: 20 }),
2115
+ category: "Text",
2116
+ searchTerms: ["codeblock"],
2117
+ command: ({ editor, range }) => {
2118
+ editor.chain().focus().deleteRange(range).toggleCodeBlock().run();
2119
+ }
2120
+ };
2121
+ const BUTTON = {
2122
+ title: "Button",
2123
+ description: "Clickable button",
2124
+ icon: /* @__PURE__ */ jsx(MousePointer, { size: 20 }),
2125
+ category: "Layout",
2126
+ searchTerms: ["button"],
2127
+ command: ({ editor, range }) => {
2128
+ editor.chain().focus().deleteRange(range).setButton().run();
2129
+ }
2130
+ };
2131
+ const DIVIDER = {
2132
+ title: "Divider",
2133
+ description: "Horizontal separator",
2134
+ icon: /* @__PURE__ */ jsx(SplitSquareVertical, { size: 20 }),
2135
+ category: "Layout",
2136
+ searchTerms: [
2137
+ "hr",
2138
+ "divider",
2139
+ "separator"
2140
+ ],
2141
+ command: ({ editor, range }) => {
2142
+ editor.chain().focus().deleteRange(range).setHorizontalRule().run();
2143
+ }
2144
+ };
2145
+ const SECTION = {
2146
+ title: "Section",
2147
+ description: "Content section",
2148
+ icon: /* @__PURE__ */ jsx(Rows2, { size: 20 }),
2149
+ category: "Layout",
2150
+ searchTerms: [
2151
+ "section",
2152
+ "row",
2153
+ "container"
2154
+ ],
2155
+ command: ({ editor, range }) => {
2156
+ editor.chain().focus().deleteRange(range).insertSection().run();
2157
+ }
2158
+ };
2159
+ const TWO_COLUMNS = {
2160
+ title: "2 columns",
2161
+ description: "Two column layout",
2162
+ icon: /* @__PURE__ */ jsx(Columns2, { size: 20 }),
2163
+ category: "Layout",
2164
+ searchTerms: [
2165
+ "columns",
2166
+ "column",
2167
+ "layout",
2168
+ "grid",
2169
+ "split",
2170
+ "side-by-side",
2171
+ "multi-column",
2172
+ "row",
2173
+ "two",
2174
+ "2"
2175
+ ],
2176
+ command: ({ editor, range }) => {
2177
+ editor.chain().focus().deleteRange(range).insertColumns(2).run();
2178
+ }
2179
+ };
2180
+ const THREE_COLUMNS = {
2181
+ title: "3 columns",
2182
+ description: "Three column layout",
2183
+ icon: /* @__PURE__ */ jsx(Columns3, { size: 20 }),
2184
+ category: "Layout",
2185
+ searchTerms: [
2186
+ "columns",
2187
+ "column",
2188
+ "layout",
2189
+ "grid",
2190
+ "split",
2191
+ "multi-column",
2192
+ "row",
2193
+ "three",
2194
+ "3"
2195
+ ],
2196
+ command: ({ editor, range }) => {
2197
+ editor.chain().focus().deleteRange(range).insertColumns(3).run();
2198
+ }
2199
+ };
2200
+ const FOUR_COLUMNS = {
2201
+ title: "4 columns",
2202
+ description: "Four column layout",
2203
+ icon: /* @__PURE__ */ jsx(Columns4, { size: 20 }),
2204
+ category: "Layout",
2205
+ searchTerms: [
2206
+ "columns",
2207
+ "column",
2208
+ "layout",
2209
+ "grid",
2210
+ "split",
2211
+ "multi-column",
2212
+ "row",
2213
+ "four",
2214
+ "4"
2215
+ ],
2216
+ command: ({ editor, range }) => {
2217
+ editor.chain().focus().deleteRange(range).insertColumns(4).run();
2218
+ }
2219
+ };
2220
+ const defaultSlashCommands = [
2221
+ TEXT,
2222
+ H1,
2223
+ H2,
2224
+ H3,
2225
+ BULLET_LIST,
2226
+ NUMBERED_LIST,
2227
+ QUOTE,
2228
+ CODE,
2229
+ BUTTON,
2230
+ DIVIDER,
2231
+ SECTION,
2232
+ TWO_COLUMNS,
2233
+ THREE_COLUMNS,
2234
+ FOUR_COLUMNS
2235
+ ];
2236
+
2237
+ //#endregion
2238
+ //#region src/ui/slash-command/search.ts
2239
+ function scoreItem(item, query) {
2240
+ if (!query) return 100;
2241
+ const q = query.toLowerCase();
2242
+ const title = item.title.toLowerCase();
2243
+ const description = item.description.toLowerCase();
2244
+ const terms = item.searchTerms?.map((t) => t.toLowerCase()) ?? [];
2245
+ if (title === q) return 100;
2246
+ if (title.startsWith(q)) return 90;
2247
+ if (title.split(/\s+/).some((w) => w.startsWith(q))) return 80;
2248
+ if (terms.some((t) => t === q)) return 70;
2249
+ if (terms.some((t) => t.startsWith(q))) return 60;
2250
+ if (title.includes(q)) return 40;
2251
+ if (terms.some((t) => t.includes(q))) return 30;
2252
+ if (description.includes(q)) return 20;
2253
+ return 0;
2254
+ }
2255
+ function filterAndRankItems(items, query) {
2256
+ const trimmed = query.trim();
2257
+ if (!trimmed) return items;
2258
+ const scored = items.map((item) => ({
2259
+ item,
2260
+ score: scoreItem(item, trimmed)
2261
+ })).filter(({ score }) => score > 0);
2262
+ scored.sort((a, b) => b.score - a.score);
2263
+ return scored.map(({ item }) => item);
2264
+ }
2265
+
2266
+ //#endregion
2267
+ //#region src/ui/slash-command/root.tsx
2268
+ const pluginKey = new PluginKey("slash-command");
2269
+ const INITIAL_STATE = {
2270
+ active: false,
2271
+ query: "",
2272
+ items: [],
2273
+ clientRect: null
2274
+ };
2275
+ function defaultFilterItems(items, query, editor) {
2276
+ return filterAndRankItems(isAtMaxColumnsDepth(editor) ? items.filter((item) => item.category !== "Layout" || !item.title.includes("column")) : items, query);
2277
+ }
2278
+ function SlashCommandRoot({ items: itemsProp, filterItems: filterItemsProp, char = "/", allow: allowProp, children }) {
2279
+ const { editor } = useCurrentEditor();
2280
+ const [state, setState] = useState(INITIAL_STATE);
2281
+ const [selectedIndex, setSelectedIndex] = useState(0);
2282
+ const itemsRef = useRef(itemsProp ?? defaultSlashCommands);
2283
+ const filterRef = useRef(filterItemsProp ?? defaultFilterItems);
2284
+ const allowRef = useRef(allowProp ?? (({ editor: e }) => !e.isActive("codeBlock")));
2285
+ itemsRef.current = itemsProp ?? defaultSlashCommands;
2286
+ filterRef.current = filterItemsProp ?? defaultFilterItems;
2287
+ allowRef.current = allowProp ?? (({ editor: e }) => !e.isActive("codeBlock"));
2288
+ const commandRef = useRef(null);
2289
+ const suggestionItemsRef = useRef([]);
2290
+ const selectedIndexRef = useRef(0);
2291
+ suggestionItemsRef.current = state.items;
2292
+ selectedIndexRef.current = selectedIndex;
2293
+ const { refs, floatingStyles } = useFloating({
2294
+ open: state.active,
2295
+ placement: "bottom-start",
2296
+ middleware: [
2297
+ offset(8),
2298
+ flip(),
2299
+ shift({ padding: 8 })
2300
+ ],
2301
+ whileElementsMounted: autoUpdate
2302
+ });
2303
+ useEffect(() => {
2304
+ if (!state.clientRect) return;
2305
+ refs.setReference({ getBoundingClientRect: state.clientRect });
2306
+ }, [state.clientRect, refs]);
2307
+ useEffect(() => {
2308
+ setSelectedIndex(0);
2309
+ }, [state.items]);
2310
+ const onSelect = useCallback((index) => {
2311
+ const item = suggestionItemsRef.current[index];
2312
+ if (item && commandRef.current) commandRef.current(item);
2313
+ }, []);
2314
+ useEffect(() => {
2315
+ if (!editor) return;
2316
+ const plugin = Suggestion({
2317
+ pluginKey,
2318
+ editor,
2319
+ char,
2320
+ allow: ({ editor: e }) => allowRef.current({ editor: e }),
2321
+ command: ({ editor: e, range, props }) => {
2322
+ props.command({
2323
+ editor: e,
2324
+ range
2325
+ });
2326
+ },
2327
+ items: ({ query, editor: e }) => filterRef.current(itemsRef.current, query, e),
2328
+ render: () => ({
2329
+ onStart: (props) => {
2330
+ commandRef.current = props.command;
2331
+ setState({
2332
+ active: true,
2333
+ query: props.query,
2334
+ items: props.items,
2335
+ clientRect: props.clientRect ?? null
2336
+ });
2337
+ },
2338
+ onUpdate: (props) => {
2339
+ commandRef.current = props.command;
2340
+ setState({
2341
+ active: true,
2342
+ query: props.query,
2343
+ items: props.items,
2344
+ clientRect: props.clientRect ?? null
2345
+ });
2346
+ },
2347
+ onKeyDown: ({ event }) => {
2348
+ if (event.key === "Escape") {
2349
+ setState(INITIAL_STATE);
2350
+ return true;
2351
+ }
2352
+ const items = suggestionItemsRef.current;
2353
+ if (items.length === 0) return false;
2354
+ if (event.key === "ArrowUp") {
2355
+ setSelectedIndex((i) => (i + items.length - 1) % items.length);
2356
+ return true;
2357
+ }
2358
+ if (event.key === "ArrowDown") {
2359
+ setSelectedIndex((i) => (i + 1) % items.length);
2360
+ return true;
2361
+ }
2362
+ if (event.key === "Enter") {
2363
+ const item = items[selectedIndexRef.current];
2364
+ if (item && commandRef.current) commandRef.current(item);
2365
+ return true;
2366
+ }
2367
+ return false;
2368
+ },
2369
+ onExit: () => {
2370
+ setState(INITIAL_STATE);
2371
+ requestAnimationFrame(() => {
2372
+ commandRef.current = null;
2373
+ });
2374
+ }
2375
+ })
2376
+ });
2377
+ editor.registerPlugin(plugin, (newPlugin, plugins) => [newPlugin, ...plugins]);
2378
+ return () => {
2379
+ editor.unregisterPlugin(pluginKey);
2380
+ };
2381
+ }, [editor, char]);
2382
+ if (!editor || !state.active) return null;
2383
+ const renderProps = {
2384
+ items: state.items,
2385
+ query: state.query,
2386
+ selectedIndex,
2387
+ onSelect
2388
+ };
2389
+ let content;
2390
+ if (children) content = children(renderProps);
2391
+ else content = /* @__PURE__ */ jsx(CommandList, { ...renderProps });
2392
+ return createPortal(/* @__PURE__ */ jsx("div", {
2393
+ ref: refs.setFloating,
2394
+ style: floatingStyles,
2395
+ children: content
2396
+ }), document.body);
2397
+ }
2398
+
2399
+ //#endregion
2400
+ export { BubbleMenuItemGroup as $, ImageBubbleMenuDefault as A, ChevronDown as At, ButtonBubbleMenuEditLink as B, LinkBubbleMenuUnlink as C, Heading1 as Ct, LinkBubbleMenuForm as D, Columns2 as Dt, LinkBubbleMenuOpenLink as E, Columns3 as Et, ButtonBubbleMenuDefault as F, AlignLeftIcon as Ft, BubbleMenuStrike as G, BubbleMenuDefault as H, ButtonBubbleMenuUnlink as I, AlignCenterIcon as It, NodeSelectorContent as J, BubbleMenuRoot as K, ButtonBubbleMenuToolbar as L, ImageBubbleMenuRoot as M, CaseUpperIcon as Mt, ImageBubbleMenuEditLink as N, BoldIcon as Nt, LinkBubbleMenuEditLink as O, Code as Ot, useImageBubbleMenuContext as P, AlignRightIcon as Pt, BubbleMenuItalic as Q, ButtonBubbleMenuRoot as R, LinkBubbleMenuDefault as S, Heading2 as St, LinkBubbleMenuRoot as T, Columns4 as Tt, BubbleMenuUppercase as U, useButtonBubbleMenuContext as V, BubbleMenuUnderline as W, NodeSelectorTrigger as X, NodeSelectorRoot as Y, BubbleMenuLinkSelector as Z, TWO_COLUMNS as _, ListOrdered as _t, BUTTON as a, BubbleMenuItem as at, isAtMaxColumnsDepth as b, ItalicIcon as bt, FOUR_COLUMNS as c, TextQuote as ct, H3 as d, StrikethroughIcon as dt, BubbleMenuCode as et, NUMBERED_LIST as f, SquareCode as ft, THREE_COLUMNS as g, MousePointer as gt, TEXT as h, PencilIcon as ht, BULLET_LIST as i, BubbleMenuAlignCenter as it, ImageBubbleMenuToolbar as j, Check as jt, useLinkBubbleMenuContext as k, CodeIcon as kt, H1 as l, Text as lt, SECTION as m, Rows2 as mt, filterAndRankItems as n, BubbleMenuAlignRight as nt, CODE as o, UnlinkIcon as ot, QUOTE as p, SplitSquareVertical as pt, BubbleMenuNodeSelector as q, scoreItem as r, BubbleMenuAlignLeft as rt, DIVIDER as s, UnderlineIcon as st, SlashCommandRoot as t, BubbleMenuBold as tt, H2 as u, TextIcon as ut, defaultSlashCommands as v, List as vt, LinkBubbleMenuToolbar as w, ExternalLinkIcon as wt, isInsideNode as x, Heading3 as xt, CommandList as y, LinkIcon as yt, ButtonBubbleMenuForm as z };
2401
+ //# sourceMappingURL=root-BMxsq1NF.mjs.map