@constructor-io/constructorio-ui-pia 2.3.0 → 2.4.0

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.
@@ -3,11 +3,12 @@ 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
+ const contentTransformers_1 = require("../../utils/contentTransformers");
6
7
  function Answer({ text, componentOverride }) {
7
8
  if (!text) {
8
9
  return null;
9
10
  }
10
11
  return (react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: { text }, override: componentOverride === null || componentOverride === void 0 ? void 0 : componentOverride.reactNode },
11
- react_1.default.createElement("div", { className: 'cio-pia-answer', "data-testid": 'answer-text' }, text)));
12
+ react_1.default.createElement("div", { className: 'cio-pia-answer', "data-testid": 'answer-text', dangerouslySetInnerHTML: { __html: (0, contentTransformers_1.renderMarkdown)(text) } })));
12
13
  }
13
14
  exports.default = Answer;
@@ -3,17 +3,14 @@ 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
- const Disclaimer_1 = tslib_1.__importDefault(require("./Disclaimer"));
7
6
  const Input_1 = tslib_1.__importDefault(require("../Input/Input"));
8
7
  const SuggestedQuestionsContainer_1 = tslib_1.__importDefault(require("../SuggestedQuestionsContainer/SuggestedQuestionsContainer"));
9
- const Answer_1 = tslib_1.__importDefault(require("../Answer/Answer"));
10
- const Feedback_1 = tslib_1.__importDefault(require("../Feedback/Feedback"));
11
8
  const useCioPia_1 = tslib_1.__importDefault(require("../../hooks/useCioPia"));
12
9
  const useConversation_1 = tslib_1.__importDefault(require("../../hooks/useConversation"));
13
10
  const ErrorBlock_1 = tslib_1.__importDefault(require("../Error/ErrorBlock"));
14
11
  const LoadingSkeleton_1 = tslib_1.__importDefault(require("../LoadingSkeleton/LoadingSkeleton"));
15
12
  const translate_1 = require("../../utils/translate");
16
- const PiaCustomCarousel_1 = tslib_1.__importDefault(require("./PiaCustomCarousel"));
13
+ const PiaInlineAnswer_1 = tslib_1.__importDefault(require("../PiaInlineAnswer/PiaInlineAnswer"));
17
14
  const PiaModal_1 = tslib_1.__importDefault(require("../PiaConversation/PiaModal"));
18
15
  const PiaConversation_1 = tslib_1.__importDefault(require("../PiaConversation/PiaConversation"));
19
16
  function CioPia(props) {
@@ -61,7 +58,6 @@ function CioPia(props) {
61
58
  }
62
59
  if (isConversation)
63
60
  return react_1.default.createElement(PiaConversation_1.default, Object.assign({}, conversationHistoryProps));
64
- const disclaimer = (react_1.default.createElement(Disclaimer_1.default, { learnMoreUrl: learnMoreUrl, translations: translations, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.disclaimer }));
65
61
  // Default inline mode
66
62
  return (react_1.default.createElement("div", { className: 'cio-pia-container', "data-testid": 'cio-pia-container' },
67
63
  react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: renderProps, override: children || (componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.reactNode) },
@@ -70,12 +66,7 @@ function CioPia(props) {
70
66
  isLoading && react_1.default.createElement(LoadingSkeleton_1.default, null),
71
67
  !isLoading && error && react_1.default.createElement(ErrorBlock_1.default, { message: (error === null || error === void 0 ? void 0 : error.message) || 'Unexpected error' }),
72
68
  !isLoading && !error && (react_1.default.createElement(react_1.default.Fragment, null,
73
- currentAnswer && (react_1.default.createElement("div", { className: 'cio-pia-answer-container' },
74
- disclaimerPosition === 'top' && disclaimer,
75
- react_1.default.createElement(Answer_1.default, { text: currentAnswer, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.answer }),
76
- currentItems && (react_1.default.createElement(PiaCustomCarousel_1.default, { items: currentItems, componentOverrides: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.carousel, callbacks: callbacks })),
77
- showFeedback && (react_1.default.createElement(Feedback_1.default, { translations: translations, onFeedback: callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFeedback, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.feedback })),
78
- disclaimerPosition === 'bottom' && disclaimer)),
69
+ currentAnswer && (react_1.default.createElement(PiaInlineAnswer_1.default, { currentAnswer: currentAnswer, currentItems: currentItems, showFeedback: showFeedback, learnMoreUrl: learnMoreUrl, disclaimerPosition: disclaimerPosition, translations: translations, callbacks: callbacks, componentOverrides: componentOverrides })),
79
70
  react_1.default.createElement(SuggestedQuestionsContainer_1.default, { questions: displayedQuestions, onQuestionClick: handleSubmitQuestion, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.suggestedQuestions }))))));
