@constructor-io/constructorio-ui-pia 2.12.0 → 2.13.1
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/dist/constructorio-ui-pia-bundled.js +54 -54
- package/lib/cjs/components/CioPia/CioPiaQna.js +8 -3
- package/lib/cjs/components/CioPia/CioPiaStyles.css +5 -0
- package/lib/cjs/components/CioPia/PiaCustomCarousel.js +11 -1
- package/lib/cjs/components/ConversationHistory/ConversationHistory.js +10 -5
- package/lib/cjs/components/Error/ErrorBlock.js +7 -5
- package/lib/cjs/components/Feedback/Feedback.js +4 -4
- package/lib/cjs/components/Input/Input.js +2 -1
- package/lib/cjs/components/LoadingSkeleton/LoadingSkeleton.js +2 -1
- package/lib/cjs/components/PiaConversation/PiaModal.js +22 -4
- package/lib/cjs/components/StatusRegion/StatusRegion.js +34 -0
- package/lib/cjs/components/SuggestedQuestionsContainer/SuggestedQuestionsSkeleton.js +1 -1
- package/lib/cjs/components/icons/QuestionIcon.js +1 -1
- package/lib/cjs/components/icons/SendIcon.js +1 -1
- package/lib/cjs/components/icons/SparklesIcon.js +1 -1
- package/lib/cjs/hooks/useAnswerResults.js +12 -3
- package/lib/cjs/hooks/useConversation.js +24 -10
- package/lib/cjs/hooks/useRecsPod.js +15 -7
- package/lib/cjs/hooks/useSuggestedQuestions.js +12 -3
- package/lib/cjs/utils/translate.js +12 -0
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/CioPia/CioPiaQna.js +8 -3
- package/lib/mjs/components/CioPia/CioPiaStyles.css +5 -0
- package/lib/mjs/components/CioPia/PiaCustomCarousel.js +11 -1
- package/lib/mjs/components/ConversationHistory/ConversationHistory.js +10 -5
- package/lib/mjs/components/Error/ErrorBlock.js +7 -5
- package/lib/mjs/components/Feedback/Feedback.js +4 -4
- package/lib/mjs/components/Input/Input.js +2 -1
- package/lib/mjs/components/LoadingSkeleton/LoadingSkeleton.js +2 -1
- package/lib/mjs/components/PiaConversation/PiaModal.js +22 -4
- package/lib/mjs/components/StatusRegion/StatusRegion.js +28 -0
- package/lib/mjs/components/SuggestedQuestionsContainer/SuggestedQuestionsSkeleton.js +1 -1
- package/lib/mjs/components/icons/QuestionIcon.js +1 -1
- package/lib/mjs/components/icons/SendIcon.js +1 -1
- package/lib/mjs/components/icons/SparklesIcon.js +1 -1
- package/lib/mjs/hooks/useAnswerResults.js +13 -4
- package/lib/mjs/hooks/useConversation.js +21 -7
- package/lib/mjs/hooks/useRecsPod.js +15 -7
- package/lib/mjs/hooks/useSuggestedQuestions.js +13 -4
- package/lib/mjs/utils/translate.js +12 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/ConversationHistory/ConversationHistory.d.ts +7 -1
- package/lib/types/components/Error/ErrorBlock.d.ts +9 -1
- package/lib/types/components/StatusRegion/StatusRegion.d.ts +13 -0
- package/lib/types/types.d.ts +10 -0
- package/lib/types/utils/contentTransformers.d.ts +2 -2
- package/lib/types/utils/translate.d.ts +3 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +7 -6
|
@@ -17,6 +17,7 @@ const translate_1 = require("../../utils/translate");
|
|
|
17
17
|
const PiaInlineAnswer_1 = tslib_1.__importDefault(require("../PiaInlineAnswer/PiaInlineAnswer"));
|
|
18
18
|
const PiaModal_1 = tslib_1.__importDefault(require("../PiaConversation/PiaModal"));
|
|
19
19
|
const PiaConversation_1 = tslib_1.__importDefault(require("../PiaConversation/PiaConversation"));
|
|
20
|
+
const StatusRegion_1 = tslib_1.__importStar(require("../StatusRegion/StatusRegion"));
|
|
20
21
|
/** The question-and-answer experience: `mode: 'default'`, `mode: 'conversation'`, and the modal. */
|
|
21
22
|
// eslint-disable-next-line complexity
|
|
22
23
|
function CioPiaQna(props) {
|
|
@@ -55,10 +56,12 @@ function CioPiaQna(props) {
|
|
|
55
56
|
callbackContainerRef(node);
|
|
56
57
|
}, [viewportContainerRef, callbackContainerRef]);
|
|
57
58
|
const qnaResultId = (_a = pia.answers.data) === null || _a === void 0 ? void 0 : _a.qna_result_id;
|
|
58
|
-
// The text bars
|
|
59
|
+
// The text bars and the "Loading answer" status track the answer request only. The question
|
|
59
60
|
// row keeps the combined `isLoading`: the follow-up questions that refill it arrive with the
|
|
60
61
|
// answer, so the row is waiting on either request.
|
|
61
62
|
const isAnswerLoading = pia.answers.isLoading;
|
|
63
|
+
// Inline mode renders the answer outside any live region.
|
|
64
|
+
const answerStatus = (0, StatusRegion_1.answerStatusMessage)(isAnswerLoading, !!currentAnswer, translations);
|
|
62
65
|
const renderProps = {
|
|
63
66
|
items: currentItems,
|
|
64
67
|
isLoading,
|
|
@@ -72,6 +75,7 @@ function CioPiaQna(props) {
|
|
|
72
75
|
const conversationHistoryProps = {
|
|
73
76
|
conversationHistory,
|
|
74
77
|
isLoading,
|
|
78
|
+
isAnswerLoading,
|
|
75
79
|
error,
|
|
76
80
|
currentItems,
|
|
77
81
|
showFeedback,
|
|
@@ -103,9 +107,10 @@ function CioPiaQna(props) {
|
|
|
103
107
|
react_1.default.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, (0, translate_1.translate)('Any questions about this product?', translations)),
|
|
104
108
|
react_1.default.createElement(Input_1.default, { onSubmit: handleSubmitQuestion, onFocus: handleInputFocus, value: currentQuestion, translations: translations, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.input }),
|
|
105
109
|
isAnswerLoading && react_1.default.createElement(LoadingSkeleton_1.default, { componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.loading }),
|
|
106
|
-
!isAnswerLoading && error && react_1.default.createElement(ErrorBlock_1.default, {
|
|
110
|
+
!isAnswerLoading && error && (react_1.default.createElement(ErrorBlock_1.default, { key: error.message || (0, translate_1.translate)('Unexpected error', translations), message: error.message, translations: translations })),
|
|
107
111
|
!isAnswerLoading && !error && currentAnswer && (react_1.default.createElement(PiaInlineAnswer_1.default, { currentAnswer: currentAnswer, currentItems: currentItems, showFeedback: showFeedback, learnMoreUrl: learnMoreUrl, disclaimerPosition: disclaimerPosition, translations: translations, callbacks: callbacks, componentOverrides: componentOverrides, onFeedback: handleFeedback, onResultClick: tracking.trackResultClick, question: currentQuestion, qnaResultId: qnaResultId, priceCurrency: priceCurrency })),
|
|
108
112
|
isLoading && react_1.default.createElement(SuggestedQuestionsSkeleton_1.default, null),
|
|
109
|
-
!isLoading && !error && (react_1.default.createElement(SuggestedQuestionsContainer_1.default, { questions: displayedQuestions, onQuestionClick: handleQuestionClick, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.suggestedQuestions })))
|
|
113
|
+
!isLoading && !error && (react_1.default.createElement(SuggestedQuestionsContainer_1.default, { questions: displayedQuestions, onQuestionClick: handleQuestionClick, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.suggestedQuestions }))),
|
|
114
|
+
react_1.default.createElement(StatusRegion_1.default, { message: answerStatus, "data-testid": 'answer-status' })));
|
|
110
115
|
}
|
|
111
116
|
exports.default = CioPiaQna;
|
|
@@ -11,6 +11,13 @@ function HtmlDescription({ product }) {
|
|
|
11
11
|
return null;
|
|
12
12
|
return (react_1.default.createElement("p", { className: 'cio-product-card-description', dangerouslySetInnerHTML: { __html: (0, contentTransformers_1.sanitizeHtml)(description) } }));
|
|
13
13
|
}
|
|
14
|
+
// The card root is focusable and acts as a link, so Enter must do what a click does.
|
|
15
|
+
// Only for the card itself: Enter on the Add to Cart button inside it is that button's.
|
|
16
|
+
function handleCardKeyDown(event) {
|
|
17
|
+
if (event.key === 'Enter' && event.target === event.currentTarget) {
|
|
18
|
+
event.currentTarget.click();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
14
21
|
function createPriceSectionOverride(priceCurrency) {
|
|
15
22
|
return function PriceSectionOverride({ product }) {
|
|
16
23
|
const { price, salePrice } = product;
|
|
@@ -89,7 +96,10 @@ function PiaCustomCarousel({ items, componentOverrides, callbacks, onResultClick
|
|
|
89
96
|
}
|
|
90
97
|
// Default: render ProductCard with handlers directly
|
|
91
98
|
const addToCartText = onAddToCart ? (0, translate_1.translate)('Add to Cart', translations) : undefined;
|
|
92
|
-
return Object.assign(Object.assign({}, baseOverrides), { item: Object.assign(Object.assign({}, baseOverrides.item), { productCard: Object.assign(Object.assign({}, cardOverrides), { reactNode: ({ product }) => (react_1.default.createElement(constructorio_ui_components_1.ProductCard, { product: product, className: 'w-full h-full',
|
|
99
|
+
return Object.assign(Object.assign({}, baseOverrides), { item: Object.assign(Object.assign({}, baseOverrides.item), { productCard: Object.assign(Object.assign({}, cardOverrides), { reactNode: ({ product }) => (react_1.default.createElement(constructorio_ui_components_1.ProductCard, { product: product, className: 'w-full h-full',
|
|
100
|
+
// Reachable by Tab. The name is the product name: a name computed from the
|
|
101
|
+
// card's content would also swallow the Add to Cart button's text.
|
|
102
|
+
role: 'link', "aria-label": product.name || undefined, tabIndex: 0, onKeyDown: handleCardKeyDown, addToCartText: addToCartText, onAddToCart: clickHandlerProps.onAddToCart, onProductClick: clickHandlerProps.onProductClick, componentOverrides: cardOverrides })) }) }) });
|
|
93
103
|
}, [componentOverrides, priceSectionOverride, clickHandlerProps, onAddToCart, translations]);
|
|
94
104
|
if (items.length === 0) {
|
|
95
105
|
return null;
|
|
@@ -8,7 +8,9 @@ const Disclaimer_1 = tslib_1.__importDefault(require("../CioPia/Disclaimer"));
|
|
|
8
8
|
const ErrorBlock_1 = tslib_1.__importDefault(require("../Error/ErrorBlock"));
|
|
9
9
|
const LoadingSkeleton_1 = tslib_1.__importDefault(require("../LoadingSkeleton/LoadingSkeleton"));
|
|
10
10
|
const PiaCustomCarousel_1 = tslib_1.__importDefault(require("../CioPia/PiaCustomCarousel"));
|
|
11
|
-
|
|
11
|
+
const StatusRegion_1 = tslib_1.__importStar(require("../StatusRegion/StatusRegion"));
|
|
12
|
+
const translate_1 = require("../../utils/translate");
|
|
13
|
+
function ConversationHistory({ conversationHistory, isLoading, isAnswerLoading = isLoading, error, currentItems, showFeedback, showPreviousItems = true, learnMoreUrl, disclaimerPosition = 'bottom', translations, callbacks, componentOverrides, handleFeedback, onResultClick, qnaResultId, priceCurrency, }) {
|
|
12
14
|
const scrollContainerRef = (0, react_1.useRef)(null);
|
|
13
15
|
(0, react_1.useEffect)(() => {
|
|
14
16
|
const container = scrollContainerRef.current;
|
|
@@ -19,24 +21,27 @@ function ConversationHistory({ conversationHistory, isLoading, error, currentIte
|
|
|
19
21
|
});
|
|
20
22
|
return () => cancelAnimationFrame(frameId);
|
|
21
23
|
}, [conversationHistory, isLoading]);
|
|
24
|
+
const lastEntry = conversationHistory[conversationHistory.length - 1];
|
|
25
|
+
const answerStatus = (0, StatusRegion_1.answerStatusMessage)(isAnswerLoading, !!(lastEntry === null || lastEntry === void 0 ? void 0 : lastEntry.answer), translations);
|
|
22
26
|
const disclaimer = (react_1.default.createElement(Disclaimer_1.default, { learnMoreUrl: learnMoreUrl, translations: translations, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.disclaimer }));
|
|
23
27
|
return (react_1.default.createElement("div", { className: 'cio-pia-conversation-history' },
|
|
24
28
|
disclaimerPosition === 'top' && disclaimer,
|
|
25
|
-
react_1.default.createElement("div", { ref: scrollContainerRef, className: 'cio-pia-conversation-entries', role: 'log', "aria-label": 'Conversation history' }, conversationHistory.map((entry, index) => {
|
|
29
|
+
react_1.default.createElement("div", { ref: scrollContainerRef, className: 'cio-pia-conversation-entries', role: 'log', tabIndex: 0, "aria-label": (0, translate_1.translate)('Conversation history', translations) }, conversationHistory.map((entry, index) => {
|
|
26
30
|
const isLast = index === conversationHistory.length - 1;
|
|
27
31
|
const previousEntryItems = showPreviousItems ? entry.items : null;
|
|
28
32
|
const latestEntryItems = currentItems !== undefined ? currentItems : entry.items;
|
|
29
33
|
const carouselItems = isLast ? latestEntryItems : previousEntryItems;
|
|
30
34
|
return (react_1.default.createElement("div", { key: entry.id, className: 'cio-pia-conversation-entry' },
|
|
31
35
|
react_1.default.createElement("div", { className: 'cio-pia-chat-question' }, entry.question),
|
|
32
|
-
isLast && isLoading && (react_1.default.createElement("div", { className: 'cio-pia-conversation-loading'
|
|
36
|
+
isLast && isLoading && (react_1.default.createElement("div", { className: 'cio-pia-conversation-loading' },
|
|
33
37
|
react_1.default.createElement(LoadingSkeleton_1.default, { componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.loading }))),
|
|
34
|
-
isLast && !isLoading && error && (react_1.default.createElement(ErrorBlock_1.default, {
|
|
38
|
+
isLast && !isLoading && error && (react_1.default.createElement(ErrorBlock_1.default, { key: error.message || (0, translate_1.translate)('Unexpected error', translations), message: error.message, translations: translations, announce: false })),
|
|
35
39
|
entry.answer && (react_1.default.createElement("div", { className: 'cio-pia-answer-container' },
|
|
36
40
|
react_1.default.createElement(Answer_1.default, { text: entry.answer, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.answer }),
|
|
37
41
|
carouselItems && (react_1.default.createElement(PiaCustomCarousel_1.default, { items: carouselItems, componentOverrides: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.carousel, callbacks: callbacks, onResultClick: onResultClick, question: entry.question, qnaResultId: qnaResultId, translations: translations, priceCurrency: priceCurrency })),
|
|
38
42
|
isLast && showFeedback && (react_1.default.createElement(Feedback_1.default, { translations: translations, onFeedback: handleFeedback, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.feedback }))))));
|
|
39
43
|
})),
|
|
40
|
-
disclaimerPosition === 'bottom' && disclaimer
|
|
44
|
+
disclaimerPosition === 'bottom' && disclaimer,
|
|
45
|
+
react_1.default.createElement(StatusRegion_1.default, { message: answerStatus, "data-testid": 'answer-status' })));
|
|
41
46
|
}
|
|
42
47
|
exports.default = ConversationHistory;
|
|
@@ -2,22 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
|
+
const translate_1 = require("../../utils/translate");
|
|
5
6
|
function WarningIcon() {
|
|
6
|
-
return (react_1.default.createElement("svg", { width: '24', height: '24', viewBox: '0 0 24 24', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
7
|
+
return (react_1.default.createElement("svg", { width: '24', height: '24', viewBox: '0 0 24 24', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-hidden": 'true', focusable: 'false' },
|
|
7
8
|
react_1.default.createElement("path", { d: 'M12.0004 2C6.4804 2 2.0004 6.48 2.0004 12C2.0004 17.52 6.4804 22 12.0004 22C17.5204 22 22.0004 17.52 22.0004 12C22.0004 6.48 17.5204 2 12.0004 2ZM13.0004 17H11.0004V15H13.0004V17ZM13.0004 13H11.0004V7H13.0004V13Z', fill: '#F1923A' })));
|
|
8
9
|
}
|
|
9
10
|
function RetryIcon() {
|
|
10
|
-
return (react_1.default.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
11
|
+
return (react_1.default.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-hidden": 'true', focusable: 'false' },
|
|
11
12
|
react_1.default.createElement("path", { d: 'M11.7633 4.23329C10.7966 3.26663 9.46992 2.66663 7.99659 2.66663C5.04992 2.66663 2.66992 5.05329 2.66992 7.99996C2.66992 10.9466 5.04992 13.3333 7.99659 13.3333C10.4833 13.3333 12.5566 11.6333 13.1499 9.33329H11.7633C11.2166 10.8866 9.73659 12 7.99659 12C5.78992 12 3.99659 10.2066 3.99659 7.99996C3.99659 5.79329 5.78992 3.99996 7.99659 3.99996C9.10326 3.99996 10.0899 4.45996 10.8099 5.18663L8.66326 7.33329H13.3299V2.66663L11.7633 4.23329Z', fill: 'white' })));
|
|
12
13
|
}
|
|
13
|
-
function ErrorBlock({ message, onRetry = undefined }) {
|
|
14
|
+
function ErrorBlock({ message, onRetry = undefined, translations, announce = true, }) {
|
|
15
|
+
const resolvedMessage = message || (0, translate_1.translate)('Unexpected error', translations);
|
|
14
16
|
return (react_1.default.createElement("div", { className: 'cio-pia-error-block-container', "data-testid": 'error-block' },
|
|
15
17
|
react_1.default.createElement("div", { className: 'cio-pia-error-block-warning-icon-container', "data-testid": 'error-block-warning-icon' },
|
|
16
18
|
react_1.default.createElement(WarningIcon, null)),
|
|
17
19
|
react_1.default.createElement("div", { className: 'cio-pia-error-block-text-container' },
|
|
18
|
-
react_1.default.createElement("p", { className: 'cio-pia-error-block-text' },
|
|
20
|
+
react_1.default.createElement("p", { className: 'cio-pia-error-block-text', role: announce ? 'alert' : undefined }, resolvedMessage),
|
|
19
21
|
onRetry && (react_1.default.createElement("button", { type: 'button', onClick: onRetry, className: 'cio-pia-error-block-retry-button' },
|
|
20
22
|
react_1.default.createElement(RetryIcon, null),
|
|
21
|
-
|
|
23
|
+
(0, translate_1.translate)('Retry', translations))))));
|
|
22
24
|
}
|
|
23
25
|
exports.default = ErrorBlock;
|
|
@@ -6,10 +6,10 @@ const constructorio_ui_components_1 = require("@constructor-io/constructorio-ui-
|
|
|
6
6
|
const types_1 = require("../../types");
|
|
7
7
|
const translate_1 = require("../../utils/translate");
|
|
8
8
|
function ThumbsUpIcon({ isSelected }) {
|
|
9
|
-
return (react_1.default.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' }, isSelected ? (react_1.default.createElement("path", { d: 'M3.33317 6.66667H0.666504V14.6667H3.33317V6.66667ZM5.99984 14.6667C5.2665 14.6667 4.6665 14.0667 4.6665 13.3333V6.66667C4.6665 6.3 4.81317 5.96667 5.05317 5.72667L9.4465 1.33333L10.1532 2.03333C10.3332 2.21333 10.4465 2.46667 10.4465 2.74L10.4265 2.95333L9.79317 6.00001H13.9998C14.7332 6.00001 15.3332 6.60001 15.3332 7.33334V8.66668C15.3332 8.84001 15.2998 9.00001 15.2398 9.15334L13.2265 13.8533C13.0265 14.3333 12.5532 14.6667 11.9998 14.6667H5.99984Z', fill: '#4CAF50', fillOpacity: '1' })) : (react_1.default.createElement("path", { d: 'M5.99984 14.6667H11.9998C12.5532 14.6667 13.0265 14.3333 13.2265 13.8533L15.2398 9.15334C15.2998 9.00001 15.3332 8.84001 15.3332 8.66668V7.33334C15.3332 6.60001 14.7332 6.00001 13.9998 6.00001H9.79317L10.4265 2.95334L10.4465 2.74001C10.4465 2.46668 10.3332 2.21334 10.1532 2.03334L9.4465 1.33334L5.05317 5.72668C4.81317 5.96668 4.6665 6.30001 4.6665 6.66668V13.3333C4.6665 14.0667 5.2665 14.6667 5.99984 14.6667ZM5.99984 6.66668L8.89317 3.77334L7.99984 7.33334H13.9998V8.66668L11.9998 13.3333H5.99984V6.66668ZM0.666504 6.66668H3.33317V14.6667H0.666504V6.66668Z', fill: '#0F1324', fillOpacity: '0.6' }))));
|
|
9
|
+
return (react_1.default.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-hidden": 'true', focusable: 'false' }, isSelected ? (react_1.default.createElement("path", { d: 'M3.33317 6.66667H0.666504V14.6667H3.33317V6.66667ZM5.99984 14.6667C5.2665 14.6667 4.6665 14.0667 4.6665 13.3333V6.66667C4.6665 6.3 4.81317 5.96667 5.05317 5.72667L9.4465 1.33333L10.1532 2.03333C10.3332 2.21333 10.4465 2.46667 10.4465 2.74L10.4265 2.95333L9.79317 6.00001H13.9998C14.7332 6.00001 15.3332 6.60001 15.3332 7.33334V8.66668C15.3332 8.84001 15.2998 9.00001 15.2398 9.15334L13.2265 13.8533C13.0265 14.3333 12.5532 14.6667 11.9998 14.6667H5.99984Z', fill: '#4CAF50', fillOpacity: '1' })) : (react_1.default.createElement("path", { d: 'M5.99984 14.6667H11.9998C12.5532 14.6667 13.0265 14.3333 13.2265 13.8533L15.2398 9.15334C15.2998 9.00001 15.3332 8.84001 15.3332 8.66668V7.33334C15.3332 6.60001 14.7332 6.00001 13.9998 6.00001H9.79317L10.4265 2.95334L10.4465 2.74001C10.4465 2.46668 10.3332 2.21334 10.1532 2.03334L9.4465 1.33334L5.05317 5.72668C4.81317 5.96668 4.6665 6.30001 4.6665 6.66668V13.3333C4.6665 14.0667 5.2665 14.6667 5.99984 14.6667ZM5.99984 6.66668L8.89317 3.77334L7.99984 7.33334H13.9998V8.66668L11.9998 13.3333H5.99984V6.66668ZM0.666504 6.66668H3.33317V14.6667H0.666504V6.66668Z', fill: '#0F1324', fillOpacity: '0.6' }))));
|
|
10
10
|
}
|
|
11
11
|
function ThumbsDownIcon({ isSelected }) {
|
|
12
|
-
return (react_1.default.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' }, isSelected ? (react_1.default.createElement("path", { d: 'M12.6665 9.33334H15.3332V1.33334H12.6665V9.33334ZM9.99984 1.33334C10.7332 1.33334 11.3332 1.93334 11.3332 2.66668V9.33334C11.3332 9.70001 11.1865 10.0333 10.9465 10.2733L6.55317 14.6667L5.8465 13.9667C5.6665 13.7867 5.55317 13.5333 5.55317 13.26L5.57317 13.0467L6.2065 10H1.99984C1.2665 10 0.666504 9.40001 0.666504 8.66668V7.33334C0.666504 7.16001 0.699837 7.00001 0.759837 6.84668L2.77317 2.14668C2.97317 1.66668 3.4465 1.33334 3.99984 1.33334H9.99984Z', fill: '#F44336', fillOpacity: '1' })) : (react_1.default.createElement("path", { d: 'M9.99984 1.33334H3.99984C3.4465 1.33334 2.97317 1.66668 2.77317 2.14668L0.759837 6.84668C0.699837 7.00001 0.666504 7.16001 0.666504 7.33334V8.66668C0.666504 9.40001 1.2665 10 1.99984 10H6.2065L5.57317 13.0467L5.55317 13.26C5.55317 13.5333 5.6665 13.7867 5.8465 13.9667L6.55317 14.6667L10.9465 10.2733C11.1865 10.0333 11.3332 9.70001 11.3332 9.33334V2.66668C11.3332 1.93334 10.7332 1.33334 9.99984 1.33334ZM9.99984 9.33334L7.1065 12.2267L7.99984 8.66668H1.99984V7.33334L3.99984 2.66668H9.99984V9.33334ZM12.6665 1.33334H15.3332V9.33334H12.6665V1.33334Z', fill: '#0F1324', fillOpacity: '0.6' }))));
|
|
12
|
+
return (react_1.default.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-hidden": 'true', focusable: 'false' }, isSelected ? (react_1.default.createElement("path", { d: 'M12.6665 9.33334H15.3332V1.33334H12.6665V9.33334ZM9.99984 1.33334C10.7332 1.33334 11.3332 1.93334 11.3332 2.66668V9.33334C11.3332 9.70001 11.1865 10.0333 10.9465 10.2733L6.55317 14.6667L5.8465 13.9667C5.6665 13.7867 5.55317 13.5333 5.55317 13.26L5.57317 13.0467L6.2065 10H1.99984C1.2665 10 0.666504 9.40001 0.666504 8.66668V7.33334C0.666504 7.16001 0.699837 7.00001 0.759837 6.84668L2.77317 2.14668C2.97317 1.66668 3.4465 1.33334 3.99984 1.33334H9.99984Z', fill: '#F44336', fillOpacity: '1' })) : (react_1.default.createElement("path", { d: 'M9.99984 1.33334H3.99984C3.4465 1.33334 2.97317 1.66668 2.77317 2.14668L0.759837 6.84668C0.699837 7.00001 0.666504 7.16001 0.666504 7.33334V8.66668C0.666504 9.40001 1.2665 10 1.99984 10H6.2065L5.57317 13.0467L5.55317 13.26C5.55317 13.5333 5.6665 13.7867 5.8465 13.9667L6.55317 14.6667L10.9465 10.2733C11.1865 10.0333 11.3332 9.70001 11.3332 9.33334V2.66668C11.3332 1.93334 10.7332 1.33334 9.99984 1.33334ZM9.99984 9.33334L7.1065 12.2267L7.99984 8.66668H1.99984V7.33334L3.99984 2.66668H9.99984V9.33334ZM12.6665 1.33334H15.3332V9.33334H12.6665V1.33334Z', fill: '#0F1324', fillOpacity: '0.6' }))));
|
|
13
13
|
}
|
|
14
14
|
function Feedback({ translations, onFeedback, componentOverride }) {
|
|
15
15
|
const [feedback, setFeedback] = (0, react_1.useState)(null);
|
|
@@ -20,9 +20,9 @@ function Feedback({ translations, onFeedback, componentOverride }) {
|
|
|
20
20
|
return (react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: { translations, onFeedback }, override: componentOverride === null || componentOverride === void 0 ? void 0 : componentOverride.reactNode },
|
|
21
21
|
react_1.default.createElement("div", { className: 'cio-pia-feedback-container' },
|
|
22
22
|
react_1.default.createElement("p", { className: 'cio-pia-feedback-text' }, (0, translate_1.translate)('Is this answer useful?', translations)),
|
|
23
|
-
react_1.default.createElement("button", { type: 'button', className: 'cio-pia-feedback-button', "aria-label": 'thumbs up', onClick: () => handleFeedback(types_1.FeedbackType.UP) },
|
|
23
|
+
react_1.default.createElement("button", { type: 'button', className: 'cio-pia-feedback-button', "aria-label": (0, translate_1.translate)('thumbs up', translations), "aria-pressed": feedback === types_1.FeedbackType.UP, onClick: () => handleFeedback(types_1.FeedbackType.UP) },
|
|
24
24
|
react_1.default.createElement(ThumbsUpIcon, { isSelected: feedback === types_1.FeedbackType.UP })),
|
|
25
|
-
react_1.default.createElement("button", { type: 'button', className: 'cio-pia-feedback-button', "aria-label": 'thumbs down', onClick: () => handleFeedback(types_1.FeedbackType.DOWN) },
|
|
25
|
+
react_1.default.createElement("button", { type: 'button', className: 'cio-pia-feedback-button', "aria-label": (0, translate_1.translate)('thumbs down', translations), "aria-pressed": feedback === types_1.FeedbackType.DOWN, onClick: () => handleFeedback(types_1.FeedbackType.DOWN) },
|
|
26
26
|
react_1.default.createElement(ThumbsDownIcon, { isSelected: feedback === types_1.FeedbackType.DOWN })))));
|
|
27
27
|
}
|
|
28
28
|
exports.default = Feedback;
|
|
@@ -45,6 +45,7 @@ function Input({ value: providedValue, placeholder, disabled = false, onSubmit,
|
|
|
45
45
|
const resolvedPlaceholder = (translations === null || translations === void 0 ? void 0 : translations[placeholderKey]) !== undefined
|
|
46
46
|
? (0, translate_1.translate)(placeholderKey, translations)
|
|
47
47
|
: (placeholder !== null && placeholder !== void 0 ? placeholder : (0, translate_1.translate)(placeholderKey));
|
|
48
|
+
const accessibleName = resolvedPlaceholder || (0, translate_1.translate)('Your question', translations);
|
|
48
49
|
return (react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: {
|
|
49
50
|
disabled,
|
|
50
51
|
placeholder: resolvedPlaceholder,
|
|
@@ -55,7 +56,7 @@ function Input({ value: providedValue, placeholder, disabled = false, onSubmit,
|
|
|
55
56
|
}, override: componentOverride === null || componentOverride === void 0 ? void 0 : componentOverride.reactNode },
|
|
56
57
|
react_1.default.createElement(react_1.default.Fragment, null,
|
|
57
58
|
react_1.default.createElement("div", { className: 'cio-pia-input-container' },
|
|
58
|
-
react_1.default.createElement("input", { type: 'text', value: value, onChange: (e) => setValue(e.target.value), onKeyDown: handleSubmitOnEnter, onFocus: onFocus, placeholder: resolvedPlaceholder, disabled: disabled, className: (0, classNames_1.cx)('cio-pia-input', error && 'cio-pia-input--error', !showSendButton && 'cio-pia-input--no-send'), "aria-invalid": error ? true : undefined, "aria-describedby": error ? errorId : undefined }),
|
|
59
|
+
react_1.default.createElement("input", { type: 'text', value: value, onChange: (e) => setValue(e.target.value), onKeyDown: handleSubmitOnEnter, onFocus: onFocus, placeholder: resolvedPlaceholder, "aria-label": accessibleName, disabled: disabled, className: (0, classNames_1.cx)('cio-pia-input', error && 'cio-pia-input--error', !showSendButton && 'cio-pia-input--no-send'), "aria-invalid": error ? true : undefined, "aria-describedby": error ? errorId : undefined }),
|
|
59
60
|
showSendButton && (react_1.default.createElement("button", { type: 'button', onClick: () => handleSubmit(value), className: 'cio-pia-send-button', disabled: disabled },
|
|
60
61
|
(0, translate_1.translate)('Send', translations),
|
|
61
62
|
react_1.default.createElement(icons_1.SendIcon, null)))),
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
5
|
const constructorio_ui_components_1 = require("@constructor-io/constructorio-ui-components");
|
|
6
|
-
|
|
6
|
+
// Decorative: loading is announced by the always-mounted status region.
|
|
7
|
+
const skeleton = (react_1.default.createElement("div", { className: 'cio-pia-loading-skeleton', "data-testid": 'loading-skeleton', "aria-hidden": 'true' },
|
|
7
8
|
react_1.default.createElement("div", { className: 'skeleton-bar' }),
|
|
8
9
|
react_1.default.createElement("div", { className: 'skeleton-bar' }),
|
|
9
10
|
react_1.default.createElement("div", { className: 'skeleton-bar skeleton-short' })));
|
|
@@ -7,13 +7,17 @@ const translate_1 = require("../../utils/translate");
|
|
|
7
7
|
const SuggestedQuestionsContainer_1 = tslib_1.__importDefault(require("../SuggestedQuestionsContainer/SuggestedQuestionsContainer"));
|
|
8
8
|
const OVERFLOW_HIDDEN_CLASS = 'cio-pia-modal-open';
|
|
9
9
|
function CloseIcon() {
|
|
10
|
-
return (react_1.default.createElement("svg", { width: '20', height: '20', viewBox: '0 0 20 20', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
10
|
+
return (react_1.default.createElement("svg", { width: '20', height: '20', viewBox: '0 0 20 20', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-hidden": 'true', focusable: 'false' },
|
|
11
11
|
react_1.default.createElement("path", { d: 'M15.8334 5.34166L14.6584 4.16666L10.0001 8.82499L5.34175 4.16666L4.16675 5.34166L8.82508 9.99999L4.16675 14.6583L5.34175 15.8333L10.0001 11.175L14.6584 15.8333L15.8334 14.6583L11.1751 9.99999L15.8334 5.34166Z', fill: 'currentColor' })));
|
|
12
12
|
}
|
|
13
13
|
function PiaModal({ initialQuestions, handleSubmitQuestion, handleQuestionClick, containerRef, isLoading, componentOverrides, translations, onInputFocus, onClose, children, }) {
|
|
14
14
|
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
15
15
|
const dialogRef = (0, react_1.useRef)(null);
|
|
16
|
+
const triggerRef = (0, react_1.useRef)(null);
|
|
16
17
|
const openModal = (0, react_1.useCallback)(() => {
|
|
18
|
+
const active = document.activeElement;
|
|
19
|
+
const isRealTrigger = !!active && active !== document.body && active !== document.documentElement;
|
|
20
|
+
triggerRef.current = isRealTrigger ? active : null;
|
|
17
21
|
setIsOpen(true);
|
|
18
22
|
}, []);
|
|
19
23
|
const closeModal = (0, react_1.useCallback)(() => {
|
|
@@ -28,14 +32,28 @@ function PiaModal({ initialQuestions, handleSubmitQuestion, handleQuestionClick,
|
|
|
28
32
|
dialog.showModal();
|
|
29
33
|
document.body.classList.add(OVERFLOW_HIDDEN_CLASS);
|
|
30
34
|
}
|
|
31
|
-
else
|
|
32
|
-
dialog.
|
|
35
|
+
else {
|
|
36
|
+
if (dialog.open)
|
|
37
|
+
dialog.close();
|
|
33
38
|
document.body.classList.remove(OVERFLOW_HIDDEN_CLASS);
|
|
34
39
|
}
|
|
35
40
|
return () => {
|
|
36
41
|
document.body.classList.remove(OVERFLOW_HIDDEN_CLASS);
|
|
37
42
|
};
|
|
38
43
|
}, [isOpen]);
|
|
44
|
+
// Restore focus to the trigger. Re-runs on `isLoading`: the input trigger is
|
|
45
|
+
// disabled while a request is in flight and `focus()` would no-op.
|
|
46
|
+
(0, react_1.useEffect)(() => {
|
|
47
|
+
if (isOpen)
|
|
48
|
+
return;
|
|
49
|
+
const trigger = triggerRef.current;
|
|
50
|
+
if (!trigger || !trigger.isConnected)
|
|
51
|
+
return;
|
|
52
|
+
if (trigger.disabled)
|
|
53
|
+
return;
|
|
54
|
+
trigger.focus();
|
|
55
|
+
triggerRef.current = null;
|
|
56
|
+
}, [isOpen, isLoading]);
|
|
39
57
|
(0, react_1.useEffect)(() => {
|
|
40
58
|
const dialog = dialogRef.current;
|
|
41
59
|
if (!dialog)
|
|
@@ -72,7 +90,7 @@ function PiaModal({ initialQuestions, handleSubmitQuestion, handleQuestionClick,
|
|
|
72
90
|
react_1.default.createElement("div", { className: 'cio-pia-modal-content' },
|
|
73
91
|
react_1.default.createElement("div", { className: 'cio-pia-modal-header' },
|
|
74
92
|
react_1.default.createElement("p", { className: 'cio-pia-title', id: 'cio-pia-modal-title' }, (0, translate_1.translate)('Ask about this product', translations)),
|
|
75
|
-
react_1.default.createElement("button", { type: 'button', className: 'cio-pia-modal-close-button', "aria-label": 'Close', onClick: closeModal },
|
|
93
|
+
react_1.default.createElement("button", { type: 'button', className: 'cio-pia-modal-close-button', "aria-label": (0, translate_1.translate)('Close', translations), onClick: closeModal },
|
|
76
94
|
react_1.default.createElement(CloseIcon, null))),
|
|
77
95
|
react_1.default.createElement("div", { className: 'cio-pia-modal-body' }, children)))));
|
|
78
96
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.answerStatusMessage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const translate_1 = require("../../utils/translate");
|
|
7
|
+
// Inline so it stays hidden for consumers who do not load the stylesheet.
|
|
8
|
+
const SR_ONLY_STYLE = {
|
|
9
|
+
position: 'absolute',
|
|
10
|
+
width: 1,
|
|
11
|
+
height: 1,
|
|
12
|
+
padding: 0,
|
|
13
|
+
margin: -1,
|
|
14
|
+
overflow: 'hidden',
|
|
15
|
+
clip: 'rect(0, 0, 0, 0)',
|
|
16
|
+
whiteSpace: 'nowrap',
|
|
17
|
+
border: 0,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Visually hidden `role='status'`. Keep it mounted and change only `message`:
|
|
21
|
+
* a live region created together with its text is announced inconsistently.
|
|
22
|
+
*/
|
|
23
|
+
function StatusRegion({ message, 'data-testid': testId }) {
|
|
24
|
+
return (react_1.default.createElement("div", { className: 'cio-pia-sr-only', style: SR_ONLY_STYLE, role: 'status', "data-testid": testId }, message));
|
|
25
|
+
}
|
|
26
|
+
exports.default = StatusRegion;
|
|
27
|
+
function answerStatusMessage(isLoading, hasAnswer, translations) {
|
|
28
|
+
if (isLoading)
|
|
29
|
+
return (0, translate_1.translate)('Loading answer', translations);
|
|
30
|
+
if (hasAnswer)
|
|
31
|
+
return (0, translate_1.translate)('Answer ready', translations);
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
exports.answerStatusMessage = answerStatusMessage;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
5
|
function SuggestedQuestionsSkeleton() {
|
|
6
|
-
return (react_1.default.createElement("div", { className: 'cio-pia-suggested-questions-container', "data-testid": 'suggested-questions-skeleton', "aria-
|
|
6
|
+
return (react_1.default.createElement("div", { className: 'cio-pia-suggested-questions-container', "data-testid": 'suggested-questions-skeleton', "aria-hidden": 'true' },
|
|
7
7
|
react_1.default.createElement("div", { className: 'cio-pia-suggested-question-skeleton' }),
|
|
8
8
|
react_1.default.createElement("div", { className: 'cio-pia-suggested-question-skeleton' }),
|
|
9
9
|
react_1.default.createElement("div", { className: 'cio-pia-suggested-question-skeleton' })));
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
5
|
function QuestionIcon() {
|
|
6
|
-
return (react_1.default.createElement("svg", { "aria-hidden": 'true', width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
6
|
+
return (react_1.default.createElement("svg", { "aria-hidden": 'true', focusable: 'false', width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
7
7
|
react_1.default.createElement("path", { d: 'M8.00004 1.33331C4.32004 1.33331 1.33337 4.31998 1.33337 7.99998C1.33337 11.68 4.32004 14.6666 8.00004 14.6666C11.68 14.6666 14.6667 11.68 14.6667 7.99998C14.6667 4.31998 11.68 1.33331 8.00004 1.33331ZM8.66671 12.6666H7.33337V11.3333H8.66671V12.6666ZM10.0467 7.49998L9.44671 8.11331C8.96671 8.59998 8.66671 8.99998 8.66671 9.99998H7.33337V9.66665C7.33337 8.93331 7.63337 8.26665 8.11337 7.77998L8.94004 6.93998C9.18671 6.69998 9.33337 6.36665 9.33337 5.99998C9.33337 5.26665 8.73337 4.66665 8.00004 4.66665C7.26671 4.66665 6.66671 5.26665 6.66671 5.99998H5.33337C5.33337 4.52665 6.52671 3.33331 8.00004 3.33331C9.47337 3.33331 10.6667 4.52665 10.6667 5.99998C10.6667 6.58665 10.4267 7.11998 10.0467 7.49998Z', fill: '#0F1324', fillOpacity: '0.6' })));
|
|
8
8
|
}
|
|
9
9
|
exports.default = QuestionIcon;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
5
|
function SendIcon() {
|
|
6
|
-
return (react_1.default.createElement("svg", { "aria-hidden": 'true', width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
6
|
+
return (react_1.default.createElement("svg", { "aria-hidden": 'true', focusable: 'false', width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
7
7
|
react_1.default.createElement("path", { d: 'M14.8934 7.09533L14.8884 7.09314L1.54219 1.55752C1.42993 1.51053 1.30778 1.49211 1.18666 1.50388C1.06554 1.51566 0.949225 1.55728 0.848125 1.62502C0.741311 1.69501 0.653573 1.79045 0.592805 1.90277C0.532037 2.01509 0.500145 2.14075 0.5 2.26845V5.80877C0.50006 5.98335 0.561019 6.15243 0.67237 6.28689C0.783722 6.42134 0.938491 6.51274 1.11 6.54533L8.38906 7.89127C8.41767 7.89669 8.44348 7.91193 8.46205 7.93435C8.48062 7.95677 8.49078 7.98497 8.49078 8.01408C8.49078 8.04319 8.48062 8.07139 8.46205 8.09381C8.44348 8.11623 8.41767 8.13147 8.38906 8.13689L1.11031 9.48283C0.938851 9.51533 0.784092 9.60661 0.67269 9.74094C0.561288 9.87528 0.500219 10.0443 0.5 10.2188V13.7597C0.499917 13.8816 0.530111 14.0017 0.587871 14.1091C0.645632 14.2165 0.729152 14.3079 0.830938 14.375C0.953375 14.4564 1.09706 14.4998 1.24406 14.5C1.34626 14.4999 1.4474 14.4794 1.54156 14.4397L14.8875 8.93564L14.8934 8.93283C15.0731 8.85563 15.2262 8.72745 15.3337 8.56415C15.4413 8.40086 15.4986 8.20961 15.4986 8.01408C15.4986 7.81855 15.4413 7.6273 15.3337 7.46401C15.2262 7.30071 15.0731 7.17253 14.8934 7.09533Z', fill: 'white' })));
|
|
8
8
|
}
|
|
9
9
|
exports.default = SendIcon;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
5
|
function SparklesIcon() {
|
|
6
|
-
return (react_1.default.createElement("svg", { "aria-hidden": 'true', width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
6
|
+
return (react_1.default.createElement("svg", { "aria-hidden": 'true', focusable: 'false', width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
7
7
|
react_1.default.createElement("path", { d: 'M12.6667 6.0013L13.5001 4.16797L15.3334 3.33464L13.5001 2.5013L12.6667 0.667969L11.8334 2.5013L10.0001 3.33464L11.8334 4.16797L12.6667 6.0013Z', fill: '#1C1917' }),
|
|
8
8
|
react_1.default.createElement("path", { d: 'M12.6667 10.0013L11.8334 11.8346L10.0001 12.668L11.8334 13.5013L12.6667 15.3346L13.5001 13.5013L15.3334 12.668L13.5001 11.8346L12.6667 10.0013Z', fill: '#1C1917' }),
|
|
9
9
|
react_1.default.createElement("path", { d: 'M7.66675 6.33464L6.00008 2.66797L4.33341 6.33464L0.666748 8.0013L4.33341 9.66797L6.00008 13.3346L7.66675 9.66797L11.3334 8.0013L7.66675 6.33464ZM6.66008 8.6613L6.00008 10.1146L5.34008 8.6613L3.88675 8.0013L5.34008 7.3413L6.00008 5.88797L6.66008 7.3413L8.11341 8.0013L6.66008 8.6613Z', fill: '#1C1917' })));
|
|
@@ -6,14 +6,21 @@ function useAnswerResults({ itemId, variationId, threadId, cioClient, parameters
|
|
|
6
6
|
const [answerResults, setAnswerResults] = (0, react_1.useState)(null);
|
|
7
7
|
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
8
8
|
const [error, setError] = (0, react_1.useState)(null);
|
|
9
|
+
const serializedParameters = (0, react_1.useMemo)(() => JSON.stringify(parameters), [parameters]);
|
|
9
10
|
const items = (0, react_1.useMemo)(() => (0, transformers_1.extractAndTransformItems)(answerResults, formatImageUrl), [answerResults, formatImageUrl]);
|
|
11
|
+
// A host that rebuilds the client on render must not change getAnswer's identity.
|
|
12
|
+
const cioClientRef = (0, react_1.useRef)(cioClient);
|
|
13
|
+
(0, react_1.useEffect)(() => {
|
|
14
|
+
cioClientRef.current = cioClient;
|
|
15
|
+
}, [cioClient]);
|
|
10
16
|
const fetchResult = (0, react_1.useCallback)((question) => {
|
|
11
|
-
|
|
17
|
+
const client = cioClientRef.current;
|
|
18
|
+
if (!client)
|
|
12
19
|
return;
|
|
13
20
|
setIsLoading(true);
|
|
14
21
|
setError(null);
|
|
15
22
|
setAnswerResults(null);
|
|
16
|
-
|
|
23
|
+
client.agent.pia
|
|
17
24
|
.getAnswerResults(itemId, question, Object.assign({ threadId, variationId }, parameters))
|
|
18
25
|
.then((response) => {
|
|
19
26
|
setAnswerResults(response);
|
|
@@ -26,7 +33,9 @@ function useAnswerResults({ itemId, variationId, threadId, cioClient, parameters
|
|
|
26
33
|
.finally(() => {
|
|
27
34
|
setIsLoading(false);
|
|
28
35
|
});
|
|
29
|
-
},
|
|
36
|
+
},
|
|
37
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
+
[itemId, variationId, threadId, serializedParameters]);
|
|
30
39
|
return {
|
|
31
40
|
data: answerResults,
|
|
32
41
|
items,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
4
|
function useConversation({ pia, itemId, isConversation, callbacks, tracking, }) {
|
|
5
|
-
var _a, _b, _c
|
|
5
|
+
var _a, _b, _c;
|
|
6
6
|
const { suggestedQuestions, answers, threadId } = pia;
|
|
7
7
|
const { getAnswer } = answers;
|
|
8
8
|
const context = (0, react_1.useMemo)(() => ({ itemId, threadId }), [itemId, threadId]);
|
|
@@ -10,7 +10,7 @@ function useConversation({ pia, itemId, isConversation, callbacks, tracking, })
|
|
|
10
10
|
const [displayedQuestions, setDisplayedQuestions] = (0, react_1.useState)([]);
|
|
11
11
|
const [conversationHistory, setConversationHistory] = (0, react_1.useState)([]);
|
|
12
12
|
const entryIdRef = (0, react_1.useRef)(0);
|
|
13
|
-
const
|
|
13
|
+
const prevAnswerDataRef = (0, react_1.useRef)(answers.data);
|
|
14
14
|
const hasTrackedCurrentAnswerRef = (0, react_1.useRef)(false);
|
|
15
15
|
const answersRef = (0, react_1.useRef)(answers);
|
|
16
16
|
const callbacksRef = (0, react_1.useRef)(callbacks);
|
|
@@ -18,6 +18,9 @@ function useConversation({ pia, itemId, isConversation, callbacks, tracking, })
|
|
|
18
18
|
const trackingRef = (0, react_1.useRef)(tracking);
|
|
19
19
|
const lastQuestionRef = (0, react_1.useRef)('');
|
|
20
20
|
const lastSourceRef = (0, react_1.useRef)('user');
|
|
21
|
+
// Set once an answer owns the question row, so a later suggested-questions
|
|
22
|
+
// response cannot take it back.
|
|
23
|
+
const showsFollowUpsRef = (0, react_1.useRef)(false);
|
|
21
24
|
(0, react_1.useEffect)(() => {
|
|
22
25
|
callbacksRef.current = callbacks;
|
|
23
26
|
}, [callbacks]);
|
|
@@ -68,21 +71,30 @@ function useConversation({ pia, itemId, isConversation, callbacks, tracking, })
|
|
|
68
71
|
setCurrentQuestion('');
|
|
69
72
|
setDisplayedQuestions(suggestedQuestions.data);
|
|
70
73
|
setConversationHistory([]);
|
|
71
|
-
|
|
74
|
+
prevAnswerDataRef.current = null;
|
|
75
|
+
showsFollowUpsRef.current = false;
|
|
72
76
|
}, [suggestedQuestions.data]);
|
|
73
77
|
(0, react_1.useEffect)(() => {
|
|
74
78
|
setCurrentQuestion('');
|
|
75
79
|
setDisplayedQuestions([]);
|
|
76
80
|
setConversationHistory([]);
|
|
77
|
-
|
|
81
|
+
prevAnswerDataRef.current = null;
|
|
82
|
+
showsFollowUpsRef.current = false;
|
|
78
83
|
}, [itemId]);
|
|
79
84
|
(0, react_1.useEffect)(() => {
|
|
85
|
+
// The ref, not `answers.data`, which outlives the item it answered.
|
|
86
|
+
if (showsFollowUpsRef.current)
|
|
87
|
+
return;
|
|
80
88
|
setDisplayedQuestions(suggestedQuestions.data);
|
|
81
89
|
}, [suggestedQuestions.data]);
|
|
82
90
|
(0, react_1.useEffect)(() => {
|
|
83
91
|
var _a, _b;
|
|
84
|
-
if (
|
|
85
|
-
|
|
92
|
+
if (answers.data) {
|
|
93
|
+
// An answer with no follow-ups empties the row: the pre-generated questions
|
|
94
|
+
// include the one just asked.
|
|
95
|
+
setDisplayedQuestions((_a = answers.data.follow_up_questions) !== null && _a !== void 0 ? _a : []);
|
|
96
|
+
showsFollowUpsRef.current = true;
|
|
97
|
+
}
|
|
86
98
|
if (answers.data && lastQuestionRef.current && !hasTrackedCurrentAnswerRef.current) {
|
|
87
99
|
hasTrackedCurrentAnswerRef.current = true;
|
|
88
100
|
(_b = trackingRef.current) === null || _b === void 0 ? void 0 : _b.trackAnswerView(lastQuestionRef.current, answers.data, answers.items);
|
|
@@ -93,9 +105,11 @@ function useConversation({ pia, itemId, isConversation, callbacks, tracking, })
|
|
|
93
105
|
const answerValue = (_b = (_a = answers.data) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
|
|
94
106
|
if (!answerValue)
|
|
95
107
|
return;
|
|
96
|
-
|
|
108
|
+
// Compare by response object, not by text: two consecutive answers with
|
|
109
|
+
// identical text are still two answers and both must reach the history.
|
|
110
|
+
if (answers.data === prevAnswerDataRef.current)
|
|
97
111
|
return;
|
|
98
|
-
|
|
112
|
+
prevAnswerDataRef.current = answers.data;
|
|
99
113
|
const answerThreadId = (_c = answers.data) === null || _c === void 0 ? void 0 : _c.thread_id;
|
|
100
114
|
const qnaResultId = (_d = answers.data) === null || _d === void 0 ? void 0 : _d.qna_result_id;
|
|
101
115
|
if (isConversation) {
|
|
@@ -122,8 +136,8 @@ function useConversation({ pia, itemId, isConversation, callbacks, tracking, })
|
|
|
122
136
|
(_f = (_e = callbacksRef.current) === null || _e === void 0 ? void 0 : _e.onAnswer) === null || _f === void 0 ? void 0 : _f.call(_e, [entry], contextRef.current);
|
|
123
137
|
}
|
|
124
138
|
}, [isConversation, answers.data, answers.items]);
|
|
125
|
-
const currentAnswer = (
|
|
126
|
-
const currentItems = (
|
|
139
|
+
const currentAnswer = (_b = (_a = answers.data) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
|
|
140
|
+
const currentItems = (_c = answers.items) !== null && _c !== void 0 ? _c : null;
|
|
127
141
|
const error = answers.error || suggestedQuestions.error;
|
|
128
142
|
const isLoading = answers.isLoading || suggestedQuestions.isLoading;
|
|
129
143
|
return {
|
|
@@ -30,15 +30,23 @@ function useRecsPod({ itemId, variationId, threadId, cioClient, parameters, form
|
|
|
30
30
|
(0, react_1.useEffect)(() => {
|
|
31
31
|
formatImageUrlRef.current = formatImageUrl;
|
|
32
32
|
}, [formatImageUrl]);
|
|
33
|
+
// A host that rebuilds the client on render must not restart the request.
|
|
34
|
+
const cioClientRef = (0, react_1.useRef)(cioClient);
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
36
|
+
cioClientRef.current = cioClient;
|
|
37
|
+
}, [cioClient]);
|
|
38
|
+
// A client arriving where there was none still warrants a fetch.
|
|
39
|
+
const hasClient = !!cioClient;
|
|
33
40
|
const strategy = (parameters === null || parameters === void 0 ? void 0 : parameters.strategy) || DEFAULT_STRATEGY;
|
|
34
41
|
const { numResults, defaultTitle } = parameters || {};
|
|
35
42
|
const fetchResult = (0, react_1.useCallback)((shopperInput, source) => {
|
|
36
43
|
var _a;
|
|
37
44
|
// TODO: once getRecs is added to the JS client SDK, replace this guard+cast
|
|
38
45
|
// with a direct call: cioClient.agent.getRecs({...})
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
const client = cioClientRef.current;
|
|
47
|
+
const getRecs = (_a = client === null || client === void 0 ? void 0 : client.agent) === null || _a === void 0 ? void 0 : _a.getRecs;
|
|
48
|
+
if (!client || !getRecs) {
|
|
49
|
+
if (client && !getRecs) {
|
|
42
50
|
console.info('[CioPia] getRecs is not available on the client SDK yet.');
|
|
43
51
|
}
|
|
44
52
|
setIsLoading(false);
|
|
@@ -51,7 +59,7 @@ function useRecsPod({ itemId, variationId, threadId, cioClient, parameters, form
|
|
|
51
59
|
setError(null);
|
|
52
60
|
setHasUnsupportedInput(false);
|
|
53
61
|
getRecs
|
|
54
|
-
.call(
|
|
62
|
+
.call(client.agent, {
|
|
55
63
|
itemId,
|
|
56
64
|
variationId,
|
|
57
65
|
threadId,
|
|
@@ -91,9 +99,9 @@ function useRecsPod({ itemId, variationId, threadId, cioClient, parameters, form
|
|
|
91
99
|
setIsLoading(false);
|
|
92
100
|
});
|
|
93
101
|
},
|
|
94
|
-
// Every dependency is a primitive
|
|
95
|
-
//
|
|
96
|
-
[
|
|
102
|
+
// Every dependency is a primitive; `formatImageUrl` and the client are read through refs.
|
|
103
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
104
|
+
[hasClient, itemId, variationId, threadId, strategy, numResults]);
|
|
97
105
|
(0, react_1.useEffect)(() => {
|
|
98
106
|
fetchResult();
|
|
99
107
|
}, [fetchResult]);
|
|
@@ -6,12 +6,21 @@ function useSuggestedQuestions({ itemId, variationId, threadId, cioClient, param
|
|
|
6
6
|
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
7
7
|
const [error, setError] = (0, react_1.useState)(null);
|
|
8
8
|
const serializedParameters = (0, react_1.useMemo)(() => JSON.stringify(parameters), [parameters]);
|
|
9
|
+
// The client is how the question is asked, not part of the question: a host that
|
|
10
|
+
// rebuilds it on render must not make the widget ask the same thing again.
|
|
11
|
+
const cioClientRef = (0, react_1.useRef)(cioClient);
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
cioClientRef.current = cioClient;
|
|
14
|
+
}, [cioClient]);
|
|
15
|
+
// A client arriving where there was none is the one client change worth a fetch.
|
|
16
|
+
const hasClient = !!cioClient;
|
|
9
17
|
const fetchResult = (0, react_1.useCallback)(() => {
|
|
10
|
-
|
|
18
|
+
const client = cioClientRef.current;
|
|
19
|
+
if (!client)
|
|
11
20
|
return;
|
|
12
21
|
setIsLoading(true);
|
|
13
22
|
setError(null);
|
|
14
|
-
|
|
23
|
+
client.agent.pia
|
|
15
24
|
.getSuggestedQuestions(itemId, Object.assign({ threadId,
|
|
16
25
|
variationId }, parameters))
|
|
17
26
|
.then((response) => {
|
|
@@ -26,7 +35,7 @@ function useSuggestedQuestions({ itemId, variationId, threadId, cioClient, param
|
|
|
26
35
|
});
|
|
27
36
|
// parameters is serialized via serializedParameters to prevent refetch on identity changes
|
|
28
37
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
-
}, [
|
|
38
|
+
}, [hasClient, itemId, variationId, threadId, serializedParameters]);
|
|
30
39
|
(0, react_1.useEffect)(() => {
|
|
31
40
|
fetchResult();
|
|
32
41
|
}, [fetchResult]);
|
|
@@ -5,12 +5,21 @@ const constants_1 = require("../constants");
|
|
|
5
5
|
const defaultTranslations = {
|
|
6
6
|
'Any questions about this product?': 'Any questions about this product?',
|
|
7
7
|
'Ask anything': 'Ask anything',
|
|
8
|
+
'Your question': 'Your question',
|
|
8
9
|
Send: 'Send',
|
|
9
10
|
[constants_1.DISCLAIMER_TEXT]: constants_1.DISCLAIMER_TEXT,
|
|
10
11
|
'Is this answer useful?': 'Is this answer useful?',
|
|
11
12
|
'Learn More.': 'Learn More.',
|
|
12
13
|
'Ask about this product': 'Ask about this product',
|
|
13
14
|
'Add to Cart': 'Add to Cart',
|
|
15
|
+
'Unexpected error': 'Unexpected error',
|
|
16
|
+
'thumbs up': 'thumbs up',
|
|
17
|
+
'thumbs down': 'thumbs down',
|
|
18
|
+
Close: 'Close',
|
|
19
|
+
Retry: 'Retry',
|
|
20
|
+
'Conversation history': 'Conversation history',
|
|
21
|
+
'Loading answer': 'Loading answer',
|
|
22
|
+
'Answer ready': 'Answer ready',
|
|
14
23
|
[constants_1.RECS_LOADING_TITLE]: constants_1.RECS_LOADING_TITLE,
|
|
15
24
|
[constants_1.RECS_FALLBACK_TITLE]: constants_1.RECS_FALLBACK_TITLE,
|
|
16
25
|
[constants_1.RECS_UNSUPPORTED_REQUEST]: constants_1.RECS_UNSUPPORTED_REQUEST,
|
|
@@ -21,6 +30,9 @@ const defaultTranslations = {
|
|
|
21
30
|
* Translates a word using the provided translations object.
|
|
22
31
|
* Falls back to English defaults if translation is not provided.
|
|
23
32
|
*
|
|
33
|
+
* An explicitly empty string is returned as-is: blanking out a string is how
|
|
34
|
+
* consumers hide it.
|
|
35
|
+
*
|
|
24
36
|
* @param word - The key to translate
|
|
25
37
|
* @param translations - Optional user-provided translations object
|
|
26
38
|
* @returns The translated string or the original word if no translation exists
|