react-mention-input 1.1.17 → 1.1.19

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/demo.tsx CHANGED
@@ -8,14 +8,16 @@ const Demo: React.FC = () => {
8
8
  name: 'John Doe',
9
9
  date: '2 hours ago',
10
10
  comment: 'Updated the status to Draft. Need <span class="mention-highlight">@team-leads</span> review before proceeding. <span class="hashtag-highlight">#urgent</span> <span class="hashtag-highlight">#review</span>',
11
- objectName: '26may_item001 (A)',
11
+ objectName: '26may_item001',
12
+ revision: 'A',
12
13
  },
13
14
  {
14
15
  id: 2,
15
16
  name: 'Mike Johnson',
16
17
  date: '1 day ago',
17
18
  comment: 'Revision A completed successfully. Ready for next phase. <span class="hashtag-highlight">#milestone</span>',
18
- objectName: '26may_item001 (A)',
19
+ objectName: '26may_item001',
20
+ revision: 'A',
19
21
  }
20
22
  ]);
21
23
 
@@ -48,7 +50,8 @@ const Demo: React.FC = () => {
48
50
  imageUrl: messageData.imageUrl,
49
51
  tags: messageData.tags,
50
52
  mentions: messageData.userSelectListName,
51
- objectName: 'new_item001 (A)', // You can customize this or make it dynamic
53
+ objectName: 'new_item001', // You can customize this or make it dynamic
54
+ revision: 'A', // You can customize this or make it dynamic
52
55
  };
53
56
 
54
57
  setMessages([...messages, newMessage]);
@@ -27,6 +27,7 @@ interface MentionInputProps {
27
27
  name: string;
28
28
  }[];
29
29
  userSelectListName: string[];
30
+ tags: string[];
30
31
  images?: File[];
31
32
  imageUrl?: string | null;
32
33
  }) => void;
@@ -38,26 +38,33 @@ import React, { useState, useRef } from "react";
38
38
  import ReactDOM from "react-dom";
39
39
  import "./MentionInput.css";
