@constructor-io/constructorio-ui-pia 2.10.1 → 2.10.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.
@@ -92,7 +92,7 @@ function CioPia(props) {
92
92
  return (react_1.default.createElement("div", { ref: containerRef, className: 'cio-pia-container', "data-testid": 'cio-pia-container' },
93
93
  react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: renderProps, override: children || (componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.reactNode) },
94
94
  react_1.default.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, (0, translate_1.translate)('Any questions about this product?', translations)),
95
- react_1.default.createElement(Input_1.default, { onSubmit: handleSubmitQuestion, onFocus: handleInputFocus, value: currentQuestion, translations: translations }),
95
+ 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 }),
96
96
  isLoading && react_1.default.createElement(LoadingSkeleton_1.default, { componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.loading }),
97
97
  !isLoading && error && react_1.default.createElement(ErrorBlock_1.default, { message: (error === null || error === void 0 ? void 0 : error.message) || 'Unexpected error' }),
98
98
  !isLoading && !error && (react_1.default.createElement(react_1.default.Fragment, null,
@@ -2,41 +2,49 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const react_1 = tslib_1.__importStar(require("react"));
5
+ const constructorio_ui_components_1 = require("@constructor-io/constructorio-ui-components");
5
6
  const translate_1 = require("../../utils/translate");
6
7
  function SendIcon() {
7
8
  return (react_1.default.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
8
9
  react_1.default.createElement("g", { id: '.icon-send' },
9
10
  react_1.default.createElement("path", { id: 'Vector', 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' }))));
10
11
  }
11
- function Input({ value: providedValue, placeholder, disabled = false, onSubmit, onFocus, translations, }) {
12
+ function Input({ value: providedValue, placeholder, disabled = false, onSubmit, onFocus, translations, componentOverride, }) {
12
13
  const [value, setValue] = (0, react_1.useState)(providedValue || '');
13
14
  (0, react_1.useEffect)(() => {
14
15
  if (providedValue) {
15
16
  setValue(providedValue);
16
17
  }
17
18
  }, [providedValue]);
18
- const handleSubmit = () => {
19
- if (value.trim()) {
20
- onSubmit(value.trim());
21
- if (value.trim() !== providedValue) {
19
+ const handleSubmit = (0, react_1.useCallback)((submittedValue) => {
20
+ if (submittedValue.trim()) {
21
+ onSubmit(submittedValue.trim());
22
+ if (submittedValue.trim() !== providedValue) {
22
23
  setValue('');
23
24
  }
24
25
  }
25
- };
26
+ }, [onSubmit, providedValue]);
26
27
  const handleSubmitOnEnter = (e) => {
27
28
  if (e.key === 'Enter') {
28
29
  e.preventDefault();
29
- handleSubmit();
30
+ handleSubmit(value);
30
31
  }
31
32
  };
32
33
  // Priority: translations > placeholder prop > default
33
34
  const resolvedPlaceholder = (translations === null || translations === void 0 ? void 0 : translations['Ask anything']) !== undefined
34
35
  ? (0, translate_1.translate)('Ask anything', translations)
35
36
  : (placeholder !== null && placeholder !== void 0 ? placeholder : (0, translate_1.translate)('Ask anything'));
36
- return (react_1.default.createElement("div", { className: 'cio-pia-input-container' },
37
- react_1.default.createElement("input", { type: 'text', value: value, onChange: (e) => setValue(e.target.value), onKeyDown: handleSubmitOnEnter, onFocus: onFocus, placeholder: resolvedPlaceholder, disabled: disabled, className: 'cio-pia-input' }),
38
- react_1.default.createElement("button", { type: 'button', onClick: handleSubmit, className: 'cio-pia-send-button', disabled: disabled },
39
- (0, translate_1.translate)('Send', translations),
40
- react_1.default.createElement(SendIcon, null))));
37
+ return (react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: {
38
+ disabled,
39
+ placeholder: resolvedPlaceholder,
40
+ onSubmit: handleSubmit,
41
+ onFocus,
42
+ translations,
43
+ }, override: componentOverride === null || componentOverride === void 0 ? void 0 : componentOverride.reactNode },
44
+ react_1.default.createElement("div", { className: 'cio-pia-input-container' },
45
+ react_1.default.createElement("input", { type: 'text', value: value, onChange: (e) => setValue(e.target.value), onKeyDown: handleSubmitOnEnter, onFocus: onFocus, placeholder: resolvedPlaceholder, disabled: disabled, className: 'cio-pia-input' }),
46
+ react_1.default.createElement("button", { type: 'button', onClick: () => handleSubmit(value), className: 'cio-pia-send-button', disabled: disabled },
47
+ (0, translate_1.translate)('Send', translations),
48
+ react_1.default.createElement(SendIcon, null)))));
41
49
  }
42
50
  exports.default = Input;
@@ -15,6 +15,6 @@ function PiaConversation({ conversationHistory, isLoading, error, currentItems,
15
15
  react_1.default.createElement("div", { className: 'cio-pia-conversation-footer' },
16
16
  isLoading && !error && react_1.default.createElement(SuggestedQuestionsSkeleton_1.default, null),
17
17
  !isLoading && !error && (react_1.default.createElement(SuggestedQuestionsContainer_1.default, { questions: displayedQuestions, onQuestionClick: handleQuestionClick, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.suggestedQuestions })),
18
- react_1.default.createElement(Input_1.default, { onSubmit: handleSubmitQuestion, onFocus: onInputFocus, disabled: isLoading, translations: translations }))));
18
+ react_1.default.createElement(Input_1.default, { onSubmit: handleSubmitQuestion, onFocus: onInputFocus, disabled: isLoading, translations: translations, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.input }))));
19
19
  }
20
20
  exports.default = PiaConversation;
@@ -67,7 +67,7 @@ function PiaModal({ initialQuestions, handleSubmitQuestion, handleQuestionClick,
67
67
  react_1.default.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, (0, translate_1.translate)('Any questions about this product?', translations)),
68
68
  react_1.default.createElement("div", { className: 'cio-pia-conversation-footer' },
69
69
  initialQuestions.length > 0 && (react_1.default.createElement(SuggestedQuestionsContainer_1.default, { questions: initialQuestions, onQuestionClick: handleQuestionClicked, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.suggestedQuestions })),
70
- react_1.default.createElement(Input_1.default, { onSubmit: handleQuestion, onFocus: onInputFocus, disabled: isLoading || isOpen, translations: translations })),
70
+ react_1.default.createElement(Input_1.default, { onSubmit: handleQuestion, onFocus: onInputFocus, disabled: isLoading || isOpen, translations: translations, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.input })),
71
71
  react_1.default.createElement("dialog", { ref: dialogRef, className: 'cio-pia-modal', "aria-labelledby": 'cio-pia-modal-title' },
72
72
  react_1.default.createElement("div", { className: 'cio-pia-modal-content' },
73
73
  react_1.default.createElement("div", { className: 'cio-pia-modal-header' },
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '2.10.1';
3
+ exports.default = '2.10.2';
@@ -88,7 +88,7 @@ export default function CioPia(props) {
88
88
  return (React.createElement("div", { ref: containerRef, className: 'cio-pia-container', "data-testid": 'cio-pia-container' },
89
89
  React.createElement(RenderPropsWrapper, { props: renderProps, override: children || componentOverrides?.reactNode },
90
90
  React.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, translate('Any questions about this product?', translations)),
91
- React.createElement(Input, { onSubmit: handleSubmitQuestion, onFocus: handleInputFocus, value: currentQuestion, translations: translations }),
91
+ React.createElement(Input, { onSubmit: handleSubmitQuestion, onFocus: handleInputFocus, value: currentQuestion, translations: translations, componentOverride: componentOverrides?.input }),
92
92
  isLoading && React.createElement(LoadingSkeleton, { componentOverride: componentOverrides?.loading }),
93
93
  !isLoading && error && React.createElement(ErrorBlock, { message: error?.message || 'Unexpected error' }),
94
94
  !isLoading && !error && (React.createElement(React.Fragment, null,
@@ -1,39 +1,47 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
+ import { RenderPropsWrapper, } from '@constructor-io/constructorio-ui-components';
2
3
  import { translate } from '../../utils/translate';
3
4
  function SendIcon() {
4
5
  return (React.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
5
6
  React.createElement("g", { id: '.icon-send' },
6
7
  React.createElement("path", { id: 'Vector', 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' }))));
7
8
  }
8
- function Input({ value: providedValue, placeholder, disabled = false, onSubmit, onFocus, translations, }) {
9
+ function Input({ value: providedValue, placeholder, disabled = false, onSubmit, onFocus, translations, componentOverride, }) {
9
10
  const [value, setValue] = useState(providedValue || '');
10
11
  useEffect(() => {
11
12
  if (providedValue) {
12
13
  setValue(providedValue);
13
14
  }
14
15
  }, [providedValue]);
15
- const handleSubmit = () => {
16
- if (value.trim()) {
17
- onSubmit(value.trim());
18
- if (value.trim() !== providedValue) {
16
+ const handleSubmit = useCallback((submittedValue) => {
17
+ if (submittedValue.trim()) {
18
+ onSubmit(submittedValue.trim());
19
+ if (submittedValue.trim() !== providedValue) {
19
20
  setValue('');
20
21
  }
21
22
  }
22
- };
23
+ }, [onSubmit, providedValue]);
23
24
  const handleSubmitOnEnter = (e) => {
24
25
  if (e.key === 'Enter') {
25
26
  e.preventDefault();
26
- handleSubmit();
27
+ handleSubmit(value);
27
28
  }
28
29
  };
29
30
  // Priority: translations > placeholder prop > default
30
31
  const resolvedPlaceholder = translations?.['Ask anything'] !== undefined
31
32
  ? translate('Ask anything', translations)
32
33
  : (placeholder ?? translate('Ask anything'));
33
- return (React.createElement("div", { className: 'cio-pia-input-container' },
34
- React.createElement("input", { type: 'text', value: value, onChange: (e) => setValue(e.target.value), onKeyDown: handleSubmitOnEnter, onFocus: onFocus, placeholder: resolvedPlaceholder, disabled: disabled, className: 'cio-pia-input' }),
35
- React.createElement("button", { type: 'button', onClick: handleSubmit, className: 'cio-pia-send-button', disabled: disabled },
36
- translate('Send', translations),
37
- React.createElement(SendIcon, null))));
34
+ return (React.createElement(RenderPropsWrapper, { props: {
35
+ disabled,
36
+ placeholder: resolvedPlaceholder,
37
+ onSubmit: handleSubmit,
38
+ onFocus,
39
+ translations,
40
+ }, override: componentOverride?.reactNode },
41
+ React.createElement("div", { className: 'cio-pia-input-container' },
42
+ React.createElement("input", { type: 'text', value: value, onChange: (e) => setValue(e.target.value), onKeyDown: handleSubmitOnEnter, onFocus: onFocus, placeholder: resolvedPlaceholder, disabled: disabled, className: 'cio-pia-input' }),
43
+ React.createElement("button", { type: 'button', onClick: () => handleSubmit(value), className: 'cio-pia-send-button', disabled: disabled },
44
+ translate('Send', translations),
45
+ React.createElement(SendIcon, null)))));
38
46
  }
39
47
  export default Input;
@@ -12,5 +12,5 @@ export default function PiaConversation({ conversationHistory, isLoading, error,
12
12
  React.createElement("div", { className: 'cio-pia-conversation-footer' },
13
13
  isLoading && !error && React.createElement(SuggestedQuestionsSkeleton, null),
14
14
  !isLoading && !error && (React.createElement(SuggestedQuestionsContainer, { questions: displayedQuestions, onQuestionClick: handleQuestionClick, componentOverride: componentOverrides?.suggestedQuestions })),
15
- React.createElement(Input, { onSubmit: handleSubmitQuestion, onFocus: onInputFocus, disabled: isLoading, translations: translations }))));
15
+ React.createElement(Input, { onSubmit: handleSubmitQuestion, onFocus: onInputFocus, disabled: isLoading, translations: translations, componentOverride: componentOverrides?.input }))));
16
16
  }
@@ -64,7 +64,7 @@ export default function PiaModal({ initialQuestions, handleSubmitQuestion, handl
64
64
  React.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, translate('Any questions about this product?', translations)),
65
65
  React.createElement("div", { className: 'cio-pia-conversation-footer' },
66
66
  initialQuestions.length > 0 && (React.createElement(SuggestedQuestionsContainer, { questions: initialQuestions, onQuestionClick: handleQuestionClicked, componentOverride: componentOverrides?.suggestedQuestions })),
67
- React.createElement(Input, { onSubmit: handleQuestion, onFocus: onInputFocus, disabled: isLoading || isOpen, translations: translations })),
67
+ React.createElement(Input, { onSubmit: handleQuestion, onFocus: onInputFocus, disabled: isLoading || isOpen, translations: translations, componentOverride: componentOverrides?.input })),
68
68
  React.createElement("dialog", { ref: dialogRef, className: 'cio-pia-modal', "aria-labelledby": 'cio-pia-modal-title' },
69
69
  React.createElement("div", { className: 'cio-pia-modal-content' },
70
70
  React.createElement("div", { className: 'cio-pia-modal-header' },
@@ -1 +1 @@
1
- export default '2.10.1';
1
+ export default '2.10.2';
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
- import { Translations } from '../../types';
2
+ import { ComponentOverrideProps } from '@constructor-io/constructorio-ui-components';
3
+ import { InputRenderProps, Translations } from '../../types';
3
4
  interface InputProps {
4
5
  value?: string;
5
6
  disabled?: boolean;
@@ -8,6 +9,7 @@ interface InputProps {
8
9
  onSubmit: (value: string) => void;
9
10
  onFocus?: () => void;
10
11
  translations?: Translations;
12
+ componentOverride?: ComponentOverrideProps<InputRenderProps>;
11
13
  }
12
- declare function Input({ value: providedValue, placeholder, disabled, onSubmit, onFocus, translations, }: InputProps): React.JSX.Element;
14
+ declare function Input({ value: providedValue, placeholder, disabled, onSubmit, onFocus, translations, componentOverride, }: InputProps): React.JSX.Element;
13
15
  export default Input;
@@ -146,6 +146,16 @@ export interface FeedbackRenderProps {
146
146
  export interface LoadingRenderProps {
147
147
  skeleton: ReactNode;
148
148
  }
149
+ /**
150
+ * Render props passed to a custom Input override.
151
+ */
152
+ export interface InputRenderProps {
153
+ disabled: boolean;
154
+ placeholder: string;
155
+ onSubmit: (value: string) => void;
156
+ onFocus?: () => void;
157
+ translations?: Translations;
158
+ }
149
159
  /**
150
160
  * Component overrides for CioPia.
151
161
  * Allows customization of sub-components via reactNode or render props functions.
@@ -153,6 +163,7 @@ export interface LoadingRenderProps {
153
163
  export interface CioPiaComponentOverrides extends ComponentOverrideProps<CioPiaRenderProps> {
154
164
  carousel?: CarouselOverrides<Item>;
155
165
  answer?: ComponentOverrideProps<AnswerRenderProps>;
166
+ input?: ComponentOverrideProps<InputRenderProps>;
156
167
  suggestedQuestions?: ComponentOverrideProps<SuggestedQuestionsRenderProps>;
157
168
  disclaimer?: ComponentOverrideProps<DisclaimerRenderProps>;
158
169
  feedback?: ComponentOverrideProps<FeedbackRenderProps>;
@@ -1,2 +1,2 @@
1
- declare const _default: "2.10.1";
1
+ declare const _default: "2.10.2";
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.10.1",
3
+ "version": "2.10.2",
4
4
  "description": "Constructor.io AI Product Insights Agent UI library for web applications",
5
5
  "author": "Constructor.io Corporation",
6
6
  "license": "MIT",