Skip to content

Commit 14275ba

Browse files
committed
Env docs with feedback applied
1 parent 56a00b5 commit 14275ba

File tree

4 files changed

+87
-185
lines changed

4 files changed

+87
-185
lines changed

async-collaboration/comments/customize-behavior.mdx

Lines changed: 22 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ commentElement.addCommentOnSelectedText();
9090

9191
Adds a Comment on a specific element by ID.
9292

93-
To add a comment on a specific element through an API method, use the `addCommentOnElement()` method and pass in an object with the schema shown in the examples:
93+
To add a comment on a specific element through an API method, use the `addCommentOnElement()` method and pass in an object with the schema shows in the example:
9494

9595
**Example 1: Add comment with targetElementId only:**
9696

@@ -100,17 +100,17 @@ To add a comment on a specific element through an API method, use the `addCommen
100100
```jsx
101101
const element = {
102102
"targetElement": {
103-
"elementId": "element_id",
103+
"elementId": "element_id", // optional (pass elementId if you want to add comment on a specific element)
104104
"targetText": "target_text", // optional (pass targetText if you want to add comment on a specific text)
105105
"occurrence": 1, // optional (default: 1) This is relevant for text comment. By default, we will attach comment to the first occurence of the target text in your document. You can change this to attach your comment on a more specific text.
106106
"selectAllContent": true, // Set to `true` if you want to select all the text content of the target element.
107107
},
108108
"commentData": [
109109
{
110-
"commentText": "This is awesome! Well done.",
111-
"commentHtml": "This <span style=\"color: green; background-color: aliceblue; display: inline-block; padding: 4px; border-radius: 4px;\">is test</span> comment.",
112-
"replaceContentText": "This is new comment",
113-
"replaceContentHtml": "<span>This is <b>new</b> comment.</span>",
110+
"commentText": "This is awesome! Well done.", // To set plain text content
111+
"commentHtml": "This <span style=\"color: green; background-color: aliceblue; display: inline-block; padding: 4px; border-radius: 4px;\">is test</span> comment.", // To set HTML formatted content
112+
"replaceContentText": "This is new comment", // provide this replaceContentText to replace current text with
113+
"replaceContentHtml": "<span>This is <b>new</b> comment.</span>", // If replacement text contains html formatted text, then provide it here
114114
}
115115
],
116116
"status": "open", // optional (default: open)
@@ -126,17 +126,17 @@ commentElement.addCommentOnElement(element);
126126
```jsx
127127
const element = {
128128
"targetElement": {
129-
"elementId": "element_id",
129+
"elementId": "element_id", // optional (pass elementId if you want to add comment on a specific element)
130130
"targetText": "target_text", // optional (pass targetText if you want to add comment on a specific text)
131131
"occurrence": 1, // optional (default: 1) This is relevant for text comment. By default, we will attach comment to the first occurence of the target text in your document. You can change this to attach your comment on a more specific text.
132132
"selectAllContent": true, // Set to `true` if you want to select all the text content of the target element.
133133
},
134134
"commentData": [
135135
{
136-
"commentText": "This is awesome! Well done.",
137-
"commentHtml": "This <span style=\"color: green; background-color: aliceblue; display: inline-block; padding: 4px; border-radius: 4px;\">is test</span> comment.",
138-
"replaceContentText": "This is new comment",
139-
"replaceContentHtml": "<span>This is <b>new</b> comment.</span>",
136+
"commentText": "This is awesome! Well done.", // To set plain text content
137+
"commentHtml": "This <span style=\"color: green; background-color: aliceblue; display: inline-block; padding: 4px; border-radius: 4px;\">is test</span> comment.", // To set HTML formatted content
138+
"replaceContentText": "This is new comment", // provide this replaceContentText to replace current text with
139+
"replaceContentHtml": "<span>This is <b>new</b> comment.</span>", // If replacement text contains html formatted text, then provide it here
140140
}
141141
],
142142
"status": "open", // optional (default: open)
@@ -148,58 +148,6 @@ commentElement.addCommentOnElement(element);
148148
</Tab>
149149
</Tabs>
150150

151-
**Example 2: Add comment with context metadata:**
152-
153-
<Tabs>
154-
<Tab title="React / Next.js">
155-
156-
```jsx
157-
const element = {
158-
"targetElement": {
159-
"elementId": "element_id",
160-
},
161-
"commentData": [
162-
{
163-
"commentText": "This is awesome! Well done.",
164-
}
165-
],
166-
"context": {
167-
"product": "cheese",
168-
"location": "zurich"
169-
},
170-
"status": "open",
171-
}
172-
173-
const commentElement = client.getCommentElement();
174-
commentElement.addCommentOnElement(element);
175-
```
176-
</Tab>
177-
178-
<Tab title="Other Frameworks">
179-
180-
```jsx
181-
const element = {
182-
"targetElement": {
183-
"elementId": "element_id",
184-
},
185-
"commentData": [
186-
{
187-
"commentText": "This is awesome! Well done.",
188-
}
189-
],
190-
"context": {
191-
"product": "cheese",
192-
"location": "zurich"
193-
},
194-
"status": "open",
195-
}
196-
197-
const commentElement = Velt.getCommentElement();
198-
commentElement.addCommentOnElement(element);
199-
```
200-
</Tab>
201-
</Tabs>
202-
203151
#### addManualComment
204152
- This feature is particularly useful for complex UIs where you need precise control over the placement of Comment Pins.
205153
- Using this you can manually set the position of Comment Annotations.
@@ -2118,33 +2066,18 @@ Extra fields in the comment context don't prevent a match.
21182066
{ product: "cheese", category: "dairy"} ❌ No match (missing field)
21192067
```
21202068
2121-
**Example 1: Comment Bubble with Partial Match**
2069+
**Example**
21222070
21232071
<Tabs>
21242072
<Tab title="React / Next.js">
21252073
```jsx
2074+
{/* Comment Bubble with Partial Match */}
21262075
<VeltCommentBubble
21272076
context={{ product: "cheese" }}
21282077
contextOptions={{ partialMatch: true }}
21292078
/>
2130-
```
2131-
</Tab>
2132-
<Tab title="Other Frameworks">
2133-
```html
2134-
<velt-comment-bubble
2135-
context='{ "product": "cheese" }'
2136-
context-options='{ "partialMatch": true }'
2137-
>
2138-
</velt-comment-bubble>
2139-
```
2140-
</Tab>
2141-
</Tabs>
21422079

2143-
**Example 2: Comment Tool with Partial Match**
2144-
2145-
<Tabs>
2146-
<Tab title="React / Next.js">
2147-
```jsx
2080+
{/* Comment Tool with Partial Match */}
21482081
<VeltCommentTool
21492082
targetElementId="element_id"
21502083
context={{ product: "cheese" }}
@@ -2154,6 +2087,14 @@ Extra fields in the comment context don't prevent a match.
21542087
</Tab>
21552088
<Tab title="Other Frameworks">
21562089
```html
2090+
<!-- Comment Bubble with Partial Match -->
2091+
<velt-comment-bubble
2092+
context='{ "product": "cheese" }'
2093+
context-options='{ "partialMatch": true }'
2094+
>
2095+
</velt-comment-bubble>
2096+
2097+
<!-- Comment Tool with Partial Match -->
21572098
<velt-comment-tool
21582099
target-element-id="element_id"
21592100
context='{ "product": "cheese" }'

async-collaboration/comments/setup/popover.mdx

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This component is required to render comments in your app. Popover mode means co
4444
```
4545

4646
</Tab>
47-
<Tab title="HTML">
47+
<Tab title="Other Frameworks">
4848

4949
Add the comment component to your template close to the root level of your `<body>`.
5050

@@ -70,6 +70,7 @@ Add a Comment Tool near each cell or element you want to comment on. For example
7070
- Add unique DOM ID to each element
7171
- Set the `targetElementId` to match the element's ID
7272
- When users click on the Comment Tool, it attaches a Comment to that element
73+
- If your app is more complex and cannot have unique IDs for each element (e.g., table cell), you could also use `context` to bind the element and comment with custom metadata, which can then be used to filter, group, and render comments that match specific criteria. [Learn more](/async-collaboration/comments/customize-behavior#aggregation)
7374

7475
![](/images/comment-tool.png)
7576

@@ -116,7 +117,8 @@ Add a Comment Tool in a single location such as the navigation bar.
116117

117118
- Add unique DOM ID and `data-velt-target-comment-element-id` attribute to each element (both with the same value)
118119
- When users click on the Comment Tool and then click on the target element, it attaches a Comment to it
119-
- You can only add one Comment per element with this approach
120+
- You can only add one Comment Annotation (thread) per element with this approach
121+
- If your app is more complex and cannot have unique IDs for each element (e.g., table cell), you could also use `context` to bind the element and comment with custom metadata, which can then be used to filter, group, and render comments that match specific criteria. [Learn more](/async-collaboration/comments/customize-behavior#aggregation)
120122

121123
<Warning>
122124
If you don't add the `data-velt-target-comment-element-id` attribute, you will be adding multiple Comment Annotations on the same element.
@@ -157,11 +159,10 @@ If you don't add the `data-velt-target-comment-element-id` attribute, you will b
157159

158160
## Step 4: Add Metadata to the Comment
159161

160-
You can add metadata to comments to:
161-
- Render additional data on comments
162-
- Position comment pins manually
162+
- Render additional data on comments UI
163163
- Create custom UI components
164164
- Enable comment filtering on custom data
165+
- Use the metadata later when processing notifications
165166

166167
### a. Using Comment Tool
167168

@@ -196,7 +197,7 @@ Either use this or the default triangle component. Using both could cause visual
196197

197198
The Comment Bubble component:
198199
- Displays a count of replies for a comment thread
199-
- Must have the same `targetElementId` as its associated element
200+
- Must have the same `targetElementId` or `context` as its associated element and comment tool
200201
- Can show either total replies or only unread replies
201202
- Can be placed anywhere in your UI
202203

@@ -252,7 +253,7 @@ The Comment Bubble component:
252253
</Tab>
253254
</Tabs>
254255

255-
## Step 6: Remove Popover Mode Triangle (optional)
256+
### Remove Popover Mode Triangle (optional)
256257

257258
![](/images/popover-comment-pin.png)
258259

@@ -293,7 +294,7 @@ commentElement.disablePopoverTriangleComponent();
293294
</Tab>
294295
</Tabs>
295296

296-
## Step 7: Test Integration
297+
## Step 6: Test Integration
297298

298299
Test it out by opening the page with Velt components in your browser.
299300

@@ -319,23 +320,26 @@ export default function App() {
319320
<VeltProvider apiKey="API_KEY">
320321
<VeltComments popoverMode={true} popoverTriangleComponent={true} />
321322

322-
{/* Comment Tool next to each element */}
323+
{/* Pattern a: Comment Tool next to each element */}
323324
<div className="table">
324-
<div className="cell" id="cell-id-1">
325-
<VeltCommentTool targetElementId="cell-id-1" />
325+
<div className="cell" id="cell-1">
326+
<VeltCommentTool targetElementId="cell-1" />
327+
<VeltCommentBubble targetElementId="cell-1" />
326328
</div>
327-
<div className="cell" id="cell-id-2">
328-
<VeltCommentBubble targetElementId="cell-id-2" />
329+
<div className="cell" id="cell-2">
330+
<VeltCommentTool targetElementId="cell-2" />
329331
</div>
330332
</div>
331333

332-
{/* Single Comment Tool */}
334+
{/* Pattern b: Single Comment Tool */}
333335
<div>
334-
<VeltCommentTool/>
336+
<VeltCommentTool />
335337
<div className="table">
336-
<div className="cell" data-velt-target-comment-element-id="cell-id-A" id="cell-id-A">
338+
<div className="cell" id="cell-A" data-velt-target-comment-element-id="cell-A">
339+
Content
337340
</div>
338-
<div className="cell" data-velt-target-comment-element-id="cell-id-B" id="cell-id-B">
341+
<div className="cell" id="cell-B" data-velt-target-comment-element-id="cell-B">
342+
Content
339343
</div>
340344
</div>
341345
</div>
@@ -348,36 +352,33 @@ export default function App() {
348352
<Tab title="HTML">
349353

350354
```html
351-
<!DOCTYPE html>
352-
<html lang="en">
353-
<head>
354-
<title>Comment documentation</title>
355-
</head>
356-
<body>
357-
<velt-comments popover-triangle-component="true"></velt-comments>
358-
359-
<!-- Comment Tool next to each element -->
360-
<div class="table">
361-
<div class="cell" id="cell-id-1">
362-
<velt-comment-tool target-element-id="cell-id-1"></velt-comment-tool>
363-
</div>
364-
<div class="cell" id="cell-id-2">
365-
<velt-comment-bubble target-element-id="cell-id-2"></velt-comment-bubble>
366-
</div>
355+
<body>
356+
<velt-comments popover-mode="true" popover-triangle-component="true"></velt-comments>
357+
358+
<!-- Pattern a: Comment Tool next to each element -->
359+
<div class="table">
360+
<div class="cell" id="cell-1">
361+
<velt-comment-tool target-element-id="cell-1"></velt-comment-tool>
362+
<velt-comment-bubble target-element-id="cell-1"></velt-comment-bubble>
363+
</div>
364+
<div class="cell" id="cell-2">
365+
<velt-comment-tool target-element-id="cell-2"></velt-comment-tool>
367366
</div>
367+
</div>
368368

369-
<!-- Single Comment Tool -->
370-
<div>
371-
<velt-comment-tool></velt-comment-tool>
372-
<div class="table">
373-
<div class="cell" data-velt-target-comment-element-id="cell-id-A" id="cell-id-A">
374-
</div>
375-
<div class="cell" data-velt-target-comment-element-id="cell-id-B" id="cell-id-B">
376-
</div>
369+
<!-- Pattern b: Single Comment Tool -->
370+
<div>
371+
<velt-comment-tool></velt-comment-tool>
372+
<div class="table">
373+
<div class="cell" id="cell-A" data-velt-target-comment-element-id="cell-A">
374+
Content
375+
</div>
376+
<div class="cell" id="cell-B" data-velt-target-comment-element-id="cell-B">
377+
Content
377378
</div>
378379
</div>
379-
</body>
380-
</html>
380+
</div>
381+
</body>
381382
```
382383

383384
</Tab>

async-collaboration/comments/setup/tiptap.mdx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ title: "Tiptap Setup"
3232
#### Step 2: Install the Velt Tiptap extension
3333

3434
```bash
35-
npm i @veltdev/tiptap-velt-comments @tiptap/react @tiptap/starter-kit
35+
npm i @veltdev/tiptap-velt-comments
3636
```
3737

3838
#### Step 3: Import and add the extension to your Tiptap editor
@@ -94,6 +94,7 @@ Add a button in your existing bubble menu or create a new bubble menu that appea
9494
<BubbleMenu editor={editor} tippyOptions={{ duration: 100 }}>
9595
<div className="bubble-menu">
9696
<button
97+
className="comment-button"
9798
onClick={(e) => {
9899
e.preventDefault();
99100
e.stopPropagation();
@@ -117,11 +118,27 @@ Add a button in your existing bubble menu or create a new bubble menu that appea
117118
```
118119
</Tab>
119120
<Tab title="Other Frameworks">
121+
```html
122+
<!-- HTML Structure -->
123+
<div id="editor"></div>
124+
<div class="bubble-menu">
125+
<button class="comment-button" title="Add comment">
126+
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="currentColor">
127+
<path
128+
d="M10 17.25H4C3.30964 17.25 2.75 16.6904 2.75 16V10C2.75 5.99594 5.99594 2.75 10 2.75C14.0041 2.75 17.25 5.99594 17.25 10C17.25 14.0041 14.0041 17.25 10 17.25Z"
129+
stroke-width="1.5"
130+
/>
131+
</svg>
132+
</button>
133+
</div>
134+
```
135+
120136
```js
121137
import { BubbleMenu, Editor } from '@tiptap/core';
122138
import { addComment } from '@veltdev/tiptap-velt-comments';
123139

124140
const editor = new Editor({
141+
element: document.querySelector('#editor'),
125142
// ... your editor configuration
126143
});
127144

@@ -155,7 +172,7 @@ Refer to the [Tiptap BubbleMenu documentation](https://tiptap.dev/docs/editor/ex
155172
#### Step 5: Call `addComment` to add a comment
156173

157174
- Call this method to add a comment to selected text in the Tiptap editor. You can use this when the user clicks on the comment button in context menu or presses a keyboard shortcut.
158-
- Params: `AddCommentRequest`. It has the following properties:
175+
- Params: [`AddCommentRequest`](/api-reference/sdk/models/data-models#addcommentrequest). It has the following properties:
159176
- `editor`: instance of the Tiptap editor.
160177
- `editorId`: Id of the tiptap editor. Use this if you have multiple tiptap editors on the same page in your app. (optional)
161178
- `context`: Add any custom metadata to the Comment Annotation. [Learn more](/async-collaboration/comments/customize-behavior#metadata). (optional)
@@ -198,7 +215,7 @@ Refer to the [Tiptap BubbleMenu documentation](https://tiptap.dev/docs/editor/ex
198215
#### Step 6: Render Comments in Tiptap Editor
199216

200217
- Get the comment data from Velt SDK and render it in the Tiptap Editor.
201-
- Params: `RenderCommentsRequest`. It has the following properties:
218+
- Params: [`RenderCommentsRequest`](/api-reference/sdk/models/data-models#rendercommentsrequest). It has the following properties:
202219
- `editor`: Instance of the Tiptap editor.
203220
- `editorId`: Id of the tiptap editor. Use this if you have multiple tiptap editors on the same page in your app. (optional)
204221
- `commentAnnotations`: Array of Comment Annotation objects.

0 commit comments

Comments
 (0)