80
71
  }
81
72
  exports.default = CioPia;
@@ -3,6 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const react_1 = tslib_1.__importStar(require("react"));
5
5
  const constructorio_ui_components_1 = require("@constructor-io/constructorio-ui-components");
6
+ const contentTransformers_1 = require("../../utils/contentTransformers");
7
+ function HtmlDescription({ product }) {
8
+ const { description } = product;
9
+ if (!description)
10
+ return null;
11
+ return (react_1.default.createElement("p", { className: 'cio-product-card-description', dangerouslySetInnerHTML: { __html: (0, contentTransformers_1.sanitizeHtml)(description) } }));
12
+ }
6
13
  function PiaCustomCarousel({ items, componentOverrides, callbacks, }) {
7
14
  const wrapperRef = (0, react_1.useRef)(null);
8
15
  // Determine to use user-defined click handler or default behavior
@@ -31,11 +38,18 @@ function PiaCustomCarousel({ items, componentOverrides, callbacks, }) {
31
38
  el.removeEventListener(constructorio_ui_components_1.CIO_EVENTS.productCard.click, handleClick);
32
39
  };
33
40
  }, [productClickHandler]);
41
+ const mergedOverrides = (0, react_1.useMemo)(() => {
42
+ var _a, _b, _c, _d, _e, _f;
43
+ if ((_c = (_b = (_a = componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.item) === null || _a === void 0 ? void 0 : _a.productCard) === null || _b === void 0 ? void 0 : _b.content) === null || _c === void 0 ? void 0 : _c.description) {
44
+ return componentOverrides;
45
+ }
46
+ return Object.assign(Object.assign({}, componentOverrides), { item: Object.assign(Object.assign({}, componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.item), { productCard: Object.assign(Object.assign({}, (_d = componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.item) === null || _d === void 0 ? void 0 : _d.productCard), { content: Object.assign(Object.assign({}, (_f = (_e = componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.item) === null || _e === void 0 ? void 0 : _e.productCard) === null || _f === void 0 ? void 0 : _f.content), { description: { reactNode: HtmlDescription } }) }) }) });
47
+ }, [componentOverrides]);
34
48
  // If there are no items, do not render the carousel
35
49
  if (items.length === 0) {
36
50
  return null;
37
51
  }
38
52
  return (react_1.default.createElement("div", { ref: wrapperRef },
39
- react_1.default.createElement(constructorio_ui_components_1.Carousel, { items: items, componentOverrides: componentOverrides })));
53
+ react_1.default.createElement(constructorio_ui_components_1.Carousel, { items: items, componentOverrides: mergedOverrides })));
40
54
  }
41
55
  exports.default = PiaCustomCarousel;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const react_1 = tslib_1.__importDefault(require("react"));
