@editora/plugins 1.1.0 → 1.2.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.
@@ -1,103 +1,1242 @@
1
- import { f as M, p as N, k as D } from "./dialogHelpers-BbwpIXD9.mjs";
2
- import { r as $ } from "./historyHelpers-BEKwNOtA.mjs";
3
- const y = /* @__PURE__ */ new WeakMap();
4
- let h = null, R = !1, H = 0;
5
- const T = "User";
1
+ import { f as Ge, p as Ze, k as Xe } from "./dialogHelpers-BbwpIXD9.mjs";
2
+ import { r as Je } from "./historyHelpers-BEKwNOtA.mjs";
3
+ const j = 60, W = 60 * j, _ = 24 * W;
4
+ function ae(e, t = Date.now(), n) {
5
+ const r = new Date(e).getTime();
6
+ if (Number.isNaN(r)) return "";
7
+ const o = Math.round((r - t) / 1e3), i = Math.abs(o);
8
+ let a = null;
9
+ try {
10
+ a = new Intl.RelativeTimeFormat(n, { numeric: "auto", style: "short" });
11
+ } catch {
12
+ a = null;
13
+ }
14
+ if (i < j) return a ? a.format(0, "second") : "now";
15
+ if (i < W) return a ? a.format(Math.round(o / j), "minute") : `${Math.round(i / j)}m ago`;
16
+ if (i < _) return a ? a.format(Math.round(o / W), "hour") : `${Math.round(i / W)}h ago`;
17
+ if (i < 7 * _) return a ? a.format(Math.round(o / _), "day") : `${Math.round(i / _)}d ago`;
18
+ const d = new Date(r), l = d.getFullYear() === new Date(t).getFullYear();
19
+ return d.toLocaleDateString(n, {
20
+ month: "short",
21
+ day: "numeric",
22
+ year: l ? void 0 : "numeric"
23
+ });
24
+ }
25
+ function Me(e, t) {
26
+ const n = new Date(e);
27
+ return Number.isNaN(n.getTime()) ? "" : n.toLocaleString(t, { dateStyle: "medium", timeStyle: "short" });
28
+ }
29
+ function Qe(e) {
30
+ const t = e.trim().split(/\s+/).filter(Boolean);
31
+ if (t.length === 0) return "?";
32
+ const n = Array.from(t[0])[0] ?? "", r = t.length > 1 ? Array.from(t[t.length - 1])[0] ?? "" : "";
33
+ return (n + r).toUpperCase() || "?";
34
+ }
35
+ const he = [
36
+ "hsl(215 55% 36%)",
37
+ "hsl(262 45% 45%)",
38
+ "hsl(330 52% 40%)",
39
+ "hsl(8 58% 40%)",
40
+ "hsl(28 70% 32%)",
41
+ "hsl(150 55% 28%)",
42
+ "hsl(180 60% 27%)",
43
+ "hsl(240 40% 48%)"
44
+ ];
45
+ function et(e) {
46
+ let t = 0;
47
+ for (let n = 0; n < e.length; n += 1)
48
+ t = t * 31 + e.charCodeAt(n) >>> 0;
49
+ return he[t % he.length];
50
+ }
51
+ const ge = "rte-comments-panel-styles", tt = `
52
+ .rte-comments-panel,
53
+ .rte-comments-panel * {
54
+ box-sizing: border-box;
55
+ }
56
+
57
+ .rte-comments-panel {
58
+ --rte-comments-panel-width: min(340px, 42vw);
59
+ position: absolute;
60
+ top: 0;
61
+ right: 0;
62
+ bottom: 0;
63
+ width: var(--rte-comments-panel-width);
64
+ display: flex;
65
+ flex-direction: column;
66
+ background: var(--rte-color-bg-primary, #ffffff);
67
+ color: var(--rte-color-text-primary, #111827);
68
+ border-left: 1px solid var(--rte-color-border-light, #e5e7eb);
69
+ box-shadow: -8px 0 24px rgba(15, 23, 42, 0.08);
70
+ font-size: 13px;
71
+ line-height: 1.45;
72
+ transform: translateX(100%);
73
+ opacity: 0;
74
+ pointer-events: none;
75
+ transition: transform 180ms ease, opacity 180ms ease;
76
+ /* Above the editor's sticky toolbar (z-index 100): on a narrow screen the panel lies over the editor, and
77
+ under the toolbar its header, and the button that closes it, could not be clicked. */
78
+ z-index: 110;
79
+ }
80
+
81
+ .rte-comments-panel.is-open {
82
+ transform: translateX(0);
83
+ opacity: 1;
84
+ pointer-events: auto;
85
+ }
86
+
87
+ /* The panel's width is set on the editor itself, not only on the panel: the toolbar and the text make room for the
88
+ panel with a margin of that width, and a variable set on the panel is not visible to them (the margin was
89
+ silently 0, so the panel lay over the toolbar and the text and its header could not be reached). */
90
+ [data-rte-comments-open="true"] {
91
+ --rte-comments-panel-width: min(340px, 42vw);
92
+ }
93
+
94
+ /* The toolbar's wrapper is the element that is as wide as the editor, and it sits above the panel (it is sticky,
95
+ z-index 100): it has to give up the panel's width too, or its empty right-hand end covers the panel's header. */
96
+ [data-rte-comments-open="true"] :is(.rte-toolbar-wrapper, .rte-toolbar:not(.rte-toolbar-wrapper .rte-toolbar), .editora-toolbar, .rte-content, .editora-content, .editora-statusbar, .editora-statusbar-container) {
97
+ margin-right: var(--rte-comments-panel-width);
98
+ transition: margin-right 180ms ease;
99
+ }
100
+
101
+ .rte-comments-panel :is(button, textarea, [role="tab"]):focus-visible {
102
+ outline: 2px solid var(--rte-color-border-focus, #2563eb);
103
+ outline-offset: 1px;
104
+ }
105
+
106
+ /* ---- Header and tabs ---- */
107
+
108
+ .rte-comments-header {
109
+ display: flex;
110
+ align-items: center;
111
+ justify-content: space-between;
112
+ gap: 8px;
113
+ padding: 12px 12px 8px 16px;
114
+ }
115
+
116
+ .rte-comments-title {
117
+ display: flex;
118
+ align-items: center;
119
+ gap: 8px;
120
+ min-width: 0;
121
+ }
122
+
123
+ .rte-comments-title h3 {
124
+ margin: 0;
125
+ font-size: 15px;
126
+ font-weight: 600;
127
+ line-height: 1.3;
128
+ }
129
+
130
+ .rte-comments-count {
131
+ min-width: 20px;
132
+ padding: 0 6px;
133
+ border-radius: 999px;
134
+ background: var(--rte-color-bg-tertiary, #e2e8f0);
135
+ color: var(--rte-color-text-secondary, #475569);
136
+ font-size: 11px;
137
+ font-weight: 600;
138
+ line-height: 20px;
139
+ text-align: center;
140
+ }
141
+
142
+ .rte-comments-header-actions {
143
+ display: flex;
144
+ align-items: center;
145
+ gap: 4px;
146
+ }
147
+
148
+ .rte-comments-tabs {
149
+ display: flex;
150
+ gap: 2px;
151
+ margin: 0 16px;
152
+ padding: 2px;
153
+ border-radius: 8px;
154
+ background: var(--rte-color-bg-tertiary, #eef2f6);
155
+ }
156
+
157
+ .rte-comments-tab {
158
+ flex: 1;
159
+ border: 0;
160
+ border-radius: 6px;
161
+ padding: 5px 8px;
162
+ background: transparent;
163
+ color: var(--rte-color-text-secondary, #475569);
164
+ font: inherit;
165
+ font-size: 12px;
166
+ font-weight: 500;
167
+ cursor: pointer;
168
+ }
169
+
170
+ .rte-comments-tab:hover {
171
+ color: var(--rte-color-text-primary, #0f172a);
172
+ }
173
+
174
+ .rte-comments-tab[aria-selected="true"] {
175
+ background: var(--rte-color-bg-primary, #ffffff);
176
+ color: var(--rte-color-text-primary, #0f172a);
177
+ box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
178
+ }
179
+
180
+ .rte-comments-tab-count {
181
+ margin-left: 4px;
182
+ font-weight: 400;
183
+ color: var(--rte-color-text-muted, #64748b);
184
+ }
185
+
186
+ .rte-comments-body {
187
+ flex: 1;
188
+ min-height: 0;
189
+ overflow-y: auto;
190
+ padding: 12px 12px 16px;
191
+ display: flex;
192
+ flex-direction: column;
193
+ gap: 10px;
194
+ }
195
+
196
+ /* ---- Buttons ---- */
197
+
198
+ .rte-comment-icon-btn,
199
+ .rte-comments-new,
200
+ .rte-comments-close {
201
+ display: inline-flex;
202
+ align-items: center;
203
+ justify-content: center;
204
+ gap: 6px;
205
+ border: 0;
206
+ border-radius: 6px;
207
+ background: transparent;
208
+ color: var(--rte-color-text-secondary, #475569);
209
+ font: inherit;
210
+ cursor: pointer;
211
+ }
212
+
213
+ .rte-comment-icon-btn,
214
+ .rte-comments-close {
215
+ width: 28px;
216
+ height: 28px;
217
+ padding: 0;
218
+ }
219
+
220
+ .rte-comments-new {
221
+ height: 28px;
222
+ padding: 0 10px 0 8px;
223
+ font-size: 12px;
224
+ font-weight: 500;
225
+ color: var(--rte-color-primary, #2563eb);
226
+ }
227
+
228
+ .rte-comment-icon-btn:hover,
229
+ .rte-comments-new:hover,
230
+ .rte-comments-close:hover {
231
+ background: var(--rte-color-bg-hover, #f1f5f9);
232
+ color: var(--rte-color-text-primary, #0f172a);
233
+ }
234
+
235
+ /* Not the grey hover of the other buttons: the primary colour on that grey is below 4.5:1 in the dark theme. */
236
+ .rte-comments-new:hover {
237
+ background: color-mix(in srgb, var(--rte-color-primary, #2563eb) 12%, transparent);
238
+ color: var(--rte-color-primary, #2563eb);
239
+ }
240
+
241
+ .rte-comment-icon-btn[data-action="resolve"]:hover {
242
+ background: color-mix(in srgb, var(--rte-color-success, #15803d) 14%, transparent);
243
+ color: var(--rte-color-success, #15803d);
244
+ }
245
+
246
+ .rte-comment-icon-btn svg,
247
+ .rte-comments-new svg,
248
+ .rte-comments-close svg {
249
+ width: 16px;
250
+ height: 16px;
251
+ flex: none;
252
+ }
253
+
254
+ .rte-comment-btn {
255
+ border: 1px solid var(--rte-color-border, #d1d5db);
256
+ border-radius: 7px;
257
+ padding: 5px 12px;
258
+ font: inherit;
259
+ font-size: 12px;
260
+ font-weight: 500;
261
+ cursor: pointer;
262
+ background: var(--rte-color-bg-primary, #ffffff);
263
+ color: var(--rte-color-text-secondary, #334155);
264
+ }
265
+
266
+ .rte-comment-btn:hover {
267
+ background: var(--rte-color-bg-hover, #f1f5f9);
268
+ color: var(--rte-color-text-primary, #0f172a);
269
+ }
270
+
271
+ .rte-comment-btn.ghost {
272
+ border-color: transparent;
273
+ background: transparent;
274
+ }
275
+
276
+ .rte-comment-btn.primary {
277
+ border-color: var(--rte-color-primary, #2563eb);
278
+ background: var(--rte-color-primary, #2563eb);
279
+ color: var(--rte-color-text-inverse, #ffffff);
280
+ }
281
+
282
+ .rte-comment-btn.primary:hover {
283
+ background: var(--rte-color-primary-hover, #1d4ed8);
284
+ border-color: var(--rte-color-primary-hover, #1d4ed8);
285
+ color: var(--rte-color-text-inverse, #ffffff);
286
+ }
287
+
288
+ .rte-comment-btn:disabled,
289
+ .rte-comment-btn.primary:disabled {
290
+ border-color: var(--rte-color-border-light, #e2e8f0);
291
+ background: var(--rte-color-bg-tertiary, #e2e8f0);
292
+ color: var(--rte-color-text-muted, #64748b);
293
+ cursor: not-allowed;
294
+ }
295
+
296
+ /* ---- Cards (a thread, and the form for a new comment) ---- */
297
+
298
+ .rte-comment-item,
299
+ .rte-comment-composer {
300
+ border: 1px solid var(--rte-color-border-light, #e5e7eb);
301
+ border-radius: 10px;
302
+ background: var(--rte-color-bg-primary, #ffffff);
303
+ padding: 12px;
304
+ transition: border-color 120ms ease, box-shadow 120ms ease;
305
+ }
306
+
307
+ .rte-comment-item:hover {
308
+ border-color: var(--rte-color-border, #cbd5e1);
309
+ }
310
+
311
+ .rte-comment-item.is-active,
312
+ .rte-comment-composer {
313
+ border-color: var(--rte-color-primary, #2563eb);
314
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--rte-color-primary, #2563eb) 14%, transparent);
315
+ }
316
+
317
+ .rte-comment-item.resolved .rte-comment-text,
318
+ .rte-comment-item.resolved .rte-comment-selection {
319
+ color: var(--rte-color-text-secondary, #475569);
320
+ }
321
+
322
+ .rte-comment-header,
323
+ .rte-comment-reply-header {
324
+ display: flex;
325
+ align-items: center;
326
+ gap: 8px;
327
+ }
328
+
329
+ .rte-comment-avatar {
330
+ flex: none;
331
+ width: 28px;
332
+ height: 28px;
333
+ border-radius: 50%;
334
+ color: #ffffff;
335
+ font-size: 11px;
336
+ font-weight: 600;
337
+ line-height: 28px;
338
+ text-align: center;
339
+ user-select: none;
340
+ }
341
+
342
+ .rte-comment-avatar {
343
+ position: relative;
344
+ overflow: hidden;
345
+ }
346
+
347
+ /* The picture covers the initials; if it fails to load it is removed and the initials show. */
348
+ .rte-comment-avatar img {
349
+ position: absolute;
350
+ inset: 0;
351
+ width: 100%;
352
+ height: 100%;
353
+ object-fit: cover;
354
+ border-radius: 50%;
355
+ }
356
+
357
+ .rte-comment-avatar.small {
358
+ width: 22px;
359
+ height: 22px;
360
+ font-size: 9px;
361
+ line-height: 22px;
362
+ }
363
+
364
+ .rte-comment-meta {
365
+ flex: 1;
366
+ min-width: 0;
367
+ display: flex;
368
+ flex-direction: column;
369
+ }
370
+
371
+ .rte-comment-author {
372
+ overflow: hidden;
373
+ text-overflow: ellipsis;
374
+ white-space: nowrap;
375
+ font-size: 13px;
376
+ font-weight: 600;
377
+ line-height: 1.3;
378
+ color: var(--rte-color-text-primary, #0f172a);
379
+ }
380
+
381
+ .rte-comment-when {
382
+ display: flex;
383
+ align-items: baseline;
384
+ gap: 4px;
385
+ font-size: 11px;
386
+ line-height: 1.3;
387
+ color: var(--rte-color-text-muted, #64748b);
388
+ }
389
+
390
+ .rte-comment-date {
391
+ font-size: 11px;
392
+ line-height: 1.3;
393
+ color: var(--rte-color-text-muted, #64748b);
394
+ }
395
+
396
+ .rte-comment-header-actions {
397
+ display: flex;
398
+ align-items: center;
399
+ gap: 2px;
400
+ }
401
+
402
+ .rte-comment-more {
403
+ position: relative;
404
+ }
405
+
406
+ .rte-comment-menu {
407
+ position: absolute;
408
+ top: calc(100% + 4px);
409
+ right: 0;
410
+ z-index: 2;
411
+ min-width: 140px;
412
+ padding: 4px;
413
+ border: 1px solid var(--rte-color-border, #d1d5db);
414
+ border-radius: 8px;
415
+ background: var(--rte-color-bg-primary, #ffffff);
416
+ box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
417
+ }
418
+
419
+ .rte-comment-menu[hidden] {
420
+ display: none;
421
+ }
422
+
423
+ .rte-comment-menu-item {
424
+ display: flex;
425
+ align-items: center;
426
+ gap: 8px;
427
+ width: 100%;
428
+ border: 0;
429
+ border-radius: 6px;
430
+ padding: 6px 8px;
431
+ background: transparent;
432
+ color: var(--rte-color-text-primary, #0f172a);
433
+ font: inherit;
434
+ font-size: 13px;
435
+ text-align: left;
436
+ cursor: pointer;
437
+ }
438
+
439
+ .rte-comment-menu-item svg {
440
+ width: 15px;
441
+ height: 15px;
442
+ flex: none;
443
+ }
444
+
445
+ .rte-comment-menu-item:hover,
446
+ .rte-comment-menu-item:focus-visible {
447
+ background: var(--rte-color-bg-hover, #f1f5f9);
448
+ }
449
+
450
+ .rte-comment-menu-item.danger {
451
+ color: var(--rte-color-danger, #b91c1c);
452
+ }
453
+
454
+ .rte-comment-menu-item.danger:hover,
455
+ .rte-comment-menu-item.danger:focus-visible {
456
+ background: color-mix(in srgb, var(--rte-color-danger, #b91c1c) 10%, transparent);
457
+ }
458
+
459
+ /* What the comment is about: one line of the quoted text. */
460
+ .rte-comment-selection {
461
+ display: block;
462
+ width: 100%;
463
+ margin: 10px 0 0;
464
+ padding: 4px 8px;
465
+ border: 0;
466
+ border-left: 3px solid var(--rte-color-warning, #d97706);
467
+ border-radius: 0 4px 4px 0;
468
+ background: var(--rte-color-bg-secondary, #f8fafc);
469
+ color: var(--rte-color-text-secondary, #475569);
470
+ font: inherit;
471
+ font-size: 12px;
472
+ text-align: left;
473
+ overflow: hidden;
474
+ text-overflow: ellipsis;
475
+ white-space: nowrap;
476
+ }
477
+
478
+ button.rte-comment-selection {
479
+ cursor: pointer;
480
+ }
481
+
482
+ button.rte-comment-selection:hover {
483
+ background: var(--rte-color-bg-hover, #f1f5f9);
484
+ }
485
+
486
+ .rte-comment-text {
487
+ margin-top: 10px;
488
+ font-size: 13px;
489
+ line-height: 1.5;
490
+ color: var(--rte-color-text-primary, #0f172a);
491
+ white-space: pre-wrap;
492
+ overflow-wrap: anywhere;
493
+ }
494
+
495
+ .rte-comment-status {
496
+ display: flex;
497
+ align-items: center;
498
+ gap: 4px;
499
+ margin-top: 8px;
500
+ font-size: 11px;
501
+ color: var(--rte-color-success, #15803d);
502
+ }
503
+
504
+ .rte-comment-status svg {
505
+ width: 12px;
506
+ height: 12px;
507
+ }
508
+
509
+ /* ---- Replies ---- */
510
+
511
+ .rte-comment-replies {
512
+ display: flex;
513
+ flex-direction: column;
514
+ gap: 12px;
515
+ margin-top: 12px;
516
+ padding-top: 12px;
517
+ border-top: 1px solid var(--rte-color-border-light, #e5e7eb);
518
+ }
519
+
520
+ .rte-comment-reply-header .rte-comment-icon-btn {
521
+ width: 24px;
522
+ height: 24px;
523
+ }
524
+
525
+ .rte-comment-reply-header .rte-comment-icon-btn svg {
526
+ width: 14px;
527
+ height: 14px;
528
+ }
529
+
530
+ .rte-comment-reply-text {
531
+ margin: 4px 0 0 30px;
532
+ font-size: 13px;
533
+ line-height: 1.5;
534
+ color: var(--rte-color-text-primary, #0f172a);
535
+ white-space: pre-wrap;
536
+ overflow-wrap: anywhere;
537
+ }
538
+
539
+ .rte-comment-more-replies {
540
+ align-self: flex-start;
541
+ border: 0;
542
+ padding: 0;
543
+ background: transparent;
544
+ color: var(--rte-color-primary, #2563eb);
545
+ font: inherit;
546
+ font-size: 12px;
547
+ font-weight: 500;
548
+ cursor: pointer;
549
+ }
550
+
551
+ .rte-comment-more-replies:hover {
552
+ text-decoration: underline;
553
+ }
554
+
555
+ /* ---- Reply box: one line until it is used ---- */
556
+
557
+ .rte-comment-reply-box {
558
+ margin-top: 12px;
559
+ }
560
+
561
+ .rte-comment-reply .rte-comment-edit {
562
+ margin: 6px 0 0 30px;
563
+ }
564
+
565
+ .rte-comment-edit {
566
+ margin-top: 10px;
567
+ }
568
+
569
+ .new-comment-textarea,
570
+ .rte-comment-reply-textarea,
571
+ .rte-comment-edit-textarea {
572
+ display: block;
573
+ width: 100%;
574
+ resize: none;
575
+ min-height: 34px;
576
+ max-height: 160px;
577
+ font: inherit;
578
+ font-size: 13px;
579
+ line-height: 1.45;
580
+ border: 1px solid var(--rte-color-border, #d1d5db);
581
+ border-radius: 8px;
582
+ background: var(--rte-color-bg-primary, #ffffff);
583
+ color: var(--rte-color-text-primary, #0f172a);
584
+ padding: 7px 10px;
585
+ outline: none;
586
+ }
587
+
588
+ .new-comment-textarea {
589
+ min-height: 64px;
590
+ }
591
+
592
+ .new-comment-textarea::placeholder,
593
+ .rte-comment-reply-textarea::placeholder,
594
+ .rte-comment-edit-textarea::placeholder {
595
+ color: var(--rte-color-text-muted, #64748b);
596
+ }
597
+
598
+ .new-comment-textarea:focus,
599
+ .rte-comment-reply-textarea:focus,
600
+ .rte-comment-edit-textarea:focus {
601
+ border-color: var(--rte-color-border-focus, #2563eb);
602
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--rte-color-border-focus, #2563eb) 20%, transparent);
603
+ }
604
+
605
+ .rte-comment-form-actions {
606
+ display: flex;
607
+ justify-content: flex-end;
608
+ gap: 6px;
609
+ margin-top: 8px;
610
+ }
611
+
612
+ .rte-comment-reply-box:not(:focus-within):not(.has-text) .rte-comment-form-actions {
613
+ display: none;
614
+ }
615
+
616
+ /* ---- New comment ---- */
617
+
618
+ .rte-comment-composer .rte-comment-selection {
619
+ margin: 0 0 10px;
620
+ display: flex;
621
+ align-items: center;
622
+ gap: 6px;
623
+ padding-right: 4px;
624
+ }
625
+
626
+ .rte-comment-composer .rte-comment-selection span {
627
+ flex: 1;
628
+ min-width: 0;
629
+ overflow: hidden;
630
+ text-overflow: ellipsis;
631
+ }
632
+
633
+ .rte-comment-composer .rte-comment-selection .rte-comment-icon-btn {
634
+ width: 22px;
635
+ height: 22px;
636
+ }
637
+
638
+ .rte-comment-composer-hint {
639
+ margin: 0 0 8px;
640
+ font-size: 12px;
641
+ color: var(--rte-color-text-muted, #64748b);
642
+ }
643
+
644
+ .rte-comment-error {
645
+ margin: 8px 0 0;
646
+ font-size: 12px;
647
+ color: var(--rte-color-danger, #b91c1c);
648
+ }
649
+
650
+ /* ---- Empty state ---- */
651
+
652
+ .rte-comments-empty {
653
+ display: flex;
654
+ flex-direction: column;
655
+ align-items: center;
656
+ gap: 6px;
657
+ padding: 36px 16px;
658
+ text-align: center;
659
+ color: var(--rte-color-text-muted, #64748b);
660
+ }
661
+
662
+ .rte-comments-empty svg {
663
+ width: 32px;
664
+ height: 32px;
665
+ margin-bottom: 4px;
666
+ opacity: 0.6;
667
+ }
668
+
669
+ .rte-comments-empty strong {
670
+ font-size: 14px;
671
+ font-weight: 600;
672
+ color: var(--rte-color-text-primary, #0f172a);
673
+ }
674
+
675
+ .rte-comments-empty p {
676
+ margin: 0;
677
+ max-width: 240px;
678
+ font-size: 12px;
679
+ }
680
+
681
+ /* ---- "Comment deleted - Undo" ---- */
682
+
683
+ .rte-comments-toast {
684
+ position: absolute;
685
+ left: 12px;
686
+ right: 12px;
687
+ bottom: 12px;
688
+ display: flex;
689
+ align-items: center;
690
+ justify-content: space-between;
691
+ gap: 12px;
692
+ padding: 9px 12px;
693
+ border-radius: 8px;
694
+ background: #1f2937;
695
+ color: #ffffff;
696
+ font-size: 13px;
697
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
698
+ }
699
+
700
+ .rte-comments-toast[hidden] {
701
+ display: none;
702
+ }
703
+
704
+ .rte-comments-toast-action {
705
+ flex: none;
706
+ border: 0;
707
+ border-radius: 4px;
708
+ padding: 2px 6px;
709
+ background: transparent;
710
+ color: #93c5fd;
711
+ font: inherit;
712
+ font-weight: 600;
713
+ cursor: pointer;
714
+ }
715
+
716
+ .rte-comments-toast-action:hover {
717
+ text-decoration: underline;
718
+ }
719
+
720
+ /* ---- The button that appears over selected text ---- */
721
+
722
+ .rte-comments-bubble {
723
+ position: fixed;
724
+ z-index: 1000;
725
+ display: inline-flex;
726
+ align-items: center;
727
+ gap: 6px;
728
+ height: 32px;
729
+ padding: 0 12px 0 10px;
730
+ border: 0;
731
+ border-radius: 999px;
732
+ background: #1f2937;
733
+ color: #ffffff;
734
+ /* It lives on the page, outside the editor, so it must bring its own font: inheriting would show the host page's. */
735
+ font-family: var(--rte-font-family-base, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif);
736
+ font-size: 13px;
737
+ font-weight: 500;
738
+ line-height: 1;
739
+ cursor: pointer;
740
+ box-shadow: 0 4px 14px rgba(15, 23, 42, 0.3);
741
+ }
742
+
743
+ .rte-comments-bubble[hidden] {
744
+ display: none;
745
+ }
746
+
747
+ .rte-comments-bubble:hover {
748
+ background: #111827;
749
+ }
750
+
751
+ .rte-comments-bubble:focus-visible {
752
+ outline: 2px solid #93c5fd;
753
+ outline-offset: 2px;
754
+ }
755
+
756
+ .rte-comments-bubble svg {
757
+ width: 16px;
758
+ height: 16px;
759
+ }
760
+
761
+ /* ---- The highlighted text in the document ---- */
762
+
763
+ .rte-comment-anchor {
764
+ background: rgba(250, 204, 21, 0.34);
765
+ border-bottom: 2px solid rgba(217, 119, 6, 0.75);
766
+ border-radius: 2px;
767
+ cursor: pointer;
768
+ transition: outline-color 120ms ease, box-shadow 120ms ease;
769
+ }
770
+
771
+ .rte-comment-anchor.rte-comment-anchor-resolved {
772
+ background: rgba(148, 163, 184, 0.2);
773
+ border-bottom-color: rgba(100, 116, 139, 0.6);
774
+ }
775
+
776
+ :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-comments-panel {
777
+ box-shadow: -10px 0 28px rgba(0, 0, 0, 0.4);
778
+ }
779
+
780
+ @media (max-width: 900px) {
781
+ [data-rte-comments-open="true"],
782
+ .rte-comments-panel {
783
+ --rte-comments-panel-width: min(420px, 100%);
784
+ }
785
+
786
+ .rte-comments-panel {
787
+ box-shadow: -12px 0 28px rgba(15, 23, 42, 0.2);
788
+ }
789
+
790
+ [data-rte-comments-open="true"] :is(.rte-toolbar-wrapper, .rte-toolbar:not(.rte-toolbar-wrapper .rte-toolbar), .editora-toolbar, .rte-content, .editora-content, .editora-statusbar, .editora-statusbar-container) {
791
+ margin-right: 0;
792
+ }
793
+ }
794
+
795
+ /* A phone: the panel is a sheet that rises from the bottom, over the page, with the text still above it. */
796
+ @media (max-width: 640px) {
797
+ .rte-comments-panel {
798
+ --rte-comments-panel-width: 100%;
799
+ position: fixed;
800
+ top: auto;
801
+ left: 0;
802
+ right: 0;
803
+ bottom: 0;
804
+ width: 100%;
805
+ height: min(72vh, 560px);
806
+ border-left: 0;
807
+ border-top: 1px solid var(--rte-color-border, #d1d5db);
808
+ border-radius: 16px 16px 0 0;
809
+ box-shadow: 0 -12px 32px rgba(15, 23, 42, 0.22);
810
+ padding-bottom: env(safe-area-inset-bottom, 0px);
811
+ transform: translateY(100%);
812
+ z-index: 1000;
813
+ }
814
+
815
+ .rte-comments-panel.is-open {
816
+ transform: translateY(0);
817
+ }
818
+
819
+ /* The grip that says "this is a sheet". */
820
+ .rte-comments-header::before {
821
+ content: "";
822
+ position: absolute;
823
+ top: 6px;
824
+ left: 50%;
825
+ width: 36px;
826
+ height: 4px;
827
+ margin-left: -18px;
828
+ border-radius: 2px;
829
+ background: var(--rte-color-border, #d1d5db);
830
+ }
831
+
832
+ .rte-comments-header {
833
+ position: relative;
834
+ padding-top: 18px;
835
+ }
836
+
837
+ .rte-comment-icon-btn,
838
+ .rte-comments-close {
839
+ width: 36px;
840
+ height: 36px;
841
+ }
842
+
843
+ .rte-comments-new {
844
+ height: 36px;
845
+ }
846
+
847
+ .rte-comments-tab {
848
+ padding: 8px;
849
+ }
850
+
851
+ .rte-comment-menu-item {
852
+ padding: 10px;
853
+ }
854
+
855
+ .new-comment-textarea,
856
+ .rte-comment-reply-textarea,
857
+ .rte-comment-edit-textarea {
858
+ font-size: 16px; /* below 16px iOS zooms the page when a field is focused */
859
+ }
860
+ }
861
+
862
+ @media (prefers-reduced-motion: reduce) {
863
+ .rte-comments-panel,
864
+ .rte-comment-item,
865
+ .rte-comment-composer,
866
+ .rte-comment-anchor,
867
+ [data-rte-comments-open="true"] :is(.rte-toolbar-wrapper, .rte-toolbar, .editora-toolbar, .rte-content, .editora-content, .editora-statusbar, .editora-statusbar-container) {
868
+ transition: none;
869
+ }
870
+ }
871
+ `, ne = { name: "User" }, nt = /^[A-Za-z0-9_:.-]{1,200}$/;
872
+ function Y(e) {
873
+ return typeof e == "string" && nt.test(e);
874
+ }
875
+ function rt(e) {
876
+ if (typeof e != "string") return !1;
877
+ const t = e.trim();
878
+ return t ? /^data:image\/(png|jpe?g|gif|webp|avif);/i.test(t) ? t.length <= 3e5 : t.length > 2e3 ? !1 : /^(https?:)?\/\//i.test(t) ? !0 : !/^[a-z][a-z0-9+.-]*:/i.test(t) : !1;
879
+ }
6
880
  function S(e) {
7
- return H += 1, `${e}-${Date.now()}-${H}`;
881
+ if (typeof e == "string") {
882
+ const o = e.trim();
883
+ return o ? { name: o } : null;
884
+ }
885
+ if (!e || typeof e != "object") return null;
886
+ const t = e, n = typeof t.name == "string" ? t.name.trim() : "";
887
+ if (!n) return null;
888
+ const r = { name: n };
889
+ return t.id !== void 0 && t.id !== null && String(t.id) !== "" && (r.id = String(t.id)), rt(t.avatar) && (r.avatar = t.avatar.trim()), r;
890
+ }
891
+ function be(e, t) {
892
+ return typeof e != "string" || Number.isNaN(new Date(e).getTime()) ? t : e;
893
+ }
894
+ function ee(e) {
895
+ return typeof e == "string" && !Number.isNaN(new Date(e).getTime()) ? e : void 0;
896
+ }
897
+ function le(e, t = (/* @__PURE__ */ new Date()).toISOString()) {
898
+ if (!Array.isArray(e)) return [];
899
+ const n = /* @__PURE__ */ new Set(), r = [];
900
+ for (const o of e) {
901
+ if (!o || typeof o != "object") continue;
902
+ const i = o;
903
+ if (!Y(i.id) || n.has(i.id)) continue;
904
+ const a = typeof i.text == "string" ? i.text.trim() : "";
905
+ if (!a) continue;
906
+ n.add(i.id);
907
+ const d = {
908
+ id: i.id,
909
+ author: S(i.author) ?? ne,
910
+ text: a,
911
+ createdAt: be(i.createdAt, t),
912
+ resolved: i.resolved === !0,
913
+ replies: []
914
+ };
915
+ Y(i.anchorId) && (d.anchorId = i.anchorId), typeof i.quote == "string" && i.quote.trim() && (d.quote = i.quote.trim());
916
+ const l = ee(i.editedAt);
917
+ if (l && (d.editedAt = l), d.resolved) {
918
+ const c = ee(i.resolvedAt);
919
+ c && (d.resolvedAt = c);
920
+ const m = S(i.resolvedBy);
921
+ m && (d.resolvedBy = m);
922
+ }
923
+ if (Array.isArray(i.replies)) {
924
+ const c = /* @__PURE__ */ new Set();
925
+ i.replies.forEach((m, s) => {
926
+ if (!m || typeof m != "object") return;
927
+ const u = m, h = typeof u.text == "string" ? u.text.trim() : "";
928
+ if (!h) return;
929
+ let f = Y(u.id) ? u.id : `${i.id}-reply-${s + 1}`;
930
+ for (; c.has(f); ) f = `${f}-x`;
931
+ c.add(f);
932
+ const L = {
933
+ id: f,
934
+ author: S(u.author) ?? ne,
935
+ text: h,
936
+ createdAt: be(u.createdAt, t)
937
+ }, N = ee(u.editedAt);
938
+ N && (L.editedAt = N), d.replies.push(L);
939
+ });
940
+ }
941
+ r.push(d);
942
+ }
943
+ return r;
944
+ }
945
+ const v = /* @__PURE__ */ new WeakMap();
946
+ let E = null, xe = !1, ve = 0;
947
+ const ot = 2;
948
+ function q(e) {
949
+ return ve += 1, `${e}-${Date.now()}-${ve}`;
8
950
  }
