@toantranmei/comments 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_openBlock","_createElementBlock","_normalizeClass","_createElementVNode","_createVNode","_unref","_toDisplayString","_createCommentVNode","_sfc_main","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_openBlock","_createElementBlock","_createElementVNode","_toDisplayString","_unref","_createTextVNode","_Fragment","_createCommentVNode","_createVNode","_createBlock","CommentComposer","_sfc_main","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_openBlock","_createElementBlock","_normalizeClass","_createElementVNode","_toDisplayString","_createCommentVNode","_withModifiers","_createBlock","_unref","_Fragment","_renderList","CommentItem","CommentComposer","_sfc_main","_hoisted_1","_hoisted_2","canComment","canCommentAt","_openBlock","_createElementBlock","_createElementVNode","_toDisplayString","_normalizeClass","_unref","_createTextVNode","_createCommentVNode","_createBlock","CommentComposer","_Fragment","_renderList","ThreadCard","_sfc_main","_openBlock","_createBlock","_Teleport","_createElementVNode","_createElementBlock","_Fragment","_renderList","_normalizeClass","_normalizeStyle","_withModifiers","_createVNode","_unref","_createTextVNode","_toDisplayString","_createCommentVNode","_sfc_main","StarterKit","COMMENT_MARK","blockIdAt","$pos","state","pos","d","id","selectionAnchor","empty","blockId","from","end","$from","to","quote","indexDocument","marks","blocks","doc","node","mark","list","last","findQuote","found","search","text","positions","child","i","start","offset","at","block","threadRanges","marked","index","thread","a","range","threadBlockId","states","useCommentsState","source","activeId","ref","draft","shallowRef","filter","stopMapping","drafts","track","editor","b","onTransaction","transaction","cancelDraft","startDraft","submitDraft","body","current","\"comment\"","draftRange","tr","size","CommentMark","Mark","el","attrs","mergeAttributes","HTMLAttributes","dispatch","ranges","m","threadId","commentsPluginKey","PluginKey","decorate","decos","s","r","Decoration","\"class\"","DecorationSet","levelOf","level","isRef","canComment","CommentsExtension","options","t","Plugin","meta","value","next","view","spec","scope","effectScope","messages","commentsMessages","key","locale","overrides","comments","defineBlock","o","MessageSquareText","inner","_hoisted_1$4","_hoisted_2$4","_hoisted_3$3","_hoisted_4$3","_hoisted_5$2","CommentComposer_default","defineComponent","__expose","__emit","props","__props","emit","busy","error","Keys","Extension","submit","\"Escape\"","Editor","MeiConfig","resolveMessages","MentionNode","query","p","isEmpty","hasMention","computed","openBlock","createElementBlock","normalizeClass","createElementVNode","createVNode","unref","EditorContent","toDisplayString","createCommentVNode","_cache","ESC","esc","v","c","safeHref","url","scheme","MARKS","n","out","tag","href","bodyHtml","formatters","formatTime","iso","date","f","initials","name","w","_hoisted_1$3","_hoisted_2$3","_hoisted_3$2","_hoisted_4$2","_hoisted_5$1","_hoisted_6$1","_hoisted_7$1","_hoisted_8$1","_hoisted_9$1","_hoisted_10$1","_hoisted_11$1","_hoisted_12$1","CommentItem_default","own","menu","editing","html","save","remove","createTextVNode","Fragment","Ellipsis","createBlock","_hoisted_1$2","_hoisted_2$2","_hoisted_3$1","_hoisted_4$1","ThreadCard_default","resolved","reply","toggleResolved","withModifiers","RotateCcw","Check","renderList","_hoisted_1$1","_hoisted_2$1","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","CommentsPanel_default","canComment$1","version","off","bump","map","visible","openCount","resolvedCount","select","dom","root","nextTick","createThread","_hoisted_1","_hoisted_2","CommentsGutter_default","badges","target","frame","schedule","measure","byBlock","rootTop","threads","observer","watch","onBeforeUnmount","open","badge","isActive","label","Teleport","normalizeStyle"],"sources":["../src/anchor.ts","../src/store.ts","../src/extension.ts","../src/messages.ts","../src/definition.ts","../src/CommentComposer.vue","../src/CommentComposer.vue","../src/format.ts","../src/CommentItem.vue","../src/CommentItem.vue","../src/ThreadCard.vue","../src/ThreadCard.vue","../src/CommentsPanel.vue","../src/CommentsPanel.vue","../src/CommentsGutter.vue","../src/CommentsGutter.vue"],"sourcesContent":["import type { Node as PMNode } from '@tiptap/pm/model'\nimport type { EditorState } from '@tiptap/pm/state'\nimport type { Anchor, Thread } from './types'\n\n/** Longest quote kept in an anchor. */\nexport const MAX_QUOTE = 500\nexport const COMMENT_MARK = 'comment'\n\n/** Id (`data-id`) of the innermost block around `pos` that has one. */\nexport function blockIdAt(state: EditorState, pos: number): string | null {\n const $pos = state.doc.resolve(pos)\n for (let d = $pos.depth; d > 0; d--) {\n const id = $pos.node(d).attrs.id\n if (typeof id === 'string' && id) return id\n }\n return null\n}\n\n/**\n * Anchor for the current text selection: the first block's id and the selected text.\n * Comment-only users can't change the document, so the anchor is all that identifies the\n * text; the quote is limited to the first block so it can be found again by search.\n */\nexport function selectionAnchor(state: EditorState): { anchor: Anchor, from: number, to: number } | null {\n const { from, to, empty, $from } = state.selection\n if (empty) return null\n const blockId = blockIdAt(state, from)\n if (!blockId) return null\n // Within the first textblock (comment-only anchors are found by searching that block).\n const end = $from.parent.isTextblock ? Math.min(to, $from.end()) : to\n const quote = state.doc.textBetween(from, Math.max(from, end), ' ', ' ').trim().slice(0, MAX_QUOTE)\n if (!quote) return null\n return { anchor: { kind: 'text', block_id: blockId, quote }, from, to }\n}\n\nexport interface AnchorIndex {\n /** Ranges of `comment` marks, per thread id. */\n marks: Map<string, { from: number, to: number }[]>\n /** Blocks with an id: position and node. */\n blocks: Map<string, { pos: number, node: PMNode }>\n}\n\n/** One pass over the document: comment-mark ranges and block positions. */\nexport function indexDocument(doc: PMNode): AnchorIndex {\n const marks = new Map<string, { from: number, to: number }[]>()\n const blocks = new Map<string, { pos: number, node: PMNode }>()\n doc.descendants((node, pos) => {\n const id = node.attrs?.id\n if (typeof id === 'string' && id && !node.isText) blocks.set(id, { pos, node })\n if (node.isText) {\n for (const mark of node.marks) {\n if (mark.type.name !== COMMENT_MARK || !mark.attrs.threadId) continue\n const list = marks.get(mark.attrs.threadId) ?? []\n const last = list[list.length - 1]\n if (last && last.to === pos) last.to = pos + node.nodeSize\n else list.push({ from: pos, to: pos + node.nodeSize })\n marks.set(mark.attrs.threadId, list)\n }\n }\n return true\n })\n return { marks, blocks }\n}\n\n/** Finds `quote` in a textblock (or the first textblock containing it inside a block). */\nexport function findQuote(block: { pos: number, node: PMNode }, quote: string): { from: number, to: number } | null {\n if (!quote) return null\n let found: { from: number, to: number } | null = null\n const search = (node: PMNode, start: number) => {\n if (found) return\n if (node.isTextblock) {\n // Text offsets → document positions (inline atoms count as one char of \"\").\n let text = ''\n const positions: number[] = []\n node.forEach((child, offset) => {\n if (child.isText) {\n for (let i = 0; i < child.text!.length; i++) positions.push(start + 1 + offset + i)\n text += child.text\n }\n else {\n positions.push(start + 1 + offset)\n text += ''\n }\n })\n const at = text.indexOf(quote)\n if (at >= 0) found = { from: positions[at]!, to: positions[at + quote.length - 1]! + 1 }\n return\n }\n node.forEach((child, offset) => search(child, start + 1 + offset))\n }\n search(block.node, block.pos)\n return found\n}\n\n/** Document ranges to highlight for a thread: its marks, else its quote searched in its block. */\nexport function threadRanges(thread: Thread, index: AnchorIndex): { from: number, to: number }[] {\n const marked = index.marks.get(thread.id)\n if (marked?.length) return marked\n const a = thread.anchor\n if (a.kind !== 'text') return []\n const block = index.blocks.get(a.block_id)\n const range = block && findQuote(block, a.quote)\n return range ? [range] : []\n}\n\n/** Block id a thread belongs to (gutter), or null for page comments. */\nexport const threadBlockId = (thread: Thread) => (thread.anchor.kind === 'page' ? null : thread.anchor.block_id)\n","import type { Editor } from '@tiptap/core'\nimport { type Ref, ref, type ShallowRef, shallowRef } from 'vue'\nimport { COMMENT_MARK, findQuote, indexDocument } from './anchor'\nimport type { CommentDraft, CommentsSource, Thread } from './types'\n\nexport interface ActiveDraft extends CommentDraft {\n editor: Editor\n /** Stable per draft (ranges change as the document is edited). */\n key: number\n}\n\n/** UI state shared by the editor extension, the gutter and the panel of one source. */\nexport interface CommentsState {\n /** Thread shown / highlighted (clicked highlight or badge, or picked in the panel). */\n activeId: Ref<string | null>\n /** Comment being written for a selection. */\n draft: ShallowRef<ActiveDraft | null>\n /** Panel filter. */\n filter: Ref<'open' | 'resolved'>\n startDraft: (editor: Editor, draft: CommentDraft) => void\n cancelDraft: () => void\n /** Saves the draft as a new thread; editors also get the `comment` mark on the text. */\n submitDraft: (body: Parameters<CommentsSource['create']>[1]) => Promise<Thread | null>\n}\n\nconst states = new WeakMap<CommentsSource, CommentsState>()\n\n/** The shared state of a source (created on first use). */\nexport function useCommentsState(source: CommentsSource): CommentsState {\n let state = states.get(source)\n if (state) return state\n\n const activeId = ref<string | null>(null)\n const draft = shallowRef<ActiveDraft | null>(null)\n const filter = ref<'open' | 'resolved'>('open')\n let stopMapping: (() => void) | null = null\n let drafts = 0\n\n // Keep the draft's range in step with edits made while the comment is written. The\n // editor's mappable positions follow remote Yjs changes too (they rebuild the document).\n function track(editor: Editor, from: number, to: number) {\n let a = editor.utils.createMappablePosition(from)\n let b = editor.utils.createMappablePosition(to)\n const onTransaction = ({ transaction }: { transaction: Parameters<Editor['utils']['getUpdatedPosition']>[1] }) => {\n const d = draft.value\n if (!d || !transaction.docChanged) return\n a = editor.utils.getUpdatedPosition(a, transaction).position\n b = editor.utils.getUpdatedPosition(b, transaction).position\n draft.value = { ...d, from: a.position, to: b.position }\n }\n editor.on('transaction', onTransaction)\n return () => editor.off('transaction', onTransaction)\n }\n\n function cancelDraft() {\n stopMapping?.()\n stopMapping = null\n draft.value = null\n }\n\n function startDraft(editor: Editor, d: CommentDraft) {\n cancelDraft()\n draft.value = { ...d, editor, key: ++drafts }\n stopMapping = track(editor, d.from, d.to)\n activeId.value = null\n }\n\n async function submitDraft(body: Parameters<CommentsSource['create']>[1]) {\n const d = draft.value\n if (!d) return null\n const thread = await source.create(d.anchor, body)\n const current = draft.value\n cancelDraft()\n const { editor } = current ?? d\n // Editors mark the text (synced through Yjs in collaboration mode). Comment-only users\n // can't change the document: their anchor (block id + quote) is all that's stored.\n if (thread && editor.isEditable && !editor.isDestroyed && editor.schema.marks[COMMENT_MARK]) {\n const range = draftRange(editor, current ?? d)\n if (range) {\n const tr = editor.state.tr.addMark(range.from, range.to, editor.schema.marks[COMMENT_MARK]!.create({ threadId: thread.id }))\n editor.view.dispatch(tr.setMeta('addToHistory', false))\n }\n }\n if (thread) activeId.value = thread.id\n return thread\n }\n\n state = { activeId, draft, filter, startDraft, cancelDraft, submitDraft }\n states.set(source, state)\n return state\n}\n\n/**\n * The draft's text now: its mapped range when it still holds the quote, else the quote\n * searched in its block (remote edits can rebuild the document in collaboration mode).\n */\nfunction draftRange(editor: Editor, d: CommentDraft): { from: number, to: number } | null {\n const { doc } = editor.state\n const quote = d.anchor.kind === 'text' ? d.anchor.quote : ''\n const size = doc.content.size\n if (d.from < d.to && d.to <= size && doc.textBetween(d.from, d.to, ' ', ' ').trim().startsWith(quote.slice(0, 40))) return { from: d.from, to: d.to }\n if (d.anchor.kind !== 'text') return null\n const block = indexDocument(doc).blocks.get(d.anchor.block_id)\n return block ? findQuote(block, quote) : null\n}\n","import { type Editor, Mark, mergeAttributes } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\nimport { effectScope, isRef, watch } from 'vue'\nimport { COMMENT_MARK, indexDocument, threadRanges } from './anchor'\nimport { useCommentsState } from './store'\nimport type { CommentsLevel, CommentsOptions, Thread } from './types'\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n comment: {\n /** Marks the selection (or `range`) as commented by `threadId`. */\n setComment: (threadId: string, range?: { from: number, to: number }) => ReturnType\n /** Removes a thread's marks from the whole document. */\n unsetComment: (threadId: string) => ReturnType\n }\n }\n}\n\n/**\n * `comment` mark: `threadId` on the commented text. Not inclusive (typing at its edges\n * isn't commented) and overlapping threads can share text. Works in collaboration mode\n * (marks are synced through the Yjs document).\n */\nexport const CommentMark = Mark.create({\n name: COMMENT_MARK,\n inclusive: false,\n excludes: '',\n spanning: true,\n\n addAttributes() {\n return {\n threadId: {\n default: null,\n parseHTML: el => el.getAttribute('data-comment-thread'),\n renderHTML: attrs => (attrs.threadId ? { 'data-comment-thread': attrs.threadId } : {}),\n },\n }\n },\n\n parseHTML() {\n return [{ tag: 'span[data-comment-thread]' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['span', mergeAttributes(HTMLAttributes, { class: 'me-comment-mark' }), 0]\n },\n\n addCommands() {\n return {\n setComment: (threadId, range) => ({ tr, state, dispatch }) => {\n const { from, to } = range ?? state.selection\n if (from === to) return false\n if (dispatch) tr.addMark(from, to, this.type.create({ threadId }))\n return true\n },\n unsetComment: threadId => ({ tr, state, dispatch }) => {\n const ranges: { from: number, to: number }[] = []\n state.doc.descendants((node, pos) => {\n if (node.isText && node.marks.some(m => m.type === this.type && m.attrs.threadId === threadId)) ranges.push({ from: pos, to: pos + node.nodeSize })\n })\n if (!ranges.length) return false\n if (dispatch) {\n for (const r of ranges) {\n const mark = state.doc.nodeAt(r.from)?.marks.find(m => m.type === this.type && m.attrs.threadId === threadId)\n if (mark) tr.removeMark(r.from, r.to, mark)\n }\n }\n return true\n },\n }\n },\n})\n\nexport const commentsPluginKey = new PluginKey<HighlightState>('comments')\n\ninterface HighlightState {\n threads: Thread[]\n activeId: string | null\n draft: { from: number, to: number } | null\n decorations: DecorationSet\n}\n\ntype Meta = Partial<Pick<HighlightState, 'threads' | 'activeId' | 'draft'>>\n\nfunction decorate(doc: Parameters<typeof DecorationSet.create>[0], s: Omit<HighlightState, 'decorations'>): DecorationSet {\n const decos: Decoration[] = []\n if (s.threads.length) {\n const index = indexDocument(doc)\n for (const thread of s.threads) {\n for (const r of threadRanges(thread, index)) {\n decos.push(Decoration.inline(r.from, r.to, {\n 'class': `me-comment-highlight${thread.id === s.activeId ? ' is-active' : ''}`,\n 'data-thread-id': thread.id,\n }, { threadId: thread.id }))\n }\n }\n }\n if (s.draft && s.draft.from < s.draft.to && s.draft.to <= doc.content.size) {\n decos.push(Decoration.inline(s.draft.from, s.draft.to, { class: 'me-comment-highlight is-active is-draft' }))\n }\n return DecorationSet.create(doc, decos)\n}\n\nexport const levelOf = (level: CommentsOptions['level']): CommentsLevel =>\n (typeof level === 'function' ? level() : isRef(level) ? level.value : level) ?? 'edit'\n\n/** True when this level may add comments and replies. */\nexport const canComment = (level: CommentsLevel) => level !== 'view'\n\n/**\n * Highlights open threads (their marks, or the quote of comment-only anchors), the active\n * thread and the draft; clicking a highlight opens its thread.\n */\nexport const CommentsExtension = CommentMark.extend<CommentsOptions>({\n addOptions: () => ({ source: null, level: 'edit', onCompose: null, onOpenThread: null, messages: null }),\n\n addProseMirrorPlugins() {\n const options = this.options\n const source = options.source\n const editor = this.editor as Editor\n const current = (): Omit<HighlightState, 'decorations'> => {\n if (!source) return { threads: [], activeId: null, draft: null }\n const state = useCommentsState(source)\n const draft = state.draft.value?.editor === editor ? state.draft.value : null\n return {\n threads: source.threads.value.filter(t => !t.resolved_at),\n activeId: state.activeId.value,\n draft: draft ? { from: draft.from, to: draft.to } : null,\n }\n }\n return [\n new Plugin<HighlightState>({\n key: commentsPluginKey,\n state: {\n init: (_, state) => {\n const s = current()\n return { ...s, decorations: decorate(state.doc, s) }\n },\n apply: (tr, value, _old, state) => {\n const meta = tr.getMeta(commentsPluginKey) as Meta | undefined\n if (!meta && !tr.docChanged) return value\n const next = { ...value, ...meta }\n if (!meta?.draft && next.draft && tr.docChanged) next.draft = { from: tr.mapping.map(next.draft.from, 1), to: tr.mapping.map(next.draft.to, -1) }\n return { ...next, decorations: decorate(state.doc, next) }\n },\n },\n props: {\n decorations: state => commentsPluginKey.getState(state)?.decorations,\n handleClick: (view, pos) => {\n const s = commentsPluginKey.getState(view.state)\n if (!s || !source) return false\n const id = s.decorations.find(pos, pos, spec => !!spec.threadId)[0]?.spec.threadId as string | undefined\n if (!id) return false\n useCommentsState(source).activeId.value = id\n options.onOpenThread?.(id)\n return false\n },\n },\n // Follow the source: threads, the active thread and this editor's draft.\n view: (view) => {\n if (!source) return {}\n const state = useCommentsState(source)\n const scope = effectScope(true)\n scope.run(() => {\n watch(\n // Signatures, so adapters may replace or mutate threads in place.\n [\n () => source.threads.value.map(t => `${t.id}:${t.resolved_at ? 1 : 0}:${t.anchor.kind === 'text' ? `${t.anchor.block_id}:${t.anchor.quote}` : ''}`).join('|'),\n state.activeId,\n () => (state.draft.value?.editor === editor ? state.draft.value : null),\n ],\n () => {\n if (!view.isDestroyed) view.dispatch(view.state.tr.setMeta(commentsPluginKey, current() satisfies Meta))\n },\n )\n })\n return { destroy: () => scope.stop() }\n },\n }),\n ]\n },\n\n})\n","import type { LocaleName } from '@toantranmei/editor'\n\nexport interface CommentsMessages {\n /** Bubble-menu action. */\n comment: string\n /** Panel title. */\n title: string\n open: string\n resolved: string\n resolve: string\n reopen: string\n reply: string\n replyPlaceholder: string\n placeholder: string\n send: string\n cancel: string\n edit: string\n delete: string\n save: string\n edited: string\n /** No open threads. */\n empty: string\n emptyResolved: string\n /** Gutter badge label: `{count}` is replaced. */\n threads: string\n /** Thread whose text was deleted from the page. */\n detached: string\n /** Comment on the whole page. */\n pageComment: string\n readOnly: string\n failed: string\n /** More actions on a comment. */\n more: string\n}\n\nexport const messages: Record<LocaleName, CommentsMessages> = {\n vi: {\n comment: 'Bình luận',\n title: 'Bình luận',\n open: 'Đang mở',\n resolved: 'Đã giải quyết',\n resolve: 'Giải quyết',\n reopen: 'Mở lại',\n reply: 'Trả lời',\n replyPlaceholder: 'Trả lời…',\n placeholder: 'Thêm bình luận… (@ để nhắc tên)',\n send: 'Gửi',\n cancel: 'Huỷ',\n edit: 'Sửa',\n delete: 'Xoá',\n save: 'Lưu',\n edited: 'đã sửa',\n empty: 'Chưa có bình luận nào. Chọn một đoạn văn bản để bình luận.',\n emptyResolved: 'Chưa có bình luận nào được giải quyết.',\n threads: '{count} bình luận',\n detached: 'Đoạn văn bản này đã bị xoá khỏi trang',\n pageComment: 'Bình luận về trang',\n readOnly: 'Bạn chỉ có quyền xem bình luận',\n failed: 'Không gửi được, thử lại',\n more: 'Thêm',\n },\n en: {\n comment: 'Comment',\n title: 'Comments',\n open: 'Open',\n resolved: 'Resolved',\n resolve: 'Resolve',\n reopen: 'Re-open',\n reply: 'Reply',\n replyPlaceholder: 'Reply…',\n placeholder: 'Add a comment… (@ to mention)',\n send: 'Send',\n cancel: 'Cancel',\n edit: 'Edit',\n delete: 'Delete',\n save: 'Save',\n edited: 'edited',\n empty: 'No comments yet. Select some text to comment.',\n emptyResolved: 'No resolved comments.',\n threads: '{count} comments',\n detached: 'This text was removed from the page',\n pageComment: 'Comment on the page',\n readOnly: 'You can only view comments',\n failed: 'Couldn’t send, try again',\n more: 'More',\n },\n zh: {\n comment: '评论',\n title: '评论',\n open: '未解决',\n resolved: '已解决',\n resolve: '解决',\n reopen: '重新打开',\n reply: '回复',\n replyPlaceholder: '回复…',\n placeholder: '添加评论…(输入 @ 提及成员)',\n send: '发送',\n cancel: '取消',\n edit: '编辑',\n delete: '删除',\n save: '保存',\n edited: '已编辑',\n empty: '暂无评论。选中文字即可评论。',\n emptyResolved: '暂无已解决的评论。',\n threads: '{count} 条评论',\n detached: '这段文字已从页面中删除',\n pageComment: '对页面的评论',\n readOnly: '你只能查看评论',\n failed: '发送失败,请重试',\n more: '更多',\n },\n}\n\n/** Strings for a locale with the app's overrides. */\nexport function commentsMessages(locale: string | undefined, overrides?: Partial<Record<LocaleName, Partial<CommentsMessages>>> | null): CommentsMessages {\n const key = (locale && locale in messages ? locale : 'vi') as LocaleName\n return { ...messages[key], ...overrides?.[key] }\n}\n","import { MessageSquareText } from '@lucide/vue'\nimport { defineBlock } from '@toantranmei/editor'\nimport { selectionAnchor } from './anchor'\nimport { canComment, CommentsExtension, levelOf } from './extension'\nimport { commentsMessages } from './messages'\nimport { useCommentsState } from './store'\nimport type { CommentsOptions } from './types'\n\n/**\n * Comments for `<MeiEditor :blocks>`: `comments.configure({ source, level })`.\n * Adds the `comment` mark, highlights open threads, and a \"Comment\" button in the\n * selection bubble menu (also in read-only editors at `comment` level). Show the threads\n * with `<CommentsPanel>` and per-block counts with `<CommentsGutter>`.\n */\nexport const comments = defineBlock<CommentsOptions>({\n name: 'comments',\n defaults: { source: null, level: 'edit', onCompose: null, onOpenThread: null, messages: null },\n extensions: o => [CommentsExtension.configure(o)],\n formatActions: o => [{\n id: 'comment',\n icon: MessageSquareText,\n readOnly: true,\n title: editor => commentsMessages(editor.storage.meiConfig?.locale, o.messages).comment,\n isVisible: editor => !!o.source?.me.value && canComment(levelOf(o.level)) && !!selectionAnchor(editor.state),\n run: (editor) => {\n if (!o.source) return\n const found = selectionAnchor(editor.state)\n if (!found) return\n const state = useCommentsState(o.source)\n state.startDraft(editor, found)\n o.onCompose?.(found)\n },\n }],\n // Public pages don't show comments: the mark renders as plain text.\n render: () => ({ marks: { comment: (_mark, inner) => inner } }),\n})\n","<script setup lang=\"ts\">\n/**\n * Small rich-text box for a comment body: paragraphs, bold/italic/code/links and\n * @mentions of people (`source.people`). ⌘/Ctrl+Enter sends, Esc cancels.\n */\nimport { Extension } from '@tiptap/core'\nimport StarterKit from '@tiptap/starter-kit'\nimport { Editor, EditorContent, type JSONContent } from '@tiptap/vue-3'\nimport { MeiConfig, MentionNode, type LocaleName, type MentionItem, resolveMessages } from '@toantranmei/editor'\nimport { computed, onBeforeUnmount, ref, shallowRef } from 'vue'\nimport type { CommentsMessages } from './messages'\nimport type { CommentsSource } from './types'\n\nconst props = defineProps<{\n source: CommentsSource\n locale: LocaleName\n m: CommentsMessages\n placeholder: string\n submitLabel: string\n initial?: JSONContent | null\n autofocus?: boolean\n /** Show Cancel. */\n cancellable?: boolean\n /** Saves the body; the box clears when it resolves and shows an error when it rejects. */\n send: (body: JSONContent) => Promise<unknown>\n}>()\nconst emit = defineEmits<{ cancel: [] }>()\n\nconst busy = ref(false)\nconst error = ref(false)\n\nconst Keys = Extension.create({\n name: 'commentKeys',\n addKeyboardShortcuts: () => ({\n 'Mod-Enter': () => {\n submit()\n return true\n },\n 'Escape': () => {\n if (props.cancellable) emit('cancel')\n return props.cancellable\n },\n }),\n})\n\nconst editor = shallowRef(new Editor({\n extensions: [\n StarterKit.configure({ heading: false, codeBlock: false, blockquote: false, horizontalRule: false, bulletList: false, orderedList: false, listItem: false, listKeymap: false, dropcursor: false, gapcursor: false, trailingNode: false, link: { openOnClick: false, autolink: true } }),\n MeiConfig.configure({ locale: props.locale, messages: resolveMessages(props.locale) }),\n MentionNode.configure({\n search: async (query: string): Promise<MentionItem[]> => {\n const people = await props.source.people(query)\n return people.map(p => ({ id: p.id, label: p.name, kind: 'user', avatar: p.avatar ?? undefined, description: p.description }))\n },\n }),\n Keys,\n ],\n content: props.initial ?? null,\n autofocus: props.autofocus ? 'end' : false,\n editorProps: { attributes: { 'class': 'me-content me-comment-input', 'aria-label': props.placeholder } },\n}))\nonBeforeUnmount(() => editor.value.destroy())\n\nconst isEmpty = () => {\n const { doc } = editor.value.state\n return doc.textContent.trim() === '' && !hasMention(doc.toJSON())\n}\n// Reading `state` makes this reactive (Tiptap's Vue editor re-renders once per frame).\nconst empty = computed(isEmpty)\nfunction hasMention(node: JSONContent): boolean {\n return node.type === 'mention' || !!node.content?.some(hasMention)\n}\n\nasync function submit() {\n if (busy.value || isEmpty()) return\n busy.value = true\n error.value = false\n try {\n await props.send(editor.value.getJSON())\n if (!editor.value.isDestroyed) editor.value.commands.clearContent(true)\n }\n catch (e) {\n console.error('[comments]', e)\n error.value = true\n }\n finally {\n busy.value = false\n }\n}\n\ndefineExpose({ editor, submit })\n</script>\n\n<template>\n <div class=\"me-comment-composer\" :class=\"{ 'is-busy': busy }\">\n <div class=\"me-comment-field\">\n <EditorContent :editor=\"editor\" />\n <span v-if=\"empty\" class=\"me-comment-placeholder\">{{ placeholder }}</span>\n </div>\n <p v-if=\"error\" class=\"me-comment-error\" role=\"alert\">\n {{ m.failed }}\n </p>\n <div class=\"me-comment-actions\">\n <button v-if=\"cancellable\" type=\"button\" class=\"me-btn\" @click=\"emit('cancel')\">\n {{ m.cancel }}\n </button>\n <button type=\"button\" class=\"me-btn me-btn--primary\" :disabled=\"busy || empty\" @click=\"submit\">\n {{ submitLabel }}\n </button>\n </div>\n </div>\n</template>\n","<script setup lang=\"ts\">\n/**\n * Small rich-text box for a comment body: paragraphs, bold/italic/code/links and\n * @mentions of people (`source.people`). ⌘/Ctrl+Enter sends, Esc cancels.\n */\nimport { Extension } from '@tiptap/core'\nimport StarterKit from '@tiptap/starter-kit'\nimport { Editor, EditorContent, type JSONContent } from '@tiptap/vue-3'\nimport { MeiConfig, MentionNode, type LocaleName, type MentionItem, resolveMessages } from '@toantranmei/editor'\nimport { computed, onBeforeUnmount, ref, shallowRef } from 'vue'\nimport type { CommentsMessages } from './messages'\nimport type { CommentsSource } from './types'\n\nconst props = defineProps<{\n source: CommentsSource\n locale: LocaleName\n m: CommentsMessages\n placeholder: string\n submitLabel: string\n initial?: JSONContent | null\n autofocus?: boolean\n /** Show Cancel. */\n cancellable?: boolean\n /** Saves the body; the box clears when it resolves and shows an error when it rejects. */\n send: (body: JSONContent) => Promise<unknown>\n}>()\nconst emit = defineEmits<{ cancel: [] }>()\n\nconst busy = ref(false)\nconst error = ref(false)\n\nconst Keys = Extension.create({\n name: 'commentKeys',\n addKeyboardShortcuts: () => ({\n 'Mod-Enter': () => {\n submit()\n return true\n },\n 'Escape': () => {\n if (props.cancellable) emit('cancel')\n return props.cancellable\n },\n }),\n})\n\nconst editor = shallowRef(new Editor({\n extensions: [\n StarterKit.configure({ heading: false, codeBlock: false, blockquote: false, horizontalRule: false, bulletList: false, orderedList: false, listItem: false, listKeymap: false, dropcursor: false, gapcursor: false, trailingNode: false, link: { openOnClick: false, autolink: true } }),\n MeiConfig.configure({ locale: props.locale, messages: resolveMessages(props.locale) }),\n MentionNode.configure({\n search: async (query: string): Promise<MentionItem[]> => {\n const people = await props.source.people(query)\n return people.map(p => ({ id: p.id, label: p.name, kind: 'user', avatar: p.avatar ?? undefined, description: p.description }))\n },\n }),\n Keys,\n ],\n content: props.initial ?? null,\n autofocus: props.autofocus ? 'end' : false,\n editorProps: { attributes: { 'class': 'me-content me-comment-input', 'aria-label': props.placeholder } },\n}))\nonBeforeUnmount(() => editor.value.destroy())\n\nconst isEmpty = () => {\n const { doc } = editor.value.state\n return doc.textContent.trim() === '' && !hasMention(doc.toJSON())\n}\n// Reading `state` makes this reactive (Tiptap's Vue editor re-renders once per frame).\nconst empty = computed(isEmpty)\nfunction hasMention(node: JSONContent): boolean {\n return node.type === 'mention' || !!node.content?.some(hasMention)\n}\n\nasync function submit() {\n if (busy.value || isEmpty()) return\n busy.value = true\n error.value = false\n try {\n await props.send(editor.value.getJSON())\n if (!editor.value.isDestroyed) editor.value.commands.clearContent(true)\n }\n catch (e) {\n console.error('[comments]', e)\n error.value = true\n }\n finally {\n busy.value = false\n }\n}\n\ndefineExpose({ editor, submit })\n</script>\n\n<template>\n <div class=\"me-comment-composer\" :class=\"{ 'is-busy': busy }\">\n <div class=\"me-comment-field\">\n <EditorContent :editor=\"editor\" />\n <span v-if=\"empty\" class=\"me-comment-placeholder\">{{ placeholder }}</span>\n </div>\n <p v-if=\"error\" class=\"me-comment-error\" role=\"alert\">\n {{ m.failed }}\n </p>\n <div class=\"me-comment-actions\">\n <button v-if=\"cancellable\" type=\"button\" class=\"me-btn\" @click=\"emit('cancel')\">\n {{ m.cancel }}\n </button>\n <button type=\"button\" class=\"me-btn me-btn--primary\" :disabled=\"busy || empty\" @click=\"submit\">\n {{ submitLabel }}\n </button>\n </div>\n </div>\n</template>\n","import type { JSONContent, LocaleName } from '@toantranmei/editor'\n\n// Comment bodies hold paragraphs, a few marks and mentions. A small renderer instead of\n// `renderHTML`, which would bring every code grammar into the browser bundle.\nconst ESC: Record<string, string> = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;', '\\'': '&#39;' }\nconst esc = (v: unknown) => String(v ?? '').replace(/[&<>\"']/g, c => ESC[c]!)\n/** http(s), mailto and relative links only (control characters stripped before checking). */\nexport function safeHref(url: unknown): string | null {\n if (typeof url !== 'string' || !url.trim()) return null\n // eslint-disable-next-line no-control-regex\n const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(url.trim().replace(/[\\u0000-\\u001F\\u007F\\s]+/g, ''))?.[1]?.toLowerCase()\n return !scheme || ['http', 'https', 'mailto'].includes(scheme) ? url.trim() : null\n}\nconst MARKS: Record<string, string> = { bold: 'strong', italic: 'em', underline: 'u', strike: 's', code: 'code' }\n\nfunction node(n: JSONContent): string {\n if (n.type === 'text') {\n let out = esc(n.text)\n for (const mark of [...(n.marks ?? [])].reverse()) {\n const tag = MARKS[mark.type]\n if (tag) out = `<${tag}>${out}</${tag}>`\n else if (mark.type === 'link') {\n const href = safeHref(mark.attrs?.href)\n if (href) out = `<a href=\"${esc(href)}\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">${out}</a>`\n }\n }\n return out\n }\n const inner = (n.content ?? []).map(node).join('')\n switch (n.type) {\n case 'doc': return inner\n case 'paragraph': return `<p>${inner}</p>`\n case 'hardBreak': return '<br>'\n case 'mention': return `<span class=\"me-mention me-mention--${n.attrs?.kind === 'date' ? 'date' : 'user'}\" data-type=\"mention\" data-id=\"${esc(n.attrs?.id)}\"><span>@${esc(n.attrs?.label ?? n.attrs?.id)}</span></span>`\n default: return inner\n }\n}\n\n/** Comment body → safe HTML (escaped text, allow-listed links; mentions as chips). */\nexport function bodyHtml(body: JSONContent | null | undefined, _locale?: LocaleName): string {\n return body ? node(body) : ''\n}\n\nconst formatters = new Map<string, Intl.DateTimeFormat>()\n\n/** \"Oct 30, 2026, 2:05 PM\" in the UI language. */\nexport function formatTime(iso: string | null | undefined, locale: LocaleName): string {\n if (!iso) return ''\n const date = new Date(iso)\n if (Number.isNaN(date.getTime())) return ''\n let f = formatters.get(locale)\n if (!f) {\n f = new Intl.DateTimeFormat(locale === 'zh' ? 'zh-CN' : locale, { dateStyle: 'medium', timeStyle: 'short' })\n formatters.set(locale, f)\n }\n return f.format(date)\n}\n\n/** Up to two initials for an avatar placeholder. */\nexport const initials = (name: string) => name.trim().split(/\\s+/).slice(-2).map(w => w[0]?.toUpperCase() ?? '').join('') || '?'\n","<script setup lang=\"ts\">\nimport { Ellipsis } from '@lucide/vue'\nimport type { JSONContent, LocaleName } from '@toantranmei/editor'\nimport { computed, ref } from 'vue'\nimport CommentComposer from './CommentComposer.vue'\nimport { bodyHtml, formatTime, initials } from './format'\nimport type { CommentsMessages } from './messages'\nimport type { Comment, CommentsSource } from './types'\n\nconst props = defineProps<{ comment: Comment, source: CommentsSource, m: CommentsMessages, locale: LocaleName, canComment: boolean }>()\n\nconst own = computed(() => !!props.source.me.value && props.source.me.value.id === props.comment.author.id)\nconst menu = ref(false)\nconst editing = ref(false)\nconst html = computed(() => bodyHtml(props.comment.body, props.locale))\n\nasync function save(body: JSONContent) {\n await props.source.edit(props.comment.id, body)\n editing.value = false\n}\nasync function remove() {\n menu.value = false\n await props.source.remove(props.comment.id)\n}\n</script>\n\n<template>\n <div class=\"me-comment\">\n <div class=\"me-comment-head\">\n <img v-if=\"comment.author.avatar_url\" class=\"me-comment-avatar\" :src=\"comment.author.avatar_url\" alt=\"\">\n <span v-else class=\"me-comment-avatar me-comment-avatar--initials\" aria-hidden=\"true\">{{ initials(comment.author.name) }}</span>\n <span class=\"me-comment-author\">{{ comment.author.name }}</span>\n <span class=\"me-comment-meta\">\n {{ formatTime(comment.created_at, locale) }}<template v-if=\"comment.edited_at\"> · {{ m.edited }}</template>\n </span>\n <span v-if=\"own && canComment && !editing\" class=\"me-comment-menu-anchor\">\n <button type=\"button\" class=\"me-tool-btn me-comment-more\" :title=\"m.more\" :aria-expanded=\"menu\" @click=\"menu = !menu\">\n <Ellipsis />\n </button>\n <span v-if=\"menu\" class=\"me-popover me-menu me-comment-menu\">\n <button type=\"button\" class=\"me-menu-item\" @click=\"editing = true; menu = false\">\n <span class=\"me-menu-title\">{{ m.edit }}</span>\n </button>\n <button type=\"button\" class=\"me-menu-item me-menu-item--danger\" @click=\"remove\">\n <span class=\"me-menu-title\">{{ m.delete }}</span>\n </button>\n </span>\n </span>\n </div>\n <CommentComposer\n v-if=\"editing\"\n :source=\"source\"\n :locale=\"locale\"\n :m=\"m\"\n :placeholder=\"m.placeholder\"\n :submit-label=\"m.save\"\n :initial=\"comment.body\"\n :send=\"save\"\n autofocus\n cancellable\n @cancel=\"editing = false\"\n />\n <!-- Rendered by @toantranmei/editor/render: text escaped, URLs allow-listed. -->\n <div v-else class=\"me-content me-comment-body\" v-html=\"html\" />\n </div>\n</template>\n","<script setup lang=\"ts\">\nimport { Ellipsis } from '@lucide/vue'\nimport type { JSONContent, LocaleName } from '@toantranmei/editor'\nimport { computed, ref } from 'vue'\nimport CommentComposer from './CommentComposer.vue'\nimport { bodyHtml, formatTime, initials } from './format'\nimport type { CommentsMessages } from './messages'\nimport type { Comment, CommentsSource } from './types'\n\nconst props = defineProps<{ comment: Comment, source: CommentsSource, m: CommentsMessages, locale: LocaleName, canComment: boolean }>()\n\nconst own = computed(() => !!props.source.me.value && props.source.me.value.id === props.comment.author.id)\nconst menu = ref(false)\nconst editing = ref(false)\nconst html = computed(() => bodyHtml(props.comment.body, props.locale))\n\nasync function save(body: JSONContent) {\n await props.source.edit(props.comment.id, body)\n editing.value = false\n}\nasync function remove() {\n menu.value = false\n await props.source.remove(props.comment.id)\n}\n</script>\n\n<template>\n <div class=\"me-comment\">\n <div class=\"me-comment-head\">\n <img v-if=\"comment.author.avatar_url\" class=\"me-comment-avatar\" :src=\"comment.author.avatar_url\" alt=\"\">\n <span v-else class=\"me-comment-avatar me-comment-avatar--initials\" aria-hidden=\"true\">{{ initials(comment.author.name) }}</span>\n <span class=\"me-comment-author\">{{ comment.author.name }}</span>\n <span class=\"me-comment-meta\">\n {{ formatTime(comment.created_at, locale) }}<template v-if=\"comment.edited_at\"> · {{ m.edited }}</template>\n </span>\n <span v-if=\"own && canComment && !editing\" class=\"me-comment-menu-anchor\">\n <button type=\"button\" class=\"me-tool-btn me-comment-more\" :title=\"m.more\" :aria-expanded=\"menu\" @click=\"menu = !menu\">\n <Ellipsis />\n </button>\n <span v-if=\"menu\" class=\"me-popover me-menu me-comment-menu\">\n <button type=\"button\" class=\"me-menu-item\" @click=\"editing = true; menu = false\">\n <span class=\"me-menu-title\">{{ m.edit }}</span>\n </button>\n <button type=\"button\" class=\"me-menu-item me-menu-item--danger\" @click=\"remove\">\n <span class=\"me-menu-title\">{{ m.delete }}</span>\n </button>\n </span>\n </span>\n </div>\n <CommentComposer\n v-if=\"editing\"\n :source=\"source\"\n :locale=\"locale\"\n :m=\"m\"\n :placeholder=\"m.placeholder\"\n :submit-label=\"m.save\"\n :initial=\"comment.body\"\n :send=\"save\"\n autofocus\n cancellable\n @cancel=\"editing = false\"\n />\n <!-- Rendered by @toantranmei/editor/render: text escaped, URLs allow-listed. -->\n <div v-else class=\"me-content me-comment-body\" v-html=\"html\" />\n </div>\n</template>\n","<script setup lang=\"ts\">\nimport { Check, RotateCcw } from '@lucide/vue'\nimport type { JSONContent, LocaleName } from '@toantranmei/editor'\nimport { computed } from 'vue'\nimport CommentComposer from './CommentComposer.vue'\nimport CommentItem from './CommentItem.vue'\nimport type { CommentsMessages } from './messages'\nimport type { CommentsSource, Thread } from './types'\n\nconst props = defineProps<{\n thread: Thread\n source: CommentsSource\n m: CommentsMessages\n locale: LocaleName\n canComment: boolean\n active: boolean\n /** The commented text is no longer in the document. */\n detached: boolean\n}>()\nconst emit = defineEmits<{ select: [] }>()\n\nconst resolved = computed(() => !!props.thread.resolved_at)\nconst quote = computed(() => (props.thread.anchor.kind === 'text' ? props.thread.anchor.quote : props.thread.anchor.kind === 'page' ? props.m.pageComment : ''))\n\nconst reply = (body: JSONContent) => props.source.reply(props.thread.id, body)\nconst toggleResolved = () => props.source.resolve(props.thread.id, !resolved.value)\n</script>\n\n<template>\n <article\n class=\"me-comment-thread\"\n :class=\"{ 'is-active': active, 'is-resolved': resolved }\"\n :data-thread-id=\"thread.id\"\n @click=\"emit('select')\"\n >\n <div class=\"me-comment-thread-head\">\n <blockquote v-if=\"quote\" class=\"me-comment-quote\" :class=\"{ 'is-detached': detached }\" :title=\"detached ? m.detached : undefined\">\n {{ quote }}\n </blockquote>\n <button\n v-if=\"canComment\"\n type=\"button\"\n class=\"me-tool-btn me-comment-resolve\"\n :title=\"resolved ? m.reopen : m.resolve\"\n @click.stop=\"toggleResolved\"\n >\n <RotateCcw v-if=\"resolved\" />\n <Check v-else />\n </button>\n </div>\n <CommentItem\n v-for=\"c in thread.comments\"\n :key=\"c.id\"\n :comment=\"c\"\n :source=\"source\"\n :m=\"m\"\n :locale=\"locale\"\n :can-comment=\"canComment\"\n />\n <CommentComposer\n v-if=\"active && canComment && !resolved && source.me.value\"\n :source=\"source\"\n :locale=\"locale\"\n :m=\"m\"\n :placeholder=\"m.replyPlaceholder\"\n :submit-label=\"m.reply\"\n :send=\"reply\"\n @click.stop\n />\n </article>\n</template>\n","<script setup lang=\"ts\">\nimport { Check, RotateCcw } from '@lucide/vue'\nimport type { JSONContent, LocaleName } from '@toantranmei/editor'\nimport { computed } from 'vue'\nimport CommentComposer from './CommentComposer.vue'\nimport CommentItem from './CommentItem.vue'\nimport type { CommentsMessages } from './messages'\nimport type { CommentsSource, Thread } from './types'\n\nconst props = defineProps<{\n thread: Thread\n source: CommentsSource\n m: CommentsMessages\n locale: LocaleName\n canComment: boolean\n active: boolean\n /** The commented text is no longer in the document. */\n detached: boolean\n}>()\nconst emit = defineEmits<{ select: [] }>()\n\nconst resolved = computed(() => !!props.thread.resolved_at)\nconst quote = computed(() => (props.thread.anchor.kind === 'text' ? props.thread.anchor.quote : props.thread.anchor.kind === 'page' ? props.m.pageComment : ''))\n\nconst reply = (body: JSONContent) => props.source.reply(props.thread.id, body)\nconst toggleResolved = () => props.source.resolve(props.thread.id, !resolved.value)\n</script>\n\n<template>\n <article\n class=\"me-comment-thread\"\n :class=\"{ 'is-active': active, 'is-resolved': resolved }\"\n :data-thread-id=\"thread.id\"\n @click=\"emit('select')\"\n >\n <div class=\"me-comment-thread-head\">\n <blockquote v-if=\"quote\" class=\"me-comment-quote\" :class=\"{ 'is-detached': detached }\" :title=\"detached ? m.detached : undefined\">\n {{ quote }}\n </blockquote>\n <button\n v-if=\"canComment\"\n type=\"button\"\n class=\"me-tool-btn me-comment-resolve\"\n :title=\"resolved ? m.reopen : m.resolve\"\n @click.stop=\"toggleResolved\"\n >\n <RotateCcw v-if=\"resolved\" />\n <Check v-else />\n </button>\n </div>\n <CommentItem\n v-for=\"c in thread.comments\"\n :key=\"c.id\"\n :comment=\"c\"\n :source=\"source\"\n :m=\"m\"\n :locale=\"locale\"\n :can-comment=\"canComment\"\n />\n <CommentComposer\n v-if=\"active && canComment && !resolved && source.me.value\"\n :source=\"source\"\n :locale=\"locale\"\n :m=\"m\"\n :placeholder=\"m.replyPlaceholder\"\n :submit-label=\"m.reply\"\n :send=\"reply\"\n @click.stop\n />\n </article>\n</template>\n","<script setup lang=\"ts\">\n/**\n * Side panel: open / resolved threads of the page, the draft for a new comment, replies,\n * edit / delete own comments, resolve / re-open. Clicking a thread scrolls the editor to it.\n */\nimport type { Editor } from '@tiptap/core'\nimport type { JSONContent, LocaleName } from '@toantranmei/editor'\nimport { computed, nextTick, shallowRef, watch } from 'vue'\nimport { indexDocument, threadRanges } from './anchor'\nimport CommentComposer from './CommentComposer.vue'\nimport { canComment as canCommentAt, levelOf } from './extension'\nimport { commentsMessages, type CommentsMessages } from './messages'\nimport { useCommentsState } from './store'\nimport ThreadCard from './ThreadCard.vue'\nimport type { CommentsLevel, CommentsSource, Thread } from './types'\n\nconst props = withDefaults(defineProps<{\n source: CommentsSource\n /** The page's editor: threads follow document order and clicking one scrolls to it. */\n editor?: Editor | null\n level?: CommentsLevel\n locale?: LocaleName\n messages?: Partial<Record<LocaleName, Partial<CommentsMessages>>>\n}>(), { editor: null, level: 'edit', locale: 'vi', messages: undefined })\n\nconst m = computed(() => commentsMessages(props.locale, props.messages))\nconst state = useCommentsState(props.source)\nconst canComment = computed(() => canCommentAt(levelOf(props.level)) && !!props.source.me.value)\nconst draft = computed(() => state.draft.value)\n\n// Document positions of each thread's text (re-read on every document change).\nconst version = shallowRef(0)\nlet off: (() => void) | null = null\nwatch(() => props.editor, (editor) => {\n off?.()\n off = null\n if (!editor) return\n const bump = () => version.value++\n editor.on('update', bump)\n off = () => editor.off('update', bump)\n}, { immediate: true })\n\nconst positions = computed(() => {\n void version.value\n const map = new Map<string, number>()\n const editor = props.editor\n if (!editor || editor.isDestroyed) return map\n const index = indexDocument(editor.state.doc)\n for (const t of props.source.threads.value) {\n const r = threadRanges(t, index)[0]\n if (r) map.set(t.id, r.from)\n }\n return map\n})\n\nconst visible = computed<Thread[]>(() => {\n const list = props.source.threads.value\n if (state.filter.value === 'resolved') {\n return list.filter(t => t.resolved_at).sort((a, b) => (b.resolved_at ?? '').localeCompare(a.resolved_at ?? ''))\n }\n const pos = positions.value\n const end = Number.MAX_SAFE_INTEGER\n return list.filter(t => !t.resolved_at).sort((a, b) => (pos.get(a.id) ?? end) - (pos.get(b.id) ?? end) || (a.comments[0]?.created_at ?? '').localeCompare(b.comments[0]?.created_at ?? ''))\n})\nconst openCount = computed(() => props.source.threads.value.filter(t => !t.resolved_at).length)\nconst resolvedCount = computed(() => props.source.threads.value.length - openCount.value)\n\nfunction select(thread: Thread) {\n state.activeId.value = thread.id\n const editor = props.editor\n const pos = positions.value.get(thread.id)\n if (!editor || pos === undefined || editor.isDestroyed) return\n const dom = editor.view.domAtPos(pos).node\n const el = (dom.nodeType === 1 ? dom : dom.parentElement) as HTMLElement | null\n el?.scrollIntoView?.({ behavior: 'smooth', block: 'center' })\n}\n\n// Show the thread picked in the editor (highlight / badge click).\nconst root = shallowRef<HTMLElement | null>(null)\nwatch(state.activeId, (id) => {\n if (!id) return\n const thread = props.source.threads.value.find(t => t.id === id)\n if (thread) state.filter.value = thread.resolved_at ? 'resolved' : 'open'\n nextTick(() => root.value?.querySelector(`[data-thread-id=\"${CSS.escape(id)}\"]`)?.scrollIntoView?.({ block: 'nearest' }))\n})\n\nconst createThread = (body: JSONContent) => state.submitDraft(body)\n</script>\n\n<template>\n <aside ref=\"root\" class=\"me-scope me-comments-panel\" :aria-label=\"m.title\">\n <header class=\"me-comments-header\">\n <h2 class=\"me-comments-title\">\n {{ m.title }}\n </h2>\n <div class=\"me-tabs me-tabs--inline me-comments-tabs\" role=\"tablist\">\n <button type=\"button\" role=\"tab\" class=\"me-tab\" :class=\"{ 'is-active': state.filter.value === 'open' }\" :aria-selected=\"state.filter.value === 'open'\" @click=\"state.filter.value = 'open'\">\n {{ m.open }} <span class=\"me-comments-count\">{{ openCount }}</span>\n </button>\n <button type=\"button\" role=\"tab\" class=\"me-tab\" :class=\"{ 'is-active': state.filter.value === 'resolved' }\" :aria-selected=\"state.filter.value === 'resolved'\" @click=\"state.filter.value = 'resolved'\">\n {{ m.resolved }} <span class=\"me-comments-count\">{{ resolvedCount }}</span>\n </button>\n </div>\n </header>\n\n <div v-if=\"draft && canComment\" class=\"me-comment-thread is-active is-draft\">\n <blockquote v-if=\"draft.anchor.kind === 'text'\" class=\"me-comment-quote\">\n {{ draft.anchor.quote }}\n </blockquote>\n <CommentComposer\n :key=\"draft.key\"\n :source=\"source\"\n :locale=\"locale\"\n :m=\"m\"\n :placeholder=\"m.placeholder\"\n :submit-label=\"m.send\"\n :send=\"createThread\"\n autofocus\n cancellable\n @cancel=\"state.cancelDraft()\"\n />\n </div>\n\n <p v-if=\"!canComment && source.me.value && levelOf(level) === 'view'\" class=\"me-hint me-comments-hint\">\n {{ m.readOnly }}\n </p>\n\n <ThreadCard\n v-for=\"t in visible\"\n :key=\"t.id\"\n :thread=\"t\"\n :source=\"source\"\n :m=\"m\"\n :locale=\"locale\"\n :can-comment=\"canComment\"\n :active=\"state.activeId.value === t.id\"\n :detached=\"!!editor && t.anchor.kind === 'text' && !positions.has(t.id)\"\n @select=\"select(t)\"\n />\n <p v-if=\"!visible.length && !draft\" class=\"me-hint me-comments-empty\">\n {{ state.filter.value === 'open' ? m.empty : m.emptyResolved }}\n </p>\n </aside>\n</template>\n","<script setup lang=\"ts\">\n/**\n * Side panel: open / resolved threads of the page, the draft for a new comment, replies,\n * edit / delete own comments, resolve / re-open. Clicking a thread scrolls the editor to it.\n */\nimport type { Editor } from '@tiptap/core'\nimport type { JSONContent, LocaleName } from '@toantranmei/editor'\nimport { computed, nextTick, shallowRef, watch } from 'vue'\nimport { indexDocument, threadRanges } from './anchor'\nimport CommentComposer from './CommentComposer.vue'\nimport { canComment as canCommentAt, levelOf } from './extension'\nimport { commentsMessages, type CommentsMessages } from './messages'\nimport { useCommentsState } from './store'\nimport ThreadCard from './ThreadCard.vue'\nimport type { CommentsLevel, CommentsSource, Thread } from './types'\n\nconst props = withDefaults(defineProps<{\n source: CommentsSource\n /** The page's editor: threads follow document order and clicking one scrolls to it. */\n editor?: Editor | null\n level?: CommentsLevel\n locale?: LocaleName\n messages?: Partial<Record<LocaleName, Partial<CommentsMessages>>>\n}>(), { editor: null, level: 'edit', locale: 'vi', messages: undefined })\n\nconst m = computed(() => commentsMessages(props.locale, props.messages))\nconst state = useCommentsState(props.source)\nconst canComment = computed(() => canCommentAt(levelOf(props.level)) && !!props.source.me.value)\nconst draft = computed(() => state.draft.value)\n\n// Document positions of each thread's text (re-read on every document change).\nconst version = shallowRef(0)\nlet off: (() => void) | null = null\nwatch(() => props.editor, (editor) => {\n off?.()\n off = null\n if (!editor) return\n const bump = () => version.value++\n editor.on('update', bump)\n off = () => editor.off('update', bump)\n}, { immediate: true })\n\nconst positions = computed(() => {\n void version.value\n const map = new Map<string, number>()\n const editor = props.editor\n if (!editor || editor.isDestroyed) return map\n const index = indexDocument(editor.state.doc)\n for (const t of props.source.threads.value) {\n const r = threadRanges(t, index)[0]\n if (r) map.set(t.id, r.from)\n }\n return map\n})\n\nconst visible = computed<Thread[]>(() => {\n const list = props.source.threads.value\n if (state.filter.value === 'resolved') {\n return list.filter(t => t.resolved_at).sort((a, b) => (b.resolved_at ?? '').localeCompare(a.resolved_at ?? ''))\n }\n const pos = positions.value\n const end = Number.MAX_SAFE_INTEGER\n return list.filter(t => !t.resolved_at).sort((a, b) => (pos.get(a.id) ?? end) - (pos.get(b.id) ?? end) || (a.comments[0]?.created_at ?? '').localeCompare(b.comments[0]?.created_at ?? ''))\n})\nconst openCount = computed(() => props.source.threads.value.filter(t => !t.resolved_at).length)\nconst resolvedCount = computed(() => props.source.threads.value.length - openCount.value)\n\nfunction select(thread: Thread) {\n state.activeId.value = thread.id\n const editor = props.editor\n const pos = positions.value.get(thread.id)\n if (!editor || pos === undefined || editor.isDestroyed) return\n const dom = editor.view.domAtPos(pos).node\n const el = (dom.nodeType === 1 ? dom : dom.parentElement) as HTMLElement | null\n el?.scrollIntoView?.({ behavior: 'smooth', block: 'center' })\n}\n\n// Show the thread picked in the editor (highlight / badge click).\nconst root = shallowRef<HTMLElement | null>(null)\nwatch(state.activeId, (id) => {\n if (!id) return\n const thread = props.source.threads.value.find(t => t.id === id)\n if (thread) state.filter.value = thread.resolved_at ? 'resolved' : 'open'\n nextTick(() => root.value?.querySelector(`[data-thread-id=\"${CSS.escape(id)}\"]`)?.scrollIntoView?.({ block: 'nearest' }))\n})\n\nconst createThread = (body: JSONContent) => state.submitDraft(body)\n</script>\n\n<template>\n <aside ref=\"root\" class=\"me-scope me-comments-panel\" :aria-label=\"m.title\">\n <header class=\"me-comments-header\">\n <h2 class=\"me-comments-title\">\n {{ m.title }}\n </h2>\n <div class=\"me-tabs me-tabs--inline me-comments-tabs\" role=\"tablist\">\n <button type=\"button\" role=\"tab\" class=\"me-tab\" :class=\"{ 'is-active': state.filter.value === 'open' }\" :aria-selected=\"state.filter.value === 'open'\" @click=\"state.filter.value = 'open'\">\n {{ m.open }} <span class=\"me-comments-count\">{{ openCount }}</span>\n </button>\n <button type=\"button\" role=\"tab\" class=\"me-tab\" :class=\"{ 'is-active': state.filter.value === 'resolved' }\" :aria-selected=\"state.filter.value === 'resolved'\" @click=\"state.filter.value = 'resolved'\">\n {{ m.resolved }} <span class=\"me-comments-count\">{{ resolvedCount }}</span>\n </button>\n </div>\n </header>\n\n <div v-if=\"draft && canComment\" class=\"me-comment-thread is-active is-draft\">\n <blockquote v-if=\"draft.anchor.kind === 'text'\" class=\"me-comment-quote\">\n {{ draft.anchor.quote }}\n </blockquote>\n <CommentComposer\n :key=\"draft.key\"\n :source=\"source\"\n :locale=\"locale\"\n :m=\"m\"\n :placeholder=\"m.placeholder\"\n :submit-label=\"m.send\"\n :send=\"createThread\"\n autofocus\n cancellable\n @cancel=\"state.cancelDraft()\"\n />\n </div>\n\n <p v-if=\"!canComment && source.me.value && levelOf(level) === 'view'\" class=\"me-hint me-comments-hint\">\n {{ m.readOnly }}\n </p>\n\n <ThreadCard\n v-for=\"t in visible\"\n :key=\"t.id\"\n :thread=\"t\"\n :source=\"source\"\n :m=\"m\"\n :locale=\"locale\"\n :can-comment=\"canComment\"\n :active=\"state.activeId.value === t.id\"\n :detached=\"!!editor && t.anchor.kind === 'text' && !positions.has(t.id)\"\n @select=\"select(t)\"\n />\n <p v-if=\"!visible.length && !draft\" class=\"me-hint me-comments-empty\">\n {{ state.filter.value === 'open' ? m.empty : m.emptyResolved }}\n </p>\n </aside>\n</template>\n","<script setup lang=\"ts\">\n/**\n * Badges in the editor's right margin: the number of open threads per block (`data-id`).\n * Click to open the block's first thread. Mounted inside the editor root, next to its blocks.\n */\nimport { MessageSquareText } from '@lucide/vue'\nimport type { Editor } from '@tiptap/core'\nimport type { LocaleName } from '@toantranmei/editor'\nimport { computed, onBeforeUnmount, shallowRef, watch } from 'vue'\nimport { indexDocument, threadBlockId } from './anchor'\nimport { commentsMessages, type CommentsMessages } from './messages'\nimport { useCommentsState } from './store'\nimport type { CommentsSource, Thread } from './types'\n\nconst props = withDefaults(defineProps<{\n editor: Editor | null | undefined\n source: CommentsSource\n locale?: LocaleName\n messages?: Partial<Record<LocaleName, Partial<CommentsMessages>>>\n}>(), { locale: 'vi', messages: undefined })\nconst emit = defineEmits<{ open: [threadIds: string[]] }>()\n\nconst m = computed(() => commentsMessages(props.locale, props.messages))\nconst state = useCommentsState(props.source)\n\ninterface Badge { blockId: string, top: number, threads: Thread[] }\nconst badges = shallowRef<Badge[]>([])\nconst target = shallowRef<HTMLElement | null>(null)\n\nlet frame = 0\nfunction schedule() {\n cancelAnimationFrame(frame)\n frame = requestAnimationFrame(measure)\n}\n\nfunction measure() {\n const editor = props.editor\n if (!editor || editor.isDestroyed || !editor.view?.dom?.isConnected) {\n badges.value = []\n return\n }\n const root = (editor.view.dom.closest('.me-root') as HTMLElement | null) ?? editor.view.dom.parentElement\n target.value = root\n if (!root) return\n const byBlock = new Map<string, Thread[]>()\n for (const t of props.source.threads.value) {\n const id = !t.resolved_at && threadBlockId(t)\n if (id) byBlock.set(id, [...(byBlock.get(id) ?? []), t])\n }\n if (!byBlock.size) {\n badges.value = []\n return\n }\n const { blocks } = indexDocument(editor.state.doc)\n const rootTop = root.getBoundingClientRect().top\n const next: Badge[] = []\n for (const [blockId, threads] of byBlock) {\n const block = blocks.get(blockId)\n const dom = block && editor.view.nodeDOM(block.pos)\n if (!(dom instanceof HTMLElement)) continue\n next.push({ blockId, top: dom.getBoundingClientRect().top - rootTop, threads })\n }\n badges.value = next.sort((a, b) => a.top - b.top)\n}\n\nlet observer: ResizeObserver | null = null\nlet off: (() => void) | null = null\nwatch(() => props.editor, (editor) => {\n off?.()\n observer?.disconnect()\n off = null\n if (!editor) return\n editor.on('update', schedule)\n editor.on('create', schedule)\n off = () => {\n editor.off('update', schedule)\n editor.off('create', schedule)\n }\n if (typeof ResizeObserver !== 'undefined' && editor.view?.dom) {\n observer = new ResizeObserver(schedule)\n observer.observe(editor.view.dom)\n }\n schedule()\n}, { immediate: true })\nwatch(() => props.source.threads.value.map(t => `${t.id}:${t.resolved_at ? 1 : 0}`).join('|'), schedule)\nif (typeof window !== 'undefined') window.addEventListener('resize', schedule)\nonBeforeUnmount(() => {\n off?.()\n observer?.disconnect()\n cancelAnimationFrame(frame)\n if (typeof window !== 'undefined') window.removeEventListener('resize', schedule)\n})\n\nfunction open(badge: Badge) {\n state.activeId.value = badge.threads[0]!.id\n emit('open', badge.threads.map(t => t.id))\n}\nconst isActive = (badge: Badge) => badge.threads.some(t => t.id === state.activeId.value)\nconst label = (badge: Badge) => m.value.threads.replace('{count}', String(badge.threads.length))\n</script>\n\n<template>\n <Teleport v-if=\"target\" :to=\"target\">\n <div class=\"me-comments-gutter\">\n <button\n v-for=\"b in badges\"\n :key=\"b.blockId\"\n type=\"button\"\n class=\"me-comments-badge\"\n :class=\"{ 'is-active': isActive(b) }\"\n :style=\"{ top: `${b.top}px` }\"\n :title=\"label(b)\"\n :aria-label=\"label(b)\"\n :data-block-id=\"b.blockId\"\n @mousedown.prevent\n @click=\"open(b)\"\n >\n <MessageSquareText /> {{ b.threads.length }}\n </button>\n </div>\n </Teleport>\n</template>\n","<script setup lang=\"ts\">\n/**\n * Badges in the editor's right margin: the number of open threads per block (`data-id`).\n * Click to open the block's first thread. Mounted inside the editor root, next to its blocks.\n */\nimport { MessageSquareText } from '@lucide/vue'\nimport type { Editor } from '@tiptap/core'\nimport type { LocaleName } from '@toantranmei/editor'\nimport { computed, onBeforeUnmount, shallowRef, watch } from 'vue'\nimport { indexDocument, threadBlockId } from './anchor'\nimport { commentsMessages, type CommentsMessages } from './messages'\nimport { useCommentsState } from './store'\nimport type { CommentsSource, Thread } from './types'\n\nconst props = withDefaults(defineProps<{\n editor: Editor | null | undefined\n source: CommentsSource\n locale?: LocaleName\n messages?: Partial<Record<LocaleName, Partial<CommentsMessages>>>\n}>(), { locale: 'vi', messages: undefined })\nconst emit = defineEmits<{ open: [threadIds: string[]] }>()\n\nconst m = computed(() => commentsMessages(props.locale, props.messages))\nconst state = useCommentsState(props.source)\n\ninterface Badge { blockId: string, top: number, threads: Thread[] }\nconst badges = shallowRef<Badge[]>([])\nconst target = shallowRef<HTMLElement | null>(null)\n\nlet frame = 0\nfunction schedule() {\n cancelAnimationFrame(frame)\n frame = requestAnimationFrame(measure)\n}\n\nfunction measure() {\n const editor = props.editor\n if (!editor || editor.isDestroyed || !editor.view?.dom?.isConnected) {\n badges.value = []\n return\n }\n const root = (editor.view.dom.closest('.me-root') as HTMLElement | null) ?? editor.view.dom.parentElement\n target.value = root\n if (!root) return\n const byBlock = new Map<string, Thread[]>()\n for (const t of props.source.threads.value) {\n const id = !t.resolved_at && threadBlockId(t)\n if (id) byBlock.set(id, [...(byBlock.get(id) ?? []), t])\n }\n if (!byBlock.size) {\n badges.value = []\n return\n }\n const { blocks } = indexDocument(editor.state.doc)\n const rootTop = root.getBoundingClientRect().top\n const next: Badge[] = []\n for (const [blockId, threads] of byBlock) {\n const block = blocks.get(blockId)\n const dom = block && editor.view.nodeDOM(block.pos)\n if (!(dom instanceof HTMLElement)) continue\n next.push({ blockId, top: dom.getBoundingClientRect().top - rootTop, threads })\n }\n badges.value = next.sort((a, b) => a.top - b.top)\n}\n\nlet observer: ResizeObserver | null = null\nlet off: (() => void) | null = null\nwatch(() => props.editor, (editor) => {\n off?.()\n observer?.disconnect()\n off = null\n if (!editor) return\n editor.on('update', schedule)\n editor.on('create', schedule)\n off = () => {\n editor.off('update', schedule)\n editor.off('create', schedule)\n }\n if (typeof ResizeObserver !== 'undefined' && editor.view?.dom) {\n observer = new ResizeObserver(schedule)\n observer.observe(editor.view.dom)\n }\n schedule()\n}, { immediate: true })\nwatch(() => props.source.threads.value.map(t => `${t.id}:${t.resolved_at ? 1 : 0}`).join('|'), schedule)\nif (typeof window !== 'undefined') window.addEventListener('resize', schedule)\nonBeforeUnmount(() => {\n off?.()\n observer?.disconnect()\n cancelAnimationFrame(frame)\n if (typeof window !== 'undefined') window.removeEventListener('resize', schedule)\n})\n\nfunction open(badge: Badge) {\n state.activeId.value = badge.threads[0]!.id\n emit('open', badge.threads.map(t => t.id))\n}\nconst isActive = (badge: Badge) => badge.threads.some(t => t.id === state.activeId.value)\nconst label = (badge: Badge) => m.value.threads.replace('{count}', String(badge.threads.length))\n</script>\n\n<template>\n <Teleport v-if=\"target\" :to=\"target\">\n <div class=\"me-comments-gutter\">\n <button\n v-for=\"b in badges\"\n :key=\"b.blockId\"\n type=\"button\"\n class=\"me-comments-badge\"\n :class=\"{ 'is-active': isActive(b) }\"\n :style=\"{ top: `${b.top}px` }\"\n :title=\"label(b)\"\n :aria-label=\"label(b)\"\n :data-block-id=\"b.blockId\"\n @mousedown.prevent\n @click=\"open(b)\"\n >\n <MessageSquareText /> {{ b.threads.length }}\n </button>\n </div>\n </Teleport>\n</template>\n"],"mappings":";;;;;;;;AAMA,IAAa2F,IAAe;AAG5B,SAAgBC,EAAU,GAAoB,GAA4B;CACxE,IAAMC,IAAOC,EAAM,IAAI,QAAQC,CAAG;CAClC,KAAK,IAAIC,IAAIH,EAAK,OAAOG,IAAI,GAAG,KAAK;EACnC,IAAMC,IAAKJ,EAAK,KAAKG,CAAC,CAAC,CAAC,MAAM;EAC9B,IAAI,OAAOC,KAAO,YAAYA,GAAI,OAAOA;CAC3C;CACA,OAAO;AACT;AAOA,SAAgBC,EAAgB,GAAyE;CACvG,IAAM,EAAE,SAAM,OAAI,UAAO,aAAUJ,EAAM;CACzC,IAAIK,GAAO,OAAO;CAClB,IAAMC,IAAUR,EAAUE,GAAOO,CAAI;CACrC,IAAI,CAACD,GAAS,OAAO;CAErB,IAAME,IAAMC,EAAM,OAAO,cAAc,KAAK,IAAIC,GAAID,EAAM,IAAI,CAAC,IAAIC,GAC7DC,IAAQX,EAAM,IAAI,YAAYO,GAAM,KAAK,IAAIA,GAAMC,CAAG,GAAG,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,GAAA,GAAY;CAElG,OADKG,IACE;EAAE,QAAQ;GAAE,MAAM;GAAQ,UAAUL;GAAS;EAAM;EAAG;EAAM;CAAG,I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0,0 +1,2 @@
1
+ @layer mei-editor{.me-content .me-comment-highlight{background:var(--me-comments-highlight);border-bottom:var(--me-border-width-medium) solid var(--me-comments-underline);cursor:pointer}.me-content .me-comment-highlight.is-active{background:var(--me-comments-highlight-active)}.me-comments-gutter{z-index:5;width:0;height:0;position:absolute;top:0;right:0}.me-comments-badge{--me-icon-size:var(--me-comments-badge-font-size);right:var(--me-comments-badge-offset);align-items:center;gap:var(--me-space-1);height:var(--me-comments-badge-size);padding:0 var(--me-space-3);border-radius:var(--me-radius-sm);background:var(--me-comments-badge-bg);color:var(--me-comments-badge-color);font-size:var(--me-comments-badge-font-size);font-weight:var(--me-font-weight-medium);white-space:nowrap;display:inline-flex;position:absolute}.me-comments-badge:hover,.me-comments-badge.is-active{background:var(--me-comments-badge-active-bg);color:var(--me-comments-badge-active-color)}.me-comments-panel{gap:var(--me-comments-thread-gap);width:var(--me-comments-panel-width);max-width:100%;padding:var(--me-comments-panel-padding);border-left:var(--me-border-width-thin) solid var(--me-comments-panel-border);background:var(--me-comments-panel-bg);flex-direction:column;display:flex}.me-comments-header{gap:var(--me-space-4);flex-direction:column;display:flex}.me-comments-title{font-size:var(--me-font-size-md);font-weight:var(--me-font-weight-semibold)}.me-comments-count{color:var(--me-comments-meta-color);font-size:var(--me-comments-meta-font-size)}.me-comments-empty,.me-comments-hint{padding:var(--me-space-4) 0}.me-comment-thread{gap:var(--me-space-5);padding:var(--me-comments-thread-padding);border:var(--me-border-width-thin) solid var(--me-comments-thread-border);border-radius:var(--me-comments-thread-radius);cursor:pointer;flex-direction:column;display:flex}.me-comment-thread.is-active{border-color:var(--me-comments-thread-active-border);cursor:auto}.me-comment-thread.is-resolved{opacity:.75}.me-comment-thread-head{align-items:flex-start;gap:var(--me-space-3);display:flex}.me-comment-quote{min-width:0;padding-left:var(--me-space-4);border-left:var(--me-border-width-medium) solid var(--me-comments-quote-border);color:var(--me-comments-quote-color);font-size:var(--me-comments-body-font-size);-webkit-line-clamp:2;-webkit-box-orient:vertical;flex:1;display:-webkit-box;overflow:hidden}.me-comment-quote.is-detached{text-decoration:line-through}.me-comment-resolve{flex-shrink:0}.me-comment{gap:var(--me-space-2);flex-direction:column;display:flex}.me-comment-head{align-items:center;gap:var(--me-space-3);min-width:0;display:flex;position:relative}.me-comment-avatar{width:var(--me-comments-avatar-size);height:var(--me-comments-avatar-size);border-radius:var(--me-rounded-full);object-fit:cover;flex-shrink:0}.me-comment-avatar--initials{background:var(--me-color-surface);color:var(--me-color-text-muted);font-size:var(--me-comments-meta-font-size);font-weight:var(--me-font-weight-medium);justify-content:center;align-items:center;display:inline-flex}.me-comment-author{font-size:var(--me-comments-body-font-size);font-weight:var(--me-font-weight-medium);text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.me-comment-meta{min-width:0;color:var(--me-comments-meta-color);font-size:var(--me-comments-meta-font-size);white-space:nowrap;text-overflow:ellipsis;flex:1;overflow:hidden}.me-comment-menu-anchor{display:inline-flex;position:relative}.me-comment-more{opacity:0;transition:opacity var(--me-duration-fast)}.me-comment:hover .me-comment-more,.me-comment-more[aria-expanded=true],.me-comment-more:focus-visible{opacity:1}.me-comment-menu{z-index:30;margin-top:var(--me-space-2);position:absolute;top:100%;right:0}.me-menu-item--danger{color:var(--me-color-danger)}.me-comment-body{font-size:var(--me-comments-body-font-size);padding-left:calc(var(--me-comments-avatar-size) + var(--me-space-3))}.me-comment-body p{min-height:0;margin:0;padding:0}.me-comment-composer{gap:var(--me-space-3);cursor:auto;flex-direction:column;display:flex}.me-comment-field{position:relative}.me-comment-input{min-height:var(--me-comments-composer-min-height);padding:var(--me-comments-composer-padding);border-radius:var(--me-radius-md);background:var(--me-comments-composer-bg);font-size:var(--me-comments-body-font-size)}.me-comment-input p{min-height:0;margin:0;padding:0}.me-comment-placeholder{padding:var(--me-comments-composer-padding);color:var(--me-color-text-faint);font-size:var(--me-comments-body-font-size);pointer-events:none;position:absolute;top:0;left:0}.me-comment-actions{justify-content:flex-end;gap:var(--me-space-3);display:flex}.me-comment-error{color:var(--me-color-danger);font-size:var(--me-comments-meta-font-size)}}
2
+ /*$vite$:1*/
@@ -0,0 +1,28 @@
1
+ import { Editor, type JSONContent } from '@tiptap/vue-3';
2
+ import { type LocaleName } from '@toantranmei/editor';
3
+ import type { CommentsMessages } from './messages';
4
+ import type { CommentsSource } from './types';
5
+ type __VLS_Props = {
6
+ source: CommentsSource;
7
+ locale: LocaleName;
8
+ m: CommentsMessages;
9
+ placeholder: string;
10
+ submitLabel: string;
11
+ initial?: JSONContent | null;
12
+ autofocus?: boolean;
13
+ /** Show Cancel. */
14
+ cancellable?: boolean;
15
+ /** Saves the body; the box clears when it resolves and shows an error when it rejects. */
16
+ send: (body: JSONContent) => Promise<unknown>;
17
+ };
18
+ declare function submit(): Promise<void>;
19
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
20
+ editor: import("vue").ShallowRef<Editor, Editor>;
21
+ submit: typeof submit;
22
+ }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
23
+ cancel: () => any;
24
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
25
+ onCancel?: (() => any) | undefined;
26
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
27
+ declare const _default: typeof __VLS_export;
28
+ export default _default;
@@ -0,0 +1,13 @@
1
+ import type { LocaleName } from '@toantranmei/editor';
2
+ import type { CommentsMessages } from './messages';
3
+ import type { Comment, CommentsSource } from './types';
4
+ type __VLS_Props = {
5
+ comment: Comment;
6
+ source: CommentsSource;
7
+ m: CommentsMessages;
8
+ locale: LocaleName;
9
+ canComment: boolean;
10
+ };
11
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
@@ -0,0 +1,20 @@
1
+ import type { Editor } from '@tiptap/core';
2
+ import type { LocaleName } from '@toantranmei/editor';
3
+ import { type CommentsMessages } from './messages';
4
+ import type { CommentsSource } from './types';
5
+ type __VLS_Props = {
6
+ editor: Editor | null | undefined;
7
+ source: CommentsSource;
8
+ locale?: LocaleName;
9
+ messages?: Partial<Record<LocaleName, Partial<CommentsMessages>>>;
10
+ };
11
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
12
+ open: (threadIds: string[]) => any;
13
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
14
+ onOpen?: ((threadIds: string[]) => any) | undefined;
15
+ }>, {
16
+ messages: Partial<Record<"vi" | "en" | "zh", Partial<CommentsMessages>>>;
17
+ locale: "vi" | "en" | "zh";
18
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
19
+ declare const _default: typeof __VLS_export;
20
+ export default _default;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Side panel: open / resolved threads of the page, the draft for a new comment, replies,
3
+ * edit / delete own comments, resolve / re-open. Clicking a thread scrolls the editor to it.
4
+ */
5
+ import type { Editor } from '@tiptap/core';
6
+ import type { LocaleName } from '@toantranmei/editor';
7
+ import { type CommentsMessages } from './messages';
8
+ import type { CommentsLevel, CommentsSource } from './types';
9
+ type __VLS_Props = {
10
+ source: CommentsSource;
11
+ /** The page's editor: threads follow document order and clicking one scrolls to it. */
12
+ editor?: Editor | null;
13
+ level?: CommentsLevel;
14
+ locale?: LocaleName;
15
+ messages?: Partial<Record<LocaleName, Partial<CommentsMessages>>>;
16
+ };
17
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
18
+ editor: Editor | null;
19
+ level: CommentsLevel;
20
+ messages: Partial<Record<"vi" | "en" | "zh", Partial<CommentsMessages>>>;
21
+ locale: "vi" | "en" | "zh";
22
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
23
+ declare const _default: typeof __VLS_export;
24
+ export default _default;
@@ -0,0 +1,20 @@
1
+ import type { LocaleName } from '@toantranmei/editor';
2
+ import type { CommentsMessages } from './messages';
3
+ import type { CommentsSource, Thread } from './types';
4
+ type __VLS_Props = {
5
+ thread: Thread;
6
+ source: CommentsSource;
7
+ m: CommentsMessages;
8
+ locale: LocaleName;
9
+ canComment: boolean;
10
+ active: boolean;
11
+ /** The commented text is no longer in the document. */
12
+ detached: boolean;
13
+ };
14
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
15
+ select: () => any;
16
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
17
+ onSelect?: (() => any) | undefined;
18
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
19
+ declare const _default: typeof __VLS_export;
20
+ export default _default;
@@ -0,0 +1,47 @@
1
+ import type { Node as PMNode } from '@tiptap/pm/model';
2
+ import type { EditorState } from '@tiptap/pm/state';
3
+ import type { Anchor, Thread } from './types';
4
+ /** Longest quote kept in an anchor. */
5
+ export declare const MAX_QUOTE = 500;
6
+ export declare const COMMENT_MARK = "comment";
7
+ /** Id (`data-id`) of the innermost block around `pos` that has one. */
8
+ export declare function blockIdAt(state: EditorState, pos: number): string | null;
9
+ /**
10
+ * Anchor for the current text selection: the first block's id and the selected text.
11
+ * Comment-only users can't change the document, so the anchor is all that identifies the
12
+ * text; the quote is limited to the first block so it can be found again by search.
13
+ */
14
+ export declare function selectionAnchor(state: EditorState): {
15
+ anchor: Anchor;
16
+ from: number;
17
+ to: number;
18
+ } | null;
19
+ export interface AnchorIndex {
20
+ /** Ranges of `comment` marks, per thread id. */
21
+ marks: Map<string, {
22
+ from: number;
23
+ to: number;
24
+ }[]>;
25
+ /** Blocks with an id: position and node. */
26
+ blocks: Map<string, {
27
+ pos: number;
28
+ node: PMNode;
29
+ }>;
30
+ }
31
+ /** One pass over the document: comment-mark ranges and block positions. */
32
+ export declare function indexDocument(doc: PMNode): AnchorIndex;
33
+ /** Finds `quote` in a textblock (or the first textblock containing it inside a block). */
34
+ export declare function findQuote(block: {
35
+ pos: number;
36
+ node: PMNode;
37
+ }, quote: string): {
38
+ from: number;
39
+ to: number;
40
+ } | null;
41
+ /** Document ranges to highlight for a thread: its marks, else its quote searched in its block. */
42
+ export declare function threadRanges(thread: Thread, index: AnchorIndex): {
43
+ from: number;
44
+ to: number;
45
+ }[];
46
+ /** Block id a thread belongs to (gutter), or null for page comments. */
47
+ export declare const threadBlockId: (thread: Thread) => string | null;
@@ -0,0 +1,8 @@
1
+ import type { CommentsOptions } from './types';
2
+ /**
3
+ * Comments for `<MeiEditor :blocks>`: `comments.configure({ source, level })`.
4
+ * Adds the `comment` mark, highlights open threads, and a "Comment" button in the
5
+ * selection bubble menu (also in read-only editors at `comment` level). Show the threads
6
+ * with `<CommentsPanel>` and per-block counts with `<CommentsGutter>`.
7
+ */
8
+ export declare const comments: import("@toantranmei/editor").BlockDefinition<CommentsOptions>;
@@ -0,0 +1,42 @@
1
+ import { Mark } from '@tiptap/core';
2
+ import { PluginKey } from '@tiptap/pm/state';
3
+ import { DecorationSet } from '@tiptap/pm/view';
4
+ import type { CommentsLevel, CommentsOptions, Thread } from './types';
5
+ declare module '@tiptap/core' {
6
+ interface Commands<ReturnType> {
7
+ comment: {
8
+ /** Marks the selection (or `range`) as commented by `threadId`. */
9
+ setComment: (threadId: string, range?: {
10
+ from: number;
11
+ to: number;
12
+ }) => ReturnType;
13
+ /** Removes a thread's marks from the whole document. */
14
+ unsetComment: (threadId: string) => ReturnType;
15
+ };
16
+ }
17
+ }
18
+ /**
19
+ * `comment` mark: `threadId` on the commented text. Not inclusive (typing at its edges
20
+ * isn't commented) and overlapping threads can share text. Works in collaboration mode
21
+ * (marks are synced through the Yjs document).
22
+ */
23
+ export declare const CommentMark: Mark<any, any>;
24
+ export declare const commentsPluginKey: PluginKey<HighlightState>;
25
+ interface HighlightState {
26
+ threads: Thread[];
27
+ activeId: string | null;
28
+ draft: {
29
+ from: number;
30
+ to: number;
31
+ } | null;
32
+ decorations: DecorationSet;
33
+ }
34
+ export declare const levelOf: (level: CommentsOptions["level"]) => CommentsLevel;
35
+ /** True when this level may add comments and replies. */
36
+ export declare const canComment: (level: CommentsLevel) => level is "comment" | "edit" | "full";
37
+ /**
38
+ * Highlights open threads (their marks, or the quote of comment-only anchors), the active
39
+ * thread and the draft; clicking a highlight opens its thread.
40
+ */
41
+ export declare const CommentsExtension: Mark<CommentsOptions, any>;
42
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { JSONContent, LocaleName } from '@toantranmei/editor';
2
+ /** http(s), mailto and relative links only (control characters stripped before checking). */
3
+ export declare function safeHref(url: unknown): string | null;
4
+ /** Comment body → safe HTML (escaped text, allow-listed links; mentions as chips). */
5
+ export declare function bodyHtml(body: JSONContent | null | undefined, _locale?: LocaleName): string;
6
+ /** "Oct 30, 2026, 2:05 PM" in the UI language. */
7
+ export declare function formatTime(iso: string | null | undefined, locale: LocaleName): string;
8
+ /** Up to two initials for an avatar placeholder. */
9
+ export declare const initials: (name: string) => string;
@@ -0,0 +1,11 @@
1
+ import './styles/comments.css';
2
+ export { comments } from './definition';
3
+ export { canComment, CommentMark, CommentsExtension, commentsPluginKey, levelOf } from './extension';
4
+ export { default as CommentsPanel } from './CommentsPanel.vue';
5
+ export { default as CommentsGutter } from './CommentsGutter.vue';
6
+ export { default as CommentComposer } from './CommentComposer.vue';
7
+ export { useCommentsState, type ActiveDraft, type CommentsState } from './store';
8
+ export { blockIdAt, findQuote, indexDocument, selectionAnchor, threadRanges, COMMENT_MARK } from './anchor';
9
+ export { bodyHtml } from './format';
10
+ export { commentsMessages, messages, type CommentsMessages } from './messages';
11
+ export type { Anchor, Comment, CommentAuthor, CommentDraft, CommentsLevel, CommentsOptions, CommentsSource, CommentsUser, Person, Thread, } from './types';
@@ -0,0 +1,36 @@
1
+ import type { LocaleName } from '@toantranmei/editor';
2
+ export interface CommentsMessages {
3
+ /** Bubble-menu action. */
4
+ comment: string;
5
+ /** Panel title. */
6
+ title: string;
7
+ open: string;
8
+ resolved: string;
9
+ resolve: string;
10
+ reopen: string;
11
+ reply: string;
12
+ replyPlaceholder: string;
13
+ placeholder: string;
14
+ send: string;
15
+ cancel: string;
16
+ edit: string;
17
+ delete: string;
18
+ save: string;
19
+ edited: string;
20
+ /** No open threads. */
21
+ empty: string;
22
+ emptyResolved: string;
23
+ /** Gutter badge label: `{count}` is replaced. */
24
+ threads: string;
25
+ /** Thread whose text was deleted from the page. */
26
+ detached: string;
27
+ /** Comment on the whole page. */
28
+ pageComment: string;
29
+ readOnly: string;
30
+ failed: string;
31
+ /** More actions on a comment. */
32
+ more: string;
33
+ }
34
+ export declare const messages: Record<LocaleName, CommentsMessages>;
35
+ /** Strings for a locale with the app's overrides. */
36
+ export declare function commentsMessages(locale: string | undefined, overrides?: Partial<Record<LocaleName, Partial<CommentsMessages>>> | null): CommentsMessages;
@@ -0,0 +1,23 @@
1
+ import type { Editor } from '@tiptap/core';
2
+ import { type Ref, type ShallowRef } from 'vue';
3
+ import type { CommentDraft, CommentsSource, Thread } from './types';
4
+ export interface ActiveDraft extends CommentDraft {
5
+ editor: Editor;
6
+ /** Stable per draft (ranges change as the document is edited). */
7
+ key: number;
8
+ }
9
+ /** UI state shared by the editor extension, the gutter and the panel of one source. */
10
+ export interface CommentsState {
11
+ /** Thread shown / highlighted (clicked highlight or badge, or picked in the panel). */
12
+ activeId: Ref<string | null>;
13
+ /** Comment being written for a selection. */
14
+ draft: ShallowRef<ActiveDraft | null>;
15
+ /** Panel filter. */
16
+ filter: Ref<'open' | 'resolved'>;
17
+ startDraft: (editor: Editor, draft: CommentDraft) => void;
18
+ cancelDraft: () => void;
19
+ /** Saves the draft as a new thread; editors also get the `comment` mark on the text. */
20
+ submitDraft: (body: Parameters<CommentsSource['create']>[1]) => Promise<Thread | null>;
21
+ }
22
+ /** The shared state of a source (created on first use). */
23
+ export declare function useCommentsState(source: CommentsSource): CommentsState;