5
+ const Answer_1 = tslib_1.__importDefault(require("../Answer/Answer"));
6
+ const Feedback_1 = tslib_1.__importDefault(require("../Feedback/Feedback"));
7
+ const Disclaimer_1 = tslib_1.__importDefault(require("../CioPia/Disclaimer"));
8
+ const PiaCustomCarousel_1 = tslib_1.__importDefault(require("../CioPia/PiaCustomCarousel"));
9
+ function PiaInlineAnswer({ currentAnswer, currentItems, showFeedback, learnMoreUrl, disclaimerPosition = 'bottom', translations, callbacks, componentOverrides, }) {
10
+ const disclaimer = (react_1.default.createElement(Disclaimer_1.default, { learnMoreUrl: learnMoreUrl, translations: translations, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.disclaimer }));
11
+ return (react_1.default.createElement("div", { className: 'cio-pia-answer-container' },
12
+ disclaimerPosition === 'top' && disclaimer,
13
+ react_1.default.createElement(Answer_1.default, { text: currentAnswer, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.answer }),
14
+ currentItems && (react_1.default.createElement(PiaCustomCarousel_1.default, { items: currentItems, componentOverrides: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.carousel, callbacks: callbacks })),
15
+ showFeedback && (react_1.default.createElement(Feedback_1.default, { translations: translations, onFeedback: callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFeedback, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.feedback })),
16
+ disclaimerPosition === 'bottom' && disclaimer));
17
+ }
18
+ exports.default = PiaInlineAnswer;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DISCLAIMER_TEXT = exports.MOCK_QUESTIONS = exports.DEMO_QUESTION_ALTERNATIVE_PRODUCTS = exports.DEMO_QUESTION = exports.DEMO_ITEM_ID = exports.DEMO_API_KEY = void 0;
4
- // eslint-disable-next-line import/prefer-default-export
5
4
  exports.DEMO_API_KEY = 'key_13TO6qN9H3BP3Wrn';
6
5
  exports.DEMO_ITEM_ID = '149100215';
7
6
  exports.DEMO_QUESTION = 'What is the nutritional content of this shake?';
package/lib/cjs/index.js CHANGED
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CioPia = void 0;
3
+ exports.renderMarkdown = exports.sanitizeHtml = exports.CioPia = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const CioPia_1 = tslib_1.__importDefault(require("./components/CioPia"));
6
6
  // Components
7
7
  var CioPia_2 = require("./components/CioPia");
8
8
  Object.defineProperty(exports, "CioPia", { enumerable: true, get: function () { return tslib_1.__importDefault(CioPia_2).default; } });
9
+ // Utilities
10
+ var contentTransformers_1 = require("./utils/contentTransformers");
11
+ Object.defineProperty(exports, "sanitizeHtml", { enumerable: true, get: function () { return contentTransformers_1.sanitizeHtml; } });
12
+ Object.defineProperty(exports, "renderMarkdown", { enumerable: true, get: function () { return contentTransformers_1.renderMarkdown; } });
9
13
  // Default
10
14
  tslib_1.__exportStar(require("./types"), exports);
11
15
  exports.default = CioPia_1.default;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderMarkdown = exports.sanitizeHtml = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const dompurify_1 = tslib_1.__importDefault(require("dompurify"));