40
40
  var MentionInput = function (_a) {
41
- var _b, _c;
42
- var users = _a.users, _d = _a.placeholder, placeholder = _d === void 0 ? "Type a message... (or drag & drop an image)" : _d, containerClassName = _a.containerClassName, inputContainerClassName = _a.inputContainerClassName, inputClassName = _a.inputClassName, sendBtnClassName = _a.sendBtnClassName, suggestionListClassName = _a.suggestionListClassName, suggestionItemClassName = _a.suggestionItemClassName, imgClassName = _a.imgClassName, imgStyle = _a.imgStyle, attachedImageContainerClassName = _a.attachedImageContainerClassName, attachedImageContainerStyle = _a.attachedImageContainerStyle, sendButtonIcon = _a.sendButtonIcon, attachmentButtonIcon = _a.attachmentButtonIcon, onSendMessage = _a.onSendMessage, _e = _a.suggestionPosition, suggestionPosition = _e === void 0 ? 'bottom' : _e, onImageUpload = _a.onImageUpload;
43
- var _f = useState(""), inputValue = _f[0], setInputValue = _f[1]; // Plain text
44
- var _g = useState([]), suggestions = _g[0], setSuggestions = _g[1];
45
- var _h = useState(false), showSuggestions = _h[0], setShowSuggestions = _h[1];
46
- var _j = useState(null), selectedImage = _j[0], setSelectedImage = _j[1];
47
- var _k = useState(null), imageUrl = _k[0], setImageUrl = _k[1];
48
- var _l = useState(false), isUploading = _l[0], setIsUploading = _l[1];
49
- var _m = useState(false), isDraggingOver = _m[0], setIsDraggingOver = _m[1];
41
+ var _b;
42
+ var users = _a.users, _c = _a.placeholder, placeholder = _c === void 0 ? "Type a message... (or drag & drop an image)" : _c, containerClassName = _a.containerClassName, inputContainerClassName = _a.inputContainerClassName, inputClassName = _a.inputClassName, sendBtnClassName = _a.sendBtnClassName, suggestionListClassName = _a.suggestionListClassName, suggestionItemClassName = _a.suggestionItemClassName, imgClassName = _a.imgClassName, imgStyle = _a.imgStyle, attachedImageContainerClassName = _a.attachedImageContainerClassName, attachedImageContainerStyle = _a.attachedImageContainerStyle, sendButtonIcon = _a.sendButtonIcon, attachmentButtonIcon = _a.attachmentButtonIcon, onSendMessage = _a.onSendMessage, _d = _a.suggestionPosition, suggestionPosition = _d === void 0 ? 'bottom' : _d, onImageUpload = _a.onImageUpload;
43
+ var _e = useState(""), inputValue = _e[0], setInputValue = _e[1]; // Plain text
44
+ var _f = useState([]), suggestions = _f[0], setSuggestions = _f[1];
45
+ var _g = useState(false), showSuggestions = _g[0], setShowSuggestions = _g[1];
46
+ var _h = useState(null), selectedImage = _h[0], setSelectedImage = _h[1];
47
+ var _j = useState(null), imageUrl = _j[0], setImageUrl = _j[1];
48
+ var _k = useState(false), isUploading = _k[0], setIsUploading = _k[1];
49
+ var _l = useState(false), isDraggingOver = _l[0], setIsDraggingOver = _l[1];
50
50
  var inputRef = useRef(null);
51
51
  var suggestionListRef = useRef(null);
52
52
  var caretOffsetRef = useRef(0);
53
53
  var userSelectListRef = useRef([]); // Only unique names
54
54
  var userSelectListWithIdsRef = useRef([]); // Unique IDs with names
55
+ var tagsListRef = useRef([]); // Store hashtags
55
56
  var fileInputRef = useRef(null);
56
57
  var highlightMentionsAndLinks = function (text) {
57
58
  // Regular expression for detecting links
58
59
  var linkRegex = /(https?:\/\/[^\s]+)/g;
60
+ // Regular expression for detecting hashtags
61
+ var hashtagRegex = /#[\w]+/g;
59
62
  // Highlight links
60
63
  var highlightedText = text.replace(linkRegex, '<a href="$1" target="_blank" rel="noopener noreferrer" class="link-highlight">$1</a>');
64
+ // Highlight hashtags
65
+ highlightedText = highlightedText.replace(hashtagRegex, function (match) {
66
+ return "<span class=\"hashtag-highlight\">".concat(match, "</span>");
67
+ });
61
68
  // Highlight mentions manually based on `userSelectListRef`
62
69
  userSelectListRef === null || userSelectListRef === void 0 ? void 0 : userSelectListRef.current.forEach(function (userName) {
63
70
  var mentionPattern = new RegExp("@".concat(userName, "(\\s|$)"), "g");
@@ -128,8 +135,17 @@ var MentionInput = function (_a) {
128
135
  else {
129
136
  setShowSuggestions(false);
130
137
  }
131
- // Only apply highlighting if we have mentions or links to highlight
132
- if (userSelectListRef.current.length > 0 || plainText.match(/(https?:\/\/[^\s]+)/g)) {
138
+ // Extract and store hashtags
139
+ var hashtagMatches = plainText.match(/#[\w]+/g);
140
+ if (hashtagMatches) {
141
+ var uniqueTags = Array.from(new Set(hashtagMatches));
142
+ tagsListRef.current = uniqueTags;
143
+ }
144
+ else {
145
+ tagsListRef.current = [];
146
+ }
147
+ // Only apply highlighting if we have mentions, hashtags, or links to highlight
148
+ if (userSelectListRef.current.length > 0 || plainText.match(/(https?:\/\/[^\s]+)/g) || plainText.match(/#[\w]+/g)) {
133
149
  var currentHTML = inputRef.current.innerHTML;
134
150
  var htmlWithHighlights = highlightMentionsAndLinks(plainText);
135
151
  // Only update if the highlighted HTML is different to avoid cursor jumping
@@ -317,6 +333,7 @@ var MentionInput = function (_a) {
317
333
  messageHTML: messageHTML,
318
334
  userSelectListWithIds: userSelectListWithIdsRef.current,
319
335
  userSelectListName: userSelectListRef.current,
336
+ tags: tagsListRef.current,
320
337
  images: selectedImage ? [selectedImage] : [],
321
338
  imageUrl: imageUrl
322
339
  });
@@ -327,6 +344,7 @@ var MentionInput = function (_a) {
327
344
  setImageUrl(null);
328
345
  userSelectListRef.current = [];
329
346
  userSelectListWithIdsRef.current = [];
347
+ tagsListRef.current = [];
330
348
  }
331
349
  }
332
350
  };
@@ -336,7 +354,6 @@ var MentionInput = function (_a) {
336
354
  handleSendMessage(); // Trigger the same function as the Send button
337
355
  }
338
356
  };
339
- console.log(inputValue, (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.innerText.trim(), "inputValue====");
340
357
  return (React.createElement("div", { className: "mention-container ".concat(containerClassName || "") },
341
358
  imageUrl && selectedImage && (React.createElement("div", { className: "image-preview-card ".concat(attachedImageContainerClassName || ""), style: attachedImageContainerStyle },
342
359
  React.createElement("img", { src: imageUrl, alt: "Preview", className: imgClassName || "", style: imgStyle }),
@@ -348,7 +365,7 @@ var MentionInput = function (_a) {
348
365
  React.createElement("button", { onClick: function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, className: "attachment-button", type: "button", "aria-label": "Attach image" },
349
366
  React.createElement("span", { className: "attachment-icon" }, attachmentButtonIcon || "📷")),
350
367
  React.createElement("div", { className: "mention-input-wrapper" },
351
- (!inputValue || !inputRef.current || ((_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.innerText.trim()) === "") && (React.createElement("span", { className: "placeholder" }, placeholder)),
368
+ (!inputValue || !inputRef.current || ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.innerText.trim()) === "") && (React.createElement("span", { className: "placeholder" }, placeholder)),
352
369
  React.createElement("div", { ref: inputRef, contentEditable: true, suppressContentEditableWarning: true, className: "mention-input ".concat(inputClassName || ""), onInput: handleInputChange, onKeyDown: handleKeyDown, onFocus: function () { return document.execCommand('styleWithCSS', false, 'false'); } })),
353
370
  React.createElement("button", { onClick: handleSendMessage, className: "send-button ".concat(sendBtnClassName || ""), "aria-label": "Send message" }, sendButtonIcon || "➤"),
354
371
  React.createElement("input", { type: "file", ref: fileInputRef, accept: "image/*", onChange: handleImageSelect, style: { display: 'none' } }),
@@ -38,6 +38,19 @@
38
38
  padding: 4px 8px;
39
39
  border-radius: 6px;
40
40
  border: 1px solid #e0e0e0;
41
+ display: flex;
42
+ align-items: center;
43
+ white-space: nowrap;
44
+ }
45
+
46
+ .object-name-text {
47
+ font-weight: 600;
48
+ }
49
+
50
+ .revision-text {
51
+ font-weight: 400;
52
+ color: #888;
53
+ margin-left: 4px;
41
54
  }
42
55
 
43
56
  .message-card-img,
@@ -10,6 +10,8 @@ interface ShowMessageCardProps {
10
10
  commentKey?: string;
11
11
  imgSrcKey?: string;
12
12
  imageUrlKey?: string;
13
+ objectNameKey?: string;
14
+ revisionKey?: string;
13
15
  containerClassName?: string;
14
16
  containerStyle?: CSSProperties;
15
17
  cardClassName?: string;
@@ -32,6 +34,10 @@ interface ShowMessageCardProps {
32
34
  attachedImageStyle?: CSSProperties;
33
35
  attachedImageContainerClassName?: string;
34
36
  attachedImageContainerStyle?: CSSProperties;
37
+ objectNameClassName?: string;
38
+ objectNameStyle?: CSSProperties;
39
+ revisionClassName?: string;
40
+ revisionStyle?: CSSProperties;
35
41
  renderItem?: (element: MessageCardProps) => ReactNode;
36
42
  }
37
43
  export declare const ShowMessageCard: React.FC<ShowMessageCardProps>;
@@ -13,9 +13,13 @@ import React, { useState } from "react";
13
13
  import "./ShowMessageCard.css";
14
14
  export var ShowMessageCard = function (_a) {
15
15
  var data = _a.data, _b = _a.nameKey, nameKey = _b === void 0 ? "name" : _b, _c = _a.dateKey, dateKey = _c === void 0 ? "date" : _c, _d = _a.commentKey, commentKey = _d === void 0 ? "comment" : _d, _e = _a.imgSrcKey, imgSrcKey = _e === void 0 ? "imgSrc" : _e, _f = _a.imageUrlKey, imageUrlKey = _f === void 0 ? "imageUrl" : _f, // Default key for attached image
16
- containerClassName = _a.containerClassName, containerStyle = _a.containerStyle, cardClassName = _a.cardClassName, cardStyle = _a.cardStyle, headerClassName = _a.headerClassName, headerStyle = _a.headerStyle, imgClassName = _a.imgClassName, imgStyle = _a.imgStyle, infoClassName = _a.infoClassName, infoStyle = _a.infoStyle, nameClassName = _a.nameClassName, nameStyle = _a.nameStyle, dateClassName = _a.dateClassName, dateStyle = _a.dateStyle, bodyClassName = _a.bodyClassName, bodyStyle = _a.bodyStyle, commentClassName = _a.commentClassName, commentStyle = _a.commentStyle, attachedImageClassName = _a.attachedImageClassName, attachedImageStyle = _a.attachedImageStyle, attachedImageContainerClassName = _a.attachedImageContainerClassName, attachedImageContainerStyle = _a.attachedImageContainerStyle, renderItem = _a.renderItem;
16
+ _g = _a.objectNameKey, // Default key for attached image
17
+ objectNameKey = _g === void 0 ? "objectName" : _g, // Default key for object identifier
18
+ _h = _a.revisionKey, // Default key for object identifier
19
+ revisionKey = _h === void 0 ? "revision" : _h, // Default key for revision
20
+ containerClassName = _a.containerClassName, containerStyle = _a.containerStyle, cardClassName = _a.cardClassName, cardStyle = _a.cardStyle, headerClassName = _a.headerClassName, headerStyle = _a.headerStyle, imgClassName = _a.imgClassName, imgStyle = _a.imgStyle, infoClassName = _a.infoClassName, infoStyle = _a.infoStyle, nameClassName = _a.nameClassName, nameStyle = _a.nameStyle, dateClassName = _a.dateClassName, dateStyle = _a.dateStyle, bodyClassName = _a.bodyClassName, bodyStyle = _a.bodyStyle, commentClassName = _a.commentClassName, commentStyle = _a.commentStyle, attachedImageClassName = _a.attachedImageClassName, attachedImageStyle = _a.attachedImageStyle, attachedImageContainerClassName = _a.attachedImageContainerClassName, attachedImageContainerStyle = _a.attachedImageContainerStyle, objectNameClassName = _a.objectNameClassName, objectNameStyle = _a.objectNameStyle, revisionClassName = _a.revisionClassName, revisionStyle = _a.revisionStyle, renderItem = _a.renderItem;
17
21
  // State to manage initials for images that fail to load
18
- var _g = useState({}), initialsState = _g[0], setInitialsState = _g[1];
22
+ var _j = useState({}), initialsState = _j[0], setInitialsState = _j[1];
19
23
  // Handle image load failure
20
24
  var handleImageError = function (id) {
21
25
  setInitialsState(function (prevState) {
@@ -32,21 +36,40 @@ export var ShowMessageCard = function (_a) {
32
36
  .join("");
33
37
  return initials;
34
38
  };
39
+ // Helper function to extract hashtags and mentions from text
40
+ var extractTagsAndMentions = function (text) {
41
+ var plainText = text.replace(/<[^>]*>/g, ''); // Remove HTML tags to get plain text
42
+ var hashtags = plainText.match(/#[\w]+/g) || [];
43
+ var mentions = plainText.match(/@[\w\s-]+/g) || [];
44
+ return {
45
+ hashtags: Array.from(new Set(hashtags)), // Remove duplicates
46
+ mentions: Array.from(new Set(mentions.map(function (mention) { return mention.trim(); }))) // Remove duplicates and trim
47
+ };
48
+ };
35
49
  return (React.createElement("div", { className: "message-card-container ".concat(containerClassName || ""), style: containerStyle }, data.map(function (item, index) {
36
50
  if (renderItem !== undefined) {
37
51
  // Use custom render function if provided
38
52
  return (React.createElement(React.Fragment, { key: item.id || index }, renderItem(item)));
39
53
  }
40
54
  var showInitials = initialsState[item.id || index] || !item[imgSrcKey]; // Decide whether to show initials
55
+ // Extract tags and mentions from the comment
56
+ var _a = extractTagsAndMentions(item[commentKey] || ''), hashtags = _a.hashtags, mentions = _a.mentions;
41
57
  return (React.createElement("div", { key: item.id || index, className: "message-card ".concat(cardClassName || ""), style: cardStyle },
42
58
  React.createElement("div", { className: "message-card-header ".concat(headerClassName || ""), style: headerStyle },
43
- showInitials ? (React.createElement("div", { className: "message-card-initials ".concat(imgClassName || ""), style: imgStyle }, getInitials(item[nameKey]))) : (React.createElement("img", { src: item[imgSrcKey], alt: item[nameKey], className: "message-card-img ".concat(imgClassName || ""), style: imgStyle, onError: function () { return handleImageError(item.id || index); } })),
44
- React.createElement("div", { className: "message-card-info ".concat(infoClassName || ""), style: infoStyle },
45
- React.createElement("h3", { className: "message-card-name ".concat(nameClassName || ""), style: nameStyle }, item[nameKey]),
46
- React.createElement("p", { className: "message-card-date ".concat(dateClassName || ""), style: dateStyle }, item[dateKey]))),
59
+ React.createElement("div", { className: "message-card-header-left" },
60
+ showInitials ? (React.createElement("div", { className: "message-card-initials ".concat(imgClassName || ""), style: imgStyle }, getInitials(item[nameKey]))) : (React.createElement("img", { src: item[imgSrcKey], alt: item[nameKey], className: "message-card-img ".concat(imgClassName || ""), style: imgStyle, onError: function () { return handleImageError(item.id || index); } })),
61
+ React.createElement("div", { className: "message-card-info ".concat(infoClassName || ""), style: infoStyle },
62
+ React.createElement("h3", { className: "message-card-name ".concat(nameClassName || ""), style: nameStyle }, item[nameKey]),
63
+ React.createElement("p", { className: "message-card-date ".concat(dateClassName || ""), style: dateStyle }, item[dateKey]))),
64
+ (item[objectNameKey] || item[revisionKey]) && (React.createElement("div", { className: "message-card-item-name ".concat(objectNameClassName || ""), style: objectNameStyle },
65
+ item[objectNameKey] && (React.createElement("span", { className: "object-name-text" }, item[objectNameKey])),
66
+ item[revisionKey] && (React.createElement("span", { className: "revision-text ".concat(revisionClassName || ""), style: revisionStyle }, item[objectNameKey] ? " (".concat(item[revisionKey], ")") : "(".concat(item[revisionKey], ")")))))),
47
67
  React.createElement("div", { className: "message-card-body ".concat(bodyClassName || ""), style: bodyStyle },
48
68
  React.createElement("p", { className: "message-card-comment ".concat(commentClassName || ""), style: commentStyle, dangerouslySetInnerHTML: { __html: item[commentKey] } }),
49
69
  (item === null || item === void 0 ? void 0 : item[imageUrlKey]) && (React.createElement("div", { className: "message-card-attached-image-container ".concat(attachedImageContainerClassName || ""), style: attachedImageContainerStyle },
50
- React.createElement("img", { src: item[imageUrlKey], alt: "Attached", className: "message-card-attached-image ".concat(attachedImageClassName || ""), style: attachedImageStyle }))))));
70
+ React.createElement("img", { src: item[imageUrlKey], alt: "Attached", className: "message-card-attached-image ".concat(attachedImageClassName || ""), style: attachedImageStyle }))),
71
+ (hashtags.length > 0 || mentions.length > 0) && (React.createElement("div", { className: "message-card-tags" },
72
+ hashtags.map(function (tag, tagIndex) { return (React.createElement("span", { key: "hashtag-".concat(tagIndex), className: "tag-chip hashtag-chip" }, tag)); }),
73
+ mentions.map(function (mention, mentionIndex) { return (React.createElement("span", { key: "mention-".concat(mentionIndex), className: "tag-chip mention-chip" }, mention)); }))))));
51
74
  })));
52
75
  };
package/dist/demo.js CHANGED
@@ -16,14 +16,14 @@ var Demo = function () {
16
16
  name: 'John Doe',
17
17
  date: '2 hours ago',
18
18
  comment: 'Updated the status to Draft. Need <span class="mention-highlight">@team-leads</span> review before proceeding. <span class="hashtag-highlight">#urgent</span> <span class="hashtag-highlight">#review</span>',
19
- itemName: '26may_item001 (A)',
19
+ objectName: '26may_item001 (A)',
20
20
  },
21
21
  {
22
22
  id: 2,
23
23
  name: 'Mike Johnson',
24
24
  date: '1 day ago',
25
25
  comment: 'Revision A completed successfully. Ready for next phase. <span class="hashtag-highlight">#milestone</span>',
26
- itemName: '26may_item001 (A)',
26
+ objectName: '26may_item001 (A)',
27
27
  }
28
28
  ]), messages = _a[0], setMessages = _a[1];
29
29
  // Sample users for mentions
@@ -45,7 +45,7 @@ var Demo = function () {
45
45
  imageUrl: messageData.imageUrl,
46
46
  tags: messageData.tags,
47
47
  mentions: messageData.userSelectListName,
48
- itemName: 'new_item001 (A)', // You can customize this or make it dynamic
48
+ objectName: 'new_item001 (A)', // You can customize this or make it dynamic
49
49
  };
50
50
  setMessages(__spreadArray(__spreadArray([], messages, true), [newMessage], false));
51
51
  };
@@ -10,7 +10,7 @@ interface ShowMessageCardProps {
10
10
  commentKey?: string;
11
11
  imgSrcKey?: string;
12
12
  imageUrlKey?: string;
13
- itemNameKey?: string;
13
+ objectNameKey?: string;
14
14
  containerClassName?: string;
15
15
  containerStyle?: CSSProperties;
16
16
  cardClassName?: string;
@@ -33,8 +33,8 @@ interface ShowMessageCardProps {
33
33
  attachedImageStyle?: CSSProperties;
34
34
  attachedImageContainerClassName?: string;
35
35
  attachedImageContainerStyle?: CSSProperties;
36
- itemNameClassName?: string;
37
- itemNameStyle?: CSSProperties;
36
+ objectNameClassName?: string;
37
+ objectNameStyle?: CSSProperties;
38
38
  renderItem?: (element: MessageCardProps) => ReactNode;
39
39
  }
40
40
  export declare const ShowMessageCard: React.FC<ShowMessageCardProps>;
@@ -13,9 +13,10 @@ import React, { useState } from "react";
13
13
  import "./ShowMessageCard.css";
14
14
  export var ShowMessageCard = function (_a) {
15
15
  var data = _a.data, _b = _a.nameKey, nameKey = _b === void 0 ? "name" : _b, _c = _a.dateKey, dateKey = _c === void 0 ? "date" : _c, _d = _a.commentKey, commentKey = _d === void 0 ? "comment" : _d, _e = _a.imgSrcKey, imgSrcKey = _e === void 0 ? "imgSrc" : _e, _f = _a.imageUrlKey, imageUrlKey = _f === void 0 ? "imageUrl" : _f, // Default key for attached image
16
- _g = _a.itemNameKey, // Default key for attached image
17
- itemNameKey = _g === void 0 ? "name" : _g, // Default key for item identifier
18
- containerClassName = _a.containerClassName, containerStyle = _a.containerStyle, cardClassName = _a.cardClassName, cardStyle = _a.cardStyle, headerClassName = _a.headerClassName, headerStyle = _a.headerStyle, imgClassName = _a.imgClassName, imgStyle = _a.imgStyle, infoClassName = _a.infoClassName, infoStyle = _a.infoStyle, nameClassName = _a.nameClassName, nameStyle = _a.nameStyle, dateClassName = _a.dateClassName, dateStyle = _a.dateStyle, bodyClassName = _a.bodyClassName, bodyStyle = _a.bodyStyle, commentClassName = _a.commentClassName, commentStyle = _a.commentStyle, attachedImageClassName = _a.attachedImageClassName, attachedImageStyle = _a.attachedImageStyle, attachedImageContainerClassName = _a.attachedImageContainerClassName, attachedImageContainerStyle = _a.attachedImageContainerStyle, itemNameClassName = _a.itemNameClassName, itemNameStyle = _a.itemNameStyle, renderItem = _a.renderItem;
16
+ _g = _a.objectNameKey, // Default key for attached image
17
+ objectNameKey = _g === void 0 ? "objectName" : _g, // Default key for object identifier
18
+ containerClassName = _a.containerClassName, containerStyle = _a.containerStyle, cardClassName = _a.cardClassName, cardStyle = _a.cardStyle, headerClassName = _a.headerClassName, headerStyle = _a.headerStyle, imgClassName = _a.imgClassName, imgStyle = _a.imgStyle, infoClassName = _a.infoClassName, infoStyle = _a.infoStyle, nameClassName = _a.nameClassName, nameStyle = _a.nameStyle, dateClassName = _a.dateClassName, dateStyle = _a.dateStyle, bodyClassName = _a.bodyClassName, bodyStyle = _a.bodyStyle, commentClassName = _a.commentClassName, commentStyle = _a.commentStyle, attachedImageClassName = _a.attachedImageClassName, attachedImageStyle = _a.attachedImageStyle, attachedImageContainerClassName = _a.attachedImageContainerClassName, attachedImageContainerStyle = _a.attachedImageContainerStyle, objectNameClassName = _a.objectNameClassName, objectNameStyle = _a.objectNameStyle, renderItem = _a.renderItem;
19
+ console.log(data, "data==");
19
20
  // State to manage initials for images that fail to load
20
21
  var _h = useState({}), initialsState = _h[0], setInitialsState = _h[1];
21
22
  // Handle image load failure
@@ -59,7 +60,7 @@ export var ShowMessageCard = function (_a) {
59
60
  React.createElement("div", { className: "message-card-info ".concat(infoClassName || ""), style: infoStyle },
60
61
  React.createElement("h3", { className: "message-card-name ".concat(nameClassName || ""), style: nameStyle }, item[nameKey]),
61
62
  React.createElement("p", { className: "message-card-date ".concat(dateClassName || ""), style: dateStyle }, item[dateKey]))),
62
- item[itemNameKey] && (React.createElement("div", { className: "message-card-item-name ".concat(itemNameClassName || ""), style: itemNameStyle }, item[itemNameKey]))),
63
+ item[objectNameKey] && (React.createElement("div", { className: "message-card-item-name ".concat(objectNameClassName || ""), style: objectNameStyle }, item[objectNameKey]))),
63
64
  React.createElement("div", { className: "message-card-body ".concat(bodyClassName || ""), style: bodyStyle },
64
65
  React.createElement("p", { className: "message-card-comment ".concat(commentClassName || ""), style: commentStyle, dangerouslySetInnerHTML: { __html: item[commentKey] } }),
65
66
  (item === null || item === void 0 ? void 0 : item[imageUrlKey]) && (React.createElement("div", { className: "message-card-attached-image-container ".concat(attachedImageContainerClassName || ""), style: attachedImageContainerStyle },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-mention-input",
3
- "version": "1.1.17",
3
+ "version": "1.1.19",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -8,7 +8,9 @@
8
8
  "build": "tsc && npm run copy-css",
9
9
  "copy-css": "copyfiles -u 1 src/**/*.css dist",
10
10
  "dev": "vite",
11
- "demo": "vite"
11
+ "demo": "vite",
12
+ "prepublishOnly": "npm run build",
13
+ "version": "npm run build && git add -A dist"
12
14
  },
13
15
  "keywords": [
14
16
  "mention",
@@ -38,6 +38,19 @@
38
38
  padding: 4px 8px;
39
39
  border-radius: 6px;
40
40
  border: 1px solid #e0e0e0;
41
+ display: flex;
42
+ align-items: center;
43
+ white-space: nowrap;
44
+ }
45
+
46
+ .object-name-text {
47
+ font-weight: 600;
48
+ }
49
+
50
+ .revision-text {
51
+ font-weight: 400;
52
+ color: #888;
53
+ margin-left: 4px;
41
54
  }
42
55
 
43
56
  .message-card-img,
@@ -13,6 +13,7 @@ interface ShowMessageCardProps {
13
13
  imgSrcKey?: string; // Custom key for image source
14
14
  imageUrlKey?: string; // Custom key for attached image URL
15
15
  objectNameKey?: string; // Custom key for object identifier (top-right)
16
+ revisionKey?: string; // Custom key for revision (top-right)
16
17
  containerClassName?: string; // Class for the outermost container
17
18
  containerStyle?: CSSProperties; // Style for the outermost container
18
19
  cardClassName?: string; // Class for the card
@@ -37,6 +38,8 @@ interface ShowMessageCardProps {
37
38
  attachedImageContainerStyle?: CSSProperties; // Style for the attached image container
38
39
  objectNameClassName?: string; // Class for the object name (top-right)
39
40
  objectNameStyle?: CSSProperties; // Style for the object name (top-right)
41
+ revisionClassName?: string; // Class for the revision (top-right)
42
+ revisionStyle?: CSSProperties; // Style for the revision (top-right)
40
43
  renderItem?: (element: MessageCardProps) => ReactNode; // Custom render function
41
44
  }
42
45
 
@@ -48,6 +51,7 @@ export const ShowMessageCard: React.FC<ShowMessageCardProps> = ({
48
51
  imgSrcKey = "imgSrc",
49
52
  imageUrlKey = "imageUrl", // Default key for attached image
50
53
  objectNameKey = "objectName", // Default key for object identifier
54
+ revisionKey = "revision", // Default key for revision
51
55
  containerClassName,
52
56
  containerStyle,
53
57
  cardClassName,
@@ -72,10 +76,10 @@ export const ShowMessageCard: React.FC<ShowMessageCardProps> = ({
72
76
  attachedImageContainerStyle,
73
77
  objectNameClassName,
74
78
  objectNameStyle,
79
+ revisionClassName,
80
+ revisionStyle,
75
81
  renderItem, // Custom render function
76
82
  }) => {
77
-
78
- console.log(data, "data==");
79
83
  // State to manage initials for images that fail to load
80
84
  const [initialsState, setInitialsState] = useState<{ [key: string]: boolean }>(
81
85
  {}
@@ -177,13 +181,20 @@ export const ShowMessageCard: React.FC<ShowMessageCardProps> = ({
177
181
  </div>
178
182
  </div>
179
183
 
180
- {/* Object identifier in top-right corner */}
181
- {item[objectNameKey] && (
184
+ {/* Object identifier with revision in top-right corner */}
185
+ {(item[objectNameKey] || item[revisionKey]) && (
182
186
  <div
183
187
  className={`message-card-item-name ${objectNameClassName || ""}`}
184
188
  style={objectNameStyle}
185
189
  >
186
- {item[objectNameKey]}
190
+ {item[objectNameKey] && (
191
+ <span className="object-name-text">{item[objectNameKey]}</span>
192
+ )}
193
+ {item[revisionKey] && (
194
+ <span className={`revision-text ${revisionClassName || ""}`} style={revisionStyle}>
195
+ {item[objectNameKey] ? ` (${item[revisionKey]})` : `(${item[revisionKey]})`}
196
+ </span>
197
+ )}
187
198
  </div>
188
199
  )}
189
200
  </div>
package/tsconfig.json CHANGED
@@ -3,13 +3,26 @@
3
3
  "target": "ES5",
4
4
  "sourceMap": false,
5
5
  "module": "ESNext",
6
- "moduleResolution": "node",
6
+ "moduleResolution": "bundler",
7
7
  "jsx": "react",
8
- "lib": ["dom", "es6"], // Ensure karein ki 'es6' included ho
8
+ "lib": ["dom", "es6"],
9
9
  "declaration": true,
10
10
  "outDir": "./dist",
11
11
  "strict": true,
12
- "esModuleInterop": true
13
- }
14
-
12
+ "esModuleInterop": true,
13
+ "allowSyntheticDefaultImports": true,
14
+ "skipLibCheck": true
15
+ },
16
+ "include": [
17
+ "src/**/*"
18
+ ],
19
+ "exclude": [
20
+ "node_modules",
21
+ "dist",
22
+ "demo.tsx",
23
+ "main.tsx",
24
+ "vite.config.ts",
25
+ "**/*.test.*",
26
+ "**/*.spec.*"
27
+ ]
15
28
  }