@pega/cosmos-react-work 8.0.0-build.49.0 → 8.0.0-build.49.2
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/components/ArticleList/ArticleFeedback.d.ts.map +1 -1
- package/lib/components/ArticleList/ArticleFeedback.js +6 -8
- package/lib/components/ArticleList/ArticleFeedback.js.map +1 -1
- package/lib/components/GenAICoach/GenAIMessage.d.ts.map +1 -1
- package/lib/components/GenAICoach/GenAIMessage.js +3 -3
- package/lib/components/GenAICoach/GenAIMessage.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArticleFeedback.d.ts","sourceRoot":"","sources":["../../../src/components/ArticleList/ArticleFeedback.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ArticleFeedback.d.ts","sourceRoot":"","sources":["../../../src/components/ArticleList/ArticleFeedback.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAIhE,eAAO,MAAM,yBAAyB,kNAQpC,CAAC;;AAIH,wBA6FE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useRef
|
|
2
|
+
import { forwardRef, useRef } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
|
-
import { registerIcon, Text, Flex, useI18n, Button, TextArea, defaultThemeProp, Icon } from '@pega/cosmos-react-core';
|
|
4
|
+
import { registerIcon, Text, Flex, useI18n, Button, TextArea, defaultThemeProp, Icon, useElementFocus } from '@pega/cosmos-react-core';
|
|
5
5
|
import * as thumbsUpSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up-solid.icon';
|
|
6
6
|
import * as thumbsUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up.icon';
|
|
7
7
|
import * as thumbsDownSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down-solid.icon';
|
|
@@ -16,16 +16,14 @@ StyledAcknowledgementText.defaultProps = defaultThemeProp;
|
|
|
16
16
|
export default forwardRef(function ArticleFeedback({ question, comment, reaction, onReaction, onSubmit, showThankYouMessage = false, ...restProps }, ref) {
|
|
17
17
|
const t = useI18n();
|
|
18
18
|
const acknowledgmentText = useRef(null);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}, [showThankYouMessage]);
|
|
19
|
+
const feedbackCommentRef = useRef(null);
|
|
20
|
+
useElementFocus(acknowledgmentText, { shouldFocus: showThankYouMessage });
|
|
21
|
+
useElementFocus(feedbackCommentRef, { shouldFocus: !!reaction });
|
|
24
22
|
return (_jsx(Flex, { ...restProps, container: { direction: 'column' }, ref: ref, children: !showThankYouMessage ? (_jsxs(_Fragment, { children: [_jsxs(Flex, { container: { gap: 0.5, alignItems: 'center', pad: [0.5, undefined] }, children: [_jsx(Text, { children: question }), _jsxs("div", { role: 'group', "aria-label": t('confirmation_options'), children: [_jsx(Button, { "aria-pressed": reaction === 'liked', label: t('yes'), variant: 'simple', icon: true, compact: true, onClick: () => {
|
|
25
23
|
onReaction(reaction === 'liked' ? undefined : 'liked');
|
|
26
24
|
}, children: _jsx(Icon, { name: reaction === 'liked' ? 'thumbs-up-solid' : 'thumbs-up' }) }), _jsx(Button, { variant: 'simple', label: t('no'), icon: true, compact: true, "aria-pressed": reaction === 'disliked', onClick: () => {
|
|
27
25
|
onReaction(reaction === 'disliked' ? undefined : 'disliked');
|
|
28
|
-
}, children: _jsx(Icon, { name: reaction === 'disliked' ? 'thumbs-down-solid' : 'thumbs-down' }) })] })] }), reaction && comment && onSubmit && (_jsxs(Flex, { container: { direction: 'column', gap: 1, pad: [1, undefined] }, children: [_jsx(TextArea, { ...comment, label: t('add_a_comment'), autoResize: false, maxLength: 200, hardStop: true, onKeyDown: (e) => {
|
|
26
|
+
}, children: _jsx(Icon, { name: reaction === 'disliked' ? 'thumbs-down-solid' : 'thumbs-down' }) })] })] }), reaction && comment && onSubmit && (_jsxs(Flex, { container: { direction: 'column', gap: 1, pad: [1, undefined] }, children: [_jsx(TextArea, { ...comment, label: t('add_a_comment'), ref: feedbackCommentRef, autoResize: false, maxLength: 200, hardStop: true, onKeyDown: (e) => {
|
|
29
27
|
if (e.key === 'Enter' && !e.shiftKey) {
|
|
30
28
|
e.preventDefault();
|
|
31
29
|
if (comment.value?.trim()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArticleFeedback.js","sourceRoot":"","sources":["../../../src/components/ArticleList/ArticleFeedback.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"ArticleFeedback.js","sourceRoot":"","sources":["../../../src/components/ArticleList/ArticleFeedback.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,YAAY,EACZ,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,IAAI,EACJ,eAAe,EAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,iBAAiB,MAAM,wEAAwE,CAAC;AAC5G,OAAO,KAAK,YAAY,MAAM,kEAAkE,CAAC;AACjG,OAAO,KAAK,mBAAmB,MAAM,0EAA0E,CAAC;AAChH,OAAO,KAAK,cAAc,MAAM,oEAAoE,CAAC;AAKrG,YAAY,CAAC,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,EAAE,cAAc,CAAC,CAAC;AAEnF,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EACrD,KAAK,EAAE,EACL,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OAAO,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;oCAC1D,CAAC;gCACH,CAAC;4BACH,CAAC,GACD,EACF,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,YACzC,KAAC,MAAM,IACL,OAAO,EAAC,SAAS,EACjB,OAAO,EAAE,CAAC,CAAgC,EAAE,EAAE;oCAC5C,QAAQ,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;gCAC1D,CAAC,YAEA,CAAC,CAAC,QAAQ,CAAC,GACL,GACJ,IACF,CACR,IACA,CACJ,CAAC,CAAC,CAAC,CACF,KAAC,yBAAyB,IAAC,GAAG,EAAE,kBAAkB,EAAE,QAAQ,EAAE,CAAC,CAAC,YAC7D,CAAC,CAAC,qCAAqC,CAAC,GACf,CAC7B,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC","sourcesContent":["import { forwardRef, useRef } from 'react';\nimport type { MouseEvent, KeyboardEvent, PropsWithoutRef } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n registerIcon,\n Text,\n Flex,\n useI18n,\n Button,\n TextArea,\n defaultThemeProp,\n Icon,\n useElementFocus\n} from '@pega/cosmos-react-core';\nimport * as thumbsUpSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up-solid.icon';\nimport * as thumbsUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up.icon';\nimport * as thumbsDownSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down-solid.icon';\nimport * as thumbsDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down.icon';\nimport type { RefElement } from '@pega/cosmos-react-core';\n\nimport type { ArticleFeedbackProps } from './ArticleList.types';\n\nregisterIcon(thumbsUpSolidIcon, thumbsUpIcon, thumbsDownSolidIcon, thumbsDownIcon);\n\nexport const StyledAcknowledgementText = styled(Text)(({\n theme: {\n base: { spacing }\n }\n}) => {\n return css`\n padding-block: calc(1.5 * ${spacing});\n `;\n});\n\nStyledAcknowledgementText.defaultProps = defaultThemeProp;\n\nexport default forwardRef<RefElement<ArticleFeedbackProps>, PropsWithoutRef<ArticleFeedbackProps>>(\n function ArticleFeedback(\n {\n question,\n comment,\n reaction,\n onReaction,\n onSubmit,\n showThankYouMessage = false,\n ...restProps\n },\n ref\n ) {\n const t = useI18n();\n const acknowledgmentText = useRef<HTMLSpanElement>(null);\n const feedbackCommentRef = useRef<HTMLTextAreaElement>(null);\n\n useElementFocus(acknowledgmentText, { shouldFocus: showThankYouMessage });\n useElementFocus(feedbackCommentRef, { shouldFocus: !!reaction });\n\n return (\n <Flex {...restProps} container={{ direction: 'column' }} ref={ref}>\n {!showThankYouMessage ? (\n <>\n <Flex container={{ gap: 0.5, alignItems: 'center', pad: [0.5, undefined] }}>\n <Text>{question}</Text>\n <div role='group' aria-label={t('confirmation_options')}>\n <Button\n aria-pressed={reaction === 'liked'}\n label={t('yes')}\n variant='simple'\n icon\n compact\n onClick={() => {\n onReaction(reaction === 'liked' ? undefined : 'liked');\n }}\n >\n <Icon name={reaction === 'liked' ? 'thumbs-up-solid' : 'thumbs-up'} />\n </Button>\n <Button\n variant='simple'\n label={t('no')}\n icon\n compact\n aria-pressed={reaction === 'disliked'}\n onClick={() => {\n onReaction(reaction === 'disliked' ? undefined : 'disliked');\n }}\n >\n <Icon name={reaction === 'disliked' ? 'thumbs-down-solid' : 'thumbs-down'} />\n </Button>\n </div>\n </Flex>\n\n {reaction && comment && onSubmit && (\n <Flex container={{ direction: 'column', gap: 1, pad: [1, undefined] }}>\n <TextArea\n {...comment}\n label={t('add_a_comment')}\n ref={feedbackCommentRef}\n autoResize={false}\n maxLength={200}\n hardStop\n onKeyDown={(e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n if (comment.value?.trim()) {\n onSubmit({ reaction, comment: comment.value ?? '' }, e);\n }\n }\n }}\n />\n <Flex container={{ gap: 1, justify: 'end' }}>\n <Button\n variant='primary'\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n onSubmit({ reaction, comment: comment.value ?? '' }, e);\n }}\n >\n {t('submit')}\n </Button>\n </Flex>\n </Flex>\n )}\n </>\n ) : (\n <StyledAcknowledgementText ref={acknowledgmentText} tabIndex={-1}>\n {t('article_thank_you_for_your_feedback')}\n </StyledAcknowledgementText>\n )}\n </Flex>\n );\n }\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenAIMessage.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessage.tsx"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"GenAIMessage.d.ts","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessage.tsx"],"names":[],"mappings":"AAIA,OAAO,EAgBL,KAAK,+BAA+B,EACrC,MAAM,yBAAyB,CAAC;AAQjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AA6B5D,QAAA,MAAM,YAAY,EAAE,+BAA+B,CAAC,iBAAiB,CAmNpE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { marked } from 'marked';
|
|
4
|
-
import { Button, Flex, Icon, Progress, registerIcon, useI18n, useTheme, Text, useTestIds, ErrorState, useElement, Tooltip, TextArea, FormDialog } from '@pega/cosmos-react-core';
|
|
4
|
+
import { Button, Flex, Icon, Progress, registerIcon, useI18n, useTheme, Text, useTestIds, ErrorState, useElement, Tooltip, TextArea, FormDialog, useElementFocus } from '@pega/cosmos-react-core';
|
|
5
5
|
import * as polarisSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/polaris-solid.icon';
|
|
6
6
|
import * as thumbsUpSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up-solid.icon';
|
|
7
7
|
import * as thumbsUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up.icon';
|
|
@@ -31,12 +31,12 @@ const GenAIMessage = forwardRef(function GenAIMessage(props, ref) {
|
|
|
31
31
|
const { message, announceInteraction, ...restProps } = props;
|
|
32
32
|
const plainTextMessage = markdownToPlainText(message ?? '');
|
|
33
33
|
let ariaLabel = plainTextMessage;
|
|
34
|
+
useElementFocus(wrapperEl, { shouldFocus: !showDialog && focusOnInteractionRef.current });
|
|
34
35
|
useEffect(() => {
|
|
35
36
|
if (!showDialog && focusOnInteractionRef.current) {
|
|
36
|
-
wrapperEl?.focus();
|
|
37
37
|
focusOnInteractionRef.current = false;
|
|
38
38
|
}
|
|
39
|
-
}, [
|
|
39
|
+
}, [showDialog]);
|
|
40
40
|
if (isCoachMessage(props)) {
|
|
41
41
|
const { id: messageId, coachName, suggestions, onSend, loading, error, feedback } = props;
|
|
42
42
|
const { reaction, onReaction, onFeedbackComplete } = feedback ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenAIMessage.js","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,EACP,QAAQ,EACR,UAAU,EAEX,MAAM,yBAAyB,CAAC;AAC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ffect, useRef, useState } from 'react';\nimport type { KeyboardEvent, PropsWithoutRef } from 'react';\nimport { marked } from 'marked';\n\nimport {\n Button,\n Flex,\n Icon,\n Progress,\n registerIcon,\n useI18n,\n useTheme,\n Text,\n useTestIds,\n ErrorState,\n useElement,\n Tooltip,\n TextArea,\n FormDialog,\n type ForwardRefForwardPropsComponent\n} from '@pega/cosmos-react-core';\nimport * as polarisSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/polaris-solid.icon';\nimport * as thumbsUpSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up-solid.icon';\nimport * as thumbsUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up.icon';\nimport * as thumbsDownSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down-solid.icon';\nimport * as thumbsDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down.icon';\nimport { RichTextViewer } from '@pega/cosmos-react-rte';\n\nimport type { GenAIMessageProps } from './GenAICoach.types';\nimport {\n StyledMessage,\n StyledSuggestion,\n StyledSuggestionsContainer,\n StyledUserMessage\n} from './GenAICoach.styles';\nimport { getGenAICoachTestIds } from './GenAICoach.test-ids';\nimport { isCoachMessage, isUserMessage } from './GenAICoach.utils';\n\nregisterIcon(\n polarisSolidIcon,\n thumbsUpSolidIcon,\n thumbsUpIcon,\n thumbsDownSolidIcon,\n thumbsDownIcon\n);\n\nconst markdownToPlainText = (markdown: string) => {\n // Convert Markdown to HTML\n const html = marked(markdown, { async: false });\n\n // Use DOMParser to parse HTML and extract plain text\n const parser = new DOMParser();\n const doc = parser.parseFromString(html, 'text/html');\n\n return doc.body.textContent ?? '';\n};\n\nconst GenAIMessage: ForwardRefForwardPropsComponent<GenAIMessageProps> = forwardRef(\n function GenAIMessage(props: PropsWithoutRef<GenAIMessageProps>, ref: GenAIMessageProps['ref']) {\n const testIds = useTestIds(props.testId, getGenAICoachTestIds);\n const theme = useTheme();\n const t = useI18n();\n const [wrapperEl, setWrapperEl] = useElement<HTMLDivElement>(null);\n const [feedbackVal, setFeedbackVal] = useState('');\n const [showDialog, setShowDialog] = useState(false);\n const focusOnInteractionRef = useRef(false);\n\n const { message, announceInteraction, ...restProps } = props;\n const plainTextMessage = markdownToPlainText(message ?? '');\n let ariaLabel = plainTextMessage;\n\n useEffect(() => {\n if (!showDialog && focusOnInteractionRef.current) {\n wrapperEl?.focus();\n focusOnInteractionRef.current = false;\n }\n }, [wrapperEl, showDialog]);\n\n if (isCoachMessage(props)) {\n const { id: messageId, coachName, suggestions, onSend, loading, error, feedback } = props;\n\n const { reaction, onReaction, onFeedbackComplete } = feedback ?? {};\n\n let selectedFeedbackResponse;\n\n let feedbackAriaLabel = t('sender_replied_message', [coachName, plainTextMessage ?? '']);\n\n if (feedback && reaction) {\n selectedFeedbackResponse = t('selected_noun', [\n reaction === 'liked' ? t('good_response') : t('bad_response')\n ]);\n\n feedbackAriaLabel = `${feedbackAriaLabel} ${selectedFeedbackResponse}`;\n }\n\n ariaLabel =\n suggestions && suggestions.length > 0\n ? `${feedbackAriaLabel} ${t('suggestions_in_message', [suggestions.length])}`\n : feedbackAriaLabel;\n\n if (announceInteraction) {\n ariaLabel = `${ariaLabel} ${t('interaction_message')}`;\n }\n\n return (\n <Flex\n as='li'\n data-testid={testIds.coachMessage}\n {...restProps}\n container={{ direction: 'column', pad: [1, 0] }}\n type='message'\n aria-label={ariaLabel}\n ref={ref}\n >\n <Flex container={{ gap: 1 }}>\n <Icon name='polaris-solid' color={theme.base.palette.ai} size='s' />\n <Text as='span' variant='h4'>\n {coachName}\n </Text>\n </Flex>\n <StyledMessage>\n {loading || error ? (\n <>\n {loading ? (\n <Progress variant='ellipsis' placement='inline' />\n ) : (\n <ErrorState message={error} />\n )}\n </>\n ) : (\n <>\n {message && <RichTextViewer content={message} type='markdown' />}\n {feedback && (\n <Flex container={{ pad: [0.5, undefined] }}>\n {reaction ? (\n <>\n <Flex\n container={{ pad: 0.5 }}\n aria-label={selectedFeedbackResponse}\n ref={setWrapperEl}\n tabIndex={-1}\n >\n <Icon\n name={reaction === 'liked' ? 'thumbs-up-solid' : 'thumbs-down-solid'}\n />\n </Flex>\n {showDialog ? (\n onFeedbackComplete &&\n wrapperEl && (\n <FormDialog\n target={wrapperEl}\n heading={t('share_feedback')}\n onCancel={() => {\n focusOnInteractionRef.current = true;\n setShowDialog(false);\n onFeedbackComplete(messageId);\n }}\n onSubmit={() => {\n focusOnInteractionRef.current = true;\n setShowDialog(false);\n onFeedbackComplete(messageId, feedbackVal);\n }}\n onKeyDown={e => e.stopPropagation()}\n >\n <TextArea\n value={feedbackVal}\n onChange={e => setFeedbackVal(e.target.value)}\n onKeyDown={(e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n focusOnInteractionRef.current = true;\n setShowDialog(false);\n onFeedbackComplete(messageId, feedbackVal);\n }\n }}\n autoResize={false}\n />\n </FormDialog>\n )\n ) : (\n <Tooltip target={wrapperEl} describeTarget={false}>\n {reaction === 'liked' ? t('good_response') : t('bad_response')}\n </Tooltip>\n )}\n </>\n ) : (\n <>\n <Button\n label={t('good_response')}\n variant='simple'\n icon\n compact\n onClick={() => {\n onReaction?.(messageId, 'liked');\n focusOnInteractionRef.current = true;\n }}\n >\n <Icon name='thumbs-up' />\n </Button>\n\n <Button\n label={t('bad_response')}\n variant='simple'\n icon\n compact\n onClick={() => {\n setShowDialog(true);\n onReaction?.(messageId, 'disliked');\n }}\n >\n <Icon name='thumbs-down' />\n </Button>\n </>\n )}\n </Flex>\n )}\n {suggestions && (\n <Flex as={StyledSuggestionsContainer} container={{ direction: 'column', gap: 1 }}>\n {suggestions.map(({ id, message: prompt }) => {\n return (\n <Button\n as={StyledSuggestion}\n onClick={\n onSend\n ? () => onSend({ id, message: prompt, fromCoachSuggestion: true })\n : undefined\n }\n key={id}\n >\n {prompt}\n </Button>\n );\n })}\n </Flex>\n )}\n </>\n )}\n </StyledMessage>\n </Flex>\n );\n }\n\n if (isUserMessage(props)) {\n if (plainTextMessage) {\n ariaLabel = t('you_asked', [plainTextMessage]);\n }\n\n if (announceInteraction) {\n ariaLabel = `${ariaLabel} ${t('interaction_message')}`;\n }\n\n return (\n <StyledUserMessage\n as={StyledUserMessage}\n data-testid={testIds.userMessage}\n {...restProps}\n type='message'\n aria-label={ariaLabel}\n ref={ref}\n >\n {message && <RichTextViewer content={message} type='markdown' />}\n </StyledUserMessage>\n );\n }\n\n return null;\n }\n);\n\nexport default GenAIMessage;\n"]}
|
|
1
|
+
{"version":3,"file":"GenAIMessage.js","sourceRoot":"","sources":["../../../src/components/GenAICoach/GenAIMessage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,EACP,QAAQ,EACR,UAAU,EACV,eAAe,EAEhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,gBAAgB,MAAM,sEAAsE,CAAC;AACzG,OAAO,KAAK,iBAAiB,MAAM,wEAAwE,CAAC;AAC5G,OAAO,KAAK,YAAY,MAAM,kEAAkE,CAAC;AACjG,OAAO,KAAK,mBAAmB,MAAM,0EAA0E,CAAC;AAChH,OAAO,KAAK,cAAc,MAAM,oEAAoE,CAAC;AACrG,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,0BAA0B,EAC1B,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EA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AAE,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC;4CAClE,CAAC,CAAC,SAAS,YAId,MAAM,IAFF,EAAE,CAGA,CACV,CAAC;gCACJ,CAAC,CAAC,GACG,CACR,IACA,CACJ,GACa,IACX,CACR,CAAC;IACJ,CAAC;IAED,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,IAAI,gBAAgB,EAAE,CAAC;YACrB,SAAS,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,mBAAmB,EAAE,CAAC;YACxB,SAAS,GAAG,GAAG,SAAS,IAAI,CAAC,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACzD,CAAC;QAED,OAAO,CACL,KAAC,iBAAiB,IAChB,EAAE,EAAE,iBAAiB,iBACR,OAAO,CAAC,WAAW,KAC5B,SAAS,EACb,IAAI,EAAC,SAAS,gBACF,SAAS,EACrB,GAAG,EAAE,GAAG,YAEP,OAAO,IAAI,KAAC,cAAc,IAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,UAAU,GAAG,GAC9C,CACrB,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { forwardRef, useEffect, useRef, useState } from 'react';\nimport type { KeyboardEvent, PropsWithoutRef } from 'react';\nimport { marked } from 'marked';\n\nimport {\n Button,\n Flex,\n Icon,\n Progress,\n registerIcon,\n useI18n,\n useTheme,\n Text,\n useTestIds,\n ErrorState,\n useElement,\n Tooltip,\n TextArea,\n FormDialog,\n useElementFocus,\n type ForwardRefForwardPropsComponent\n} from '@pega/cosmos-react-core';\nimport * as polarisSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/polaris-solid.icon';\nimport * as thumbsUpSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up-solid.icon';\nimport * as thumbsUpIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-up.icon';\nimport * as thumbsDownSolidIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down-solid.icon';\nimport * as thumbsDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/thumbs-down.icon';\nimport { RichTextViewer } from '@pega/cosmos-react-rte';\n\nimport type { GenAIMessageProps } from './GenAICoach.types';\nimport {\n StyledMessage,\n StyledSuggestion,\n StyledSuggestionsContainer,\n StyledUserMessage\n} from './GenAICoach.styles';\nimport { getGenAICoachTestIds } from './GenAICoach.test-ids';\nimport { isCoachMessage, isUserMessage } from './GenAICoach.utils';\n\nregisterIcon(\n polarisSolidIcon,\n thumbsUpSolidIcon,\n thumbsUpIcon,\n thumbsDownSolidIcon,\n thumbsDownIcon\n);\n\nconst markdownToPlainText = (markdown: string) => {\n // Convert Markdown to HTML\n const html = marked(markdown, { async: false });\n\n // Use DOMParser to parse HTML and extract plain text\n const parser = new DOMParser();\n const doc = parser.parseFromString(html, 'text/html');\n\n return doc.body.textContent ?? '';\n};\n\nconst GenAIMessage: ForwardRefForwardPropsComponent<GenAIMessageProps> = forwardRef(\n function GenAIMessage(props: PropsWithoutRef<GenAIMessageProps>, ref: GenAIMessageProps['ref']) {\n const testIds = useTestIds(props.testId, getGenAICoachTestIds);\n const theme = useTheme();\n const t = useI18n();\n const [wrapperEl, setWrapperEl] = useElement<HTMLDivElement>(null);\n const [feedbackVal, setFeedbackVal] = useState('');\n const [showDialog, setShowDialog] = useState(false);\n const focusOnInteractionRef = useRef(false);\n\n const { message, announceInteraction, ...restProps } = props;\n const plainTextMessage = markdownToPlainText(message ?? '');\n let ariaLabel = plainTextMessage;\n\n useElementFocus(wrapperEl, { shouldFocus: !showDialog && focusOnInteractionRef.current });\n\n useEffect(() => {\n if (!showDialog && focusOnInteractionRef.current) {\n focusOnInteractionRef.current = false;\n }\n }, [showDialog]);\n\n if (isCoachMessage(props)) {\n const { id: messageId, coachName, suggestions, onSend, loading, error, feedback } = props;\n\n const { reaction, onReaction, onFeedbackComplete } = feedback ?? {};\n\n let selectedFeedbackResponse;\n\n let feedbackAriaLabel = t('sender_replied_message', [coachName, plainTextMessage ?? '']);\n\n if (feedback && reaction) {\n selectedFeedbackResponse = t('selected_noun', [\n reaction === 'liked' ? t('good_response') : t('bad_response')\n ]);\n\n feedbackAriaLabel = `${feedbackAriaLabel} ${selectedFeedbackResponse}`;\n }\n\n ariaLabel =\n suggestions && suggestions.length > 0\n ? `${feedbackAriaLabel} ${t('suggestions_in_message', [suggestions.length])}`\n : feedbackAriaLabel;\n\n if (announceInteraction) {\n ariaLabel = `${ariaLabel} ${t('interaction_message')}`;\n }\n\n return (\n <Flex\n as='li'\n data-testid={testIds.coachMessage}\n {...restProps}\n container={{ direction: 'column', pad: [1, 0] }}\n type='message'\n aria-label={ariaLabel}\n ref={ref}\n >\n <Flex container={{ gap: 1 }}>\n <Icon name='polaris-solid' color={theme.base.palette.ai} size='s' />\n <Text as='span' variant='h4'>\n {coachName}\n </Text>\n </Flex>\n <StyledMessage>\n {loading || error ? (\n <>\n {loading ? (\n <Progress variant='ellipsis' placement='inline' />\n ) : (\n <ErrorState message={error} />\n )}\n </>\n ) : (\n <>\n {message && <RichTextViewer content={message} type='markdown' />}\n {feedback && (\n <Flex container={{ pad: [0.5, undefined] }}>\n {reaction ? (\n <>\n <Flex\n container={{ pad: 0.5 }}\n aria-label={selectedFeedbackResponse}\n ref={setWrapperEl}\n tabIndex={-1}\n >\n <Icon\n name={reaction === 'liked' ? 'thumbs-up-solid' : 'thumbs-down-solid'}\n />\n </Flex>\n {showDialog ? (\n onFeedbackComplete &&\n wrapperEl && (\n <FormDialog\n target={wrapperEl}\n heading={t('share_feedback')}\n onCancel={() => {\n focusOnInteractionRef.current = true;\n setShowDialog(false);\n onFeedbackComplete(messageId);\n }}\n onSubmit={() => {\n focusOnInteractionRef.current = true;\n setShowDialog(false);\n onFeedbackComplete(messageId, feedbackVal);\n }}\n onKeyDown={e => e.stopPropagation()}\n >\n <TextArea\n value={feedbackVal}\n onChange={e => setFeedbackVal(e.target.value)}\n onKeyDown={(e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault();\n focusOnInteractionRef.current = true;\n setShowDialog(false);\n onFeedbackComplete(messageId, feedbackVal);\n }\n }}\n autoResize={false}\n />\n </FormDialog>\n )\n ) : (\n <Tooltip target={wrapperEl} describeTarget={false}>\n {reaction === 'liked' ? t('good_response') : t('bad_response')}\n </Tooltip>\n )}\n </>\n ) : (\n <>\n <Button\n label={t('good_response')}\n variant='simple'\n icon\n compact\n onClick={() => {\n onReaction?.(messageId, 'liked');\n focusOnInteractionRef.current = true;\n }}\n >\n <Icon name='thumbs-up' />\n </Button>\n\n <Button\n label={t('bad_response')}\n variant='simple'\n icon\n compact\n onClick={() => {\n setShowDialog(true);\n onReaction?.(messageId, 'disliked');\n }}\n >\n <Icon name='thumbs-down' />\n </Button>\n </>\n )}\n </Flex>\n )}\n {suggestions && (\n <Flex as={StyledSuggestionsContainer} container={{ direction: 'column', gap: 1 }}>\n {suggestions.map(({ id, message: prompt }) => {\n return (\n <Button\n as={StyledSuggestion}\n onClick={\n onSend\n ? () => onSend({ id, message: prompt, fromCoachSuggestion: true })\n : undefined\n }\n key={id}\n >\n {prompt}\n </Button>\n );\n })}\n </Flex>\n )}\n </>\n )}\n </StyledMessage>\n </Flex>\n );\n }\n\n if (isUserMessage(props)) {\n if (plainTextMessage) {\n ariaLabel = t('you_asked', [plainTextMessage]);\n }\n\n if (announceInteraction) {\n ariaLabel = `${ariaLabel} ${t('interaction_message')}`;\n }\n\n return (\n <StyledUserMessage\n as={StyledUserMessage}\n data-testid={testIds.userMessage}\n {...restProps}\n type='message'\n aria-label={ariaLabel}\n ref={ref}\n >\n {message && <RichTextViewer content={message} type='markdown' />}\n </StyledUserMessage>\n );\n }\n\n return null;\n }\n);\n\nexport default GenAIMessage;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-work",
|
|
3
|
-
"version": "8.0.0-build.49.
|
|
3
|
+
"version": "8.0.0-build.49.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/pegasystems/cosmos-react.git",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"build": "tsc -b tsconfig.build.json"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@pega/cosmos-react-core": "8.0.0-build.49.
|
|
23
|
-
"@pega/cosmos-react-rte": "8.0.0-build.49.
|
|
22
|
+
"@pega/cosmos-react-core": "8.0.0-build.49.2",
|
|
23
|
+
"@pega/cosmos-react-rte": "8.0.0-build.49.2",
|
|
24
24
|
"@types/react": "^17.0.62 || ^18.3.3",
|
|
25
25
|
"@types/react-dom": "^17.0.20 || ^18.3.0",
|
|
26
26
|
"@types/styled-components": "^5.1.26",
|