@toantranmei/comments 0.0.0-stage → 0.1.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.
package/dist/index.js ADDED
@@ -0,0 +1,895 @@
1
+ import { Check as e, Ellipsis as t, MessageSquareText as n, RotateCcw as r } from "@lucide/vue";
2
+ import { MeiConfig as i, MentionNode as a, defineBlock as o, resolveMessages as s } from "@toantranmei/editor";
3
+ import { Extension as c, Mark as l, mergeAttributes as u } from "@tiptap/core";
4
+ import { Plugin as d, PluginKey as f } from "@tiptap/pm/state";
5
+ import { Decoration as p, DecorationSet as m } from "@tiptap/pm/view";
6
+ import { Fragment as h, Teleport as g, computed as _, createBlock as v, createCommentVNode as y, createElementBlock as b, createElementVNode as x, createTextVNode as S, createVNode as C, defineComponent as w, effectScope as T, isRef as ee, nextTick as te, normalizeClass as E, normalizeStyle as ne, onBeforeUnmount as re, openBlock as D, ref as O, renderList as k, shallowRef as A, toDisplayString as j, unref as M, watch as N, withModifiers as P } from "vue";
7
+ import ie from "@tiptap/starter-kit";
8
+ import { Editor as ae, EditorContent as oe } from "@tiptap/vue-3";
9
+ var F = "comment";
10
+ function I(e, t) {
11
+ let n = e.doc.resolve(t);
12
+ for (let e = n.depth; e > 0; e--) {
13
+ let t = n.node(e).attrs.id;
14
+ if (typeof t == "string" && t) return t;
15
+ }
16
+ return null;
17
+ }
18
+ function L(e) {
19
+ let { from: t, to: n, empty: r, $from: i } = e.selection;
20
+ if (r) return null;
21
+ let a = I(e, t);
22
+ if (!a) return null;
23
+ let o = i.parent.isTextblock ? Math.min(n, i.end()) : n, s = e.doc.textBetween(t, Math.max(t, o), " ", " ").trim().slice(0, 500);
24
+ return s ? {
25
+ anchor: {
26
+ kind: "text",
27
+ block_id: a,
28
+ quote: s
29
+ },
30
+ from: t,
31
+ to: n
32
+ } : null;
33
+ }
34
+ function R(e) {
35
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
36
+ return e.descendants((e, r) => {
37
+ let i = e.attrs?.id;
38
+ if (typeof i == "string" && i && !e.isText && n.set(i, {
39
+ pos: r,
40
+ node: e
41
+ }), e.isText) for (let n of e.marks) {
42
+ if (n.type.name !== "comment" || !n.attrs.threadId) continue;
43
+ let i = t.get(n.attrs.threadId) ?? [], a = i[i.length - 1];
44
+ a && a.to === r ? a.to = r + e.nodeSize : i.push({
45
+ from: r,
46
+ to: r + e.nodeSize
47
+ }), t.set(n.attrs.threadId, i);
48
+ }
49
+ return !0;
50
+ }), {
51
+ marks: t,
52
+ blocks: n
53
+ };
54
+ }
55
+ function z(e, t) {
56
+ if (!t) return null;
57
+ let n = null, r = (e, i) => {
58
+ if (!n) {
59
+ if (e.isTextblock) {
60
+ let r = "", a = [];
61
+ e.forEach((e, t) => {
62
+ if (e.isText) {
63
+ for (let n = 0; n < e.text.length; n++) a.push(i + 1 + t + n);
64
+ r += e.text;
65
+ } else a.push(i + 1 + t), r += "";
66
+ });
67
+ let o = r.indexOf(t);
68
+ o >= 0 && (n = {
69
+ from: a[o],
70
+ to: a[o + t.length - 1] + 1
71
+ });
72
+ } else e.forEach((e, t) => r(e, i + 1 + t));
73
+ }
74
+ };
75
+ return r(e.node, e.pos), n;
76
+ }
77
+ function B(e, t) {
78
+ let n = t.marks.get(e.id);
79
+ if (n?.length) return n;
80
+ let r = e.anchor;
81
+ if (r.kind !== "text") return [];
82
+ let i = t.blocks.get(r.block_id), a = i && z(i, r.quote);
83
+ return a ? [a] : [];
84
+ }
85
+ var se = (e) => e.anchor.kind === "page" ? null : e.anchor.block_id, V = /* @__PURE__ */ new WeakMap();
86
+ function H(e) {
87
+ let t = V.get(e);
88
+ if (t) return t;
89
+ let n = O(null), r = A(null), i = O("open"), a = null, o = 0;
90
+ function s(e, t, n) {
91
+ let i = e.utils.createMappablePosition(t), a = e.utils.createMappablePosition(n), o = ({ transaction: t }) => {
92
+ let n = r.value;
93
+ n && t.docChanged && (i = e.utils.getUpdatedPosition(i, t).position, a = e.utils.getUpdatedPosition(a, t).position, r.value = {
94
+ ...n,
95
+ from: i.position,
96
+ to: a.position
97
+ });
98
+ };
99
+ return e.on("transaction", o), () => e.off("transaction", o);
100
+ }
101
+ function c() {
102
+ a?.(), a = null, r.value = null;
103
+ }
104
+ function l(e, t) {
105
+ c(), r.value = {
106
+ ...t,
107
+ editor: e,
108
+ key: ++o
109
+ }, a = s(e, t.from, t.to), n.value = null;
110
+ }
111
+ async function u(t) {
112
+ let i = r.value;
113
+ if (!i) return null;
114
+ let a = await e.create(i.anchor, t), o = r.value;
115
+ c();
116
+ let { editor: s } = o ?? i;
117
+ if (a && s.isEditable && !s.isDestroyed && s.schema.marks.comment) {
118
+ let e = ce(s, o ?? i);
119
+ if (e) {
120
+ let t = s.state.tr.addMark(e.from, e.to, s.schema.marks[F].create({ threadId: a.id }));
121
+ s.view.dispatch(t.setMeta("addToHistory", !1));
122
+ }
123
+ }
124
+ return a && (n.value = a.id), a;
125
+ }
126
+ return t = {
127
+ activeId: n,
128
+ draft: r,
129
+ filter: i,
130
+ startDraft: l,
131
+ cancelDraft: c,
132
+ submitDraft: u
133
+ }, V.set(e, t), t;
134
+ }
135
+ function ce(e, t) {
136
+ let { doc: n } = e.state, r = t.anchor.kind === "text" ? t.anchor.quote : "", i = n.content.size;
137
+ if (t.from < t.to && t.to <= i && n.textBetween(t.from, t.to, " ", " ").trim().startsWith(r.slice(0, 40))) return {
138
+ from: t.from,
139
+ to: t.to
140
+ };
141
+ if (t.anchor.kind !== "text") return null;
142
+ let a = R(n).blocks.get(t.anchor.block_id);
143
+ return a ? z(a, r) : null;
144
+ }
145
+ // src/extension.ts
146
+ var U = l.create({
147
+ name: F,
148
+ inclusive: !1,
149
+ excludes: "",
150
+ spanning: !0,
151
+ addAttributes() {
152
+ return { threadId: {
153
+ default: null,
154
+ parseHTML: (e) => e.getAttribute("data-comment-thread"),
155
+ renderHTML: (e) => e.threadId ? { "data-comment-thread": e.threadId } : {}
156
+ } };
157
+ },
158
+ parseHTML() {
159
+ return [{ tag: "span[data-comment-thread]" }];
160
+ },
161
+ renderHTML({ HTMLAttributes: e }) {
162
+ return [
163
+ "span",
164
+ u(e, { class: "me-comment-mark" }),
165
+ 0
166
+ ];
167
+ },
168
+ addCommands() {
169
+ return {
170
+ setComment: (e, t) => ({ tr: n, state: r, dispatch: i }) => {
171
+ let { from: a, to: o } = t ?? r.selection;
172
+ return a !== o && (i && n.addMark(a, o, this.type.create({ threadId: e })), !0);
173
+ },
174
+ unsetComment: (e) => ({ tr: t, state: n, dispatch: r }) => {
175
+ let i = [];
176
+ if (n.doc.descendants((t, n) => {
177
+ t.isText && t.marks.some((t) => t.type === this.type && t.attrs.threadId === e) && i.push({
178
+ from: n,
179
+ to: n + t.nodeSize
180
+ });
181
+ }), !i.length) return !1;
182
+ if (r) for (let r of i) {
183
+ let i = n.doc.nodeAt(r.from)?.marks.find((t) => t.type === this.type && t.attrs.threadId === e);
184
+ i && t.removeMark(r.from, r.to, i);
185
+ }
186
+ return !0;
187
+ }
188
+ };
189
+ }
190
+ }), W = new f("comments");
191
+ function G(e, t) {
192
+ let n = [];
193
+ if (t.threads.length) {
194
+ let r = R(e);
195
+ for (let e of t.threads) for (let i of B(e, r)) n.push(p.inline(i.from, i.to, {
196
+ class: `me-comment-highlight${e.id === t.activeId ? " is-active" : ""}`,
197
+ "data-thread-id": e.id
198
+ }, { threadId: e.id }));
199
+ }
200
+ return t.draft && t.draft.from < t.draft.to && t.draft.to <= e.content.size && n.push(p.inline(t.draft.from, t.draft.to, { class: "me-comment-highlight is-active is-draft" })), m.create(e, n);
201
+ }
202
+ var K = (e) => (typeof e == "function" ? e() : ee(e) ? e.value : e) ?? "edit", q = (e) => e !== "view", J = U.extend({
203
+ addOptions: () => ({
204
+ source: null,
205
+ level: "edit",
206
+ onCompose: null,
207
+ onOpenThread: null,
208
+ messages: null
209
+ }),
210
+ addProseMirrorPlugins() {
211
+ let e = this.options, t = e.source, n = this.editor, r = () => {
212
+ if (!t) return {
213
+ threads: [],
214
+ activeId: null,
215
+ draft: null
216
+ };
217
+ let e = H(t), r = e.draft.value?.editor === n ? e.draft.value : null;
218
+ return {
219
+ threads: t.threads.value.filter((e) => !e.resolved_at),
220
+ activeId: e.activeId.value,
221
+ draft: r ? {
222
+ from: r.from,
223
+ to: r.to
224
+ } : null
225
+ };
226
+ };
227
+ return [new d({
228
+ key: W,
229
+ state: {
230
+ init: (e, t) => {
231
+ let n = r();
232
+ return {
233
+ ...n,
234
+ decorations: G(t.doc, n)
235
+ };
236
+ },
237
+ apply: (e, t, n, r) => {
238
+ let i = e.getMeta(W);
239
+ if (!i && !e.docChanged) return t;
240
+ let a = {
241
+ ...t,
242
+ ...i
243
+ };
244
+ return !i?.draft && a.draft && e.docChanged && (a.draft = {
245
+ from: e.mapping.map(a.draft.from, 1),
246
+ to: e.mapping.map(a.draft.to, -1)
247
+ }), {
248
+ ...a,
249
+ decorations: G(r.doc, a)
250
+ };
251
+ }
252
+ },
253
+ props: {
254
+ decorations: (e) => W.getState(e)?.decorations,
255
+ handleClick: (n, r) => {
256
+ let i = W.getState(n.state);
257
+ if (!i || !t) return !1;
258
+ let a = i.decorations.find(r, r, (e) => !!e.threadId)[0]?.spec.threadId;
259
+ return a && (H(t).activeId.value = a, e.onOpenThread?.(a)), !1;
260
+ }
261
+ },
262
+ view: (e) => {
263
+ if (!t) return {};
264
+ let i = H(t), a = T(!0);
265
+ return a.run(() => {
266
+ N([
267
+ () => t.threads.value.map((e) => `${e.id}:${+!!e.resolved_at}:${e.anchor.kind === "text" ? `${e.anchor.block_id}:${e.anchor.quote}` : ""}`).join("|"),
268
+ i.activeId,
269
+ () => i.draft.value?.editor === n ? i.draft.value : null
270
+ ], () => {
271
+ e.isDestroyed || e.dispatch(e.state.tr.setMeta(W, r()));
272
+ });
273
+ }), { destroy: () => a.stop() };
274
+ }
275
+ })];
276
+ }
277
+ }), Y = {
278
+ vi: {
279
+ comment: "Bình luận",
280
+ title: "Bình luận",
281
+ open: "Đang mở",
282
+ resolved: "Đã giải quyết",
283
+ resolve: "Giải quyết",
284
+ reopen: "Mở lại",
285
+ reply: "Trả lời",
286
+ replyPlaceholder: "Trả lời…",
287
+ placeholder: "Thêm bình luận… (@ để nhắc tên)",
288
+ send: "Gửi",
289
+ cancel: "Huỷ",
290
+ edit: "Sửa",
291
+ delete: "Xoá",
292
+ save: "Lưu",
293
+ edited: "đã sửa",
294
+ empty: "Chưa có bình luận nào. Chọn một đoạn văn bản để bình luận.",
295
+ emptyResolved: "Chưa có bình luận nào được giải quyết.",
296
+ threads: "{count} bình luận",
297
+ detached: "Đoạn văn bản này đã bị xoá khỏi trang",
298
+ pageComment: "Bình luận về trang",
299
+ readOnly: "Bạn chỉ có quyền xem bình luận",
300
+ failed: "Không gửi được, thử lại",
301
+ more: "Thêm"
302
+ },
303
+ en: {
304
+ comment: "Comment",
305
+ title: "Comments",
306
+ open: "Open",
307
+ resolved: "Resolved",
308
+ resolve: "Resolve",
309
+ reopen: "Re-open",
310
+ reply: "Reply",
311
+ replyPlaceholder: "Reply…",
312
+ placeholder: "Add a comment… (@ to mention)",
313
+ send: "Send",
314
+ cancel: "Cancel",
315
+ edit: "Edit",
316
+ delete: "Delete",
317
+ save: "Save",
318
+ edited: "edited",
319
+ empty: "No comments yet. Select some text to comment.",
320
+ emptyResolved: "No resolved comments.",
321
+ threads: "{count} comments",
322
+ detached: "This text was removed from the page",
323
+ pageComment: "Comment on the page",
324
+ readOnly: "You can only view comments",
325
+ failed: "Couldn’t send, try again",
326
+ more: "More"
327
+ },
328
+ zh: {
329
+ comment: "评论",
330
+ title: "评论",
331
+ open: "未解决",
332
+ resolved: "已解决",
333
+ resolve: "解决",
334
+ reopen: "重新打开",
335
+ reply: "回复",
336
+ replyPlaceholder: "回复…",
337
+ placeholder: "添加评论…(输入 @ 提及成员)",
338
+ send: "发送",
339
+ cancel: "取消",
340
+ edit: "编辑",
341
+ delete: "删除",
342
+ save: "保存",
343
+ edited: "已编辑",
344
+ empty: "暂无评论。选中文字即可评论。",
345
+ emptyResolved: "暂无已解决的评论。",
346
+ threads: "{count} 条评论",
347
+ detached: "这段文字已从页面中删除",
348
+ pageComment: "对页面的评论",
349
+ readOnly: "你只能查看评论",
350
+ failed: "发送失败,请重试",
351
+ more: "更多"
352
+ }
353
+ };
354
+ function X(e, t) {
355
+ let n = e && e in Y ? e : "vi";
356
+ return {
357
+ ...Y[n],
358
+ ...t?.[n]
359
+ };
360
+ }
361
+ // src/definition.ts
362
+ var le = o({
363
+ name: "comments",
364
+ defaults: {
365
+ source: null,
366
+ level: "edit",
367
+ onCompose: null,
368
+ onOpenThread: null,
369
+ messages: null
370
+ },
371
+ extensions: (e) => [J.configure(e)],
372
+ formatActions: (e) => [{
373
+ id: "comment",
374
+ icon: n,
375
+ readOnly: !0,
376
+ title: (t) => X(t.storage.meiConfig?.locale, e.messages).comment,
377
+ isVisible: (t) => !!e.source?.me.value && q(K(e.level)) && !!L(t.state),
378
+ run: (t) => {
379
+ if (!e.source) return;
380
+ let n = L(t.state);
381
+ n && (H(e.source).startDraft(t, n), e.onCompose?.(n));
382
+ }
383
+ }],
384
+ render: () => ({ marks: { comment: (e, t) => t } })
385
+ }), ue = { class: "me-comment-field" }, de = {
386
+ key: 0,
387
+ class: "me-comment-placeholder"
388
+ }, fe = {
389
+ key: 0,
390
+ class: "me-comment-error",
391
+ role: "alert"
392
+ }, pe = { class: "me-comment-actions" }, me = ["disabled"], Z = /* @__PURE__ */ w({
393
+ __name: "CommentComposer",
394
+ props: {
395
+ source: {},
396
+ locale: {},
397
+ m: {},
398
+ placeholder: {},
399
+ submitLabel: {},
400
+ initial: {},
401
+ autofocus: { type: Boolean },
402
+ cancellable: { type: Boolean },
403
+ send: { type: Function }
404
+ },
405
+ emits: ["cancel"],
406
+ setup(e, { expose: t, emit: n }) {
407
+ let r = e, o = n, l = O(!1), u = O(!1), d = c.create({
408
+ name: "commentKeys",
409
+ addKeyboardShortcuts: () => ({
410
+ "Mod-Enter": () => (g(), !0),
411
+ Escape: () => (r.cancellable && o("cancel"), r.cancellable)
412
+ })
413
+ }), f = A(new ae({
414
+ extensions: [
415
+ ie.configure({
416
+ heading: !1,
417
+ codeBlock: !1,
418
+ blockquote: !1,
419
+ horizontalRule: !1,
420
+ bulletList: !1,
421
+ orderedList: !1,
422
+ listItem: !1,
423
+ listKeymap: !1,
424
+ dropcursor: !1,
425
+ gapcursor: !1,
426
+ trailingNode: !1,
427
+ link: {
428
+ openOnClick: !1,
429
+ autolink: !0
430
+ }
431
+ }),
432
+ i.configure({
433
+ locale: r.locale,
434
+ messages: s(r.locale)
435
+ }),
436
+ a.configure({ search: async (e) => (await r.source.people(e)).map((e) => ({
437
+ id: e.id,
438
+ label: e.name,
439
+ kind: "user",
440
+ avatar: e.avatar ?? void 0,
441
+ description: e.description
442
+ })) }),
443
+ d
444
+ ],
445
+ content: r.initial ?? null,
446
+ autofocus: r.autofocus ? "end" : !1,
447
+ editorProps: { attributes: {
448
+ class: "me-content me-comment-input",
449
+ "aria-label": r.placeholder
450
+ } }
451
+ }));
452
+ re(() => f.value.destroy());
453
+ let p = () => {
454
+ let { doc: e } = f.value.state;
455
+ return e.textContent.trim() === "" && !h(e.toJSON());
456
+ }, m = _(p);
457
+ function h(e) {
458
+ return e.type === "mention" || !!e.content?.some(h);
459
+ }
460
+ async function g() {
461
+ if (!(l.value || p())) {
462
+ l.value = !0, u.value = !1;
463
+ try {
464
+ await r.send(f.value.getJSON()), f.value.isDestroyed || f.value.commands.clearContent(!0);
465
+ } catch (e) {
466
+ console.error("[comments]", e), u.value = !0;
467
+ } finally {
468
+ l.value = !1;
469
+ }
470
+ }
471
+ }
472
+ return t({
473
+ editor: f,
474
+ submit: g
475
+ }), (t, n) => (D(), b("div", { class: E(["me-comment-composer", { "is-busy": l.value }]) }, [
476
+ x("div", ue, [C(M(oe), { editor: f.value }, null, 8, ["editor"]), m.value ? (D(), b("span", de, j(e.placeholder), 1)) : y("", !0)]),
477
+ u.value ? (D(), b("p", fe, j(e.m.failed), 1)) : y("", !0),
478
+ x("div", pe, [e.cancellable ? (D(), b("button", {
479
+ key: 0,
480
+ type: "button",
481
+ class: "me-btn",
482
+ onClick: n[0] ||= (e) => o("cancel")
483
+ }, j(e.m.cancel), 1)) : y("", !0), x("button", {
484
+ type: "button",
485
+ class: "me-btn me-btn--primary",
486
+ disabled: l.value || m.value,
487
+ onClick: g
488
+ }, j(e.submitLabel), 9, me)])
489
+ ], 2));
490
+ }
491
+ }), he = {
492
+ "&": "&amp;",
493
+ "<": "&lt;",
494
+ ">": "&gt;",
495
+ "\"": "&quot;",
496
+ "'": "&#39;"
497
+ }, Q = (e) => String(e ?? "").replace(/[&<>"']/g, (e) => he[e]);
498
+ function ge(e) {
499
+ if (typeof e != "string" || !e.trim()) return null;
500
+ let t = /^([a-z][a-z0-9+.-]*):/i.exec(e.trim().replace(/[\u0000-\u001F\u007F\s]+/g, ""))?.[1]?.toLowerCase();
501
+ return !t || [
502
+ "http",
503
+ "https",
504
+ "mailto"
505
+ ].includes(t) ? e.trim() : null;
506
+ }
507
+ var _e = {
508
+ bold: "strong",
509
+ italic: "em",
510
+ underline: "u",
511
+ strike: "s",
512
+ code: "code"
513
+ };
514
+ function ve(e) {
515
+ if (e.type === "text") {
516
+ let t = Q(e.text);
517
+ for (let n of [...e.marks ?? []].reverse()) {
518
+ let e = _e[n.type];
519
+ if (e) t = `<${e}>${t}</${e}>`;
520
+ else if (n.type === "link") {
521
+ let e = ge(n.attrs?.href);
522
+ e && (t = `<a href="${Q(e)}" target="_blank" rel="noopener noreferrer nofollow">${t}</a>`);
523
+ }
524
+ }
525
+ return t;
526
+ }
527
+ let t = (e.content ?? []).map(ve).join("");
528
+ switch (e.type) {
529
+ case "doc": return t;
530
+ case "paragraph": return `<p>${t}</p>`;
531
+ case "hardBreak": return "<br>";
532
+ case "mention": return `<span class="me-mention me-mention--${e.attrs?.kind === "date" ? "date" : "user"}" data-type="mention" data-id="${Q(e.attrs?.id)}"><span>@${Q(e.attrs?.label ?? e.attrs?.id)}</span></span>`;
533
+ default: return t;
534
+ }
535
+ }
536
+ function ye(e, t) {
537
+ return e ? ve(e) : "";
538
+ }
539
+ var $ = /* @__PURE__ */ new Map();
540
+ function be(e, t) {
541
+ if (!e) return "";
542
+ let n = new Date(e);
543
+ if (Number.isNaN(n.getTime())) return "";
544
+ let r = $.get(t);
545
+ return r || (r = new Intl.DateTimeFormat(t === "zh" ? "zh-CN" : t, {
546
+ dateStyle: "medium",
547
+ timeStyle: "short"
548
+ }), $.set(t, r)), r.format(n);
549
+ }
550
+ var xe = (e) => e.trim().split(/\s+/).slice(-2).map((e) => e[0]?.toUpperCase() ?? "").join("") || "?", Se = { class: "me-comment" }, Ce = { class: "me-comment-head" }, we = ["src"], Te = {
551
+ key: 1,
552
+ class: "me-comment-avatar me-comment-avatar--initials",
553
+ "aria-hidden": "true"
554
+ }, Ee = { class: "me-comment-author" }, De = { class: "me-comment-meta" }, Oe = {
555
+ key: 2,
556
+ class: "me-comment-menu-anchor"
557
+ }, ke = ["title", "aria-expanded"], Ae = {
558
+ key: 0,
559
+ class: "me-popover me-menu me-comment-menu"
560
+ }, je = { class: "me-menu-title" }, Me = { class: "me-menu-title" }, Ne = ["innerHTML"], Pe = /* @__PURE__ */ w({
561
+ __name: "CommentItem",
562
+ props: {
563
+ comment: {},
564
+ source: {},
565
+ m: {},
566
+ locale: {},
567
+ canComment: { type: Boolean }
568
+ },
569
+ setup(e) {
570
+ let n = e, r = _(() => !!n.source.me.value && n.source.me.value.id === n.comment.author.id), i = O(!1), a = O(!1), o = _(() => ye(n.comment.body, n.locale));
571
+ async function s(e) {
572
+ await n.source.edit(n.comment.id, e), a.value = !1;
573
+ }
574
+ async function c() {
575
+ i.value = !1, await n.source.remove(n.comment.id);
576
+ }
577
+ return (n, l) => (D(), b("div", Se, [x("div", Ce, [
578
+ e.comment.author.avatar_url ? (D(), b("img", {
579
+ key: 0,
580
+ class: "me-comment-avatar",
581
+ src: e.comment.author.avatar_url,
582
+ alt: ""
583
+ }, null, 8, we)) : (D(), b("span", Te, j(M(xe)(e.comment.author.name)), 1)),
584
+ x("span", Ee, j(e.comment.author.name), 1),
585
+ x("span", De, [S(j(M(be)(e.comment.created_at, e.locale)), 1), e.comment.edited_at ? (D(), b(h, { key: 0 }, [S(" · " + j(e.m.edited), 1)], 64)) : y("", !0)]),
586
+ r.value && e.canComment && !a.value ? (D(), b("span", Oe, [x("button", {
587
+ type: "button",
588
+ class: "me-tool-btn me-comment-more",
589
+ title: e.m.more,
590
+ "aria-expanded": i.value,
591
+ onClick: l[0] ||= (e) => i.value = !i.value
592
+ }, [C(M(t))], 8, ke), i.value ? (D(), b("span", Ae, [x("button", {
593
+ type: "button",
594
+ class: "me-menu-item",
595
+ onClick: l[1] ||= (e) => {
596
+ a.value = !0, i.value = !1;
597
+ }
598
+ }, [x("span", je, j(e.m.edit), 1)]), x("button", {
599
+ type: "button",
600
+ class: "me-menu-item me-menu-item--danger",
601
+ onClick: c
602
+ }, [x("span", Me, j(e.m.delete), 1)])])) : y("", !0)])) : y("", !0)
603
+ ]), a.value ? (D(), v(Z, {
604
+ key: 0,
605
+ source: e.source,
606
+ locale: e.locale,
607
+ m: e.m,
608
+ placeholder: e.m.placeholder,
609
+ "submit-label": e.m.save,
610
+ initial: e.comment.body,
611
+ send: s,
612
+ autofocus: "",
613
+ cancellable: "",
614
+ onCancel: l[2] ||= (e) => a.value = !1
615
+ }, null, 8, [
616
+ "source",
617
+ "locale",
618
+ "m",
619
+ "placeholder",
620
+ "submit-label",
621
+ "initial"
622
+ ])) : (D(), b("div", {
623
+ key: 1,
624
+ class: "me-content me-comment-body",
625
+ innerHTML: o.value
626
+ }, null, 8, Ne))]));
627
+ }
628
+ }), Fe = ["data-thread-id"], Ie = { class: "me-comment-thread-head" }, Le = ["title"], Re = ["title"], ze = /* @__PURE__ */ w({
629
+ __name: "ThreadCard",
630
+ props: {
631
+ thread: {},
632
+ source: {},
633
+ m: {},
634
+ locale: {},
635
+ canComment: { type: Boolean },
636
+ active: { type: Boolean },
637
+ detached: { type: Boolean }
638
+ },
639
+ emits: ["select"],
640
+ setup(t, { emit: n }) {
641
+ let i = t, a = n, o = _(() => !!i.thread.resolved_at), s = _(() => i.thread.anchor.kind === "text" ? i.thread.anchor.quote : i.thread.anchor.kind === "page" ? i.m.pageComment : ""), c = (e) => i.source.reply(i.thread.id, e), l = () => i.source.resolve(i.thread.id, !o.value);
642
+ return (n, i) => (D(), b("article", {
643
+ class: E(["me-comment-thread", {
644
+ "is-active": t.active,
645
+ "is-resolved": o.value
646
+ }]),
647
+ "data-thread-id": t.thread.id,
648
+ onClick: i[1] ||= (e) => a("select")
649
+ }, [
650
+ x("div", Ie, [s.value ? (D(), b("blockquote", {
651
+ key: 0,
652
+ class: E(["me-comment-quote", { "is-detached": t.detached }]),
653
+ title: t.detached ? t.m.detached : void 0
654
+ }, j(s.value), 11, Le)) : y("", !0), t.canComment ? (D(), b("button", {
655
+ key: 1,
656
+ type: "button",
657
+ class: "me-tool-btn me-comment-resolve",
658
+ title: o.value ? t.m.reopen : t.m.resolve,
659
+ onClick: P(l, ["stop"])
660
+ }, [o.value ? (D(), v(M(r), { key: 0 })) : (D(), v(M(e), { key: 1 }))], 8, Re)) : y("", !0)]),
661
+ (D(!0), b(h, null, k(t.thread.comments, (e) => (D(), v(Pe, {
662
+ key: e.id,
663
+ comment: e,
664
+ source: t.source,
665
+ m: t.m,
666
+ locale: t.locale,
667
+ "can-comment": t.canComment
668
+ }, null, 8, [
669
+ "comment",
670
+ "source",
671
+ "m",
672
+ "locale",
673
+ "can-comment"
674
+ ]))), 128)),
675
+ t.active && t.canComment && !o.value && t.source.me.value ? (D(), v(Z, {
676
+ key: 0,
677
+ source: t.source,
678
+ locale: t.locale,
679
+ m: t.m,
680
+ placeholder: t.m.replyPlaceholder,
681
+ "submit-label": t.m.reply,
682
+ send: c,
683
+ onClick: i[0] ||= P(() => {}, ["stop"])
684
+ }, null, 8, [
685
+ "source",
686
+ "locale",
687
+ "m",
688
+ "placeholder",
689
+ "submit-label"
690
+ ])) : y("", !0)
691
+ ], 10, Fe));
692
+ }
693
+ }), Be = ["aria-label"], Ve = { class: "me-comments-header" }, He = { class: "me-comments-title" }, Ue = {
694
+ class: "me-tabs me-tabs--inline me-comments-tabs",
695
+ role: "tablist"
696
+ }, We = ["aria-selected"], Ge = { class: "me-comments-count" }, Ke = ["aria-selected"], qe = { class: "me-comments-count" }, Je = {
697
+ key: 0,
698
+ class: "me-comment-thread is-active is-draft"
699
+ }, Ye = {
700
+ key: 0,
701
+ class: "me-comment-quote"
702
+ }, Xe = {
703
+ key: 1,
704
+ class: "me-hint me-comments-hint"
705
+ }, Ze = {
706
+ key: 2,
707
+ class: "me-hint me-comments-empty"
708
+ }, Qe = /* @__PURE__ */ w({
709
+ __name: "CommentsPanel",
710
+ props: {
711
+ source: {},
712
+ editor: { default: null },
713
+ level: { default: "edit" },
714
+ locale: { default: "vi" },
715
+ messages: { default: void 0 }
716
+ },
717
+ setup(e) {
718
+ let t = e, n = _(() => X(t.locale, t.messages)), r = H(t.source), i = _(() => q(K(t.level)) && !!t.source.me.value), a = _(() => r.draft.value), o = A(0), s = null;
719
+ N(() => t.editor, (e) => {
720
+ if (s?.(), s = null, !e) return;
721
+ let t = () => o.value++;
722
+ e.on("update", t), s = () => e.off("update", t);
723
+ }, { immediate: !0 });
724
+ let c = _(() => {
725
+ o.value;
726
+ let e = /* @__PURE__ */ new Map(), n = t.editor;
727
+ if (!n || n.isDestroyed) return e;
728
+ let r = R(n.state.doc);
729
+ for (let n of t.source.threads.value) {
730
+ let t = B(n, r)[0];
731
+ t && e.set(n.id, t.from);
732
+ }
733
+ return e;
734
+ }), l = _(() => {
735
+ let e = t.source.threads.value;
736
+ if (r.filter.value === "resolved") return e.filter((e) => e.resolved_at).sort((e, t) => (t.resolved_at ?? "").localeCompare(e.resolved_at ?? ""));
737
+ let n = c.value, i = 2 ** 53 - 1;
738
+ return e.filter((e) => !e.resolved_at).sort((e, t) => (n.get(e.id) ?? i) - (n.get(t.id) ?? i) || (e.comments[0]?.created_at ?? "").localeCompare(t.comments[0]?.created_at ?? ""));
739
+ }), u = _(() => t.source.threads.value.filter((e) => !e.resolved_at).length), d = _(() => t.source.threads.value.length - u.value);
740
+ function f(e) {
741
+ r.activeId.value = e.id;
742
+ let n = t.editor, i = c.value.get(e.id);
743
+ if (!n || i === void 0 || n.isDestroyed) return;
744
+ let a = n.view.domAtPos(i).node;
745
+ (a.nodeType === 1 ? a : a.parentElement)?.scrollIntoView?.({
746
+ behavior: "smooth",
747
+ block: "center"
748
+ });
749
+ }
750
+ let p = A(null);
751
+ N(r.activeId, (e) => {
752
+ if (!e) return;
753
+ let n = t.source.threads.value.find((t) => t.id === e);
754
+ n && (r.filter.value = n.resolved_at ? "resolved" : "open"), te(() => p.value?.querySelector(`[data-thread-id="${CSS.escape(e)}"]`)?.scrollIntoView?.({ block: "nearest" }));
755
+ });
756
+ let m = (e) => r.submitDraft(e);
757
+ return (t, o) => (D(), b("aside", {
758
+ ref_key: "root",
759
+ ref: p,
760
+ class: "me-scope me-comments-panel",
761
+ "aria-label": n.value.title
762
+ }, [
763
+ x("header", Ve, [x("h2", He, j(n.value.title), 1), x("div", Ue, [x("button", {
764
+ type: "button",
765
+ role: "tab",
766
+ class: E(["me-tab", { "is-active": M(r).filter.value === "open" }]),
767
+ "aria-selected": M(r).filter.value === "open",
768
+ onClick: o[0] ||= (e) => M(r).filter.value = "open"
769
+ }, [S(j(n.value.open) + " ", 1), x("span", Ge, j(u.value), 1)], 10, We), x("button", {
770
+ type: "button",
771
+ role: "tab",
772
+ class: E(["me-tab", { "is-active": M(r).filter.value === "resolved" }]),
773
+ "aria-selected": M(r).filter.value === "resolved",
774
+ onClick: o[1] ||= (e) => M(r).filter.value = "resolved"
775
+ }, [S(j(n.value.resolved) + " ", 1), x("span", qe, j(d.value), 1)], 10, Ke)])]),
776
+ a.value && i.value ? (D(), b("div", Je, [a.value.anchor.kind === "text" ? (D(), b("blockquote", Ye, j(a.value.anchor.quote), 1)) : y("", !0), (D(), v(Z, {
777
+ key: a.value.key,
778
+ source: e.source,
779
+ locale: e.locale,
780
+ m: n.value,
781
+ placeholder: n.value.placeholder,
782
+ "submit-label": n.value.send,
783
+ send: m,
784
+ autofocus: "",
785
+ cancellable: "",
786
+ onCancel: o[2] ||= (e) => M(r).cancelDraft()
787
+ }, null, 8, [
788
+ "source",
789
+ "locale",
790
+ "m",
791
+ "placeholder",
792
+ "submit-label"
793
+ ]))])) : y("", !0),
794
+ !i.value && e.source.me.value && M(K)(e.level) === "view" ? (D(), b("p", Xe, j(n.value.readOnly), 1)) : y("", !0),
795
+ (D(!0), b(h, null, k(l.value, (t) => (D(), v(ze, {
796
+ key: t.id,
797
+ thread: t,
798
+ source: e.source,
799
+ m: n.value,
800
+ locale: e.locale,
801
+ "can-comment": i.value,
802
+ active: M(r).activeId.value === t.id,
803
+ detached: !!e.editor && t.anchor.kind === "text" && !c.value.has(t.id),
804
+ onSelect: (e) => f(t)
805
+ }, null, 8, [
806
+ "thread",
807
+ "source",
808
+ "m",
809
+ "locale",
810
+ "can-comment",
811
+ "active",
812
+ "detached",
813
+ "onSelect"
814
+ ]))), 128)),
815
+ !l.value.length && !a.value ? (D(), b("p", Ze, j(M(r).filter.value === "open" ? n.value.empty : n.value.emptyResolved), 1)) : y("", !0)
816
+ ], 8, Be));
817
+ }
818
+ }), $e = { class: "me-comments-gutter" }, et = [
819
+ "title",
820
+ "aria-label",
821
+ "data-block-id",
822
+ "onClick"
823
+ ], tt = /* @__PURE__ */ w({
824
+ __name: "CommentsGutter",
825
+ props: {
826
+ editor: {},
827
+ source: {},
828
+ locale: { default: "vi" },
829
+ messages: { default: void 0 }
830
+ },
831
+ emits: ["open"],
832
+ setup(e, { emit: t }) {
833
+ let r = e, i = t, a = _(() => X(r.locale, r.messages)), o = H(r.source), s = A([]), c = A(null), l = 0;
834
+ function u() {
835
+ cancelAnimationFrame(l), l = requestAnimationFrame(d);
836
+ }
837
+ function d() {
838
+ let e = r.editor;
839
+ if (!e || e.isDestroyed || !e.view?.dom?.isConnected) {
840
+ s.value = [];
841
+ return;
842
+ }
843
+ let t = e.view.dom.closest(".me-root") ?? e.view.dom.parentElement;
844
+ if (c.value = t, !t) return;
845
+ let n = /* @__PURE__ */ new Map();
846
+ for (let e of r.source.threads.value) {
847
+ let t = !e.resolved_at && se(e);
848
+ t && n.set(t, [...n.get(t) ?? [], e]);
849
+ }
850
+ if (!n.size) {
851
+ s.value = [];
852
+ return;
853
+ }
854
+ let { blocks: i } = R(e.state.doc), a = t.getBoundingClientRect().top, o = [];
855
+ for (let [t, r] of n) {
856
+ let n = i.get(t), s = n && e.view.nodeDOM(n.pos);
857
+ s instanceof HTMLElement && o.push({
858
+ blockId: t,
859
+ top: s.getBoundingClientRect().top - a,
860
+ threads: r
861
+ });
862
+ }
863
+ s.value = o.sort((e, t) => e.top - t.top);
864
+ }
865
+ let f = null, p = null;
866
+ N(() => r.editor, (e) => {
867
+ p?.(), f?.disconnect(), p = null, e && (e.on("update", u), e.on("create", u), p = () => {
868
+ e.off("update", u), e.off("create", u);
869
+ }, typeof ResizeObserver < "u" && e.view?.dom && (f = new ResizeObserver(u), f.observe(e.view.dom)), u());
870
+ }, { immediate: !0 }), N(() => r.source.threads.value.map((e) => `${e.id}:${+!!e.resolved_at}`).join("|"), u), typeof window < "u" && window.addEventListener("resize", u), re(() => {
871
+ p?.(), f?.disconnect(), cancelAnimationFrame(l), typeof window < "u" && window.removeEventListener("resize", u);
872
+ });
873
+ function m(e) {
874
+ o.activeId.value = e.threads[0].id, i("open", e.threads.map((e) => e.id));
875
+ }
876
+ let w = (e) => e.threads.some((e) => e.id === o.activeId.value), T = (e) => a.value.threads.replace("{count}", String(e.threads.length));
877
+ return (e, t) => c.value ? (D(), v(g, {
878
+ key: 0,
879
+ to: c.value
880
+ }, [x("div", $e, [(D(!0), b(h, null, k(s.value, (e) => (D(), b("button", {
881
+ key: e.blockId,
882
+ type: "button",
883
+ class: E(["me-comments-badge", { "is-active": w(e) }]),
884
+ style: ne({ top: `${e.top}px` }),
885
+ title: T(e),
886
+ "aria-label": T(e),
887
+ "data-block-id": e.blockId,
888
+ onMousedown: t[0] ||= P(() => {}, ["prevent"]),
889
+ onClick: (t) => m(e)
890
+ }, [C(M(n)), S(" " + j(e.threads.length), 1)], 46, et))), 128))])], 8, ["to"])) : y("", !0);
891
+ }
892
+ });
893
+ export { F as COMMENT_MARK, Z as CommentComposer, U as CommentMark, J as CommentsExtension, tt as CommentsGutter, Qe as CommentsPanel, I as blockIdAt, ye as bodyHtml, q as canComment, le as comments, X as commentsMessages, W as commentsPluginKey, z as findQuote, R as indexDocument, K as levelOf, Y as messages, L as selectionAnchor, B as threadRanges, H as useCommentsState };
894
+
895
+ //# sourceMappingURL=index.js.map