9
- function g(e) {
951
+ function x(e) {
10
952
  if (!e) return null;
11
953
  const t = e instanceof Element ? e : e.parentElement;
12
954
  return t ? t.closest("[data-editora-editor]") || t.closest(".rte-editor") || t.closest(".editora-editor") : null;
13
955
  }
14
- function q(e) {
956
+ function it(e) {
15
957
  const t = e?.editorElement || e?.contentElement || null;
16
958
  if (!(t instanceof HTMLElement)) return;
17
- const r = t.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || (t.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") ? t : null);
18
- r && (h = r);
19
- }
20
- function k(e, t) {
21
- return t.contains(e.commonAncestorContainer);
959
+ const n = t.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || (t.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") ? t : null);
960
+ n && (E = n);
22
961
  }
23
- function P() {
962
+ function Re() {
24
963
  if (typeof window < "u") {
25
- const o = window.__editoraCommandEditorRoot;
26
- if (o instanceof HTMLElement) {
27
- const a = o.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || (o.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") ? o : null);
28
- if (a)
29
- return h = a, window.__editoraCommandEditorRoot = null, a;
964
+ const r = window.__editoraCommandEditorRoot;
965
+ if (r instanceof HTMLElement) {
966
+ const o = r.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || (r.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") ? r : null);
967
+ if (o)
968
+ return E = o, window.__editoraCommandEditorRoot = null, o;
30
969
  }
31
970
  }
32
- const e = document.activeElement, t = e ? g(e) : null;
971
+ const e = document.activeElement, t = e ? x(e) : null;
33
972
  if (t) return t;
34
- const r = window.getSelection();
35
- if (r && r.rangeCount > 0) {
36
- const o = g(
37
- r.getRangeAt(0).commonAncestorContainer
973
+ const n = window.getSelection();
974
+ if (n && n.rangeCount > 0) {
975
+ const r = x(
976
+ n.getRangeAt(0).commonAncestorContainer
38
977
  );
39
- if (o) return o;
978
+ if (r) return r;
40
979
  }
41
- return h;
980
+ return E;
42
981
  }
43
- function O(e) {
44
- const t = y.get(e);
45
- if (t) return t;
982
+ const y = [], at = 20;
983
+ let ce = null, re = null;
984
+ function De(e) {
985
+ const t = S(e.options.currentUser);
986
+ t && (ce = t, re = e);
987
+ }
988
+ function lt(e) {
989
+ y.push(e), y.length > at && y.shift(), De(e);
990
+ }
991
+ function $(e) {
992
+ return S(e.instance?.options.currentUser) ?? ce ?? ne;
993
+ }
994
+ function ye(e, t) {
995
+ const n = $(e), r = e.instance?.options.canModify;
996
+ if (r)
997
+ try {
998
+ return !!r(t, n);
999
+ } catch {
1000
+ return !1;
1001
+ }
1002
+ return n.id && t.id ? n.id === t.id : !0;
1003
+ }
1004
+ function $e(e) {
1005
+ return {
1006
+ id: e.id,
1007
+ anchorId: e.anchorId ?? "",
1008
+ selectedText: e.quote ?? "",
1009
+ author: e.author,
1010
+ text: e.text,
1011
+ createdAt: e.createdAt,
1012
+ editedAt: e.editedAt,
1013
+ resolved: e.resolved,
1014
+ resolvedAt: e.resolvedAt,
1015
+ resolvedBy: e.resolvedBy,
1016
+ replies: e.replies.map((t) => ({ ...t })),
1017
+ aligned: !1
1018
+ };
1019
+ }
1020
+ function ct(e) {
1021
+ const t = {
1022
+ id: e.id,
1023
+ author: { ...e.author },
1024
+ text: e.text,
1025
+ createdAt: e.createdAt,
1026
+ resolved: e.resolved,
1027
+ replies: e.replies.map((n) => {
1028
+ const r = { id: n.id, author: { ...n.author }, text: n.text, createdAt: n.createdAt };
1029
+ return n.editedAt && (r.editedAt = n.editedAt), r;
1030
+ })
1031
+ };
1032
+ return e.anchorId && (t.anchorId = e.anchorId), e.selectedText && (t.quote = e.selectedText), e.editedAt && (t.editedAt = e.editedAt), e.resolved && e.resolvedAt && (t.resolvedAt = e.resolvedAt), e.resolved && e.resolvedBy && (t.resolvedBy = { ...e.resolvedBy }), t;
1033
+ }
1034
+ function Oe(e) {
1035
+ return H(e), Array.from(e.comments.values()).filter((t) => !t.deleted).map(ct);
1036
+ }
1037
+ function dt(e) {
1038
+ if (!e.storageKey) return null;
1039
+ try {
1040
+ const t = window.localStorage.getItem(e.storageKey);
1041
+ return t === null ? null : le(JSON.parse(t));
1042
+ } catch {
1043
+ return null;
1044
+ }
1045
+ }
1046
+ let we = !1;
1047
+ function st(e, t) {
1048
+ if (e.storageKey)
1049
+ try {
1050
+ window.localStorage.setItem(e.storageKey, JSON.stringify(t));
1051
+ } catch (n) {
1052
+ we || (we = !0, console.warn("[comments] the comments could not be saved to localStorage", n));
1053
+ }
1054
+ }
1055
+ function g(e, t, n) {
1056
+ const r = Oe(e), o = n ? { reason: t, threadId: n } : { reason: t };
1057
+ try {
1058
+ e.root.dispatchEvent(new CustomEvent("editora:comments-change", { bubbles: !0, detail: { threads: r, ...o } }));
1059
+ } catch (i) {
1060
+ console.error("[comments] a change listener threw", i);
1061
+ }
1062
+ e.instance && st(e.instance.options, r);
1063
+ try {
1064
+ e.instance?.options.onChange?.(r, o);
1065
+ } catch (i) {
1066
+ console.error("[comments] onChange threw", i);
1067
+ }
1068
+ }
1069
+ function ze(e, t) {
1070
+ e.comments.clear(), le(t).forEach((n) => e.comments.set(n.id, $e(n))), e.expandedReplies.clear(), e.replyTexts = {}, e.editing = null, e.editDraft = "", e.hoverId = null, e.activeId = null, R(e), V(e), Z(e), p(e);
1071
+ }
1072
+ function mt(e, t) {
1073
+ const [n] = le([t]);
1074
+ if (!n) return !1;
1075
+ if (e.editing && e.editing.commentId === n.id && e.editing.replyId) {
1076
+ const r = e.editing.replyId;
1077
+ n.replies.some((o) => o.id === r) || (e.editing = null, e.editDraft = "");
1078
+ }
1079
+ return e.comments.set(n.id, $e(n)), Z(e), p(e), !0;
1080
+ }
1081
+ function ut(e, t) {
1082
+ return e.comments.has(t) ? (e.comments.delete(t), e.expandedReplies.delete(t), delete e.replyTexts[t], e.editing?.commentId === t && (e.editing = null, e.editDraft = ""), e.hoverId === t && (e.hoverId = null), e.activeId === t && k(e, null), e.closeMenu?.(!1), V(e), Z(e), p(e), !0) : !1;
1083
+ }
1084
+ function G(e, t, n) {
1085
+ if (e.instance === t) {
1086
+ n || (e.instanceAssumed = !1);
1087
+ return;
1088
+ }
1089
+ e.instanceAssumed && e.instance && (e.instance?.options.initialThreads || e.instance?.options.storageKey) && e.comments.clear(), e.instance = t, e.instanceAssumed = n;
1090
+ const o = y.indexOf(t);
1091
+ if (o !== -1 && y.splice(o, 1), !t.initialApplied) {
1092
+ t.initialApplied = !0;
1093
+ const i = dt(t.options) ?? t.options.initialThreads;
1094
+ i && ze(e, i);
1095
+ }
1096
+ }
1097
+ function C(e, t) {
1098
+ const n = v.get(e);
1099
+ if (n)
1100
+ return t && n.instance !== t && (n.instanceAssumed || !n.instance) && G(n, t, !1), n;
46
1101
  const r = {
47
1102
  root: e,
1103
+ instance: null,
1104
+ instanceAssumed: !1,
1105
+ orphanIds: [],
1106
+ renderedKey: "",
1107
+ watchedContent: null,
1108
+ contentObserver: null,
1109
+ syncTimer: null,
1110
+ uid: q("rte-comments"),
48
1111
  comments: /* @__PURE__ */ new Map(),
49
1112
  panelVisible: !1,
50
1113
  panelElement: null,
51
- expandedComments: /* @__PURE__ */ new Set(),
1114
+ filter: "open",
1115
+ composer: null,
1116
+ activeId: null,
1117
+ hoverId: null,
1118
+ editing: null,
1119
+ editDraft: "",
1120
+ undoEntry: null,
1121
+ undoTimer: null,
1122
+ expandedReplies: /* @__PURE__ */ new Set(),
52
1123
  replyTexts: {},
53
1124
  savedSelection: null,
54
1125
  newCommentText: "",
55
- selectionChangeListener: null
1126
+ closeMenu: null,
1127
+ timeTimer: null
56
1128
  };
57
- return y.set(e, r), r;
1129
+ v.set(e, r);
1130
+ const o = t ?? y[0] ?? null;
1131
+ return o && G(r, o, !t), se(r), de(r), r;
1132
+ }
1133
+ function de(e) {
1134
+ e.syncTimer === null && (e.syncTimer = window.setTimeout(() => Z(e), 150));
1135
+ }
1136
+ function se(e) {
1137
+ const t = P(e.root);
1138
+ t !== e.watchedContent && (e.contentObserver?.disconnect(), e.watchedContent = t, e.contentObserver = null, !(!t || typeof MutationObserver > "u") && (e.contentObserver = new MutationObserver(() => de(e)), e.contentObserver.observe(t, { childList: !0, subtree: !0, attributes: !0, attributeFilter: ["class", "id"] })));
58
1139
  }
59
- function u() {
60
- const e = P();
61
- return e ? (h = e, O(e)) : null;
1140
+ const Ee = "rte-comments-orphans", F = /* @__PURE__ */ new Set();
1141
+ function pt(e) {
1142
+ const t = P(e.root), n = /* @__PURE__ */ new Set();
1143
+ e.comments.forEach((i) => i.anchorId && n.add(i.anchorId)), e.orphanIds = t ? Array.from(t.querySelectorAll(".rte-comment-anchor")).filter((i) => !n.has(i.id) && Y(i.id)).map((i) => i.id) : [], e.orphanIds.length ? F.add(e) : F.delete(e);
1144
+ const r = [];
1145
+ F.forEach((i) => {
1146
+ if (!i.root.isConnected) {
1147
+ F.delete(i);
1148
+ return;
1149
+ }
1150
+ i.orphanIds.forEach((a) => r.push(`.rte-comment-anchor[id="${a}"]`));
1151
+ });
1152
+ let o = document.getElementById(Ee);
1153
+ if (r.length === 0) {
1154
+ o?.remove();
1155
+ return;
1156
+ }
1157
+ o || (o = document.createElement("style"), o.id = Ee, document.head.appendChild(o)), o.textContent = `${r.join(`,
1158
+ `)} { background: none; border-bottom: 0; cursor: inherit; }`;
62
1159
  }
63
- function V(e) {
1160
+ function Z(e) {
1161
+ if (e.syncTimer !== null && (window.clearTimeout(e.syncTimer), e.syncTimer = null), !e.root.isConnected) return;
1162
+ se(e);
1163
+ const t = /* @__PURE__ */ new Map();
1164
+ e.comments.forEach((r) => t.set(r.id, `${r.resolved}|${!!r.deleted}`)), H(e);
1165
+ let n;
1166
+ e.comments.forEach((r) => {
1167
+ t.has(r.id) && t.get(r.id) !== `${r.resolved}|${!!r.deleted}` && (n = r.id);
1168
+ }), pt(e), e.panelVisible && je(H(e)) !== e.renderedKey && p(e), n && g(e, "document", n);
1169
+ }
1170
+ function X() {
1171
+ const e = Re();
1172
+ return e ? (E = e, C(e)) : null;
1173
+ }
1174
+ function P(e) {
1175
+ return e.querySelector(".rte-content") || e.querySelector("[contenteditable]");
1176
+ }
1177
+ function J(e, t) {
1178
+ const n = P(t);
1179
+ return !!n && n.contains(e.commonAncestorContainer);
1180
+ }
1181
+ function ft(e) {
64
1182
  const t = window.getSelection();
65
1183
  if (!t || t.rangeCount === 0 || t.isCollapsed) return null;
66
- const r = t.getRangeAt(0);
67
- return k(r, e) ? r.cloneRange() : null;
1184
+ const n = t.getRangeAt(0);
1185
+ return J(n, e) ? n.cloneRange() : null;
68
1186
  }
69
- function F(e) {
70
- return e.root.querySelector(".rte-content") || e.root.querySelector("[contenteditable]");
71
- }
72
- function C(e, t) {
1187
+ function D(e, t) {
73
1188
  return t.anchorId ? e.root.querySelector(`[id="${t.anchorId}"]`) : null;
74
1189
  }
75
- function _(e) {
1190
+ function H(e) {
76
1191
  const t = [];
77
- return e.comments.forEach((r) => {
78
- if (r.anchorId) {
79
- const o = C(e, r);
80
- if (!o) return;
81
- r.resolved = o.classList.contains("rte-comment-anchor-resolved");
82
- }
83
- t.push(r);
1192
+ return e.comments.forEach((n) => {
1193
+ if (n.anchorId) {
1194
+ const r = D(e, n);
1195
+ if (!r) return;
1196
+ n.deleted = !1, n.aligned === !1 ? (r.classList.toggle("rte-comment-anchor-resolved", n.resolved), n.aligned = !0) : n.resolved = r.classList.contains("rte-comment-anchor-resolved");
1197
+ } else if (n.deleted)
1198
+ return;
1199
+ t.push(n);
84
1200
  }), t;
85
1201
  }
86
- function A(e, t) {
87
- const r = F(e), o = r ? r.innerHTML : "", a = t();
88
- return r && r.innerHTML !== o && ($(r, o), r.dispatchEvent(new Event("input", { bubbles: !0 }))), a;
1202
+ function B(e, t) {
1203
+ const n = P(e.root), r = n ? n.innerHTML : "", o = t();
1204
+ return n && n.innerHTML !== r && (Je(n, r), n.dispatchEvent(new Event("input", { bubbles: !0 }))), o;
89
1205
  }
90
- function I(e, t) {
91
- const r = C(e, t);
92
- r && r.classList.toggle("rte-comment-anchor-resolved", t.resolved);
1206
+ function qe(e, t) {
1207
+ const n = D(e, t);
1208
+ n && n.classList.toggle("rte-comment-anchor-resolved", t.resolved);
93
1209
  }
94
- function E(e, t, r) {
95
- const o = e.comments.get(t);
96
- if (!o) return;
97
- const a = C(e, o);
98
- a && a.classList.toggle("highlighted", r);
1210
+ const z = /* @__PURE__ */ new Set(), Ce = "rte-comments-emphasis";
1211
+ function V(e) {
1212
+ e.activeId || e.hoverId ? z.add(e) : z.delete(e), z.forEach((o) => {
1213
+ o.root.isConnected || z.delete(o);
1214
+ });
1215
+ const t = [], n = (o, i) => {
1216
+ const a = i ? o.comments.get(i) : null;
1217
+ return a?.anchorId ? a.anchorId.replace(/["\\]/g, "") : "";
1218
+ };
1219
+ z.forEach((o) => {
1220
+ const i = n(o, o.hoverId), a = n(o, o.activeId);
1221
+ i && t.push(`.rte-comment-anchor[id="${i}"] { outline: 2px solid color-mix(in srgb, var(--rte-color-primary, #2563eb) 55%, transparent); outline-offset: 2px; }`), a && t.push(`.rte-comment-anchor[id="${a}"] { outline: 2px solid var(--rte-color-primary, #2563eb); outline-offset: 2px; background: rgba(250, 204, 21, 0.55); }`);
1222
+ });
1223
+ let r = document.getElementById(Ce);
1224
+ if (t.length === 0) {
1225
+ r?.remove();
1226
+ return;
1227
+ }
1228
+ r || (r = document.createElement("style"), r.id = Ce, document.head.appendChild(r)), r.textContent = t.join(`
1229
+ `);
99
1230
  }
100
- function j(e) {
1231
+ function M(e, t, n) {
1232
+ n ? e.hoverId = t : e.hoverId === t && (e.hoverId = null), V(e);
1233
+ }
1234
+ function k(e, t) {
1235
+ e.activeId = t, e.panelElement?.querySelectorAll(".rte-comment-item").forEach((n) => {
1236
+ n.classList.toggle("is-active", n.dataset.commentId === t);
1237
+ }), V(e);
1238
+ }
1239
+ function ht(e) {
101
1240
  const t = e.parentNode;
102
1241
  if (t) {
103
1242
  for (; e.firstChild; )
@@ -105,632 +1244,737 @@ function j(e) {
105
1244
  e.remove();
106
1245
  }
107
1246
  }
108
- function w(e, t) {
1247
+ function He(e) {
1248
+ e.root.querySelector('[contenteditable="true"]')?.focus({ preventScroll: !0 });
1249
+ }
1250
+ function Q(e, t) {
109
1251
  if (e.panelVisible = t, t) {
110
- re(), Z(e), e.root.setAttribute("data-rte-comments-open", "true"), e.panelElement && (e.panelElement.classList.add("is-open"), e.panelElement.setAttribute("aria-hidden", "false")), K(e), M(e.panelElement);
1252
+ Ye(), bt(e), e.root.setAttribute("data-rte-comments-open", "true"), e.panelElement && (e.panelElement.classList.add("is-open"), e.panelElement.setAttribute("aria-hidden", "false")), p(e), wt(e), Ge(e.panelElement);
111
1253
  return;
112
1254
  }
113
- if (e.root.removeAttribute("data-rte-comments-open"), U(e), e.panelElement) {
114
- const r = N(e.panelElement);
115
- e.panelElement.remove(), e.panelElement = null, r && e.root.querySelector('[contenteditable="true"]')?.focus({ preventScroll: !0 });
1255
+ if (e.root.removeAttribute("data-rte-comments-open"), Et(e), e.closeMenu?.(!1), e.editing = null, e.editDraft = "", R(e), e.hoverId = null, k(e, null), e.panelElement) {
1256
+ const n = Ze(e.panelElement);
1257
+ e.panelElement.remove(), e.panelElement = null, n && He(e);
116
1258
  }
117
1259
  }
118
- function Z(e) {
119
- if (e.panelElement) return;
120
- const t = document.createElement("aside");
121
- t.className = "rte-comments-panel", t.setAttribute("role", "complementary"), t.setAttribute("aria-label", "Comments"), t.setAttribute("aria-hidden", "true"), window.getComputedStyle(e.root).position === "static" && (e.root.style.position = "relative"), e.root.appendChild(t), e.panelElement = t;
1260
+ function Be(e) {
1261
+ Q(e, !1), (!e.root.contains(document.activeElement) || document.activeElement === document.body) && He(e);
122
1262
  }
123
- function K(e) {
124
- e.selectionChangeListener || (e.selectionChangeListener = () => {
125
- const t = window.getSelection();
126
- if (!t || t.rangeCount === 0 || t.isCollapsed) return;
127
- const r = t.getRangeAt(0);
128
- k(r, e.root) && (e.savedSelection = r.cloneRange(), h = e.root);
129
- }, document.addEventListener("selectionchange", e.selectionChangeListener));
130
- }
131
- function U(e) {
132
- e.selectionChangeListener && (document.removeEventListener("selectionchange", e.selectionChangeListener), e.selectionChangeListener = null);
133
- }
134
- function W(e) {
135
- return _(e).sort((t, r) => r.createdAt.localeCompare(t.createdAt));
136
- }
137
- function B(e) {
138
- return new Date(e).toLocaleString();
139
- }
140
- function X(e, t) {
141
- const r = e.expandedComments.has(t.id), o = document.createElement("article");
142
- o.className = `rte-comment-item${t.resolved ? " resolved" : ""}`, o.innerHTML = `
143
- <header class="rte-comment-header">
144
- <div class="rte-comment-meta">
145
- <strong class="rte-comment-author"></strong>
146
- <time class="rte-comment-date">${B(t.createdAt)}</time>
147
- </div>
148
- <button class="rte-comment-expand" type="button" aria-label="Toggle details">
149
- ${r ? "▾" : "▸"}
150
- </button>
151
- </header>
152
- <div class="rte-comment-text"></div>
153
- ${t.selectedText ? '<blockquote class="rte-comment-selection"></blockquote>' : ""}
154
- <section class="rte-comment-expanded${r ? " show" : ""}"></section>
155
- `;
156
- const a = o.querySelector(".rte-comment-author");
157
- a && (a.textContent = t.author);
158
- const c = o.querySelector(".rte-comment-text");
159
- c && (c.textContent = t.text);
160
- const p = o.querySelector(".rte-comment-selection");
161
- p && (p.textContent = t.selectedText), o.querySelector(".rte-comment-expand")?.addEventListener("click", () => {
162
- e.expandedComments.has(t.id) ? e.expandedComments.delete(t.id) : e.expandedComments.add(t.id), s(e);
163
- });
164
- const d = o.querySelector(".rte-comment-expanded");
165
- if (d && r) {
166
- if (t.replies.length > 0) {
167
- const n = document.createElement("div");
168
- n.className = "rte-comment-replies", t.replies.forEach((l) => {
169
- const m = document.createElement("div");
170
- m.className = "rte-comment-reply", m.innerHTML = `
171
- <div class="rte-comment-reply-header">
172
- <strong class="rte-comment-reply-author"></strong>
173
- <time>${B(l.createdAt)}</time>
174
- </div>
175
- <div class="rte-comment-reply-text"></div>
176
- `;
177
- const v = m.querySelector(".rte-comment-reply-author");
178
- v && (v.textContent = l.author);
179
- const b = m.querySelector(".rte-comment-reply-text");
180
- b && (b.textContent = l.text), n.appendChild(m);
181
- }), d.appendChild(n);
182
- }
183
- if (!t.resolved) {
184
- const n = document.createElement("div");
185
- n.className = "rte-comment-reply-composer", n.innerHTML = `
186
- <textarea class="rte-comment-reply-textarea" rows="2" placeholder="Reply..."></textarea>
187
- <button type="button" class="rte-comment-btn primary">Reply</button>
188
- `;
189
- const l = n.querySelector(
190
- ".rte-comment-reply-textarea"
191
- ), m = n.querySelector(
192
- ".rte-comment-btn.primary"
193
- );
194
- if (l && m) {
195
- l.value = e.replyTexts[t.id] || "";
196
- const v = () => {
197
- const b = !!l.value.trim();
198
- m.disabled = !b;
199
- };
200
- v(), l.addEventListener("input", () => {
201
- e.replyTexts[t.id] = l.value, v();
202
- }), m.addEventListener("click", () => {
203
- const b = l.value.trim();
204
- b && (te(t.id, T, b), e.replyTexts[t.id] = "", s(e));
205
- });
206
- }
207
- d.appendChild(n);
208
- }
209
- const i = document.createElement("div");
210
- if (i.className = "rte-comment-actions", t.anchorId) {
211
- const n = document.createElement("button");
212
- n.type = "button", n.className = "rte-comment-btn ghost", n.textContent = "Jump to text", n.onclick = () => {
213
- const l = C(e, t);
214
- l && (l.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest" }), E(e, t.id, !0), window.setTimeout(() => E(e, t.id, !1), 1200));
215
- }, i.appendChild(n);
216
- }
217
- if (t.resolved) {
218
- const n = document.createElement("button");
219
- n.type = "button", n.className = "rte-comment-btn ghost", n.textContent = "Reopen", n.onclick = () => Y(t.id), i.appendChild(n);
220
- } else {
221
- const n = document.createElement("button");
222
- n.type = "button", n.className = "rte-comment-btn success", n.textContent = "Resolve", n.onclick = () => Q(t.id, T), i.appendChild(n);
223
- }
224
- const x = document.createElement("button");
225
- x.type = "button", x.className = "rte-comment-btn danger", x.textContent = "Delete", x.onclick = () => ee(t.id), i.appendChild(x), d.appendChild(i);
226
- }
227
- return o.addEventListener("mouseenter", () => E(e, t.id, !0)), o.addEventListener("mouseleave", () => E(e, t.id, !1)), o;
1263
+ const gt = {
1264
+ check: '<path d="M3.5 8.5l3 3 6-7"/>',
1265
+ reopen: '<path d="M3 8a5 5 0 1 0 1.6-3.7M3 2.8v3.2h3.2"/>',
1266
+ more: '<circle cx="8" cy="3.5" r="1.1" fill="currentColor" stroke="none"/><circle cx="8" cy="8" r="1.1" fill="currentColor" stroke="none"/><circle cx="8" cy="12.5" r="1.1" fill="currentColor" stroke="none"/>',
1267
+ plus: '<path d="M8 3v10M3 8h10"/>',
1268
+ close: '<path d="M4 4l8 8M12 4l-8 8"/>',
1269
+ addComment: '<path d="M2.5 3.5h11v7.5H8.5l-3 2.5V11h-3zM8 5.2v3.6M6.2 7h3.6"/>',
1270
+ edit: '<path d="M10.5 3.5l2 2-7 7-2.8.8.8-2.8z"/>',
1271
+ trash: '<path d="M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.5 8.5h6l.5-8.5M7 7v4M9 7v4"/>',
1272
+ bubble: '<path d="M2.5 3.5h11v7.5H8.5l-3 2.5V11h-3z"/>'
1273
+ };
1274
+ function I(e) {
1275
+ return `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${gt[e]}</svg>`;
1276
+ }
1277
+ function b(e, t, n) {
1278
+ const r = document.createElement("button");
1279
+ return r.type = "button", r.className = e, n ? (r.innerHTML = I(n), r.setAttribute("aria-label", t), r.title = t) : r.textContent = t, r;
228
1280
  }
229
- function s(e) {
230
- const t = e || u();
231
- if (!t?.panelElement) return;
232
- const r = W(t), o = t.panelElement;
233
- D(o, () => {
234
- o.innerHTML = `
1281
+ function bt(e) {
1282
+ if (e.panelElement) return;
1283
+ const t = document.createElement("aside");
1284
+ t.className = "rte-comments-panel", t.setAttribute("role", "complementary"), t.setAttribute("aria-label", "Comments"), t.setAttribute("aria-hidden", "true");
1285
+ const n = [
1286
+ ["open", "Open"],
1287
+ ["resolved", "Resolved"],
1288
+ ["all", "All"]
1289
+ ];
1290
+ t.innerHTML = `
235
1291
  <div class="rte-comments-header">
236
- <div>
237
- <h3>Comments (${r.length})</h3>
238
- <p>Select text and add comments, or add a general note.</p>
1292
+ <div class="rte-comments-title">
1293
+ <h3>Comments</h3>
1294
+ <span class="rte-comments-count" aria-hidden="true"></span>
239
1295
  </div>
240
- <button class="rte-comments-close" type="button" aria-label="Close comments panel">✕</button>
241
- </div>
242
- <div class="rte-comments-composer">
243
- <textarea class="new-comment-textarea" rows="3" placeholder="Add a comment..."></textarea>
244
- <div class="rte-comments-composer-actions">
245
- <button class="rte-comment-btn primary add-comment-btn" type="button">Add Comment</button>
1296
+ <div class="rte-comments-header-actions">
1297
+ <button class="rte-comments-new" type="button" aria-label="New comment">${I("plus")}<span>New</span></button>
1298
+ <button class="rte-comments-close" type="button" aria-label="Close comments panel" title="Close">${I("close")}</button>
246
1299
  </div>
247
1300
  </div>
248
- ${r.length === 0 ? '<div class="rte-comments-empty">No comments yet.</div>' : '<div class="rte-comments-list"></div>'}
249
- `;
250
- }), t.panelElement.querySelector(".rte-comments-close")?.addEventListener("click", () => {
251
- w(t, !1), (!t.root.contains(document.activeElement) || document.activeElement === document.body) && t.root.querySelector('[contenteditable="true"]')?.focus({ preventScroll: !0 });
1301
+ <div class="rte-comments-tabs" role="tablist" aria-label="Show comments">
1302
+ ${n.map(
1303
+ ([a, d]) => `<button class="rte-comments-tab" type="button" role="tab" id="${e.uid}-tab-${a}" data-filter="${a}" aria-controls="${e.uid}-body"><span>${d}</span><span class="rte-comments-tab-count"></span></button>`
1304
+ ).join("")}
1305
+ </div>
1306
+ <div class="rte-comments-body" id="${e.uid}-body" role="tabpanel"></div>
1307
+ <div class="rte-comments-toast" role="status" aria-live="polite" hidden></div>
1308
+ `, t.querySelector(".rte-comments-close")?.addEventListener("click", () => Be(e)), t.querySelector(".rte-comments-new")?.addEventListener("click", () => {
1309
+ Fe(e, e.savedSelection ? e.savedSelection.cloneRange() : null);
252
1310
  });
253
- const c = t.panelElement.querySelector(
254
- ".new-comment-textarea"
255
- ), p = t.panelElement.querySelector(
256
- ".add-comment-btn"
257
- );
258
- if (c && p) {
259
- c.value = t.newCommentText;
260
- const d = () => {
261
- const i = !!c.value.trim();
262
- p.disabled = !i;
263
- };
264
- d(), c.addEventListener("input", () => {
265
- t.newCommentText = c.value, d();
266
- }), c.addEventListener("keydown", (i) => {
267
- (i.ctrlKey || i.metaKey) && i.key === "Enter" && (i.preventDefault(), p.click());
268
- }), p.addEventListener("click", () => {
269
- const i = c.value.trim();
270
- if (!i) return;
271
- const x = !!t.savedSelection;
272
- J(T, i, !x), t.newCommentText = "", s(t);
1311
+ const r = t.querySelector(".rte-comments-tabs"), o = Array.from(r.querySelectorAll(".rte-comments-tab"));
1312
+ o.forEach((a) => {
1313
+ a.addEventListener("click", () => {
1314
+ e.filter = a.dataset.filter, p(e);
273
1315
  });
1316
+ }), r.addEventListener("keydown", (a) => {
1317
+ if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(a.key)) return;
1318
+ const l = o.findIndex((m) => m === document.activeElement);
1319
+ if (l === -1) return;
1320
+ a.preventDefault();
1321
+ let c = l;
1322
+ a.key === "ArrowRight" && (c = (l + 1) % o.length), a.key === "ArrowLeft" && (c = (l - 1 + o.length) % o.length), a.key === "Home" && (c = 0), a.key === "End" && (c = o.length - 1), e.filter = o[c].dataset.filter, p(e), o[c].focus();
1323
+ }), window.getComputedStyle(e.root).position === "static" && (e.root.style.position = "relative"), e.root.appendChild(t), e.panelElement = t;
1324
+ }
1325
+ function xt(e) {
1326
+ const t = H(e), n = t.filter((o) => o.anchorId).map((o) => ({ comment: o, anchor: D(e, o) }));
1327
+ n.sort((o, i) => o.anchor === i.anchor ? 0 : o.anchor.compareDocumentPosition(i.anchor) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
1328
+ const r = t.filter((o) => !o.anchorId).sort((o, i) => o.createdAt.localeCompare(i.createdAt));
1329
+ return [...n.map((o) => o.comment), ...r];
1330
+ }
1331
+ function Ae(e, t = !1) {
1332
+ const n = document.createElement("span");
1333
+ if (n.className = `rte-comment-avatar${t ? " small" : ""}`, n.setAttribute("aria-hidden", "true"), n.style.background = et(e.id || e.name), n.textContent = Qe(e.name), e.avatar) {
1334
+ const r = document.createElement("img");
1335
+ r.alt = "", r.loading = "lazy", r.decoding = "async", r.referrerPolicy = "no-referrer", r.addEventListener("error", () => r.remove()), r.src = e.avatar, n.appendChild(r);
274
1336
  }
275
- const f = t.panelElement.querySelector(".rte-comments-list");
276
- f && r.forEach((d) => {
277
- f.appendChild(X(t, d));
1337
+ return n;
1338
+ }
1339
+ function vt(e) {
1340
+ const t = document.createElement("time");
1341
+ return t.className = "rte-comment-date", t.dateTime = e, t.dataset.created = e, t.title = Me(e), t.textContent = ae(e), t;
1342
+ }
1343
+ function yt(e) {
1344
+ e.panelElement?.querySelectorAll("time[data-created]").forEach((t) => {
1345
+ t.textContent = ae(t.dataset.created || "");
1346
+ });
1347
+ }
1348
+ function wt(e) {
1349
+ e.timeTimer === null && (e.timeTimer = window.setInterval(() => yt(e), 6e4));
1350
+ }
1351
+ function Et(e) {
1352
+ e.timeTimer !== null && (window.clearInterval(e.timeTimer), e.timeTimer = null);
1353
+ }
1354
+ function me(e) {
1355
+ if (e.style.height = "auto", !e.scrollHeight) return;
1356
+ const t = e.offsetHeight - e.clientHeight;
1357
+ e.style.height = `${Math.min(e.scrollHeight + t, 160)}px`;
1358
+ }
1359
+ function Ue() {
1360
+ return !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
1361
+ }
1362
+ function Se(e, t, n = !0) {
1363
+ const r = D(e, t);
1364
+ if (!r) return;
1365
+ const o = !!e.panelElement && window.getComputedStyle(e.panelElement).position === "fixed";
1366
+ if (r.scrollIntoView({ behavior: o || Ue() ? "auto" : "smooth", block: "center", inline: "nearest" }), o && e.panelElement) {
1367
+ const i = e.panelElement.getBoundingClientRect().top, a = r.getBoundingClientRect().bottom;
1368
+ a > i - 16 && window.scrollBy(0, a - i + 32);
1369
+ }
1370
+ n && (M(e, t.id, !0), window.setTimeout(() => M(e, t.id, !1), 1200));
1371
+ }
1372
+ function Pe(e, t) {
1373
+ const n = e.comments.get(t);
1374
+ if (!n) return;
1375
+ e.filter !== "all" && (e.filter = n.resolved ? "resolved" : "open"), k(e, t), p(e), Array.from(e.panelElement?.querySelectorAll(".rte-comment-item") ?? []).find(
1376
+ (o) => o.dataset.commentId === t
1377
+ )?.scrollIntoView({ behavior: Ue() ? "auto" : "smooth", block: "nearest" });
1378
+ }
1379
+ function Te(e, t, n, r) {
1380
+ const o = document.createElement("div");
1381
+ o.className = "rte-comment-more";
1382
+ const i = b("rte-comment-icon-btn", r, "more");
1383
+ i.setAttribute("aria-haspopup", "menu"), i.setAttribute("aria-expanded", "false"), i.dataset.action = "more", i.dataset.commentId = n.commentId, n.replyId && (i.dataset.id = n.replyId);
1384
+ const a = document.createElement("div");
1385
+ a.className = "rte-comment-menu", a.setAttribute("role", "menu"), a.setAttribute("aria-label", r), a.hidden = !0, t.forEach((s) => {
1386
+ const u = document.createElement("button");
1387
+ u.type = "button", u.className = `rte-comment-menu-item${s.danger ? " danger" : ""}`, u.setAttribute("role", "menuitem"), u.dataset.action = s.label.toLowerCase(), u.innerHTML = I(s.icon);
1388
+ const h = document.createElement("span");
1389
+ h.textContent = s.label, u.appendChild(h), u.addEventListener("click", () => {
1390
+ e.closeMenu?.(!1), s.run();
1391
+ }), a.appendChild(u);
278
1392
  });
1393
+ const d = () => Array.from(a.querySelectorAll('[role="menuitem"]')), l = (s) => {
1394
+ a.hidden || (a.hidden = !0, i.setAttribute("aria-expanded", "false"), document.removeEventListener("pointerdown", c, !0), document.removeEventListener("focusin", c, !0), e.closeMenu === l && (e.closeMenu = null), s && i.isConnected && i.focus({ preventScroll: !0 }));
1395
+ };
1396
+ function c(s) {
1397
+ s.target instanceof Node && o.contains(s.target) || l(!1);
1398
+ }
1399
+ const m = () => {
1400
+ e.closeMenu?.(!1), a.hidden = !1, i.setAttribute("aria-expanded", "true"), e.closeMenu = l, document.addEventListener("pointerdown", c, !0), document.addEventListener("focusin", c, !0), d()[0]?.focus({ preventScroll: !0 });
1401
+ };
1402
+ return i.addEventListener("click", () => a.hidden ? m() : l(!0)), i.addEventListener("keydown", (s) => {
1403
+ s.key === "ArrowDown" && a.hidden && (s.preventDefault(), m());
1404
+ }), a.addEventListener("keydown", (s) => {
1405
+ const u = d(), h = u.indexOf(document.activeElement);
1406
+ let f = -1;
1407
+ s.key === "ArrowDown" ? f = (h + 1) % u.length : s.key === "ArrowUp" ? f = (h - 1 + u.length) % u.length : s.key === "Home" ? f = 0 : s.key === "End" ? f = u.length - 1 : s.key === "Tab" && l(!1), f !== -1 && (s.preventDefault(), u[f].focus({ preventScroll: !0 }));
1408
+ }), o.append(i, a), o;
1409
+ }
1410
+ function ke(e, t) {
1411
+ const n = document.createElement("div");
1412
+ if (n.className = "rte-comment-when", n.appendChild(vt(e)), t) {
1413
+ const r = document.createElement("span");
1414
+ r.className = "rte-comment-edited", r.textContent = "· edited", r.title = `Edited ${Me(t)}`, n.appendChild(r);
1415
+ }
1416
+ return n;
1417
+ }
1418
+ function Ie(e, t) {
1419
+ const n = document.createElement("form");
1420
+ n.className = "rte-comment-edit", n.noValidate = !0;
1421
+ const r = document.createElement("textarea");
1422
+ r.className = "rte-comment-edit-textarea", r.rows = 2, r.setAttribute("aria-label", t.replyId ? "Edit reply" : "Edit comment"), r.dataset.commentId = t.commentId, t.replyId && (r.dataset.id = t.replyId), r.value = e.editDraft;
1423
+ const o = document.createElement("div");
1424
+ o.className = "rte-comment-form-actions";
1425
+ const i = b("rte-comment-btn ghost", "Cancel"), a = b("rte-comment-btn primary", "Save");
1426
+ a.type = "submit", o.append(i, a);
1427
+ const d = () => {
1428
+ a.disabled = !r.value.trim(), me(r);
1429
+ };
1430
+ return d(), r.addEventListener("input", () => {
1431
+ e.editDraft = r.value, d();
1432
+ }), r.addEventListener("keydown", (l) => {
1433
+ l.key === "Enter" && !l.shiftKey && !l.isComposing && (l.preventDefault(), n.requestSubmit());
1434
+ }), i.addEventListener("click", () => ue(e)), n.addEventListener("submit", (l) => {
1435
+ l.preventDefault(), Ct(e, r.value);
1436
+ }), n.append(r, o), n;
1437
+ }
1438
+ function Le(e, t, n) {
1439
+ const r = e.comments.get(t);
1440
+ if (!r) return;
1441
+ const o = n ? r.replies.find((a) => a.id === n) : null;
1442
+ if (n && !o) return;
1443
+ e.editing = { commentId: t, replyId: n }, e.editDraft = o ? o.text : r.text, n && e.expandedReplies.add(t), p(e);
1444
+ const i = e.panelElement?.querySelector(".rte-comment-edit-textarea");
1445
+ i && (i.focus({ preventScroll: !0 }), i.setSelectionRange(i.value.length, i.value.length));
1446
+ }
1447
+ function ue(e) {
1448
+ const t = e.editing;
1449
+ if (e.editing = null, e.editDraft = "", p(e), !t) return;
1450
+ const n = t.replyId ? `[data-action="more"][data-id="${t.replyId}"]` : `.rte-comment-item[data-comment-id="${t.commentId}"] > .rte-comment-header [data-action="more"]`;
1451
+ e.panelElement?.querySelector(n)?.focus({ preventScroll: !0 });
1452
+ }
1453
+ function Ct(e, t) {
1454
+ const n = e.editing, r = t.trim();
1455
+ if (!n || !r) return;
1456
+ const o = e.comments.get(n.commentId);
1457
+ if (!o) return;
1458
+ const i = n.replyId ? o.replies.find((d) => d.id === n.replyId) : o, a = !!i && i.text !== r;
1459
+ i && a && (i.text = r, i.editedAt = (/* @__PURE__ */ new Date()).toISOString()), ue(e), a && g(e, "edit", o.id);
279
1460
  }
280
- const L = /* @__PURE__ */ new WeakMap();
281
- function G(e) {
282
- L.has(e) || L.set(
283
- e,
284
- window.setTimeout(() => {
285
- L.delete(e), e.panelVisible && s(e);
286
- }, 120)
1461
+ function R(e) {
1462
+ e.undoTimer !== null && window.clearTimeout(e.undoTimer), e.undoTimer = null, e.undoEntry = null;
1463
+ const t = e.panelElement?.querySelector(".rte-comments-toast");
1464
+ t && (t.hidden = !0, t.replaceChildren());
1465
+ }
1466
+ function Ve(e, t) {
1467
+ const n = e.panelElement?.querySelector(".rte-comments-toast");
1468
+ if (!n) return;
1469
+ R(e), e.undoEntry = t;
1470
+ const r = document.createElement("span");
1471
+ r.textContent = t.message;
1472
+ const o = b("rte-comments-toast-action", "Undo");
1473
+ o.addEventListener("click", () => {
1474
+ const i = t.undo();
1475
+ R(e), i || (r.textContent = "This could not be restored here. Use Undo in the document.", n.replaceChildren(r), n.hidden = !1, e.undoTimer = window.setTimeout(() => R(e), 6e3));
1476
+ }), n.replaceChildren(r, o), n.hidden = !1, e.undoTimer = window.setTimeout(() => R(e), 8e3);
1477
+ }
1478
+ function At(e, t) {
1479
+ const n = document.createElement("div");
1480
+ n.className = "rte-comment-reply-box";
1481
+ const r = document.createElement("textarea");
1482
+ r.className = "rte-comment-reply-textarea", r.rows = 1, r.placeholder = "Reply…", r.setAttribute("aria-label", "Reply"), r.dataset.commentId = t.id, r.value = e.replyTexts[t.id] || "";
1483
+ const o = document.createElement("div");
1484
+ o.className = "rte-comment-form-actions";
1485
+ const i = b("rte-comment-btn ghost", "Cancel"), a = b("rte-comment-btn primary", "Reply");
1486
+ o.append(i, a);
1487
+ const d = () => {
1488
+ const c = !!r.value.trim();
1489
+ a.disabled = !c, n.classList.toggle("has-text", !!r.value), me(r);
1490
+ };
1491
+ d();
1492
+ const l = () => {
1493
+ const c = r.value.trim();
1494
+ c && (Ht(t.id, $(e), c), delete e.replyTexts[t.id], p(e));
1495
+ };
1496
+ return r.addEventListener("input", () => {
1497
+ e.replyTexts[t.id] = r.value, d();
1498
+ }), r.addEventListener("focus", () => k(e, t.id)), r.addEventListener("keydown", (c) => {
1499
+ c.key === "Enter" && !c.shiftKey && !c.isComposing && (c.preventDefault(), l());
1500
+ }), a.addEventListener("click", l), i.addEventListener("click", () => {
1501
+ delete e.replyTexts[t.id], r.value = "", d(), r.blur();
1502
+ }), n.append(r, o), n;
1503
+ }
1504
+ function St(e, t) {
1505
+ const n = document.createElement("article");
1506
+ n.className = `rte-comment-item${t.resolved ? " resolved" : ""}${e.activeId === t.id ? " is-active" : ""}`, n.dataset.commentId = t.id;
1507
+ const r = document.createElement("header");
1508
+ r.className = "rte-comment-header";
1509
+ const o = document.createElement("div");
1510
+ o.className = "rte-comment-meta";
1511
+ const i = document.createElement("strong");
1512
+ i.className = "rte-comment-author", i.textContent = t.author.name, o.append(i, ke(t.createdAt, t.editedAt));
1513
+ const a = document.createElement("div");
1514
+ a.className = "rte-comment-header-actions";
1515
+ const d = b(
1516
+ "rte-comment-icon-btn",
1517
+ t.resolved ? "Reopen thread" : "Resolve thread",
1518
+ t.resolved ? "reopen" : "check"
287
1519
  );
1520
+ if (d.dataset.action = "resolve", d.dataset.commentId = t.id, d.addEventListener("click", () => {
1521
+ t.resolved ? $t(t.id) : Dt(t.id, $(e));
1522
+ }), a.append(d), ye(e, t.author) && a.append(
1523
+ Te(
1524
+ e,
1525
+ [
1526
+ { label: "Edit", icon: "edit", run: () => Le(e, t.id, null) },
1527
+ { label: "Delete", icon: "trash", danger: !0, run: () => zt(e, t.id) }
1528
+ ],
1529
+ { commentId: t.id },
1530
+ "More actions"
1531
+ )
1532
+ ), r.append(Ae(t.author), o, a), n.appendChild(r), t.anchorId && t.selectedText) {
1533
+ const l = document.createElement("button");
1534
+ l.type = "button", l.className = "rte-comment-selection", l.textContent = t.selectedText, l.title = "Go to this text", l.setAttribute("aria-label", `Go to the commented text: ${t.selectedText}`), l.addEventListener("click", () => {
1535
+ k(e, t.id), Se(e, t);
1536
+ }), n.appendChild(l);
1537
+ }
1538
+ if (e.editing && e.editing.commentId === t.id && !e.editing.replyId)
1539
+ n.appendChild(Ie(e, e.editing));
1540
+ else {
1541
+ const l = document.createElement("div");
1542
+ l.className = "rte-comment-text", l.textContent = t.text, n.appendChild(l);
1543
+ }
1544
+ if (t.resolved) {
1545
+ const l = document.createElement("div");
1546
+ l.className = "rte-comment-status", l.innerHTML = I("check");
1547
+ const c = document.createElement("span"), m = t.resolvedBy ? ` by ${t.resolvedBy.name}` : "", s = t.resolvedAt ? ` · ${ae(t.resolvedAt)}` : "";
1548
+ c.textContent = `Resolved${m}${s}`, l.appendChild(c), n.appendChild(l);
1549
+ }
1550
+ if (t.replies.length > 0) {
1551
+ const l = document.createElement("div");
1552
+ l.className = "rte-comment-replies";
1553
+ const m = e.expandedReplies.has(t.id) ? 0 : Math.max(0, t.replies.length - ot);
1554
+ if (m > 0) {
1555
+ const s = b(
1556
+ "rte-comment-more-replies",
1557
+ `Show ${m} earlier ${m === 1 ? "reply" : "replies"}`
1558
+ );
1559
+ s.addEventListener("click", () => {
1560
+ e.expandedReplies.add(t.id), p(e);
1561
+ }), l.appendChild(s);
1562
+ }
1563
+ t.replies.slice(m).forEach((s) => {
1564
+ const u = document.createElement("div");
1565
+ u.className = "rte-comment-reply", u.dataset.replyId = s.id;
1566
+ const h = document.createElement("div");
1567
+ h.className = "rte-comment-reply-header";
1568
+ const f = document.createElement("div");
1569
+ f.className = "rte-comment-meta";
1570
+ const L = document.createElement("strong");
1571
+ if (L.className = "rte-comment-author", L.textContent = s.author.name, f.append(L, ke(s.createdAt, s.editedAt)), h.append(Ae(s.author, !0), f), ye(e, s.author) && h.append(
1572
+ Te(
1573
+ e,
1574
+ [
1575
+ { label: "Edit", icon: "edit", run: () => Le(e, t.id, s.id) },
1576
+ { label: "Delete", icon: "trash", danger: !0, run: () => qt(e, t.id, s.id) }
1577
+ ],
1578
+ { commentId: t.id, replyId: s.id },
1579
+ "More reply actions"
1580
+ )
1581
+ ), u.appendChild(h), e.editing && e.editing.commentId === t.id && e.editing.replyId === s.id)
1582
+ u.appendChild(Ie(e, e.editing));
1583
+ else {
1584
+ const N = document.createElement("div");
1585
+ N.className = "rte-comment-reply-text", N.textContent = s.text, u.appendChild(N);
1586
+ }
1587
+ l.appendChild(u);
1588
+ }), n.appendChild(l);
1589
+ }
1590
+ return t.resolved || n.appendChild(At(e, t)), n.addEventListener("click", (l) => {
1591
+ const c = l.target instanceof Element ? l.target : null;
1592
+ !c || c.closest('button, textarea, form, [role="menu"]') || window.getSelection()?.toString() || (k(e, t.id), Se(e, t, !1));
1593
+ }), n.addEventListener("mouseenter", () => M(e, t.id, !0)), n.addEventListener("mouseleave", () => M(e, t.id, !1)), n.addEventListener("focusin", () => M(e, t.id, !0)), n.addEventListener("focusout", () => M(e, t.id, !1)), n;
1594
+ }
1595
+ function Tt(e, t) {
1596
+ const n = document.createElement("form");
1597
+ if (n.className = "rte-comment-composer", n.noValidate = !0, n.setAttribute("aria-label", t.range ? "New comment on the selected text" : "New note for the whole document"), t.range) {
1598
+ const l = document.createElement("div");
1599
+ l.className = "rte-comment-selection";
1600
+ const c = document.createElement("span");
1601
+ c.textContent = t.quote, c.title = t.quote;
1602
+ const m = b("rte-comment-icon-btn", "Comment on the whole document instead", "close");
1603
+ m.addEventListener("click", () => {
1604
+ t.range = null, t.quote = "", p(e), _e(e);
1605
+ }), l.append(c, m), n.appendChild(l);
1606
+ } else {
1607
+ const l = document.createElement("p");
1608
+ l.className = "rte-comment-composer-hint", l.textContent = "A note for the whole document. To comment on a passage, select it first, then click New.", n.appendChild(l);
1609
+ }
1610
+ const r = document.createElement("textarea");
1611
+ if (r.className = "new-comment-textarea", r.rows = 3, r.placeholder = t.range ? "Add a comment…" : "Add a note…", r.setAttribute("aria-label", t.range ? "Comment" : "Note"), r.value = e.newCommentText, n.appendChild(r), t.error) {
1612
+ const l = document.createElement("p");
1613
+ l.className = "rte-comment-error", l.setAttribute("role", "alert"), l.textContent = t.error, n.appendChild(l);
1614
+ }
1615
+ const o = document.createElement("div");
1616
+ o.className = "rte-comment-form-actions";
1617
+ const i = b("rte-comment-btn ghost", "Cancel"), a = b("rte-comment-btn primary", "Comment");
1618
+ a.type = "submit", o.append(i, a), n.appendChild(o);
1619
+ const d = () => {
1620
+ a.disabled = !r.value.trim();
1621
+ };
1622
+ return d(), r.addEventListener("input", () => {
1623
+ e.newCommentText = r.value, t.error && (t.error = "", n.querySelector(".rte-comment-error")?.remove()), d();
1624
+ }), r.addEventListener("keydown", (l) => {
1625
+ l.key === "Enter" && !l.shiftKey && !l.isComposing && (l.preventDefault(), n.requestSubmit());
1626
+ }), i.addEventListener("click", () => Ke(e)), n.addEventListener("submit", (l) => {
1627
+ l.preventDefault();
1628
+ const c = r.value.trim();
1629
+ if (!c) return;
1630
+ const m = Rt(e, $(e), c, t.range);
1631
+ if (!m) {
1632
+ t.error = "That text could not be commented on. Select it again and click New.", t.range = null, t.quote = "", p(e);
1633
+ return;
1634
+ }
1635
+ e.newCommentText = "", e.composer = null, e.filter === "resolved" && (e.filter = "open"), Pe(e, m);
1636
+ }), n;
1637
+ }
1638
+ function _e(e) {
1639
+ e.panelElement?.querySelector(".new-comment-textarea")?.focus({ preventScroll: !0 });
1640
+ }
1641
+ function Fe(e, t) {
1642
+ const n = t ? t.toString().replace(/\s+/g, " ").trim() : "";
1643
+ e.composer = { range: t && n ? t.cloneRange() : null, quote: n, error: "" }, e.filter === "resolved" && (e.filter = "open"), p(e), _e(e);
1644
+ }
1645
+ function Ke(e) {
1646
+ e.composer = null, e.newCommentText = "", p(e);
1647
+ }
1648
+ function kt(e, t) {
1649
+ const n = document.createElement("div");
1650
+ n.className = "rte-comments-empty";
1651
+ let r = "No comments yet", o = "Select text in the document and click New to start a discussion.";
1652
+ t > 0 && e === "open" ? (r = "No open comments", o = "Every thread has been resolved.") : t > 0 && e === "resolved" && (r = "Nothing resolved yet", o = "Threads you resolve show up here."), n.innerHTML = I("bubble");
1653
+ const i = document.createElement("strong");
1654
+ i.textContent = r;
1655
+ const a = document.createElement("p");
1656
+ return a.textContent = o, n.append(i, a), n;
1657
+ }
1658
+ function je(e) {
1659
+ return e.map((t) => `${t.id}:${t.resolved ? 1 : 0}`).join("|");
1660
+ }
1661
+ function p(e) {
1662
+ const t = e || X(), n = t?.panelElement;
1663
+ if (!t || !n) return;
1664
+ const r = xt(t);
1665
+ t.renderedKey = je(H(t));
1666
+ const o = {
1667
+ open: r.filter((c) => !c.resolved).length,
1668
+ resolved: r.filter((c) => c.resolved).length,
1669
+ all: r.length
1670
+ }, i = n.querySelector(".rte-comments-count");
1671
+ i && (i.textContent = String(o.open), i.hidden = o.open === 0), n.querySelectorAll(".rte-comments-tab").forEach((c) => {
1672
+ const m = c.dataset.filter, s = m === t.filter;
1673
+ c.setAttribute("aria-selected", String(s)), c.tabIndex = s ? 0 : -1;
1674
+ const u = c.querySelector(".rte-comments-tab-count");
1675
+ u && (u.textContent = String(o[m]));
1676
+ });
1677
+ const a = n.querySelector(".rte-comments-body");
1678
+ if (!a) return;
1679
+ a.setAttribute("aria-labelledby", `${t.uid}-tab-${t.filter}`);
1680
+ const d = r.filter((c) => t.filter === "open" ? !c.resolved : t.filter === "resolved" ? c.resolved : !0);
1681
+ t.hoverId && (t.hoverId = null, V(t));
1682
+ const l = a.scrollTop;
1683
+ Xe(n, () => {
1684
+ const c = [];
1685
+ t.composer && c.push(Tt(t, t.composer)), d.forEach((m) => c.push(St(t, m))), d.length === 0 && !t.composer && c.push(kt(t.filter, o.all)), a.replaceChildren(...c);
1686
+ }), a.scrollTop = l, a.querySelectorAll("textarea").forEach((c) => me(c));
1687
+ }
1688
+ function We(e) {
1689
+ return v.has(e) || !!e.querySelector('[data-command="addComment"]');
1690
+ }
1691
+ function pe(e) {
1692
+ E = e;
1693
+ const t = C(e), n = ft(e) || (t.savedSelection ? t.savedSelection.cloneRange() : null);
1694
+ n && window.getSelection()?.removeAllRanges(), t.savedSelection = null, w(), Q(t, !0), Fe(t, n);
1695
+ }
1696
+ let A = null, U = null, oe = null, ie = !1;
1697
+ function It() {
1698
+ return /Mac|iPhone|iPad/.test(navigator.platform || "") ? "⌘⌥M" : "Ctrl+Alt+M";
1699
+ }
1700
+ function w() {
1701
+ A && (A.hidden = !0), U = null;
1702
+ }
1703
+ function Lt() {
1704
+ if (A && A.isConnected) return A;
1705
+ Ye();
1706
+ const e = document.createElement("button");
1707
+ return e.type = "button", e.className = "rte-comments-bubble", e.hidden = !0, e.title = `Add a comment (${It()})`, e.innerHTML = `${I("addComment")}<span>Comment</span>`, e.addEventListener("mousedown", (t) => t.preventDefault()), e.addEventListener("click", () => {
1708
+ const t = U;
1709
+ w(), t && pe(t);
1710
+ }), document.body.appendChild(e), A = e, e;
1711
+ }
1712
+ function Nt() {
1713
+ if (oe = null, ie) return w();
1714
+ const e = window.getSelection();
1715
+ if (!e || e.rangeCount === 0 || e.isCollapsed) return w();
1716
+ const t = e.getRangeAt(0), n = x(t.commonAncestorContainer);
1717
+ if (!n || !J(t, n) || !We(n) || P(n)?.closest('[contenteditable="false"]') || !t.toString().trim()) return w();
1718
+ const r = t.getClientRects?.(), o = r && r.length ? r[r.length - 1] : t.getBoundingClientRect?.();
1719
+ if (!o || !o.width && !o.height) return w();
1720
+ const i = Lt();
1721
+ i.hidden = !1, U = n;
1722
+ const a = i.offsetWidth || 96, d = i.offsetHeight || 32;
1723
+ let l = o.bottom + 8;
1724
+ l + d > window.innerHeight - 8 && (l = Math.max(8, (r && r.length ? r[0] : o).top - d - 8));
1725
+ const c = Math.min(Math.max(8, o.right - a), Math.max(8, window.innerWidth - a - 8));
1726
+ i.style.top = `${l}px`, i.style.left = `${c}px`;
1727
+ }
1728
+ function K() {
1729
+ oe === null && (oe = window.setTimeout(Nt, 40));
288
1730
  }
289
- function z() {
290
- R || (R = !0, document.addEventListener("focusin", (e) => {
291
- const t = g(e.target);
292
- t && (h = t);
293
- }), document.addEventListener("click", (e) => {
294
- const r = (e.target instanceof Element ? e.target : null)?.closest(".rte-comment-anchor");
1731
+ function fe() {
1732
+ document.querySelectorAll("[data-editora-editor], .rte-editor, .editora-editor").forEach((e) => {
1733
+ const t = x(e);
1734
+ if (!t) return;
1735
+ const n = v.get(t);
1736
+ if (n) {
1737
+ se(n), !n.instance && y.length && G(n, y[0], !0);
1738
+ return;
1739
+ }
1740
+ t.querySelector('[data-command="addComment"]') && C(t);
1741
+ });
1742
+ }
1743
+ let te = null;
1744
+ function Mt() {
1745
+ te === null && (te = window.setTimeout(() => {
1746
+ te = null, fe();
1747
+ }, 50));
1748
+ }
1749
+ function T() {
1750
+ if (xe) return;
1751
+ xe = !0, document.addEventListener("focusin", (t) => {
1752
+ const n = x(t.target);
1753
+ n && (E = n);
1754
+ }), document.addEventListener("click", (t) => {
1755
+ const r = (t.target instanceof Element ? t.target : null)?.closest(".rte-comment-anchor");
295
1756
  if (!r) return;
296
- const o = g(r), a = o ? y.get(o) : null, c = r.getAttribute("data-comment-id");
297
- !a || !c || !a.comments.has(c) || (e.preventDefault(), e.stopPropagation(), h = a.root, a.expandedComments.add(c), w(a, !0), s(a));
298
- }), document.addEventListener("input", (e) => {
299
- const t = e.target instanceof Element ? e.target : null;
300
- if (!t || t.closest(".rte-comments-panel")) return;
301
- const r = g(t), o = r ? y.get(r) : null;
302
- o?.panelVisible && G(o);
303
- }), document.addEventListener("selectionchange", () => {
304
- const e = window.getSelection();
305
- if (!e || e.rangeCount === 0) return;
306
- const t = e.getRangeAt(0), r = g(t.commonAncestorContainer);
1757
+ const o = x(r), i = o ? v.get(o) : null, a = r.getAttribute("data-comment-id");
1758
+ !i || !a || !i.comments.has(a) || (t.preventDefault(), t.stopPropagation(), E = i.root, Q(i, !0), Pe(i, a));
1759
+ }), document.addEventListener("input", (t) => {
1760
+ const n = t.target instanceof Element ? t.target : null;
1761
+ if (!n || n.closest(".rte-comments-panel")) return;
1762
+ const r = x(n), o = r ? v.get(r) : null;
1763
+ o && de(o);
1764
+ }), fe(), typeof MutationObserver < "u" && new MutationObserver((t) => {
1765
+ for (const n of t)
1766
+ for (const r of Array.from(n.addedNodes))
1767
+ if (r.nodeType === 1) {
1768
+ Mt();
1769
+ return;
1770
+ }
1771
+ }).observe(document.documentElement, { childList: !0, subtree: !0 }), document.addEventListener("selectionchange", () => {
1772
+ const t = window.getSelection();
1773
+ if (!t || t.rangeCount === 0) return;
1774
+ const n = t.getRangeAt(0), r = x(n.commonAncestorContainer);
307
1775
  if (!r) return;
308
- h = r;
309
- const o = y.get(r);
310
- !o || e.isCollapsed || k(t, r) && (o.savedSelection = t.cloneRange());
311
- }), document.addEventListener(
1776
+ E = r;
1777
+ const o = v.get(r);
1778
+ !o || !J(n, r) || (o.savedSelection = t.isCollapsed ? null : n.cloneRange());
1779
+ }), document.addEventListener("selectionchange", K), document.addEventListener(
1780
+ "pointerdown",
1781
+ (t) => {
1782
+ t.target instanceof Node && A?.contains(t.target) || (ie = !0, w());
1783
+ },
1784
+ !0
1785
+ );
1786
+ const e = () => {
1787
+ ie = !1, K();
1788
+ };
1789
+ document.addEventListener("pointerup", e, !0), document.addEventListener("pointercancel", e, !0), document.addEventListener("scroll", () => U && K(), !0), window.addEventListener("resize", () => U && K()), document.addEventListener(
1790
+ "keydown",
1791
+ (t) => {
1792
+ if (t.code !== "KeyM" || !t.altKey || t.shiftKey || !(t.metaKey || t.ctrlKey)) return;
1793
+ const n = t.target instanceof Node ? x(t.target) : null;
1794
+ !n || !We(n) || (t.preventDefault(), t.stopPropagation(), pe(n));
1795
+ },
1796
+ !0
1797
+ ), document.addEventListener(
312
1798
  "keydown",
313
- (e) => {
314
- if (e.key !== "Escape") return;
315
- const t = u();
316
- !t || !t.panelVisible || (e.preventDefault(), e.stopPropagation(), w(t, !1));
1799
+ (t) => {
1800
+ if (t.key !== "Escape") return;
1801
+ const n = t.target instanceof Node ? x(t.target) : null, r = n ? v.get(n) : null;
1802
+ if (!r || !r.panelVisible) return;
1803
+ if (r.closeMenu) {
1804
+ t.preventDefault(), t.stopPropagation(), r.closeMenu(!0);
1805
+ return;
1806
+ }
1807
+ const o = t.target instanceof HTMLTextAreaElement && r.panelElement?.contains(t.target) ? t.target : null;
1808
+ if (o?.classList.contains("new-comment-textarea")) {
1809
+ t.preventDefault(), t.stopPropagation(), Ke(r);
1810
+ return;
1811
+ }
1812
+ if (o?.classList.contains("rte-comment-edit-textarea")) {
1813
+ t.preventDefault(), t.stopPropagation(), ue(r);
1814
+ return;
1815
+ }
1816
+ if (o?.classList.contains("rte-comment-reply-textarea") && o.value) {
1817
+ t.preventDefault(), t.stopPropagation(), delete r.replyTexts[o.dataset.commentId || ""], o.value = "", o.dispatchEvent(new Event("input"));
1818
+ return;
1819
+ }
1820
+ t.preventDefault(), t.stopPropagation(), Be(r);
317
1821
  },
318
1822
  !0
319
- ));
1823
+ );
320
1824
  }
321
- function J(e, t, r = !1) {
322
- const o = u();
1825
+ function Rt(e, t, n, r) {
1826
+ const o = n.trim();
323
1827
  if (!o) return "";
324
- const a = t.trim();
325
- if (!a) return "";
326
- if (r) {
327
- const l = S("comment");
328
- return o.comments.set(l, {
329
- id: l,
1828
+ if (!r) {
1829
+ const m = q("comment");
1830
+ return e.comments.set(m, {
1831
+ id: m,
330
1832
  anchorId: "",
331
1833
  selectedText: "",
332
- author: e,
333
- text: a,
1834
+ author: t,
1835
+ text: o,
334
1836
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
335
1837
  resolved: !1,
336
- replies: []
337
- }), s(o), l;
338
- }
339
- const c = o.savedSelection || V(o.root);
340
- if (!c || !k(c, o.root)) return "";
341
- const p = c.toString().trim();
342
- if (!p) return "";
343
- const f = S("comment"), d = S("comment-anchor"), i = document.createElement("span");
344
- return i.id = d, i.className = "rte-comment-anchor", i.setAttribute("data-comment-id", f), i.setAttribute("title", "Commented text"), A(o, () => {
1838
+ replies: [],
1839
+ aligned: !0
1840
+ }), p(e), g(e, "create", m), m;
1841
+ }
1842
+ if (!J(r, e.root)) return "";
1843
+ const i = r.toString().trim();
1844
+ if (!i) return "";
1845
+ const a = q("comment"), d = q("comment-anchor"), l = document.createElement("span");
1846
+ return l.id = d, l.className = "rte-comment-anchor", l.setAttribute("data-comment-id", a), l.setAttribute("title", "Commented text"), B(e, () => {
345
1847
  try {
346
- const l = c.cloneRange(), m = l.extractContents();
347
- return m.textContent?.trim() ? (i.appendChild(m), l.insertNode(i), !0) : !1;
1848
+ const m = r.cloneRange(), s = m.extractContents();
1849
+ return s.textContent?.trim() ? (l.appendChild(s), m.insertNode(l), !0) : !1;
348
1850
  } catch {
349
1851
  return !1;
350
1852
  }
351
- }) ? (o.comments.set(f, {
352
- id: f,
1853
+ }) ? (e.comments.set(a, {
1854
+ id: a,
353
1855
  anchorId: d,
354
- selectedText: p,
355
- author: e,
356
- text: a,
1856
+ selectedText: i,
1857
+ author: t,
1858
+ text: o,
357
1859
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
358
1860
  resolved: !1,
359
- replies: []
360
- }), o.savedSelection = null, window.getSelection()?.removeAllRanges(), s(o), f) : "";
1861
+ replies: [],
1862
+ aligned: !0
1863
+ }), e.savedSelection = null, window.getSelection()?.removeAllRanges(), p(e), g(e, "create", a), a) : "";
361
1864
  }
362
- function Q(e, t) {
363
- const r = u();
364
- if (!r) return;
365
- const o = r.comments.get(e);
366
- o && (o.resolved = !0, o.resolvedBy = t, o.resolvedAt = (/* @__PURE__ */ new Date()).toISOString(), A(r, () => I(r, o)), s(r));
1865
+ function Dt(e, t) {
1866
+ const n = X();
1867
+ if (!n) return;
1868
+ const r = n.comments.get(e);
1869
+ r && (r.resolved = !0, r.resolvedBy = S(t) ?? $(n), r.resolvedAt = (/* @__PURE__ */ new Date()).toISOString(), B(n, () => qe(n, r)), p(n), g(n, "resolve", e));
367
1870
  }
368
- function Y(e) {
369
- const t = u();
1871
+ function $t(e) {
1872
+ const t = X();
370
1873
  if (!t) return;
371
- const r = t.comments.get(e);
372
- r && (r.resolved = !1, r.resolvedBy = void 0, r.resolvedAt = void 0, A(t, () => I(t, r)), s(t));
1874
+ const n = t.comments.get(e);
1875
+ n && (n.resolved = !1, n.resolvedBy = void 0, n.resolvedAt = void 0, B(t, () => qe(t, n)), p(t), g(t, "reopen", e));
373
1876
  }
374
- function ee(e) {
375
- const t = u();
376
- if (!t) return;
377
- const r = t.comments.get(e);
378
- if (r) {
379
- if (r.anchorId) {
380
- const o = C(t, r);
381
- o && A(t, () => j(o));
382
- } else
383
- t.comments.delete(e), t.expandedComments.delete(e), delete t.replyTexts[e];
384
- s(t);
385
- }
386
- }
387
- function te(e, t, r) {
388
- const o = u();
1877
+ function Ot(e, t) {
1878
+ const n = e.comments.get(t);
1879
+ if (!n) return null;
1880
+ e.activeId === t && k(e, null), e.hoverId === t && (e.hoverId = null), e.editing?.commentId === t && (e.editing = null, e.editDraft = "");
1881
+ let r = null;
1882
+ if (n.anchorId) {
1883
+ const o = D(e, n);
1884
+ if (o) {
1885
+ const i = Array.from(o.childNodes), a = Array.from(o.attributes).map((d) => [d.name, d.value]);
1886
+ B(e, () => ht(o)), n.deleted = !0, r = {
1887
+ message: "Comment deleted",
1888
+ undo: () => {
1889
+ if (D(e, n)) return !0;
1890
+ const d = i[0], l = d?.parentNode;
1891
+ if (!(!!d && d.isConnected && !!l && i.every((s, u) => s.parentNode === l && (u === 0 || i[u - 1].nextSibling === s))) || !d || !l) return !1;
1892
+ const m = document.createElement("span");
1893
+ return a.forEach(([s, u]) => m.setAttribute(s, u)), B(e, () => {
1894
+ l.insertBefore(m, d), i.forEach((s) => m.appendChild(s));
1895
+ }), n.deleted = !1, p(e), g(e, "create", n.id), !0;
1896
+ }
1897
+ };
1898
+ }
1899
+ } else {
1900
+ e.comments.delete(t), e.expandedReplies.delete(t);
1901
+ const o = e.replyTexts[t];
1902
+ delete e.replyTexts[t], r = {
1903
+ message: "Note deleted",
1904
+ undo: () => (e.comments.set(t, n), o && (e.replyTexts[t] = o), p(e), g(e, "create", t), !0)
1905
+ };
1906
+ }
1907
+ return p(e), g(e, "delete", t), r;
1908
+ }
1909
+ function zt(e, t) {
1910
+ const n = Ot(e, t);
1911
+ n && Ve(e, n);
1912
+ }
1913
+ function qt(e, t, n) {
1914
+ const r = e.comments.get(t), o = r ? r.replies.findIndex((a) => a.id === n) : -1;
1915
+ if (!r || o === -1) return;
1916
+ const [i] = r.replies.splice(o, 1);
1917
+ e.editing?.replyId === n && (e.editing = null, e.editDraft = ""), p(e), g(e, "delete", t), Ve(e, {
1918
+ message: "Reply deleted",
1919
+ undo: () => (r.replies.splice(Math.min(o, r.replies.length), 0, i), p(e), g(e, "reply", t), !0)
1920
+ });
1921
+ }
1922
+ function Ht(e, t, n) {
1923
+ const r = X();
1924
+ if (!r) return;
1925
+ const o = r.comments.get(e);
389
1926
  if (!o) return;
390
- const a = o.comments.get(e);
391
- if (!a) return;
392
- const c = r.trim();
393
- c && (a.replies.push({
394
- id: S("reply"),
395
- author: t,
396
- text: c,
1927
+ const i = n.trim();
1928
+ i && (o.replies.push({
1929
+ id: q("reply"),
1930
+ author: S(t) ?? $(r),
1931
+ text: i,
397
1932
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
398
- }), s(o));
1933
+ }), p(r), g(r, "reply", e));
399
1934
  }
400
- function re() {
401
- if (document.getElementById("rte-comments-panel-styles")) return;
1935
+ function Ye() {
1936
+ if (document.getElementById(ge)) return;
402
1937
  const e = document.createElement("style");
403
- e.id = "rte-comments-panel-styles", e.textContent = `
404
- .rte-comments-panel {
405
- --rte-comments-panel-width: min(360px, 42vw);
406
- position: absolute;
407
- top: 0;
408
- right: 0;
409
- bottom: 0;
410
- width: var(--rte-comments-panel-width);
411
- display: flex;
412
- flex-direction: column;
413
- background: var(--rte-color-bg-primary, #ffffff);
414
- color: var(--rte-color-text-primary, #111827);
415
- border-left: 1px solid var(--rte-color-border, #d1d5db);
416
- box-shadow: -12px 0 28px rgba(15, 23, 42, 0.2);
417
- transform: translateX(100%);
418
- opacity: 0;
419
- pointer-events: none;
420
- transition: transform 180ms ease, opacity 180ms ease;
421
- /* Above the editor's sticky toolbar (z-index 100): on a narrow screen the panel lies over the editor, and
422
- under the toolbar its header, and the button that closes it, could not be clicked. */
423
- z-index: 110;
424
- }
425
-
426
- .rte-comments-panel.is-open {
427
- transform: translateX(0);
428
- opacity: 1;
429
- pointer-events: auto;
430
- }
431
-
432
- /* The panel's width is set on the editor itself, not only on the panel: the toolbar and the text make room for the
433
- panel with a margin of that width, and a variable set on the panel is not visible to them (the margin was
434
- silently 0, so the panel lay over the toolbar and the text and its header could not be reached). */
435
- [data-rte-comments-open="true"] {
436
- --rte-comments-panel-width: min(360px, 42vw);
437
- }
438
-
439
- /* The toolbar's wrapper is the element that is as wide as the editor, and it sits above the panel (it is sticky,
440
- z-index 100): it has to give up the panel's width too, or its empty right-hand end covers the panel's header. */
441
- [data-rte-comments-open="true"] :is(.rte-toolbar-wrapper, .rte-toolbar:not(.rte-toolbar-wrapper .rte-toolbar), .editora-toolbar, .rte-content, .editora-content, .editora-statusbar, .editora-statusbar-container) {
442
- margin-right: var(--rte-comments-panel-width);
443
- transition: margin-right 180ms ease;
444
- }
445
-
446
- .rte-comments-header {
447
- display: flex;
448
- justify-content: space-between;
449
- align-items: flex-start;
450
- gap: 12px;
451
- padding: 14px 14px 12px;
452
- border-bottom: 1px solid var(--rte-color-border-light, #e5e7eb);
453
- background: var(--rte-color-bg-secondary, #f8fafc);
454
- }
455
-
456
- .rte-comments-header h3 {
457
- margin: 0;
458
- font-size: 15px;
459
- line-height: 1.2;
460
- }
461
-
462
- .rte-comments-header p {
463
- margin: 6px 0 0;
464
- font-size: 12px;
465
- color: var(--rte-color-text-muted, #64748b);
466
- }
467
-
468
- .rte-comments-close {
469
- border: 1px solid var(--rte-color-border, #d1d5db);
470
- background: transparent;
471
- color: var(--rte-color-text-secondary, #475569);
472
- border-radius: 6px;
473
- width: 30px;
474
- height: 30px;
475
- cursor: pointer;
476
- font-size: 16px;
477
- line-height: 1;
478
- }
479
-
480
- .rte-comments-close:hover {
481
- background: var(--rte-color-bg-hover, #f1f5f9);
482
- color: var(--rte-color-text-primary, #0f172a);
483
- }
484
-
485
- .rte-comments-composer {
486
- display: flex;
487
- flex-direction: column;
488
- gap: 8px;
489
- padding: 12px 14px;
490
- border-bottom: 1px solid var(--rte-color-border-light, #e5e7eb);
491
- background: var(--rte-color-bg-secondary, #f8fafc);
492
- }
493
-
494
- .new-comment-textarea,
495
- .rte-comment-reply-textarea {
496
- width: 100%;
497
- resize: vertical;
498
- min-height: 62px;
499
- font-family: inherit;
500
- font-size: 13px;
501
- line-height: 1.35;
502
- border: 1px solid var(--rte-color-border, #d1d5db);
503
- border-radius: 8px;
504
- background: var(--rte-color-bg-primary, #ffffff);
505
- color: var(--rte-color-text-primary, #0f172a);
506
- padding: 8px 10px;
507
- outline: none;
508
- }
509
-
510
- .new-comment-textarea:focus,
511
- .rte-comment-reply-textarea:focus {
512
- border-color: var(--rte-color-border-focus, #2563eb);
513
- box-shadow: 0 0 0 2px color-mix(in srgb, var(--rte-color-border-focus, #2563eb) 20%, transparent);
514
- }
515
-
516
- .rte-comments-composer-actions {
517
- display: flex;
518
- justify-content: flex-end;
519
- }
520
-
521
- .rte-comments-list {
522
- flex: 1;
523
- overflow: auto;
524
- padding: 12px;
525
- display: flex;
526
- flex-direction: column;
527
- gap: 10px;
528
- }
529
-
530
- .rte-comments-empty {
531
- padding: 18px 14px;
532
- color: var(--rte-color-text-muted, #64748b);
533
- font-size: 13px;
534
- }
535
-
536
- .rte-comment-item {
537
- border: 1px solid var(--rte-color-border-light, #e5e7eb);
538
- border-radius: 10px;
539
- background: var(--rte-color-bg-primary, #ffffff);
540
- padding: 10px;
541
- }
542
-
543
- .rte-comment-item.resolved {
544
- opacity: 0.74;
545
- }
546
-
547
- .rte-comment-header {
548
- display: flex;
549
- align-items: flex-start;
550
- justify-content: space-between;
551
- gap: 8px;
552
- }
553
-
554
- .rte-comment-meta {
555
- display: flex;
556
- flex-direction: column;
557
- gap: 2px;
558
- }
559
-
560
- .rte-comment-author {
561
- font-size: 13px;
562
- color: var(--rte-color-text-primary, #0f172a);
563
- }
564
-
565
- .rte-comment-date {
566
- font-size: 11px;
567
- color: var(--rte-color-text-muted, #64748b);
568
- }
569
-
570
- .rte-comment-expand {
571
- border: none;
572
- background: transparent;
573
- cursor: pointer;
574
- color: var(--rte-color-text-secondary, #475569);
575
- font-size: 16px;
576
- line-height: 1;
577
- padding: 0;
578
- }
579
-
580
- .rte-comment-text {
581
- margin-top: 8px;
582
- font-size: 13px;
583
- line-height: 1.45;
584
- color: var(--rte-color-text-primary, #0f172a);
585
- white-space: pre-wrap;
586
- word-break: break-word;
587
- }
588
-
589
- .rte-comment-selection {
590
- margin: 8px 0 0;
591
- border-left: 3px solid var(--rte-color-primary, #2563eb);
592
- background: var(--rte-color-bg-secondary, #f8fafc);
593
- color: var(--rte-color-text-secondary, #475569);
594
- padding: 6px 8px;
595
- border-radius: 6px;
596
- font-size: 12px;
597
- font-style: italic;
598
- white-space: pre-wrap;
599
- word-break: break-word;
600
- }
601
-
602
- .rte-comment-expanded {
603
- display: none;
604
- margin-top: 10px;
605
- padding-top: 10px;
606
- border-top: 1px solid var(--rte-color-border-light, #e5e7eb);
607
- }
608
-
609
- .rte-comment-expanded.show {
610
- display: block;
611
- }
612
-
613
- .rte-comment-replies {
614
- display: flex;
615
- flex-direction: column;
616
- gap: 8px;
617
- margin-bottom: 10px;
618
- }
619
-
620
- .rte-comment-reply {
621
- border: 1px solid var(--rte-color-border-light, #e5e7eb);
622
- border-radius: 8px;
623
- padding: 8px;
624
- background: var(--rte-color-bg-secondary, #f8fafc);
625
- }
626
-
627
- .rte-comment-reply-header {
628
- display: flex;
629
- justify-content: space-between;
630
- gap: 8px;
631
- margin-bottom: 4px;
632
- font-size: 11px;
633
- color: var(--rte-color-text-muted, #64748b);
634
- }
635
-
636
- .rte-comment-reply-text {
637
- font-size: 12px;
638
- color: var(--rte-color-text-secondary, #334155);
639
- white-space: pre-wrap;
640
- word-break: break-word;
641
- }
642
-
643
- .rte-comment-reply-composer {
644
- display: flex;
645
- flex-direction: column;
646
- gap: 8px;
647
- margin-bottom: 10px;
648
- }
649
-
650
- .rte-comment-actions {
651
- display: flex;
652
- justify-content: flex-end;
653
- flex-wrap: wrap;
654
- gap: 6px;
655
- }
656
-
657
- .rte-comment-btn {
658
- border: 1px solid var(--rte-color-border, #d1d5db);
659
- border-radius: 7px;
660
- padding: 5px 9px;
661
- font-size: 12px;
662
- cursor: pointer;
663
- background: var(--rte-color-bg-primary, #ffffff);
664
- color: var(--rte-color-text-secondary, #334155);
665
- }
666
-
667
- .rte-comment-btn:hover {
668
- background: var(--rte-color-bg-hover, #f1f5f9);
669
- color: var(--rte-color-text-primary, #0f172a);
670
- }
671
-
672
- .rte-comment-btn:disabled {
673
- opacity: 0.5;
674
- cursor: not-allowed;
675
- }
676
-
677
- .rte-comment-btn.primary {
678
- border-color: var(--rte-color-primary, #2563eb);
679
- background: var(--rte-color-primary, #2563eb);
680
- color: var(--rte-color-text-inverse, #ffffff);
681
- }
682
-
683
- .rte-comment-btn.primary:hover {
684
- background: var(--rte-color-primary-hover, #1d4ed8);
685
- border-color: var(--rte-color-primary-hover, #1d4ed8);
686
- color: var(--rte-color-text-inverse, #ffffff);
687
- }
688
-
689
- .rte-comment-btn.success {
690
- border-color: color-mix(in srgb, var(--rte-color-success, #15803d) 60%, transparent);
691
- color: var(--rte-color-success, #15803d);
692
- }
693
-
694
- .rte-comment-btn.danger {
695
- border-color: color-mix(in srgb, var(--rte-color-danger, #b91c1c) 60%, transparent);
696
- color: var(--rte-color-danger, #b91c1c);
697
- }
698
-
699
- .rte-comment-anchor {
700
- background: rgba(250, 204, 21, 0.34);
701
- border-bottom: 2px solid rgba(217, 119, 6, 0.75);
702
- border-radius: 2px;
703
- cursor: pointer;
704
- transition: outline-color 120ms ease, box-shadow 120ms ease;
705
- }
706
-
707
- .rte-comment-anchor.rte-comment-anchor-resolved {
708
- background: rgba(148, 163, 184, 0.2);
709
- border-bottom-color: rgba(100, 116, 139, 0.6);
710
- }
711
-
712
- .rte-comment-anchor.highlighted {
713
- outline: 2px solid var(--rte-color-primary, #2563eb);
714
- outline-offset: 2px;
715
- }
716
-
717
- :is([theme="dark"], [data-theme="dark"], .dark, .editora-theme-dark) .rte-comments-panel {
718
- box-shadow: -14px 0 30px rgba(0, 0, 0, 0.45);
719
- }
720
-
721
- @media (max-width: 900px) {
722
- [data-rte-comments-open="true"],
723
- .rte-comments-panel {
724
- --rte-comments-panel-width: min(420px, 100%);
725
- }
726
-
727
- [data-rte-comments-open="true"] :is(.rte-toolbar-wrapper, .rte-toolbar:not(.rte-toolbar-wrapper .rte-toolbar), .editora-toolbar, .rte-content, .editora-content, .editora-statusbar, .editora-statusbar-container) {
728
- margin-right: 0;
729
- }
730
- }
731
- `, document.head.appendChild(e);
1938
+ e.id = ge, e.textContent = tt, document.head.appendChild(e);
1939
+ }
1940
+ const Bt = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor";
1941
+ function O(e) {
1942
+ return e instanceof Element ? e.closest(Bt) : null;
732
1943
  }
733
- const ae = () => ({
1944
+ function _t(e) {
1945
+ const t = O(e), n = t ? v.get(t) : null;
1946
+ return n ? Oe(n) : [];
1947
+ }
1948
+ function Ft(e, t) {
1949
+ const n = O(e);
1950
+ n && (T(), ze(C(n), t));
1951
+ }
1952
+ function Kt(e, t) {
1953
+ const n = O(e);
1954
+ return n ? (T(), mt(C(n), t)) : !1;
1955
+ }
1956
+ function jt(e, t) {
1957
+ const n = O(e), r = n ? v.get(n) : null;
1958
+ return r ? ut(r, t) : !1;
1959
+ }
1960
+ function Wt(e, t) {
1961
+ const n = O(e);
1962
+ if (!n) return;
1963
+ T();
1964
+ const r = { options: t, initialApplied: !1 };
1965
+ De(r);
1966
+ const o = C(n, r);
1967
+ o.instance !== r && G(o, r, !1);
1968
+ }
1969
+ function Ne(e, t) {
1970
+ it(t);
1971
+ const n = Re();
1972
+ return n ? (E = n, C(n, e)) : null;
1973
+ }
1974
+ const Yt = (e = {}) => {
1975
+ const t = { options: e || {}, initialApplied: !1 };
1976
+ return typeof document < "u" && (lt(t), T(), fe()), Ut(t);
1977
+ }, Ut = (e) => ({
734
1978
  name: "comments",
735
1979
  toolbar: [
736
1980
  {
@@ -755,21 +1999,33 @@ const ae = () => ({
755
1999
  }
756
2000
  ],
757
2001
  commands: {
758
- addComment: (e, t) => {
759
- q(t), z();
760
- const r = u();
761
- return r ? (r.savedSelection = V(r.root), r.savedSelection && window.getSelection()?.removeAllRanges(), w(r, !0), s(r), r.panelElement?.querySelector(
762
- ".new-comment-textarea"
763
- )?.focus({ preventScroll: !0 }), !0) : !1;
2002
+ addComment: (t, n) => {
2003
+ T();
2004
+ const r = Ne(e, n);
2005
+ return r ? (pe(r.root), !0) : !1;
764
2006
  },
765
- toggleComments: (e, t) => {
766
- q(t), z();
767
- const r = u();
768
- return r ? (w(r, !r.panelVisible), r.panelVisible && s(r), !0) : !1;
2007
+ toggleComments: (t, n) => {
2008
+ T();
2009
+ const r = Ne(e, n);
2010
+ return r ? (Q(r, !r.panelVisible), !0) : !1;
769
2011
  }
770
2012
  },
2013
+ // The web component calls this with the editor that owns the plugin, which is the one sure way to tell.
2014
+ init(t) {
2015
+ const n = O(t?.editorElement);
2016
+ n && (T(), C(n, e));
2017
+ },
2018
+ destroy() {
2019
+ const t = y.indexOf(e);
2020
+ t !== -1 && y.splice(t, 1), re === e && (ce = null, re = null);
2021
+ },
771
2022
  keymap: {}
772
2023
  });
773
2024
  export {
774
- ae as CommentsPlugin
2025
+ Yt as CommentsPlugin,
2026
+ Wt as configureComments,
2027
+ _t as getCommentThreads,
2028
+ jt as removeCommentThread,
2029
+ Ft as setCommentThreads,
2030
+ Kt as upsertCommentThread
775
2031
  };