@selfcommunity/react-ui 0.10.2-alpha.10 → 0.10.2-alpha.11
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/lib/cjs/components/CommentObject/CommentObject.js +1 -1
- package/lib/cjs/utils/contribution.d.ts +7 -0
- package/lib/cjs/utils/contribution.js +13 -1
- package/lib/esm/components/CommentObject/CommentObject.js +2 -2
- package/lib/esm/utils/contribution.d.ts +7 -0
- package/lib/esm/utils/contribution.js +11 -0
- package/lib/umd/react-ui.js +1 -1
- package/package.json +2 -2
|
@@ -303,7 +303,7 @@ function CommentObject(inProps) {
|
|
|
303
303
|
}
|
|
304
304
|
const summaryHtmlTruncated = 'summary_truncated' in comment ? comment.summary_truncated : false;
|
|
305
305
|
const commentHtml = 'summary_html' in comment && truncateContent && summaryHtmlTruncated ? comment.summary_html : comment.html;
|
|
306
|
-
const summaryHtml = (0, contribution_1.
|
|
306
|
+
const summaryHtml = (0, contribution_1.getCommentContributionHtml)(commentHtml, scRoutingContext.url);
|
|
307
307
|
return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [collapsed ? ((0, jsx_runtime_1.jsx)(BaseItem_1.default, { elevation: 0, className: classes.comment, disableTypography: true, primary: (0, jsx_runtime_1.jsxs)(Widget_1.default, Object.assign({ className: (0, classnames_1.default)(classes.content, classes.collapsed), elevation: elevation }, rest, { children: [(0, jsx_runtime_1.jsx)(material_1.CardContent, Object.assign({ className: (0, classnames_1.default)({ [classes.deleted]: obj && obj.deleted }) }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.commentObject.collapsed", defaultMessage: "ui.commentObject.collapsed" }) })), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.commentActionsMenu }, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ onClick: () => setCollapsed(!collapsed) }, { children: (0, jsx_runtime_1.jsx)(material_1.Icon, { children: "visibility" }) })) }))] })) })) : editComment && editComment.id === comment.id ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.comment }, { children: (0, jsx_runtime_1.jsx)(CommentObjectReply_1.default, Object.assign({ text: comment.html, autoFocus: true, id: `edit-${comment.id}`, onSave: handleSave, onCancel: handleCancel, editable: !isReplying || !isSavingComment }, CommentObjectReplyProps)) }))) : ((0, jsx_runtime_1.jsx)(BaseItem_1.default, { elevation: 0, className: classes.comment, image: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!comment.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, comment.author) }), { onClick: comment.author.deleted ? () => setOpenAlert(true) : null }, { children: (0, jsx_runtime_1.jsx)(UserAvatar_1.default, Object.assign({ hide: !obj.author.community_badge }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { alt: obj.author.username, variant: "circular", src: comment.author.avatar, className: classes.avatar }) })) })), disableTypography: true, primary: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(Widget_1.default, Object.assign({ className: classes.content, elevation: elevation }, rest, { children: [(0, jsx_runtime_1.jsxs)(material_1.CardContent, Object.assign({ className: (0, classnames_1.default)({ [classes.deleted]: obj && obj.deleted }) }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ className: classes.author }, (!comment.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, comment.author) }), { onClick: comment.author.deleted ? () => setOpenAlert(true) : null }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ component: "span" }, { children: comment.author.username })) })), comment.collapsed && ((0, jsx_runtime_1.jsx)(material_1.Chip, { className: classes.flagChip, color: "error", size: "small", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.commentObject.flag", defaultMessage: "ui.commentObject.flag" }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, { className: classes.textContent, variant: "body2", gutterBottom: true, dangerouslySetInnerHTML: { __html: summaryHtml } }), summaryHtmlTruncated && truncateContent && ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({ to: scRoutingContext.url(react_core_1.SCRoutes.COMMENT_ROUTE_NAME, (0, contribution_1.getRouteData)(comment)), className: classes.showMoreContent }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.commentObject.showMore", defaultMessage: "ui.commentObject.showMore" }) })))] })), scUserContext.user && ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.commentActionsMenu }, { children: (0, jsx_runtime_1.jsx)(ContributionActionsMenu_1.default, { commentObject: comment, onRestoreContribution: handleRestore, onHideContribution: handleHide, onDeleteContribution: handleDelete, onEditContribution: handleEdit }) })))] })), (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ component: "span", className: classes.contentSubSection }, { children: [renderTimeAgo(comment), (0, jsx_runtime_1.jsx)(Bullet_1.default, {}), (0, jsx_runtime_1.jsx)(VoteButton_1.default, { size: "small", className: classes.vote, contributionId: comment.id, contributionType: types_1.SCContributionType.COMMENT, contribution: comment, onVote: handleVoteSuccess }), (0, jsx_runtime_1.jsx)(Bullet_1.default, {}), renderActionReply(comment), (0, jsx_runtime_1.jsx)(VoteAudienceButton_1.default, { size: "small", className: classes.voteAudience, contributionId: comment.id, contributionType: types_1.SCContributionType.COMMENT, contribution: comment })] }))] }) })), comment.comment_count > 0 && (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.nestedComments }, { children: renderLatestComment(comment) })), scUserContext.user && replyComment && (replyComment.id === comment.id || replyComment.parent === comment.id) && !comment.parent && ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: classes.nestedComments }, { children: (0, jsx_runtime_1.jsx)(CommentObjectReply_1.default, Object.assign({ text: `@${replyComment.author.username}, `, autoFocus: true, id: `reply-${replyComment.id}`, onReply: handleReply, editable: !isReplying }, CommentObjectReplyProps), `reply-${replyComment.id}`) })))] }, comment.id));
|
|
308
308
|
}
|
|
309
309
|
/**
|
|
@@ -21,6 +21,13 @@ export declare function getContributionSnippet(obj: any): any;
|
|
|
21
21
|
* @param handleUrl Func that handle urls
|
|
22
22
|
*/
|
|
23
23
|
export declare function getContributionHtml(html: any, handleUrl: any): any;
|
|
24
|
+
/**
|
|
25
|
+
* Get the contribution text for comment object
|
|
26
|
+
* Hydrate text with mention, etc.
|
|
27
|
+
* @param html Html of the contribution
|
|
28
|
+
* @param handleUrl Func that handle urls
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCommentContributionHtml(html: any, handleUrl: any): any;
|
|
24
31
|
/**
|
|
25
32
|
* Get route name for a contribution
|
|
26
33
|
* @param obj
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRouteData = exports.getContributionRouteName = exports.getContributionHtml = exports.getContributionSnippet = exports.getContribution = exports.getContributionType = void 0;
|
|
3
|
+
exports.getRouteData = exports.getContributionRouteName = exports.getCommentContributionHtml = exports.getContributionHtml = exports.getContributionSnippet = exports.getContribution = exports.getContributionType = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_core_1 = require("@selfcommunity/react-core");
|
|
6
6
|
const types_1 = require("@selfcommunity/types");
|
|
@@ -63,6 +63,18 @@ function getContributionHtml(html, handleUrl) {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
exports.getContributionHtml = getContributionHtml;
|
|
66
|
+
/**
|
|
67
|
+
* Get the contribution text for comment object
|
|
68
|
+
* Hydrate text with mention, etc.
|
|
69
|
+
* @param html Html of the contribution
|
|
70
|
+
* @param handleUrl Func that handle urls
|
|
71
|
+
*/
|
|
72
|
+
function getCommentContributionHtml(html, handleUrl) {
|
|
73
|
+
return html.replace(/<mention.*? id="([0-9]+)"{1}.*?>@([a-z\d_-]+)<\/mention>/gi, (match, id, username) => {
|
|
74
|
+
return `<a href='${handleUrl(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, { id, username })}'>@${username}</a>`;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.getCommentContributionHtml = getCommentContributionHtml;
|
|
66
78
|
/**
|
|
67
79
|
* Get route name for a contribution
|
|
68
80
|
* @param obj
|
|
@@ -14,7 +14,7 @@ import CommentsObject from '../CommentsObject';
|
|
|
14
14
|
import CommentObjectReply from '../CommentObjectReply';
|
|
15
15
|
import ContributionActionsMenu from '../../shared/ContributionActionsMenu';
|
|
16
16
|
import DateTimeAgo from '../../shared/DateTimeAgo';
|
|
17
|
-
import {
|
|
17
|
+
import { getCommentContributionHtml, getContributionType, getRouteData } from '../../utils/contribution';
|
|
18
18
|
import { useSnackbar } from 'notistack';
|
|
19
19
|
import { useThemeProps } from '@mui/system';
|
|
20
20
|
import BaseItem from '../../shared/BaseItem';
|
|
@@ -301,7 +301,7 @@ export default function CommentObject(inProps) {
|
|
|
301
301
|
}
|
|
302
302
|
const summaryHtmlTruncated = 'summary_truncated' in comment ? comment.summary_truncated : false;
|
|
303
303
|
const commentHtml = 'summary_html' in comment && truncateContent && summaryHtmlTruncated ? comment.summary_html : comment.html;
|
|
304
|
-
const summaryHtml =
|
|
304
|
+
const summaryHtml = getCommentContributionHtml(commentHtml, scRoutingContext.url);
|
|
305
305
|
return (_jsxs(React.Fragment, { children: [collapsed ? (_jsx(BaseItem, { elevation: 0, className: classes.comment, disableTypography: true, primary: _jsxs(Widget, Object.assign({ className: classNames(classes.content, classes.collapsed), elevation: elevation }, rest, { children: [_jsx(CardContent, Object.assign({ className: classNames({ [classes.deleted]: obj && obj.deleted }) }, { children: _jsx(FormattedMessage, { id: "ui.commentObject.collapsed", defaultMessage: "ui.commentObject.collapsed" }) })), _jsx(Box, Object.assign({ className: classes.commentActionsMenu }, { children: _jsx(IconButton, Object.assign({ onClick: () => setCollapsed(!collapsed) }, { children: _jsx(Icon, { children: "visibility" }) })) }))] })) })) : editComment && editComment.id === comment.id ? (_jsx(Box, Object.assign({ className: classes.comment }, { children: _jsx(CommentObjectReply, Object.assign({ text: comment.html, autoFocus: true, id: `edit-${comment.id}`, onSave: handleSave, onCancel: handleCancel, editable: !isReplying || !isSavingComment }, CommentObjectReplyProps)) }))) : (_jsx(BaseItem, { elevation: 0, className: classes.comment, image: _jsx(Link, Object.assign({}, (!comment.author.deleted && { to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, comment.author) }), { onClick: comment.author.deleted ? () => setOpenAlert(true) : null }, { children: _jsx(UserAvatar, Object.assign({ hide: !obj.author.community_badge }, { children: _jsx(Avatar, { alt: obj.author.username, variant: "circular", src: comment.author.avatar, className: classes.avatar }) })) })), disableTypography: true, primary: _jsxs(_Fragment, { children: [_jsxs(Widget, Object.assign({ className: classes.content, elevation: elevation }, rest, { children: [_jsxs(CardContent, Object.assign({ className: classNames({ [classes.deleted]: obj && obj.deleted }) }, { children: [_jsx(Link, Object.assign({ className: classes.author }, (!comment.author.deleted && { to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, comment.author) }), { onClick: comment.author.deleted ? () => setOpenAlert(true) : null }, { children: _jsx(Typography, Object.assign({ component: "span" }, { children: comment.author.username })) })), comment.collapsed && (_jsx(Chip, { className: classes.flagChip, color: "error", size: "small", label: _jsx(FormattedMessage, { id: "ui.commentObject.flag", defaultMessage: "ui.commentObject.flag" }) })), _jsx(Typography, { className: classes.textContent, variant: "body2", gutterBottom: true, dangerouslySetInnerHTML: { __html: summaryHtml } }), summaryHtmlTruncated && truncateContent && (_jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes.COMMENT_ROUTE_NAME, getRouteData(comment)), className: classes.showMoreContent }, { children: _jsx(FormattedMessage, { id: "ui.commentObject.showMore", defaultMessage: "ui.commentObject.showMore" }) })))] })), scUserContext.user && (_jsx(Box, Object.assign({ className: classes.commentActionsMenu }, { children: _jsx(ContributionActionsMenu, { commentObject: comment, onRestoreContribution: handleRestore, onHideContribution: handleHide, onDeleteContribution: handleDelete, onEditContribution: handleEdit }) })))] })), _jsxs(Box, Object.assign({ component: "span", className: classes.contentSubSection }, { children: [renderTimeAgo(comment), _jsx(Bullet, {}), _jsx(VoteButton, { size: "small", className: classes.vote, contributionId: comment.id, contributionType: SCContributionType.COMMENT, contribution: comment, onVote: handleVoteSuccess }), _jsx(Bullet, {}), renderActionReply(comment), _jsx(VoteAudienceButton, { size: "small", className: classes.voteAudience, contributionId: comment.id, contributionType: SCContributionType.COMMENT, contribution: comment })] }))] }) })), comment.comment_count > 0 && _jsx(Box, Object.assign({ className: classes.nestedComments }, { children: renderLatestComment(comment) })), scUserContext.user && replyComment && (replyComment.id === comment.id || replyComment.parent === comment.id) && !comment.parent && (_jsx(Box, Object.assign({ className: classes.nestedComments }, { children: _jsx(CommentObjectReply, Object.assign({ text: `@${replyComment.author.username}, `, autoFocus: true, id: `reply-${replyComment.id}`, onReply: handleReply, editable: !isReplying }, CommentObjectReplyProps), `reply-${replyComment.id}`) })))] }, comment.id));
|
|
306
306
|
}
|
|
307
307
|
/**
|
|
@@ -21,6 +21,13 @@ export declare function getContributionSnippet(obj: any): any;
|
|
|
21
21
|
* @param handleUrl Func that handle urls
|
|
22
22
|
*/
|
|
23
23
|
export declare function getContributionHtml(html: any, handleUrl: any): any;
|
|
24
|
+
/**
|
|
25
|
+
* Get the contribution text for comment object
|
|
26
|
+
* Hydrate text with mention, etc.
|
|
27
|
+
* @param html Html of the contribution
|
|
28
|
+
* @param handleUrl Func that handle urls
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCommentContributionHtml(html: any, handleUrl: any): any;
|
|
24
31
|
/**
|
|
25
32
|
* Get route name for a contribution
|
|
26
33
|
* @param obj
|
|
@@ -56,6 +56,17 @@ export function getContributionHtml(html, handleUrl) {
|
|
|
56
56
|
return `<a href='${handleUrl(SCRoutes.USER_PROFILE_ROUTE_NAME, { id, username })}'>@${username}</a>`;
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the contribution text for comment object
|
|
61
|
+
* Hydrate text with mention, etc.
|
|
62
|
+
* @param html Html of the contribution
|
|
63
|
+
* @param handleUrl Func that handle urls
|
|
64
|
+
*/
|
|
65
|
+
export function getCommentContributionHtml(html, handleUrl) {
|
|
66
|
+
return html.replace(/<mention.*? id="([0-9]+)"{1}.*?>@([a-z\d_-]+)<\/mention>/gi, (match, id, username) => {
|
|
67
|
+
return `<a href='${handleUrl(SCRoutes.USER_PROFILE_ROUTE_NAME, { id, username })}'>@${username}</a>`;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
59
70
|
/**
|
|
60
71
|
* Get route name for a contribution
|
|
61
72
|
* @param obj
|