6
+ const marked_1 = require("marked");
7
+ const purifyConfig = {
8
+ FORBID_TAGS: ['script', 'style', 'iframe', 'object', 'embed', 'form'],
9
+ };
10
+ function sanitizeHtml(html) {
11
+ if (!html)
12
+ return '';
13
+ return dompurify_1.default.sanitize(html, purifyConfig);
14
+ }
15
+ exports.sanitizeHtml = sanitizeHtml;
16
+ function renderMarkdown(content) {
17
+ if (!content)
18
+ return '';
19
+ const html = marked_1.marked.parse(content, { async: false });
20
+ return dompurify_1.default.sanitize(html, purifyConfig);
21
+ }
22
+ exports.renderMarkdown = renderMarkdown;
@@ -1,4 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderMarkdown = exports.sanitizeHtml = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  tslib_1.__exportStar(require("./styleHelpers"), exports);
6
+ var contentTransformers_1 = require("./contentTransformers");
7
+ Object.defineProperty(exports, "sanitizeHtml", { enumerable: true, get: function () { return contentTransformers_1.sanitizeHtml; } });
8
+ Object.defineProperty(exports, "renderMarkdown", { enumerable: true, get: function () { return contentTransformers_1.renderMarkdown; } });
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPreferredColorScheme = void 0;
4
- // eslint-disable-next-line import/prefer-default-export
5
4
  function getPreferredColorScheme() {
6
5
  var _a;
7
6
  let colorScheme = 'light';
@@ -19,7 +19,6 @@ const defaultTranslations = {
19
19
  * @param translations - Optional user-provided translations object
20
20
  * @returns The translated string or the original word if no translation exists
21
21
  */
22
- // eslint-disable-next-line import/prefer-default-export
23
22
  const translate = (word, translations) => {
24
23
  if (translations && translations[word] !== undefined) {
25
24
  return translations[word];
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '2.3.0';
3
+ exports.default = '2.4.0';
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import { RenderPropsWrapper, } from '@constructor-io/constructorio-ui-components';
3
+ import { renderMarkdown } from '../../utils/contentTransformers';
3
4
  function Answer({ text, componentOverride }) {
4
5
  if (!text) {
5
6
  return null;
6
7
  }
7
8
  return (React.createElement(RenderPropsWrapper, { props: { text }, override: componentOverride?.reactNode },
8
- React.createElement("div", { className: 'cio-pia-answer', "data-testid": 'answer-text' }, text)));
9
+ React.createElement("div", { className: 'cio-pia-answer', "data-testid": 'answer-text', dangerouslySetInnerHTML: { __html: renderMarkdown(text) } })));
9
10
  }
10
11
  export default Answer;
@@ -1,16 +1,13 @@
1
1
  import React from 'react';
2
2
  import { RenderPropsWrapper, } from '@constructor-io/constructorio-ui-components';
3
- import Disclaimer from './Disclaimer';
4
3
  import Input from '../Input/Input';
5
4
  import SuggestedQuestionsContainer from '../SuggestedQuestionsContainer/SuggestedQuestionsContainer';
6
- import Answer from '../Answer/Answer';
7
- import Feedback from '../Feedback/Feedback';
8
5
  import useCioPia from '../../hooks/useCioPia';
9
6
  import useConversation from '../../hooks/useConversation';
10
7
  import ErrorBlock from '../Error/ErrorBlock';
11
8
  import LoadingSkeleton from '../LoadingSkeleton/LoadingSkeleton';
12
9
  import { translate } from '../../utils/translate';
13
- import PiaCustomCarousel from './PiaCustomCarousel';
10
+ import PiaInlineAnswer from '../PiaInlineAnswer/PiaInlineAnswer';
14
11
  import PiaModal from '../PiaConversation/PiaModal';
15
12
  import PiaConversation from '../PiaConversation/PiaConversation';
16
13
  export default function CioPia(props) {
@@ -58,7 +55,6 @@ export default function CioPia(props) {
58
55
  }
59
56
  if (isConversation)
60
57
  return React.createElement(PiaConversation, { ...conversationHistoryProps });
61
- const disclaimer = (React.createElement(Disclaimer, { learnMoreUrl: learnMoreUrl, translations: translations, componentOverride: componentOverrides?.disclaimer }));
62
58
  // Default inline mode
63
59
  return (React.createElement("div", { className: 'cio-pia-container', "data-testid": 'cio-pia-container' },
64
60
  React.createElement(RenderPropsWrapper, { props: renderProps, override: children || componentOverrides?.reactNode },
@@ -67,11 +63,6 @@ export default function CioPia(props) {
67
63
  isLoading && React.createElement(LoadingSkeleton, null),
68
64
  !isLoading && error && React.createElement(ErrorBlock, { message: error?.message || 'Unexpected error' }),
69
65
  !isLoading && !error && (React.createElement(React.Fragment, null,
70
- currentAnswer && (React.createElement("div", { className: 'cio-pia-answer-container' },
71
- disclaimerPosition === 'top' && disclaimer,
72
- React.createElement(Answer, { text: currentAnswer, componentOverride: componentOverrides?.answer }),
73
- currentItems && (React.createElement(PiaCustomCarousel, { items: currentItems, componentOverrides: componentOverrides?.carousel, callbacks: callbacks })),
74
- showFeedback && (React.createElement(Feedback, { translations: translations, onFeedback: callbacks?.onFeedback, componentOverride: componentOverrides?.feedback })),
75
- disclaimerPosition === 'bottom' && disclaimer)),
66
+ currentAnswer && (React.createElement(PiaInlineAnswer, { currentAnswer: currentAnswer, currentItems: currentItems, showFeedback: showFeedback, learnMoreUrl: learnMoreUrl, disclaimerPosition: disclaimerPosition, translations: translations, callbacks: callbacks, componentOverrides: componentOverrides })),
76
67
  React.createElement(SuggestedQuestionsContainer, { questions: displayedQuestions, onQuestionClick: handleSubmitQuestion, componentOverride: componentOverrides?.suggestedQuestions }))))));
77
68
  }
@@ -1,5 +1,12 @@
1
- import React, { useCallback, useRef, useEffect } from 'react';
1
+ import React, { useCallback, useRef, useEffect, useMemo } from 'react';
2
2
  import { Carousel, CIO_EVENTS, } from '@constructor-io/constructorio-ui-components';
3
+ import { sanitizeHtml } from '../../utils/contentTransformers';
4
+ function HtmlDescription({ product }) {
5
+ const { description } = product;
6
+ if (!description)
7
+ return null;
8
+ return (React.createElement("p", { className: 'cio-product-card-description', dangerouslySetInnerHTML: { __html: sanitizeHtml(description) } }));
9
+ }
3
10
  export default function PiaCustomCarousel({ items, componentOverrides, callbacks, }) {
4
11
  const wrapperRef = useRef(null);
5
12
  // Determine to use user-defined click handler or default behavior
@@ -28,10 +35,28 @@ export default function PiaCustomCarousel({ items, componentOverrides, callbacks
28
35
  el.removeEventListener(CIO_EVENTS.productCard.click, handleClick);
29
36
  };
30
37
  }, [productClickHandler]);
38
+ const mergedOverrides = useMemo(() => {
39
+ if (componentOverrides?.item?.productCard?.content?.description) {
40
+ return componentOverrides;
41
+ }
42
+ return {
43
+ ...componentOverrides,
44
+ item: {
45
+ ...componentOverrides?.item,
46
+ productCard: {
47
+ ...componentOverrides?.item?.productCard,
48
+ content: {
49
+ ...componentOverrides?.item?.productCard?.content,
50
+ description: { reactNode: HtmlDescription },
51
+ },
52
+ },
53
+ },
54
+ };
55
+ }, [componentOverrides]);
31
56
  // If there are no items, do not render the carousel
32
57
  if (items.length === 0) {
33
58
  return null;
34
59
  }
35
60
  return (React.createElement("div", { ref: wrapperRef },
36
- React.createElement(Carousel, { items: items, componentOverrides: componentOverrides })));
61
+ React.createElement(Carousel, { items: items, componentOverrides: mergedOverrides })));
37
62
  }
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import Answer from '../Answer/Answer';
3
+ import Feedback from '../Feedback/Feedback';
4
+ import Disclaimer from '../CioPia/Disclaimer';
5
+ import PiaCustomCarousel from '../CioPia/PiaCustomCarousel';
6
+ export default function PiaInlineAnswer({ currentAnswer, currentItems, showFeedback, learnMoreUrl, disclaimerPosition = 'bottom', translations, callbacks, componentOverrides, }) {
7
+ const disclaimer = (React.createElement(Disclaimer, { learnMoreUrl: learnMoreUrl, translations: translations, componentOverride: componentOverrides?.disclaimer }));
8
+ return (React.createElement("div", { className: 'cio-pia-answer-container' },
9
+ disclaimerPosition === 'top' && disclaimer,
10
+ React.createElement(Answer, { text: currentAnswer, componentOverride: componentOverrides?.answer }),
11
+ currentItems && (React.createElement(PiaCustomCarousel, { items: currentItems, componentOverrides: componentOverrides?.carousel, callbacks: callbacks })),
12
+ showFeedback && (React.createElement(Feedback, { translations: translations, onFeedback: callbacks?.onFeedback, componentOverride: componentOverrides?.feedback })),
13
+ disclaimerPosition === 'bottom' && disclaimer));
14
+ }
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line import/prefer-default-export
2
1
  export const DEMO_API_KEY = 'key_13TO6qN9H3BP3Wrn';
