@react-email/editor 0.0.0-experimental.7 → 1.0.0-canary.51

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