@bizapps/design-system-testing 1.0.10 → 1.6.0

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.
@@ -0,0 +1,1242 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var react = require('react');
5
+ var react$1 = require('@tiptap/react');
6
+ var clsx = require('clsx');
7
+ var tailwindMerge = require('tailwind-merge');
8
+ var radixUi = require('radix-ui');
9
+ var jsxRuntime = require('react/jsx-runtime');
10
+ var classVarianceAuthority = require('class-variance-authority');
11
+ var lucideReact = require('lucide-react');
12
+ var react$2 = require('motion/react');
13
+ var reactDropzone = require('react-dropzone');
14
+ var menus = require('@tiptap/react/menus');
15
+ var extensionImage = require('@tiptap/extension-image');
16
+
17
+ // src/components/compounds/RichTextEditor/rich-text-editor.tsx
18
+ function cn(...inputs) {
19
+ return tailwindMerge.twMerge(clsx.clsx(inputs));
20
+ }
21
+ function Label({ className, ...props }) {
22
+ return /* @__PURE__ */ jsxRuntime.jsx(
23
+ radixUi.Label.Root,
24
+ {
25
+ "data-slot": "label",
26
+ className: cn(
27
+ "text-foreground text-sm leading-6 font-medium transition-colors select-none",
28
+ "group-has-disabled/field:cursor-not-allowed group-has-disabled/field:opacity-50",
29
+ "peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
30
+ "aria-invalid:text-destructive dark:aria-invalid:text-destructive/90",
31
+ className
32
+ ),
33
+ ...props
34
+ }
35
+ );
36
+ }
37
+ var buttonVariants = classVarianceAuthority.cva(
38
+ "group/button inline-flex shrink-0 items-center justify-center gap-2 rounded-lg border border-transparent bg-clip-padding text-sm font-semibold whitespace-nowrap transition-all duration-150 outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/30 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 data-[loading]:cursor-not-allowed data-[loading]:opacity-80 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0",
39
+ {
40
+ variants: {
41
+ variant: {
42
+ primary: "cursor-pointer bg-primary text-primary-foreground hover:bg-primary/80 focus-visible:ring-primary/30",
43
+ secondary: "cursor-pointer bg-secondary text-secondary-foreground hover:bg-[var(--color-orange-700)] focus-visible:ring-secondary/30",
44
+ cancel: "cursor-pointer bg-destructive text-secondary-foreground hover:bg-[var(--color-red-600)] focus-visible:ring-destructive/30",
45
+ outline: "border border-foreground/50 bg-transparent text-muted-foreground hover:bg-foreground/50 hover:text-white",
46
+ ghost: "cursor-pointer bg-transparent text-muted-foreground hover:bg-foreground/10 hover:text-primary focus-visible:ring-ring/30 border-none",
47
+ cancelGhost: "cursor-pointer bg-destructive/10 text-red-600 hover:bg-destructive/15 hover:text-red-600 focus-visible:ring-ring/30"
48
+ },
49
+ size: {
50
+ sm: "h-8 px-3 text-xs",
51
+ md: "h-9 px-4 text-sm",
52
+ lg: "h-10 px-6 text-sm",
53
+ "icon-sm": "size-8 rounded-full p-0"
54
+ }
55
+ },
56
+ defaultVariants: {
57
+ variant: "primary",
58
+ size: "md"
59
+ }
60
+ }
61
+ );
62
+ function Button({
63
+ className,
64
+ variant = "primary",
65
+ size = "md",
66
+ asChild = false,
67
+ isLoading = false,
68
+ children,
69
+ onClick,
70
+ ...props
71
+ }) {
72
+ const Comp = asChild ? radixUi.Slot.Root : "button";
73
+ function handleClick(e) {
74
+ if (isLoading) {
75
+ e.preventDefault();
76
+ return;
77
+ }
78
+ onClick?.(e);
79
+ }
80
+ return /* @__PURE__ */ jsxRuntime.jsxs(
81
+ Comp,
82
+ {
83
+ "data-slot": "button",
84
+ "data-variant": variant,
85
+ "data-size": size,
86
+ "data-loading": isLoading || void 0,
87
+ "aria-busy": isLoading || void 0,
88
+ className: cn(buttonVariants({ variant, size, className })),
89
+ onClick: handleClick,
90
+ ...props,
91
+ children: [
92
+ isLoading && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.LoaderCircle, { size: 16, className: "animate-spin", "aria-hidden": "true" }),
93
+ children
94
+ ]
95
+ }
96
+ );
97
+ }
98
+ function RichTextToolbar({ editor, items }) {
99
+ return /* @__PURE__ */ jsxRuntime.jsx(
100
+ "div",
101
+ {
102
+ role: "toolbar",
103
+ "data-slot": "rich-text-toolbar",
104
+ className: "flex items-center gap-1 rounded-t-md border border-b-0 p-1",
105
+ children: items.map((item, index) => {
106
+ if (item.kind === "separator") {
107
+ return /* @__PURE__ */ jsxRuntime.jsx(
108
+ "div",
109
+ {
110
+ "data-slot": "rich-text-toolbar-separator",
111
+ "aria-hidden": "true",
112
+ className: "bg-border mx-1 h-5 w-px"
113
+ },
114
+ `separator-${index}`
115
+ );
116
+ }
117
+ if (item.kind === "custom") {
118
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { children: item.render(editor) }, item.id);
119
+ }
120
+ const active = item.active ? editor?.isActive(item.active.name, item.active.attrs) ?? false : false;
121
+ return /* @__PURE__ */ jsxRuntime.jsx(
122
+ Button,
123
+ {
124
+ type: "button",
125
+ size: "sm",
126
+ variant: active ? "secondary" : "ghost",
127
+ disabled: !editor,
128
+ title: item.label,
129
+ "aria-label": item.label,
130
+ "aria-pressed": item.active ? active : void 0,
131
+ "data-slot": "rich-text-toolbar-button",
132
+ onClick: () => editor && item.run(editor),
133
+ children: item.icon
134
+ },
135
+ item.id
136
+ );
137
+ })
138
+ }
139
+ );
140
+ }
141
+ var EDITOR_CONTENT_STYLE = cn(
142
+ "min-h-[220px] px-3 py-2 text-sm outline-none",
143
+ "[&_h2]:text-lg [&_h2]:font-semibold",
144
+ "[&_ol]:my-4 [&_ol]:list-decimal [&_ol]:pl-5 [&_ul]:my-4 [&_ul]:list-disc [&_ul]:pl-5",
145
+ "[&_blockquote]:border-secondary [&_blockquote]:my-4 [&_blockquote]:ml-4 [&_blockquote]:border-l-4 [&_blockquote]:pl-2",
146
+ "[&_a]:text-primary [&_a]:underline",
147
+ // last-of-type, not last-child: prosemirror-tables appends its
148
+ // .column-resize-handle widget inside the hovered cell, which makes the
149
+ // cell's <p> stop matching :last-child and springs mb-4 back on — the row
150
+ // grows 16px on hover. The handle is absolutely positioned but still counts
151
+ // as a child for structural selectors.
152
+ "[&_p]:mb-4 [&_p]:min-h-[1.25em] [&_p:last-of-type]:mb-0",
153
+ // Paragraphs inside a quote sit closer together than body copy. Every Enter
154
+ // inside a blockquote opens a new <p>, and at the body's mb-4 the lines of a
155
+ // single quote read as separate paragraphs. Declared after the rule above so
156
+ // it wins on equal specificity.
157
+ "[&_blockquote_p]:mb-1 [&_blockquote_p:last-of-type]:mb-0",
158
+ "[&_img]:my-2 [&_img]:max-w-full [&_img]:rounded-md",
159
+ "[&_table]:my-3 [&_table]:w-full [&_table]:table-fixed [&_table]:border-collapse",
160
+ "[&_td]:relative [&_td]:border [&_td]:px-2 [&_td]:py-1 [&_td]:align-top",
161
+ "[&_th]:bg-muted [&_th]:relative [&_th]:border [&_th]:px-2 [&_th]:py-1 [&_th]:text-left [&_th]:font-semibold",
162
+ "[&_.selectedCell]:bg-primary/10",
163
+ // prosemirror-tables renders one handle PER ROW, so the column reads as a
164
+ // single bar down the table. At full primary it looked like the table had
165
+ // broken rather than like something to grab — hence the muted tint and the
166
+ // wider, border-straddling hit area (matches upstream's 4px).
167
+ "[&_.column-resize-handle]:bg-primary/40 [&_.column-resize-handle]:pointer-events-none [&_.column-resize-handle]:absolute [&_.column-resize-handle]:top-0 [&_.column-resize-handle]:-right-0.5 [&_.column-resize-handle]:bottom-0 [&_.column-resize-handle]:z-20 [&_.column-resize-handle]:w-1",
168
+ "[&.resize-cursor]:cursor-col-resize",
169
+ // Selected-node outline, scoped away from images.
170
+ //
171
+ // ProseMirror marks whichever node is selected, and this ring is the only
172
+ // cue for most of them — but an image already announces its selection with a
173
+ // visible resize handle, so the extra box only framed the picture.
174
+ //
175
+ // Excluded via `.node-image`, the class Tiptap puts on the wrapper it
176
+ // generates for a node view (`div.react-renderer.node-<name>`). That wrapper,
177
+ // not the NodeViewWrapper inside it, is what receives
178
+ // ProseMirror-selectednode — so a data-slot on our own element sits one level
179
+ // too deep to match.
180
+ "[&_.ProseMirror-selectednode:not(.node-image)]:outline-primary [&_.ProseMirror-selectednode:not(.node-image)]:outline-2 [&_.ProseMirror-selectednode:not(.node-image)]:outline-offset-2 [&_.ProseMirror-selectednode:not(.node-image)]:outline"
181
+ );
182
+ function RichTextEditor({ editor, items, label, error, footer, className }) {
183
+ const errorId = react.useId();
184
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-slot": "rich-text-editor", className: cn("flex flex-col gap-1", className), children: [
185
+ label && /* @__PURE__ */ jsxRuntime.jsx(Label, { children: label }),
186
+ /* @__PURE__ */ jsxRuntime.jsx(RichTextToolbar, { editor, items }),
187
+ /* @__PURE__ */ jsxRuntime.jsx(
188
+ react$1.EditorContent,
189
+ {
190
+ editor,
191
+ "aria-invalid": !!error,
192
+ "aria-errormessage": error ? errorId : void 0,
193
+ onClick: () => editor?.commands.focus(),
194
+ className: cn(
195
+ "rounded-t-none rounded-b-md border shadow-xs",
196
+ "focus-within:border-ring focus-within:ring-ring/30 focus-within:ring-3",
197
+ error && "border-destructive"
198
+ )
199
+ }
200
+ ),
201
+ error && /* @__PURE__ */ jsxRuntime.jsx("span", { id: errorId, role: "alert", className: "text-destructive text-xs", children: error }),
202
+ footer
203
+ ] });
204
+ }
205
+ function DropdownMenu({ ...props }) {
206
+ return /* @__PURE__ */ jsxRuntime.jsx(radixUi.DropdownMenu.Root, { ...props });
207
+ }
208
+ function DropdownMenuTrigger({
209
+ ...props
210
+ }) {
211
+ return /* @__PURE__ */ jsxRuntime.jsx(radixUi.DropdownMenu.Trigger, { "data-slot": "dropdown-menu-trigger", ...props });
212
+ }
213
+ function DropdownMenuContent({
214
+ className,
215
+ align = "start",
216
+ sideOffset = 4,
217
+ ...props
218
+ }) {
219
+ return /* @__PURE__ */ jsxRuntime.jsx(radixUi.DropdownMenu.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
220
+ radixUi.DropdownMenu.Content,
221
+ {
222
+ "data-slot": "dropdown-menu-content",
223
+ sideOffset,
224
+ align,
225
+ className: cn(
226
+ "bg-popover text-popover-foreground ring-foreground/5 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:ring-foreground/10 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-48 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-3xl p-1.5 shadow-lg ring-1 duration-100 data-[state=closed]:overflow-hidden",
227
+ className
228
+ ),
229
+ ...props
230
+ }
231
+ ) });
232
+ }
233
+ function DropdownMenuItem({
234
+ className,
235
+ inset,
236
+ variant = "default",
237
+ ...props
238
+ }) {
239
+ return /* @__PURE__ */ jsxRuntime.jsx(
240
+ radixUi.DropdownMenu.Item,
241
+ {
242
+ "data-slot": "dropdown-menu-item",
243
+ "data-inset": inset,
244
+ "data-variant": variant,
245
+ className: cn(
246
+ "group/dropdown-menu-item focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:*:[svg]:text-destructive relative flex cursor-default items-center gap-2.5 rounded-2xl px-3 py-2 text-sm font-medium outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-inset:pl-9.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
247
+ className
248
+ ),
249
+ ...props
250
+ }
251
+ );
252
+ }
253
+ function DropdownMenuSeparator({
254
+ className,
255
+ ...props
256
+ }) {
257
+ return /* @__PURE__ */ jsxRuntime.jsx(
258
+ radixUi.DropdownMenu.Separator,
259
+ {
260
+ "data-slot": "dropdown-menu-separator",
261
+ className: cn("bg-border/50 -mx-1.5 my-1.5 h-px", className),
262
+ ...props
263
+ }
264
+ );
265
+ }
266
+ var DEFAULT_ROWS = 8;
267
+ var DEFAULT_COLUMNS = 10;
268
+ function TableMenu({
269
+ editor,
270
+ labels,
271
+ icon,
272
+ maxRows = DEFAULT_ROWS,
273
+ maxColumns = DEFAULT_COLUMNS
274
+ }) {
275
+ const [hovered, setHovered] = react.useState({ rows: 0, columns: 0 });
276
+ const insideTable = editor?.can().deleteTable() ?? false;
277
+ function insert(rows, columns) {
278
+ editor?.chain().focus().insertTable({ rows, cols: columns, withHeaderRow: true }).run();
279
+ }
280
+ return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
281
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
282
+ Button,
283
+ {
284
+ type: "button",
285
+ size: "sm",
286
+ variant: editor?.isActive("table") ? "secondary" : "ghost",
287
+ disabled: !editor,
288
+ title: labels.trigger,
289
+ "aria-label": labels.trigger,
290
+ "data-slot": "table-menu-trigger",
291
+ children: icon
292
+ }
293
+ ) }),
294
+ /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align: "start", className: "w-56", children: [
295
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { role: "none", className: "px-2 py-1.5", children: [
296
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground mb-1.5 text-xs", children: labels.insert }),
297
+ /* @__PURE__ */ jsxRuntime.jsx(
298
+ "div",
299
+ {
300
+ className: "grid gap-0.5",
301
+ style: { gridTemplateColumns: `repeat(${maxColumns}, 1fr)` },
302
+ onMouseLeave: () => setHovered({ rows: 0, columns: 0 }),
303
+ children: Array.from({ length: maxRows * maxColumns }, (_, index) => {
304
+ const rows = Math.floor(index / maxColumns) + 1;
305
+ const columns = index % maxColumns + 1;
306
+ const active = rows <= hovered.rows && columns <= hovered.columns;
307
+ return /* @__PURE__ */ jsxRuntime.jsx(
308
+ "button",
309
+ {
310
+ type: "button",
311
+ "aria-label": labels.dimensions(rows, columns),
312
+ className: cn(
313
+ "h-3.5 w-3.5 cursor-pointer rounded-[2px] border",
314
+ active ? "bg-primary border-primary" : "bg-background"
315
+ ),
316
+ onMouseEnter: () => setHovered({ rows, columns }),
317
+ onFocus: () => setHovered({ rows, columns }),
318
+ onClick: () => insert(rows, columns)
319
+ },
320
+ index
321
+ );
322
+ })
323
+ }
324
+ ),
325
+ /* @__PURE__ */ jsxRuntime.jsx(
326
+ "p",
327
+ {
328
+ "aria-live": "polite",
329
+ "data-slot": "table-menu-dimensions",
330
+ className: "text-muted-foreground mt-1.5 text-xs tabular-nums",
331
+ children: labels.dimensions(hovered.rows, hovered.columns)
332
+ }
333
+ )
334
+ ] }),
335
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
336
+ /* @__PURE__ */ jsxRuntime.jsx(
337
+ DropdownMenuItem,
338
+ {
339
+ className: "cursor-pointer",
340
+ disabled: !insideTable,
341
+ onSelect: () => editor?.chain().focus().addRowBefore().run(),
342
+ children: labels.rowBefore
343
+ }
344
+ ),
345
+ /* @__PURE__ */ jsxRuntime.jsx(
346
+ DropdownMenuItem,
347
+ {
348
+ className: "cursor-pointer",
349
+ disabled: !insideTable,
350
+ onSelect: () => editor?.chain().focus().addRowAfter().run(),
351
+ children: labels.rowAfter
352
+ }
353
+ ),
354
+ /* @__PURE__ */ jsxRuntime.jsx(
355
+ DropdownMenuItem,
356
+ {
357
+ className: "cursor-pointer",
358
+ variant: "destructive",
359
+ disabled: !insideTable,
360
+ onSelect: () => editor?.chain().focus().deleteRow().run(),
361
+ children: labels.deleteRow
362
+ }
363
+ ),
364
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
365
+ /* @__PURE__ */ jsxRuntime.jsx(
366
+ DropdownMenuItem,
367
+ {
368
+ className: "cursor-pointer",
369
+ disabled: !insideTable,
370
+ onSelect: () => editor?.chain().focus().addColumnBefore().run(),
371
+ children: labels.columnBefore
372
+ }
373
+ ),
374
+ /* @__PURE__ */ jsxRuntime.jsx(
375
+ DropdownMenuItem,
376
+ {
377
+ className: "cursor-pointer",
378
+ disabled: !insideTable,
379
+ onSelect: () => editor?.chain().focus().addColumnAfter().run(),
380
+ children: labels.columnAfter
381
+ }
382
+ ),
383
+ /* @__PURE__ */ jsxRuntime.jsx(
384
+ DropdownMenuItem,
385
+ {
386
+ className: "cursor-pointer",
387
+ variant: "destructive",
388
+ disabled: !insideTable,
389
+ onSelect: () => editor?.chain().focus().deleteColumn().run(),
390
+ children: labels.deleteColumn
391
+ }
392
+ ),
393
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
394
+ /* @__PURE__ */ jsxRuntime.jsx(
395
+ DropdownMenuItem,
396
+ {
397
+ className: "cursor-pointer",
398
+ disabled: !insideTable,
399
+ onSelect: () => editor?.chain().focus().toggleHeaderRow().run(),
400
+ children: labels.toggleHeader
401
+ }
402
+ ),
403
+ /* @__PURE__ */ jsxRuntime.jsx(
404
+ DropdownMenuItem,
405
+ {
406
+ className: "cursor-pointer",
407
+ variant: "destructive",
408
+ disabled: !insideTable,
409
+ onSelect: () => editor?.chain().focus().deleteTable().run(),
410
+ children: labels.deleteTable
411
+ }
412
+ )
413
+ ] })
414
+ ] });
415
+ }
416
+
417
+ // src/tokens/animation.ts
418
+ var duration = {
419
+ normal: 0.25};
420
+ var ease = {
421
+ smooth: [0.4, 0, 0.2, 1]};
422
+ var spring = {
423
+ gentle: { type: "spring", stiffness: 260, damping: 28 }};
424
+ var transition = {
425
+ // Modal / dialog — más lento para dar peso al overlay
426
+ modal: {
427
+ ...spring.gentle
428
+ }};
429
+ var DialogContext = react.createContext(false);
430
+ function Dialog({ children, ...props }) {
431
+ const [internalOpen, setInternalOpen] = react.useState(props.defaultOpen ?? false);
432
+ const isOpen = props.open !== void 0 ? props.open : internalOpen;
433
+ return /* @__PURE__ */ jsxRuntime.jsx(DialogContext.Provider, { value: isOpen, children: /* @__PURE__ */ jsxRuntime.jsx(
434
+ radixUi.Dialog.Root,
435
+ {
436
+ "data-slot": "dialog",
437
+ open: isOpen,
438
+ onOpenChange: (v) => {
439
+ setInternalOpen(v);
440
+ props.onOpenChange?.(v);
441
+ },
442
+ ...props,
443
+ children
444
+ }
445
+ ) });
446
+ }
447
+ function DialogPortal({ children, ...props }) {
448
+ const isOpen = react.useContext(DialogContext);
449
+ return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Dialog.Portal, { "data-slot": "dialog-portal", forceMount: true, ...props, children: /* @__PURE__ */ jsxRuntime.jsx(react$2.AnimatePresence, { mode: "sync", children: isOpen && children }) });
450
+ }
451
+ function DialogOverlay({ className, ...props }) {
452
+ return /* @__PURE__ */ jsxRuntime.jsx(radixUi.Dialog.Overlay, { "data-slot": "dialog-overlay", asChild: true, forceMount: true, ...props, children: /* @__PURE__ */ jsxRuntime.jsx(
453
+ react$2.motion.div,
454
+ {
455
+ className: cn(
456
+ "fixed inset-0 isolate z-50 bg-black/30 supports-backdrop-filter:backdrop-blur-sm",
457
+ className
458
+ ),
459
+ initial: { opacity: 0 },
460
+ animate: { opacity: 1 },
461
+ exit: { opacity: 0 },
462
+ transition: { duration: duration.normal, ease: ease.smooth }
463
+ }
464
+ ) });
465
+ }
466
+ function DialogContent({
467
+ className,
468
+ children,
469
+ showCloseButton = false,
470
+ ...props
471
+ }) {
472
+ return /* @__PURE__ */ jsxRuntime.jsxs(DialogPortal, { children: [
473
+ /* @__PURE__ */ jsxRuntime.jsx(DialogOverlay, {}, "dialog-overlay"),
474
+ /* @__PURE__ */ jsxRuntime.jsx(
475
+ radixUi.Dialog.Content,
476
+ {
477
+ "data-slot": "dialog-content",
478
+ asChild: true,
479
+ forceMount: true,
480
+ className: cn(
481
+ "bg-popover text-popover-foreground ring-foreground/5 dark:ring-foreground/10 fixed top-1/2 left-1/2 z-50 flex max-h-[85vh] w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 flex-col rounded-lg text-sm shadow-xl ring-1 outline-none sm:max-w-sm",
482
+ className
483
+ ),
484
+ ...props,
485
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
486
+ react$2.motion.div,
487
+ {
488
+ className: "flex max-h-[85vh] flex-col",
489
+ initial: { opacity: 0, scale: 0.96, y: 8 },
490
+ animate: { opacity: 1, scale: 1, y: 0 },
491
+ exit: { opacity: 0, scale: 0.96, y: 4 },
492
+ transition: transition.modal,
493
+ children: [
494
+ children,
495
+ showCloseButton && /* @__PURE__ */ jsxRuntime.jsx(radixUi.Dialog.Close, { "data-slot": "dialog-close", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
496
+ Button,
497
+ {
498
+ variant: "ghost",
499
+ className: "absolute top-4 right-4",
500
+ size: "icon-sm",
501
+ children: [
502
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.XIcon, {}),
503
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Close" })
504
+ ]
505
+ }
506
+ ) })
507
+ ]
508
+ }
509
+ )
510
+ },
511
+ "dialog-content"
512
+ )
513
+ ] });
514
+ }
515
+ function DialogHeader({ className, ...props }) {
516
+ return /* @__PURE__ */ jsxRuntime.jsx(
517
+ "div",
518
+ {
519
+ "data-slot": "dialog-header",
520
+ className: cn("flex shrink-0 flex-col gap-3 px-6 pt-6", className),
521
+ ...props
522
+ }
523
+ );
524
+ }
525
+ function DialogFooter({
526
+ className,
527
+ showCloseButton = false,
528
+ children,
529
+ ...props
530
+ }) {
531
+ return /* @__PURE__ */ jsxRuntime.jsxs(
532
+ "div",
533
+ {
534
+ "data-slot": "dialog-footer",
535
+ className: cn(
536
+ "border-border bg-muted/40 flex shrink-0 flex-wrap items-center justify-end gap-2 rounded-b-lg border-t px-6 pt-4 pb-4",
537
+ className
538
+ ),
539
+ ...props,
540
+ children: [
541
+ children,
542
+ showCloseButton && /* @__PURE__ */ jsxRuntime.jsx(radixUi.Dialog.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { variant: "secondary", children: "Close" }) })
543
+ ]
544
+ }
545
+ );
546
+ }
547
+ function DialogTitle({ className, ...props }) {
548
+ return /* @__PURE__ */ jsxRuntime.jsx(
549
+ radixUi.Dialog.Title,
550
+ {
551
+ "data-slot": "dialog-title",
552
+ className: cn("font-heading text-lg leading-none font-bold", className),
553
+ ...props
554
+ }
555
+ );
556
+ }
557
+ var renderBytes = (bytes) => {
558
+ const units = ["B", "KB", "MB", "GB", "TB", "PB"];
559
+ let size = bytes;
560
+ let unitIndex = 0;
561
+ while (size >= 1024 && unitIndex < units.length - 1) {
562
+ size /= 1024;
563
+ unitIndex++;
564
+ }
565
+ return `${size.toFixed(2)}${units[unitIndex]}`;
566
+ };
567
+ var DropzoneContext = react.createContext(void 0);
568
+ var dropzoneVariants = classVarianceAuthority.cva("", {
569
+ variants: {
570
+ border: {
571
+ default: "border border-solid border-foreground/15",
572
+ dashed: "border-dashed border-foreground/50"
573
+ }
574
+ },
575
+ defaultVariants: {
576
+ border: "default"
577
+ }
578
+ });
579
+ var Dropzone = ({
580
+ accept,
581
+ maxFiles = 1,
582
+ maxSize,
583
+ minSize,
584
+ onDrop,
585
+ onError,
586
+ disabled,
587
+ src,
588
+ className,
589
+ children,
590
+ border,
591
+ ...props
592
+ }) => {
593
+ const { getRootProps, getInputProps, isDragActive } = reactDropzone.useDropzone({
594
+ accept,
595
+ maxFiles,
596
+ maxSize,
597
+ minSize,
598
+ onError,
599
+ disabled,
600
+ onDrop: (acceptedFiles, fileRejections, event) => {
601
+ if (fileRejections.length > 0) {
602
+ const message = fileRejections.at(0)?.errors.at(0)?.message;
603
+ onError?.(new Error(message));
604
+ }
605
+ if (acceptedFiles.length > 0) {
606
+ onDrop?.(acceptedFiles, fileRejections, event);
607
+ }
608
+ },
609
+ ...props
610
+ });
611
+ return /* @__PURE__ */ jsxRuntime.jsx(
612
+ DropzoneContext.Provider,
613
+ {
614
+ value: { src, accept, maxSize, minSize, maxFiles },
615
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
616
+ Button,
617
+ {
618
+ "data-slot": "dropzone",
619
+ "data-border": border ?? "default",
620
+ className: cn(
621
+ "cursor-auto relative h-auto w-full flex-col overflow-hidden p-8",
622
+ dropzoneVariants({ border }),
623
+ isDragActive && "bg-foreground/10 outline-none",
624
+ className
625
+ ),
626
+ disabled,
627
+ type: "button",
628
+ variant: "ghost",
629
+ ...getRootProps(),
630
+ children: [
631
+ /* @__PURE__ */ jsxRuntime.jsx("input", { ...getInputProps(), disabled }),
632
+ children
633
+ ]
634
+ }
635
+ )
636
+ },
637
+ JSON.stringify(src)
638
+ );
639
+ };
640
+ var useDropzoneContext = () => {
641
+ const context = react.useContext(DropzoneContext);
642
+ if (!context) {
643
+ throw new Error("useDropzoneContext must be used within a Dropzone");
644
+ }
645
+ return context;
646
+ };
647
+ var maxLabelItems = 3;
648
+ var DropzoneContent = ({ children, className }) => {
649
+ const { src } = useDropzoneContext();
650
+ if (!src) {
651
+ return null;
652
+ }
653
+ if (children) {
654
+ return children;
655
+ }
656
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col items-center justify-center", className), children: [
657
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-muted text-muted-foreground flex size-8 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.UploadIcon, { size: 16 }) }),
658
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-foreground my-2 w-full truncate text-sm font-medium", children: src.length > maxLabelItems ? `${new Intl.ListFormat("en").format(
659
+ src.slice(0, maxLabelItems).map((file) => file.name)
660
+ )} and ${src.length - maxLabelItems} more` : new Intl.ListFormat("en").format(src.map((file) => file.name)) }),
661
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground w-full text-xs font-normal text-wrap", children: "Drag and drop or click to replace" })
662
+ ] });
663
+ };
664
+ var DropzoneEmptyState = ({ children, className }) => {
665
+ const { src, accept, maxSize, minSize, maxFiles } = useDropzoneContext();
666
+ if (src) {
667
+ return null;
668
+ }
669
+ if (children) {
670
+ return children;
671
+ }
672
+ let caption = "";
673
+ if (accept) {
674
+ caption += "Accepts ";
675
+ caption += new Intl.ListFormat("en").format(Object.keys(accept));
676
+ }
677
+ if (minSize && maxSize) {
678
+ caption += ` between ${renderBytes(minSize)} and ${renderBytes(maxSize)}`;
679
+ } else if (minSize) {
680
+ caption += ` at least ${renderBytes(minSize)}`;
681
+ } else if (maxSize) {
682
+ caption += ` less than ${renderBytes(maxSize)}`;
683
+ }
684
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col items-center justify-center", className), children: [
685
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-muted text-muted-foreground flex size-8 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.UploadIcon, { size: 16 }) }),
686
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-foreground my-2 w-full text-center text-sm font-medium text-wrap", children: [
687
+ "Upload ",
688
+ maxFiles === 1 ? "a file" : "files"
689
+ ] }),
690
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-center text-xs font-normal text-wrap", children: "Drag and drop or click to upload" }),
691
+ caption && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-muted-foreground text-xs font-normal text-wrap", children: [
692
+ caption,
693
+ "."
694
+ ] })
695
+ ] });
696
+ };
697
+ function Input({ className, type, ...props }) {
698
+ return /* @__PURE__ */ jsxRuntime.jsx(
699
+ "input",
700
+ {
701
+ type,
702
+ "data-slot": "input",
703
+ className: cn(
704
+ "border-input flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none",
705
+ "placeholder:text-muted-foreground",
706
+ "focus-visible:border-ring focus-visible:ring-ring/30 focus-visible:ring-3",
707
+ "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
708
+ "aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-invalid:ring-3",
709
+ "dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
710
+ className
711
+ ),
712
+ ...props
713
+ }
714
+ );
715
+ }
716
+ var DEFAULT_MAX_SIZE = 5 * 1024 * 1024;
717
+ var DEFAULT_ACCEPT = { "image/*": [".png", ".jpg", ".jpeg", ".webp"] };
718
+ function InsertImageDialog({
719
+ open,
720
+ onOpenChange,
721
+ labels,
722
+ url,
723
+ onUrlChange,
724
+ alt,
725
+ onAltChange,
726
+ file,
727
+ onFileChange,
728
+ uploading,
729
+ onApply,
730
+ onCancel,
731
+ removable = false,
732
+ onRemove,
733
+ maxSizeBytes = DEFAULT_MAX_SIZE,
734
+ accept = DEFAULT_ACCEPT
735
+ }) {
736
+ const urlId = react.useId();
737
+ const altId = react.useId();
738
+ const canApply = Boolean(file || url.trim()) && Boolean(alt.trim()) && !uploading;
739
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "px-4 py-2", "data-slot": "insert-image-dialog", children: [
740
+ /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { children: labels.title }) }),
741
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [
742
+ /* @__PURE__ */ jsxRuntime.jsxs(
743
+ Dropzone,
744
+ {
745
+ accept,
746
+ maxFiles: 1,
747
+ maxSize: maxSizeBytes,
748
+ disabled: uploading,
749
+ src: file ? [file] : [],
750
+ onDrop: (files) => onFileChange(files[0] ?? null),
751
+ children: [
752
+ /* @__PURE__ */ jsxRuntime.jsx(DropzoneEmptyState, {}),
753
+ /* @__PURE__ */ jsxRuntime.jsx(DropzoneContent, {})
754
+ ]
755
+ }
756
+ ),
757
+ file && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs", children: file.name }),
758
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
759
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: urlId, children: labels.urlLabel }),
760
+ /* @__PURE__ */ jsxRuntime.jsx(
761
+ Input,
762
+ {
763
+ id: urlId,
764
+ placeholder: labels.urlPlaceholder,
765
+ value: url,
766
+ onChange: (event) => onUrlChange(event.target.value),
767
+ onKeyDown: (event) => {
768
+ if (event.key === "Enter" && canApply) {
769
+ event.preventDefault();
770
+ onApply();
771
+ }
772
+ }
773
+ }
774
+ )
775
+ ] }),
776
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
777
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: altId, children: labels.altLabel }),
778
+ /* @__PURE__ */ jsxRuntime.jsx(
779
+ Input,
780
+ {
781
+ id: altId,
782
+ value: alt,
783
+ onChange: (event) => onAltChange(event.target.value)
784
+ }
785
+ )
786
+ ] }),
787
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs", children: labels.hint })
788
+ ] }),
789
+ /* @__PURE__ */ jsxRuntime.jsxs(DialogFooter, { children: [
790
+ removable && onRemove && /* @__PURE__ */ jsxRuntime.jsxs(
791
+ Button,
792
+ {
793
+ type: "button",
794
+ variant: "ghost",
795
+ className: "text-destructive",
796
+ onClick: onRemove,
797
+ children: [
798
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { className: "h-4 w-4" }),
799
+ labels.remove
800
+ ]
801
+ }
802
+ ),
803
+ /* @__PURE__ */ jsxRuntime.jsx(
804
+ Button,
805
+ {
806
+ type: "button",
807
+ variant: "outline",
808
+ onClick: () => {
809
+ if (onCancel) onCancel();
810
+ else onOpenChange(false);
811
+ },
812
+ children: labels.cancel
813
+ }
814
+ ),
815
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", onClick: onApply, disabled: !canApply, children: labels.apply })
816
+ ] })
817
+ ] }) });
818
+ }
819
+ function ColorMenu({ editor, labels, icon, swatches }) {
820
+ const active = swatches.find((swatch) => editor?.isActive(swatch.mark));
821
+ function apply(mark) {
822
+ if (!editor) return;
823
+ const chain = editor.chain().focus();
824
+ for (const swatch of swatches) chain.unsetMark(swatch.mark);
825
+ if (mark) chain.setMark(mark);
826
+ chain.run();
827
+ }
828
+ return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
829
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
830
+ Button,
831
+ {
832
+ type: "button",
833
+ size: "sm",
834
+ variant: active ? "secondary" : "ghost",
835
+ disabled: !editor,
836
+ title: labels.trigger,
837
+ "aria-label": labels.trigger,
838
+ "data-slot": "color-menu-trigger",
839
+ children: icon
840
+ }
841
+ ) }),
842
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuContent, { align: "start", className: "w-auto", children: /* @__PURE__ */ jsxRuntime.jsxs(
843
+ "div",
844
+ {
845
+ role: "group",
846
+ "aria-label": labels.heading,
847
+ className: "flex items-center gap-1.5 px-1.5 py-1",
848
+ children: [
849
+ swatches.map((swatch) => /* @__PURE__ */ jsxRuntime.jsx(
850
+ "button",
851
+ {
852
+ type: "button",
853
+ "aria-label": swatch.label,
854
+ "aria-pressed": editor?.isActive(swatch.mark) ?? false,
855
+ title: swatch.label,
856
+ style: { backgroundColor: swatch.preview },
857
+ className: cn(
858
+ "h-7 w-7 cursor-pointer rounded-full border transition-transform",
859
+ "focus-visible:ring-ring/50 focus-visible:ring-2 focus-visible:outline-none",
860
+ editor?.isActive(swatch.mark) ? "border-primary scale-110 border-2" : "border-border/60 hover:scale-110"
861
+ ),
862
+ onClick: () => apply(swatch.mark)
863
+ },
864
+ swatch.mark
865
+ )),
866
+ /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: "bg-border mx-0.5 h-5 w-px" }),
867
+ /* @__PURE__ */ jsxRuntime.jsx(
868
+ "button",
869
+ {
870
+ type: "button",
871
+ "aria-label": labels.clear,
872
+ title: labels.clear,
873
+ disabled: !active,
874
+ className: cn(
875
+ "text-muted-foreground flex h-7 w-7 cursor-pointer items-center justify-center rounded-full",
876
+ "focus-visible:ring-ring/50 focus-visible:ring-2 focus-visible:outline-none",
877
+ "hover:text-foreground disabled:cursor-default disabled:opacity-40"
878
+ ),
879
+ onClick: () => apply(""),
880
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Ban, { className: "h-4 w-4" })
881
+ }
882
+ )
883
+ ]
884
+ }
885
+ ) })
886
+ ] });
887
+ }
888
+ function ListMenu({ editor, triggerLabel, icon, options }) {
889
+ const active = options.find((option) => editor?.isActive(option.node));
890
+ return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
891
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
892
+ Button,
893
+ {
894
+ type: "button",
895
+ size: "sm",
896
+ variant: active ? "secondary" : "ghost",
897
+ disabled: !editor,
898
+ title: active ? active.label : triggerLabel,
899
+ "aria-label": active ? active.label : triggerLabel,
900
+ "data-slot": "list-menu-trigger",
901
+ children: [
902
+ active ? active.icon : icon,
903
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { className: "h-3 w-3 opacity-60" })
904
+ ]
905
+ }
906
+ ) }),
907
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuContent, { align: "start", children: options.map((option) => {
908
+ const isActive = editor?.isActive(option.node) ?? false;
909
+ return /* @__PURE__ */ jsxRuntime.jsxs(
910
+ DropdownMenuItem,
911
+ {
912
+ disabled: !editor,
913
+ className: "cursor-pointer",
914
+ onSelect: () => editor && option.run(editor),
915
+ children: [
916
+ option.icon,
917
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1", children: option.label }),
918
+ /* @__PURE__ */ jsxRuntime.jsx(
919
+ lucideReact.Check,
920
+ {
921
+ "aria-hidden": "true",
922
+ className: cn("h-4 w-4", isActive ? "opacity-100" : "opacity-0")
923
+ }
924
+ )
925
+ ]
926
+ },
927
+ option.node
928
+ );
929
+ }) })
930
+ ] });
931
+ }
932
+ function InsertLinkDialog({
933
+ open,
934
+ onOpenChange,
935
+ labels,
936
+ url,
937
+ onUrlChange,
938
+ text = "",
939
+ onTextChange,
940
+ needsText = false,
941
+ onApply,
942
+ onCancel
943
+ }) {
944
+ const urlId = react.useId();
945
+ const textId = react.useId();
946
+ const canApply = needsText ? Boolean(url.trim()) && Boolean(text.trim()) : true;
947
+ function submitOnEnter(event) {
948
+ if (event.key === "Enter" && canApply) {
949
+ event.preventDefault();
950
+ onApply();
951
+ }
952
+ }
953
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "px-4 py-2", "data-slot": "insert-link-dialog", children: [
954
+ /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { children: labels.title }) }),
955
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [
956
+ needsText && onTextChange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
957
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: textId, children: labels.textLabel }),
958
+ /* @__PURE__ */ jsxRuntime.jsx(
959
+ Input,
960
+ {
961
+ id: textId,
962
+ placeholder: labels.textPlaceholder,
963
+ value: text,
964
+ onChange: (event) => onTextChange(event.target.value),
965
+ onKeyDown: submitOnEnter
966
+ }
967
+ )
968
+ ] }),
969
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
970
+ /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: urlId, children: labels.urlLabel }),
971
+ /* @__PURE__ */ jsxRuntime.jsx(
972
+ Input,
973
+ {
974
+ id: urlId,
975
+ placeholder: labels.urlPlaceholder,
976
+ value: url,
977
+ onChange: (event) => onUrlChange(event.target.value),
978
+ onKeyDown: submitOnEnter
979
+ }
980
+ ),
981
+ !needsText && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs", children: labels.hint })
982
+ ] })
983
+ ] }),
984
+ /* @__PURE__ */ jsxRuntime.jsxs(DialogFooter, { children: [
985
+ /* @__PURE__ */ jsxRuntime.jsx(
986
+ Button,
987
+ {
988
+ type: "button",
989
+ variant: "outline",
990
+ onClick: () => {
991
+ if (onCancel) onCancel();
992
+ else onOpenChange(false);
993
+ },
994
+ children: labels.cancel
995
+ }
996
+ ),
997
+ /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", onClick: onApply, disabled: !canApply, children: labels.apply })
998
+ ] })
999
+ ] }) });
1000
+ }
1001
+ function LinkActions({ editor, labels, onEdit, onOpen }) {
1002
+ const href = react$1.useEditorState({
1003
+ editor,
1004
+ selector: ({ editor: current }) => current.getAttributes("link").href ?? ""
1005
+ });
1006
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1007
+ "div",
1008
+ {
1009
+ "data-slot": "link-bubble-menu",
1010
+ className: "bg-popover text-popover-foreground flex items-center gap-1 rounded-md border p-1 shadow-md",
1011
+ children: [
1012
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground max-w-[16rem] truncate px-2 text-xs", children: href }),
1013
+ /* @__PURE__ */ jsxRuntime.jsx(
1014
+ Button,
1015
+ {
1016
+ type: "button",
1017
+ size: "sm",
1018
+ variant: "ghost",
1019
+ title: labels.open,
1020
+ "aria-label": labels.open,
1021
+ disabled: !href,
1022
+ onClick: () => {
1023
+ if (!href) return;
1024
+ if (onOpen) {
1025
+ onOpen(href);
1026
+ return;
1027
+ }
1028
+ window.open(href, "_blank", "noopener,noreferrer");
1029
+ },
1030
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ExternalLink, { className: "h-4 w-4" })
1031
+ }
1032
+ ),
1033
+ /* @__PURE__ */ jsxRuntime.jsx(
1034
+ Button,
1035
+ {
1036
+ type: "button",
1037
+ size: "sm",
1038
+ variant: "ghost",
1039
+ title: labels.edit,
1040
+ "aria-label": labels.edit,
1041
+ onClick: onEdit,
1042
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-4 w-4" })
1043
+ }
1044
+ ),
1045
+ /* @__PURE__ */ jsxRuntime.jsx(
1046
+ Button,
1047
+ {
1048
+ type: "button",
1049
+ size: "sm",
1050
+ variant: "ghost",
1051
+ className: "text-destructive",
1052
+ title: labels.remove,
1053
+ "aria-label": labels.remove,
1054
+ onClick: () => editor.chain().focus().extendMarkRange("link").unsetLink().run(),
1055
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Unlink, { className: "h-4 w-4" })
1056
+ }
1057
+ )
1058
+ ]
1059
+ }
1060
+ );
1061
+ }
1062
+ function LinkBubbleMenu({ editor, labels, onEdit, onOpen }) {
1063
+ const shouldShow = react.useCallback(
1064
+ // Only while the caret is actually in a link — otherwise this bar would
1065
+ // compete with any other bubble menu the consumer adds.
1066
+ ({ editor: current }) => current.isActive("link"),
1067
+ []
1068
+ );
1069
+ const options = react.useMemo(() => ({ placement: "bottom", offset: 8 }), []);
1070
+ if (!editor) return null;
1071
+ return /* @__PURE__ */ jsxRuntime.jsx(menus.BubbleMenu, { editor, shouldShow, options, children: /* @__PURE__ */ jsxRuntime.jsx(LinkActions, { editor, labels, onEdit, onOpen }) });
1072
+ }
1073
+ var DEFAULT_MIN_WIDTH = 120;
1074
+ var DEFAULT_START_WIDTH = 400;
1075
+ var DEFAULT_RATIO = 4 / 3;
1076
+ var KEYBOARD_STEP = 20;
1077
+ function ResizableImageView({ node, updateAttributes, selected, extension }) {
1078
+ const { src, alt, width, height } = node.attrs;
1079
+ const sizeRef = react.useRef({ width, height });
1080
+ sizeRef.current = { width, height };
1081
+ const { resizeLabel, minWidth = DEFAULT_MIN_WIDTH } = extension.options;
1082
+ const dragRef = react.useRef(null);
1083
+ const [dragging, setDragging] = react.useState(false);
1084
+ const resizeTo = react.useCallback(
1085
+ (nextWidth, ratio, maxWidth) => {
1086
+ const clamped = Math.max(minWidth, Math.min(Math.round(nextWidth), maxWidth));
1087
+ updateAttributes({ width: clamped, height: Math.round(clamped / ratio) });
1088
+ },
1089
+ [minWidth, updateAttributes]
1090
+ );
1091
+ const measure = react.useCallback((handle) => {
1092
+ const image = handle.parentElement?.querySelector("img") ?? null;
1093
+ const current = sizeRef.current;
1094
+ const editable = handle.closest(".ProseMirror");
1095
+ const available = editable?.clientWidth ?? 0;
1096
+ const naturalWidth = image?.naturalWidth ?? 0;
1097
+ const naturalHeight = image?.naturalHeight ?? 0;
1098
+ const ratio = current.width > 0 && current.height > 0 ? current.width / current.height : naturalWidth > 0 && naturalHeight > 0 ? naturalWidth / naturalHeight : DEFAULT_RATIO;
1099
+ const unbounded = current.width > 0 ? current.width : naturalWidth || DEFAULT_START_WIDTH;
1100
+ const startWidth = available > 0 ? Math.min(unbounded, available) : unbounded;
1101
+ return {
1102
+ width: startWidth,
1103
+ ratio,
1104
+ // jsdom reports clientWidth as 0, so a zero measure means "no
1105
+ // constraint" — the real clamp only applies in a browser.
1106
+ maxWidth: available > 0 ? available : Infinity
1107
+ };
1108
+ }, []);
1109
+ const imageRef = react.useRef(null);
1110
+ const fittedSrcRef = react.useRef(null);
1111
+ react.useEffect(() => {
1112
+ const img = imageRef.current;
1113
+ if (!img) return;
1114
+ if (sizeRef.current.width > 0 || fittedSrcRef.current === src) return;
1115
+ const fit = () => {
1116
+ const available = img.closest(".ProseMirror")?.clientWidth ?? 0;
1117
+ if (!img.naturalWidth || !img.naturalHeight || available <= 0) return;
1118
+ fittedSrcRef.current = src;
1119
+ const nextWidth = Math.min(img.naturalWidth, available);
1120
+ updateAttributes({
1121
+ width: nextWidth,
1122
+ height: Math.round(nextWidth / (img.naturalWidth / img.naturalHeight))
1123
+ });
1124
+ };
1125
+ if (img.complete) {
1126
+ fit();
1127
+ return;
1128
+ }
1129
+ img.addEventListener("load", fit, { once: true });
1130
+ return () => img.removeEventListener("load", fit);
1131
+ }, [src, updateAttributes]);
1132
+ const onPointerDown = react.useCallback(
1133
+ (event) => {
1134
+ event.preventDefault();
1135
+ event.stopPropagation();
1136
+ const start = measure(event.currentTarget);
1137
+ dragRef.current = { startX: event.clientX, ...start };
1138
+ setDragging(true);
1139
+ const onMove = (moveEvent) => {
1140
+ const drag = dragRef.current;
1141
+ if (!drag) return;
1142
+ resizeTo(drag.width + (moveEvent.clientX - drag.startX), drag.ratio, drag.maxWidth);
1143
+ };
1144
+ const onUp = () => {
1145
+ dragRef.current = null;
1146
+ setDragging(false);
1147
+ window.removeEventListener("pointermove", onMove);
1148
+ window.removeEventListener("pointerup", onUp);
1149
+ };
1150
+ window.addEventListener("pointermove", onMove);
1151
+ window.addEventListener("pointerup", onUp);
1152
+ },
1153
+ [measure, resizeTo]
1154
+ );
1155
+ const onKeyDown = react.useCallback(
1156
+ (event) => {
1157
+ const step = event.key === "ArrowRight" ? KEYBOARD_STEP : event.key === "ArrowLeft" ? -KEYBOARD_STEP : 0;
1158
+ if (step === 0) return;
1159
+ event.preventDefault();
1160
+ const start = measure(event.currentTarget);
1161
+ resizeTo(start.width + step, start.ratio, start.maxWidth);
1162
+ },
1163
+ [measure, resizeTo]
1164
+ );
1165
+ const sizeStyle = width > 0 ? { width, height: height > 0 ? height : void 0, maxWidth: "100%" } : void 0;
1166
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1167
+ react$1.NodeViewWrapper,
1168
+ {
1169
+ "data-slot": "resizable-image",
1170
+ className: "group relative inline-block max-w-full",
1171
+ children: [
1172
+ /* @__PURE__ */ jsxRuntime.jsx(
1173
+ "img",
1174
+ {
1175
+ ref: imageRef,
1176
+ src,
1177
+ alt,
1178
+ className: "max-w-full rounded-md",
1179
+ style: sizeStyle,
1180
+ draggable: false
1181
+ }
1182
+ ),
1183
+ /* @__PURE__ */ jsxRuntime.jsx(
1184
+ "div",
1185
+ {
1186
+ role: "button",
1187
+ tabIndex: 0,
1188
+ "aria-label": resizeLabel,
1189
+ title: resizeLabel,
1190
+ "data-slot": "resizable-image-handle",
1191
+ onPointerDown,
1192
+ onKeyDown,
1193
+ className: cn(
1194
+ "border-primary absolute -right-1 -bottom-1 h-4 w-4 cursor-se-resize touch-none rounded-full border-2 bg-white transition-opacity",
1195
+ "focus-visible:ring-ring/50 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:outline-none",
1196
+ dragging || selected ? "opacity-100" : "opacity-0 group-hover:opacity-100"
1197
+ )
1198
+ }
1199
+ )
1200
+ ]
1201
+ }
1202
+ );
1203
+ }
1204
+ function createResizableImage(options) {
1205
+ return extensionImage.Image.extend({
1206
+ addOptions() {
1207
+ return { ...this.parent(), ...options };
1208
+ },
1209
+ // The size attributes belong to the extension, not to the consumer: the
1210
+ // stock Image extension keeps width/height too, but they default to null
1211
+ // and render as HTML attributes, which pins the image to a fixed size.
1212
+ //
1213
+ // A numeric default with `rendered: false` is what makes resizing work
1214
+ // at all — Tiptap v3 gates DOM emission on `rendered`, so the size stays
1215
+ // out of the markup and lives only in the document JSON, where a
1216
+ // serializer can read it. Without these declarations the schema drops
1217
+ // every updateAttributes({ width }) call and the handle does nothing.
1218
+ addAttributes() {
1219
+ return {
1220
+ ...this.parent?.(),
1221
+ width: { default: 0, rendered: false },
1222
+ height: { default: 0, rendered: false }
1223
+ };
1224
+ },
1225
+ addNodeView() {
1226
+ return react$1.ReactNodeViewRenderer(ResizableImageView);
1227
+ }
1228
+ });
1229
+ }
1230
+
1231
+ exports.ColorMenu = ColorMenu;
1232
+ exports.EDITOR_CONTENT_STYLE = EDITOR_CONTENT_STYLE;
1233
+ exports.InsertImageDialog = InsertImageDialog;
1234
+ exports.InsertLinkDialog = InsertLinkDialog;
1235
+ exports.LinkBubbleMenu = LinkBubbleMenu;
1236
+ exports.ListMenu = ListMenu;
1237
+ exports.RichTextEditor = RichTextEditor;
1238
+ exports.RichTextToolbar = RichTextToolbar;
1239
+ exports.TableMenu = TableMenu;
1240
+ exports.createResizableImage = createResizableImage;
1241
+ //# sourceMappingURL=editor.cjs.map
1242
+ //# sourceMappingURL=editor.cjs.map