@comty.io/core 0.1.3 → 0.1.5

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/src/comments.js CHANGED
@@ -3,7 +3,7 @@ export function createCommentThread(context) {
3
3
  const {
4
4
  root, apiUrl, projectKey, commentStatuses, selectedStatusFilters, placedPins,
5
5
  closeBubbles, getCommentStatus, updateCommentStatus, applyStatusDot,
6
- renderSidepanelComments, applyStatusFilters, createThreadItem,
6
+ renderSidepanelComments, applyStatusFilters, createThreadItem, renderCommentContent,
7
7
  isOwnCommentEntry, updateCommentContent, deleteSdkComment, getCommentId,
8
8
  updateReplyContent, deleteSdkReply, createCommentAvatar, getSdkHeaders,
9
9
  showAuthPrompt,
@@ -31,14 +31,6 @@ export function createCommentThread(context) {
31
31
  const header = document.createElement("div");
32
32
  header.className = "comty-bubble-header";
33
33
 
34
- const title = document.createElement("h2");
35
- title.className = "comty-bubble-title";
36
- title.innerText = "Comment";
37
- header.appendChild(title);
38
-
39
- const headerActions = document.createElement("div");
40
- headerActions.className = "comty-bubble-header-actions";
41
-
42
34
  const statusMenuButton = document.createElement("button");
43
35
  statusMenuButton.className = "comty-status-trigger";
44
36
  statusMenuButton.type = "button";
@@ -77,7 +69,7 @@ export function createCommentThread(context) {
77
69
  };
78
70
 
79
71
  const saveStatus = async (nextStatus, control) => {
80
- if (!context.canWrite) return false;
72
+ if (!context.canManage) return false;
81
73
  control.disabled = true;
82
74
  const savedStatus = await updateCommentStatus(comment, nextStatus);
83
75
  control.disabled = false;
@@ -102,7 +94,7 @@ export function createCommentThread(context) {
102
94
  return true;
103
95
  };
104
96
 
105
- statusMenuButton.disabled = !context.canWrite;
97
+ statusMenuButton.disabled = !context.canManage;
106
98
  statusMenuButton.onclick = (event) => {
107
99
  event.stopPropagation();
108
100
  const existingPopover = document.querySelector(
@@ -114,10 +106,11 @@ export function createCommentThread(context) {
114
106
  if (existingPopover) return;
115
107
 
116
108
  const popover = document.createElement("div");
117
- popover.className = "comty-popover comty-status-popover";
109
+ popover.className = "comty-popover comty-comment-popover comty-status-popover";
118
110
  const buttonRect = statusMenuButton.getBoundingClientRect();
119
111
  popover.style.top = `${buttonRect.bottom + 4}px`;
120
- popover.style.left = `${buttonRect.right - 140}px`;
112
+ popover.style.left = `${buttonRect.left}px`;
113
+ popover.style.transformOrigin = "top left";
121
114
 
122
115
  for (const status of commentStatuses) {
123
116
  const item = document.createElement("button");
@@ -155,6 +148,13 @@ export function createCommentThread(context) {
155
148
  }
156
149
 
157
150
  root.appendChild(popover);
151
+ const popoverWidth = popover.offsetWidth;
152
+ const popoverHeight = popover.offsetHeight;
153
+ popover.style.left = `${Math.max(8, Math.min(buttonRect.left, innerWidth - popoverWidth - 8))}px`;
154
+ if (buttonRect.bottom + 4 + popoverHeight > innerHeight - 8) {
155
+ popover.style.top = `${Math.max(8, buttonRect.top - popoverHeight - 4)}px`;
156
+ popover.style.transformOrigin = "bottom left";
157
+ }
158
158
 
159
159
  const closeStatusPopover = (closeEvent) => {
160
160
  if (
@@ -171,9 +171,7 @@ export function createCommentThread(context) {
171
171
  );
172
172
  };
173
173
 
174
- headerActions.appendChild(statusMenuButton);
175
- headerActions.appendChild(closeButton);
176
- header.appendChild(headerActions);
174
+ header.append(statusMenuButton, closeButton);
177
175
  bubble.appendChild(header);
178
176
 
179
177
  const thread = document.createElement("div");
@@ -192,7 +190,7 @@ export function createCommentThread(context) {
192
190
 
193
191
  const popover = document.createElement("div");
194
192
  popover.className =
195
- "comty-popover comty-entry-actions-popover";
193
+ "comty-popover comty-comment-popover comty-entry-actions-popover";
196
194
 
197
195
  const editItem = document.createElement("button");
198
196
  editItem.className = "comty-popover-item";
@@ -278,7 +276,7 @@ export function createCommentThread(context) {
278
276
 
279
277
  const previousContent = entry.content;
280
278
  entry.content = nextContent;
281
- item.content.innerText = nextContent;
279
+ renderCommentContent(item.content, nextContent);
282
280
  editor.disabled = true;
283
281
  editor.replaceWith(item.content);
284
282
  renderSidepanelComments();
@@ -286,11 +284,11 @@ export function createCommentThread(context) {
286
284
  const savedContent = await persist(nextContent);
287
285
  if (!savedContent) {
288
286
  entry.content = previousContent;
289
- item.content.innerText = previousContent || "";
287
+ renderCommentContent(item.content, previousContent || "");
290
288
  renderSidepanelComments();
291
289
  return;
292
290
  }
293
- item.content.innerText = savedContent;
291
+ renderCommentContent(item.content, savedContent);
294
292
  renderSidepanelComments();
295
293
  };
296
294
 
@@ -396,9 +394,11 @@ export function createCommentThread(context) {
396
394
  replyForm.appendChild(createCommentAvatar(context.currentUser || { name: "You" }));
397
395
  const replyField = document.createElement("div");
398
396
  replyField.className = "comty-reply-field";
399
- const replyInput = document.createElement("input");
397
+ const replyInput = document.createElement("textarea");
400
398
  replyInput.className = "comty-reply-input";
401
399
  replyInput.placeholder = "Reply";
400
+ replyInput.rows = 1;
401
+ replyInput.setAttribute("aria-label", "Reply");
402
402
 
403
403
  const replyButton = document.createElement("button");
404
404
  replyButton.className = "comty-reply-button";
@@ -432,6 +432,7 @@ export function createCommentThread(context) {
432
432
  comment.replies = replies;
433
433
  appendReply(data.reply);
434
434
  replyInput.value = "";
435
+ syncReplySize();
435
436
  requestAnimationFrame(() => {
436
437
  threadList.scrollTop = threadList.scrollHeight;
437
438
  });
@@ -445,12 +446,28 @@ export function createCommentThread(context) {
445
446
  }
446
447
  };
447
448
 
449
+ const syncReplySize = () => {
450
+ const currentHeight = replyInput.getBoundingClientRect().height;
451
+ replyInput.style.transition = "none";
452
+ const lineHeight = parseFloat(getComputedStyle(replyInput).lineHeight);
453
+ replyInput.style.height = `${lineHeight}px`;
454
+ const contentHeight = replyInput.scrollHeight;
455
+ replyInput.style.height = `${currentHeight}px`;
456
+ replyInput.getBoundingClientRect();
457
+ replyInput.style.transition = "";
458
+ const nextHeight = Math.min(contentHeight, parseFloat(getComputedStyle(replyInput).maxHeight));
459
+ replyInput.style.height = `${nextHeight}px`;
460
+ if (contentHeight <= lineHeight + 1) replyInput.scrollTop = 0;
461
+ replyField.classList.toggle("comty-reply-expanded", contentHeight > lineHeight + 1);
462
+ };
463
+
448
464
  replyInput.oninput = () => {
465
+ syncReplySize();
449
466
  replyButton.disabled = replyInput.value.trim().length === 0;
450
467
  };
451
468
  replyInput.onkeydown = (event) => {
452
469
  event.stopPropagation();
453
- if (event.key === "Enter" && !event.shiftKey) {
470
+ if (event.key === "Enter" && !event.shiftKey && !event.isComposing) {
454
471
  event.preventDefault();
455
472
  void submitReply();
456
473
  }
@@ -468,10 +485,10 @@ export function createCommentThread(context) {
468
485
  const signInButton = document.createElement("button");
469
486
  signInButton.className = "comty-sign-in-reply";
470
487
  signInButton.type = "button";
471
- signInButton.innerText = "Sign in to reply";
488
+ signInButton.innerText = context.allowGuestComments ? "Leave a reply" : "Sign in to reply";
472
489
  signInButton.onclick = (event) => {
473
490
  event.stopPropagation();
474
- showAuthPrompt();
491
+ showAuthPrompt(false, () => openCommentThread(comment, pin, pinStatusDot, x, y, removeHoverBubble));
475
492
  };
476
493
  replyForm.appendChild(signInButton);
477
494
  }