@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.
- package/LICENSE +21 -0
- package/README.md +113 -2
- package/dist/index.js +895 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +2 -0
- package/dist/types/CommentComposer.vue.d.ts +28 -0
- package/dist/types/CommentItem.vue.d.ts +13 -0
- package/dist/types/CommentsGutter.vue.d.ts +20 -0
- package/dist/types/CommentsPanel.vue.d.ts +24 -0
- package/dist/types/ThreadCard.vue.d.ts +20 -0
- package/dist/types/anchor.d.ts +47 -0
- package/dist/types/definition.d.ts +8 -0
- package/dist/types/extension.d.ts +42 -0
- package/dist/types/format.d.ts +9 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/messages.d.ts +36 -0
- package/dist/types/store.d.ts +23 -0
- package/dist/types/types.d.ts +90 -0
- package/package.json +80 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 toantranmei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,114 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @toantranmei/comments
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Notion-style comments for [`@toantranmei/editor`](https://www.npmjs.com/package/@toantranmei/editor).
|
|
4
|
+
|
|
5
|
+
- Select text → **Comment** in the bubble menu → write in the side panel (@mention people, ⌘/Ctrl+Enter sends)
|
|
6
|
+
- `comment` mark (`threadId`) on the commented text: not inclusive, overlapping threads, synced in collaboration mode
|
|
7
|
+
- Gutter badges with the number of open threads per block (block ids = `data-id`)
|
|
8
|
+
- `<CommentsPanel>`: open / resolved filter, threads in document order, replies, edit / delete your own
|
|
9
|
+
comments, resolve / re-open; click a highlight or a badge to open its thread
|
|
10
|
+
- Access levels: `view` sees comments, `comment` comments in a **read-only** editor (no document change),
|
|
11
|
+
`edit` / `full` also mark the text
|
|
12
|
+
- Vietnamese, English and Simplified Chinese, styled with the editor's design tokens (`component.comments.*`)
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm i @toantranmei/comments
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Peers: `@toantranmei/editor` `^0.3.0`, `vue` `^3.5`, Tiptap `3.32.0` (`@tiptap/core`, `@tiptap/pm`, `@tiptap/vue-3`,
|
|
21
|
+
`@tiptap/starter-kit`) and `@lucide/vue` — all installed with the editor.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```vue
|
|
26
|
+
<script setup lang="ts">
|
|
27
|
+
import { defaultBlocks, MeiEditor, mention, type Editor } from '@toantranmei/editor'
|
|
28
|
+
import { comments, CommentsGutter, CommentsPanel, type CommentsSource } from '@toantranmei/comments'
|
|
29
|
+
import '@toantranmei/editor/style.css'
|
|
30
|
+
import '@toantranmei/comments/style.css'
|
|
31
|
+
|
|
32
|
+
const props = defineProps<{ pageId: string, level: 'view' | 'comment' | 'edit' | 'full' }>()
|
|
33
|
+
const source: CommentsSource = useCommentsApi(props.pageId) // your adapter, see below
|
|
34
|
+
const blocks = [...defaultBlocks, mention, comments.configure({ source, level: () => props.level })]
|
|
35
|
+
const editor = shallowRef<Editor | null>(null)
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<template>
|
|
39
|
+
<div class="page">
|
|
40
|
+
<div class="editor-column"><!-- leave ~40px on the right for the badges -->
|
|
41
|
+
<MeiEditor :blocks="blocks" :editable="level === 'edit' || level === 'full'" @ready="editor = $event" />
|
|
42
|
+
<CommentsGutter :editor="editor" :source="source" locale="vi" />
|
|
43
|
+
</div>
|
|
44
|
+
<CommentsPanel :source="source" :editor="editor" :level="level" locale="vi" />
|
|
45
|
+
</div>
|
|
46
|
+
</template>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Adapter (`CommentsSource`)
|
|
50
|
+
|
|
51
|
+
Data shapes follow the notes API contract (2.4):
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
type Anchor = { kind: 'page' } | { kind: 'block', block_id: string } | { kind: 'text', block_id: string, quote: string }
|
|
55
|
+
interface Thread { id: string, anchor: Anchor, resolved_at: string | null, comments: Comment[] }
|
|
56
|
+
interface Comment { id: string, author: { id, name, avatar_url? }, body: JSONContent, created_at: string, edited_at?: string | null }
|
|
57
|
+
|
|
58
|
+
interface CommentsSource {
|
|
59
|
+
me: Ref<{ id: string, name: string, avatar?: string | null } | null> // null: signed out (read only)
|
|
60
|
+
threads: Ref<Thread[]> // live list for the page
|
|
61
|
+
create(anchor: Anchor, body: JSONContent): Promise<Thread> // POST /resources/{id}/comments
|
|
62
|
+
reply(threadId: string, body: JSONContent): Promise<Comment> // POST /comments/{thread}/replies
|
|
63
|
+
edit(commentId: string, body: JSONContent): Promise<void | Comment> // PATCH /comments/{id}
|
|
64
|
+
remove(commentId: string): Promise<void> // DELETE /comments/{id}
|
|
65
|
+
resolve(threadId: string, resolved: boolean): Promise<void | Thread> // POST /comments/{thread}/resolve
|
|
66
|
+
people(query: string): Person[] | Promise<Person[]> // @mention suggestions
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The methods update `threads` themselves (optimistically or from the response); load `threads` on open and
|
|
71
|
+
refresh it on sync events. Bodies are small ProseMirror documents (paragraphs, marks, `mention` nodes with
|
|
72
|
+
`kind: 'user'`): scan them for mentions to send notifications.
|
|
73
|
+
|
|
74
|
+
### How anchors work
|
|
75
|
+
|
|
76
|
+
Every new thread is anchored `{ kind: 'text', block_id, quote }` (the first block of the selection, its
|
|
77
|
+
selected text). Editors (`edit` / `full`, editable editor) also put the `comment` mark on the text, which
|
|
78
|
+
follows edits and syncs through Yjs. Comment-only users can't change the document, so their threads are
|
|
79
|
+
found again by searching `quote` in the block `block_id`. Resolved threads aren't highlighted. Threads whose
|
|
80
|
+
text is gone stay in the panel (struck-through quote).
|
|
81
|
+
|
|
82
|
+
### Options
|
|
83
|
+
|
|
84
|
+
`comments.configure({ ... })`:
|
|
85
|
+
|
|
86
|
+
| Option | Description |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| `source` | The adapter |
|
|
89
|
+
| `level` | `'view' \| 'comment' \| 'edit' \| 'full'` (default `'edit'`), a ref or a getter |
|
|
90
|
+
| `onCompose(draft)` | Called when "Comment" starts a draft (e.g. open your panel) |
|
|
91
|
+
| `onOpenThread(id)` | Called when a highlight is clicked |
|
|
92
|
+
| `messages` | Override strings: `{ en: { comment: 'Add comment' } }` |
|
|
93
|
+
|
|
94
|
+
`<CommentsPanel>` props: `source`, `editor?`, `level?`, `locale?`, `messages?`.
|
|
95
|
+
`<CommentsGutter>` props: `editor`, `source`, `locale?`, `messages?`; event `open(threadIds)`. It renders inside
|
|
96
|
+
the editor root (`.me-root`), to its right (`component.comments.badgeOffset`).
|
|
97
|
+
|
|
98
|
+
Also exported: `useCommentsState(source)` (shared `activeId`, `draft`, `filter`, `startDraft`, `submitDraft`),
|
|
99
|
+
`CommentMark`, `selectionAnchor`, `findQuote`, `indexDocument`, `threadRanges`, `bodyHtml`,
|
|
100
|
+
`editor.commands.setComment(threadId, range?)` / `unsetComment(threadId)`.
|
|
101
|
+
|
|
102
|
+
Load `comments` in **every** editor of a page (also the read-only ones): editors without it drop the
|
|
103
|
+
`comment` marks when they save. `renderHTML` renders the mark as plain text (public pages show no comments).
|
|
104
|
+
|
|
105
|
+
### Styling
|
|
106
|
+
|
|
107
|
+
Tokens under `component.comments` (`highlight`, `highlightActive`, `underline`, `badge*`, `panel*`, `thread*`,
|
|
108
|
+
`quote*`, `avatarSize`, `meta*`, `bodyFontSize`, `composer*`). Classes: `.me-comment-highlight` (`.is-active`),
|
|
109
|
+
`.me-comments-badge`, `.me-comments-panel`, `.me-comment-thread` (`.is-active`, `.is-resolved`, `.is-draft`),
|
|
110
|
+
`.me-comment`, `.me-comment-composer`.
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT
|