3
2
  export const DEMO_ITEM_ID = '149100215';
4
3
  export const DEMO_QUESTION = 'What is the nutritional content of this shake?';
package/lib/mjs/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import CioPia from './components/CioPia';
2
2
  // Components
3
3
  export { default as CioPia } from './components/CioPia';
4
+ // Utilities
5
+ export { sanitizeHtml, renderMarkdown } from './utils/contentTransformers';
4
6
  // Default
5
7
  export * from './types';
6
8
  export default CioPia;
@@ -0,0 +1,16 @@
1
+ import DOMPurify from 'dompurify';
2
+ import { marked } from 'marked';
3
+ const purifyConfig = {
4
+ FORBID_TAGS: ['script', 'style', 'iframe', 'object', 'embed', 'form'],
5
+ };
6
+ export function sanitizeHtml(html) {
7
+ if (!html)
8
+ return '';
9
+ return DOMPurify.sanitize(html, purifyConfig);
10
+ }
11
+ export function renderMarkdown(content) {
12
+ if (!content)
13
+ return '';
14
+ const html = marked.parse(content, { async: false });
15
+ return DOMPurify.sanitize(html, purifyConfig);
16
+ }
@@ -1 +1,2 @@
1
1
  export * from './styleHelpers';
2
+ export { sanitizeHtml, renderMarkdown } from './contentTransformers';
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line import/prefer-default-export
2
1
  export function getPreferredColorScheme() {
3
2
  let colorScheme = 'light';
4
3
  // Check if the dark-mode Media-Query matches
@@ -16,7 +16,6 @@ const defaultTranslations = {
16
16
  * @param translations - Optional user-provided translations object
17
17
  * @returns The translated string or the original word if no translation exists
18
18
  */
19
- // eslint-disable-next-line import/prefer-default-export
20
19
  export const translate = (word, translations) => {
21
20
  if (translations && translations[word] !== undefined) {
22
21
  return translations[word];
@@ -1 +1 @@
1
- export default '2.3.0';
1
+ export default '2.4.0';
@@ -3,29 +3,27 @@ import { IncludeComponentOverrides, IncludeRenderProps } from '@constructor-io/c
3
3
  import MockConstructorIOClient from '../../hooks/mocks/MockConstructorIOClient';
4
4
  import { CioPiaRenderProps, CioPiaComponentOverrides, Callbacks, CioPiaDisplayConfigs, Translations, SuggestedQuestionsParameters, Formatters } from '../../types';
5
5
  export interface CioPiaProps extends IncludeRenderProps<CioPiaRenderProps>, IncludeComponentOverrides<CioPiaComponentOverrides> {
6
+ /** Your Constructor.io API key. */
6
7
  apiKey: string;
8
+ /** The product item ID to fetch insights for. */
7
9
  itemId: string;
8
- /** Thread ID for conversation context. Must be a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000") */
10
+ /** Thread ID for conversation context. Must be a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000"). */
9
11
  threadId?: string;
12
+ /** Optional variation ID for the product. */
10
13
  variationId?: string;
14
+ /** Optional Constructor.io client instance. If not provided, one will be created internally. */
11
15
  cioClient?: MockConstructorIOClient;
16
+ /** Display configuration options (mode, type, showFeedback, etc.). */
12
17
  displayConfigs?: CioPiaDisplayConfigs;
13
- /**
14
- * Callback handlers for user interactions:
15
- *
16
- * `onQuestionSubmit: (question: string) => void`
17
- * Called when a question is submitted (via Enter key, Send button, or suggested question click).
18
- *
19
- * `onProductCardClick: (item: Item) => void`
20
- * Called when a product card in the carousel is clicked.
21
- *
22
- * `onFeedback: (type: 'up' | 'down') => void`
23
- * Called when the user submits positive or negative feedback on an answer.
24
- */
18
+ /** Callback handlers for user interactions (onQuestionSubmit, onProductCardClick, onFeedback). */
25
19
  callbacks?: Callbacks;
26
- /** Define formatter functions outside the component or memoize to avoid unnecessary re-renders. */
20
+ /** Custom component overrides via reactNode or render props functions. */
21
+ componentOverrides?: CioPiaComponentOverrides;
22
+ /** Formatter functions for transforming data before display. */
27
23
  formatters?: Formatters;
24
+ /** UI string translations for internationalization. */
28
25
  translations?: Translations;
26
+ /** Parameters for the suggested questions request. */
29
27
  suggestedQuestionsParameters?: SuggestedQuestionsParameters;
30
28
  }
31
29
  export default function CioPia(props: CioPiaProps): React.JSX.Element;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { Callbacks, CioPiaComponentOverrides, DisclaimerPosition, Translations, Item } from '../../types';
3
+ interface PiaInlineAnswerProps {
4
+ currentAnswer: string;
5
+ currentItems: Item[] | null;
6
+ showFeedback?: boolean;
7
+ learnMoreUrl?: string;
8
+ disclaimerPosition?: DisclaimerPosition;
9
+ translations?: Translations;
10
+ callbacks?: Callbacks;
11
+ componentOverrides?: CioPiaComponentOverrides;
12
+ }
13
+ export default function PiaInlineAnswer({ currentAnswer, currentItems, showFeedback, learnMoreUrl, disclaimerPosition, translations, callbacks, componentOverrides, }: PiaInlineAnswerProps): React.JSX.Element;
14
+ export {};
@@ -1,5 +1,6 @@
1
1
  import CioPia from './components/CioPia';
2
2
  export { default as CioPia } from './components/CioPia';
3
3
  export type { CioPiaProps } from './components/CioPia';
4
+ export { sanitizeHtml, renderMarkdown } from './utils/contentTransformers';
4
5
  export * from './types';
5
6
  export default CioPia;
@@ -113,8 +113,8 @@ export interface FeedbackRenderProps {
113
113
  onFeedback?: (type: FeedbackType) => void;
114
114
  }
115
115
  /**
116
- * Component overrides for CioPia
117
- * Allows customization of sub-components via reactNode or render props functions
116
+ * Component overrides for CioPia.
117
+ * Allows customization of sub-components via reactNode or render props functions.
118
118
  */
119
119
  export interface CioPiaComponentOverrides extends ComponentOverrideProps<CioPiaRenderProps> {
120
120
  carousel?: CarouselOverrides<Item>;
@@ -0,0 +1,2 @@
1
+ export declare function sanitizeHtml(html: string): string;
2
+ export declare function renderMarkdown(content: string): string;
@@ -1 +1,2 @@
1
1
  export * from './styleHelpers';
2
+ export { sanitizeHtml, renderMarkdown } from './contentTransformers';
@@ -1,2 +1,2 @@
1
- declare const _default: "2.3.0";
1
+ declare const _default: "2.4.0";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-pia",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Constructor.io AI Product Insights Agent UI library for web applications",
5
5
  "author": "Constructor.io Corporation",
6
6
  "license": "MIT",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "types": "lib/types/index.d.ts",
53
53
  "scripts": {
54
- "lint": "eslint src --ext js,ts,jsx,tsx",
54
+ "lint": "eslint src",
55
55
  "check-types": "npx tsc --noEmit",
56
56
  "copy-styles": "rsync -am --include='*/' --include='*.css' --exclude='*' src/ lib/mjs/ && rsync -am --include='*/' --include='*.css' --exclude='*' src/ lib/cjs/",
57
57
  "dev": "storybook dev -p 6006",
@@ -64,7 +64,7 @@
64
64
  "storybook-docs-dev": "storybook dev --docs -p 6007",
65
65
  "serve-built-storybook": "npx http-server docs",
66
66
  "compile": "rm -rf lib && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && npm run copy-styles && vite build",
67
- "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause;ISC' --excludePackages 'picocolors@1.0.0;graceful-fs@4.2.11;lightningcss@1.30.2;lightningcss-darwin-arm64@1.30.2;lightningcss-linux-x64-gnu@1.30.2;lightningcss-linux-x64-musl@1.30.2'",
67
+ "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause;ISC' --excludePackages 'lightningcss@1.32.0;lightningcss-darwin-arm64@1.32.0;lightningcss-linux-x64-gnu@1.32.0;lightningcss-linux-x64-musl@1.32.0'",
68
68
  "prepare": "husky"
69
69
  },
70
70
  "peerDependencies": {
@@ -82,10 +82,11 @@
82
82
  "@babel/preset-typescript": "^7.23.3",
83
83
  "@chromatic-com/storybook": "^3.2.5",
84
84
  "@cspell/eslint-plugin": "^8.17.5",
85
+ "@eslint/js": "^9.39.4",
85
86
  "@storybook/addon-a11y": "^8.6.4",
86
87
  "@storybook/addon-actions": "^8.6.4",
87
- "@storybook/addon-essentials": "^8.6.4",
88
- "@storybook/addon-interactions": "^8.6.4",
88
+ "@storybook/addon-essentials": "^8.6.18",
89
+ "@storybook/addon-interactions": "^8.6.18",
89
90
  "@storybook/addon-links": "^8.6.4",
90
91
  "@storybook/addon-onboarding": "^8.6.4",
91
92
  "@storybook/blocks": "^8.6.4",
@@ -97,32 +98,31 @@
97
98
  "@storybook/testing-library": "^0.2.1",
98
99
  "@testing-library/jest-dom": "^6.6.3",
99
100
  "@testing-library/react": "^16.2.0",
100
- "@types/jest": "^29.5.14",
101
+ "@types/dompurify": "^3.0.5",
102
+ "@types/jest": "^30.0.0",
101
103
  "@types/react": "^19.0.10",
102
104
  "@types/react-dom": "^19.0.4",
103
- "@typescript-eslint/eslint-plugin": "^7.18.0",
104
- "@typescript-eslint/parser": "^7.18.0",
105
105
  "chromatic": "^11.27.0",
106
- "eslint": "^8.57.1",
107
- "eslint-config-airbnb": "^19.0.4",
108
- "eslint-config-airbnb-typescript": "^18.0.0",
106
+ "eslint": "^9.39.4",
109
107
  "eslint-config-prettier": "^10.1.1",
108
+ "eslint-import-resolver-typescript": "^4.4.4",
110
109
  "eslint-plugin-import": "^2.31.0",
111
110
  "eslint-plugin-jsx-a11y": "^6.10.2",
112
111
  "eslint-plugin-prettier": "^5.2.3",
113
112
  "eslint-plugin-react": "^7.37.4",
114
- "eslint-plugin-react-hooks": "^4.3.0",
115
- "eslint-plugin-storybook": "^0.11.4",
116
- "globals": "^16.0.0",
113
+ "eslint-plugin-react-hooks": "^7.1.1",
114
+ "eslint-plugin-storybook": "^0.12.0",
115
+ "globals": "^16.5.0",
117
116
  "husky": "^9.1.7",
118
- "jest": "^29.7.0",
117
+ "jest": "^30.3.0",
119
118
  "jest-environment-jsdom": "^30.2.0",
119
+ "jest-environment-node": "^30.4.1",
120
120
  "license-checker": "^25.0.1",
121
121
  "prop-types": "^15.8.1",
122
122
  "start-server-and-test": "^2.0.10",
123
123
  "storybook": "^8.6.4",
124
124
  "typescript": "^4.9.4",
125
- "typescript-eslint": "^8.26.1",
125
+ "typescript-eslint": "^8.59.2",
126
126
  "vite": "^6.3.5",
127
127
  "vite-plugin-css-injected-by-js": "^3.5.2",
128
128
  "webpack": "^5.98.0"
@@ -130,5 +130,9 @@
130
130
  "volta": {
131
131
  "node": "22.18.0",
132
132
  "npm": "10.9.3"
133
+ },
134
+ "dependencies": {
135
+ "dompurify": "^3.4.2",
136
+ "marked": "^15.0.12"
133
137
  }
134
138
  }