@constructor-io/constructorio-ui-asa 1.0.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.
Files changed (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +253 -0
  3. package/dist/constructorio-ui-asa-bundled.js +33 -0
  4. package/lib/cjs/components/Button/Button.css +61 -0
  5. package/lib/cjs/components/Button/Button.js +12 -0
  6. package/lib/cjs/components/Chat/AiMessage.css +35 -0
  7. package/lib/cjs/components/Chat/AiMessage.js +34 -0
  8. package/lib/cjs/components/Chat/Chat.css +103 -0
  9. package/lib/cjs/components/Chat/Chat.js +34 -0
  10. package/lib/cjs/components/Chat/ChatHeader.css +41 -0
  11. package/lib/cjs/components/Chat/ChatHeader.js +18 -0
  12. package/lib/cjs/components/Chat/ChatInput.css +83 -0
  13. package/lib/cjs/components/Chat/ChatInput.js +30 -0
  14. package/lib/cjs/components/Chat/ChatMessageList.css +23 -0
  15. package/lib/cjs/components/Chat/ChatMessageList.js +46 -0
  16. package/lib/cjs/components/Chat/TypingIndicator.css +51 -0
  17. package/lib/cjs/components/Chat/TypingIndicator.js +14 -0
  18. package/lib/cjs/components/Chat/UserMessage.css +25 -0
  19. package/lib/cjs/components/Chat/UserMessage.js +14 -0
  20. package/lib/cjs/components/Chat/WelcomeScreen.css +205 -0
  21. package/lib/cjs/components/Chat/WelcomeScreen.js +43 -0
  22. package/lib/cjs/components/CioAsaProvider/CioAsaProvider.js +23 -0
  23. package/lib/cjs/components/ResultsBlock/ResultsBlock.css +217 -0
  24. package/lib/cjs/components/ResultsBlock/ResultsBlock.js +73 -0
  25. package/lib/cjs/components/ResultsBlock/constants.js +11 -0
  26. package/lib/cjs/components/ResultsBlock/renderProductCard.js +21 -0
  27. package/lib/cjs/components/icons/ArrowRightIcon.js +9 -0
  28. package/lib/cjs/components/icons/ChatBubbleDarkIcon.js +9 -0
  29. package/lib/cjs/components/icons/ChatBubbleLightIcon.js +9 -0
  30. package/lib/cjs/components/icons/SendArrowIcon.js +9 -0
  31. package/lib/cjs/components/icons/SendPlaneIcon.js +9 -0
  32. package/lib/cjs/components/icons/index.js +16 -0
  33. package/lib/cjs/constants.js +6 -0
  34. package/lib/cjs/hooks/asaStreamHandlers.js +34 -0
  35. package/lib/cjs/hooks/useAsaResults.js +120 -0
  36. package/lib/cjs/hooks/useCioAsaContext.js +15 -0
  37. package/lib/cjs/hooks/useCioClient.js +21 -0
  38. package/lib/cjs/hooks/useFocusTrap.js +38 -0
  39. package/lib/cjs/hooks/useMessageInput.js +22 -0
  40. package/lib/cjs/hooks/useRequestConfigs.js +27 -0
  41. package/lib/cjs/index.js +24 -0
  42. package/lib/cjs/styles.css +34 -0
  43. package/lib/cjs/types.js +6 -0
  44. package/lib/cjs/utils/formatters.js +11 -0
  45. package/lib/cjs/utils/productNormalizer.js +20 -0
  46. package/lib/cjs/utils/translate.js +30 -0
  47. package/lib/cjs/utils/typeHelpers.js +2 -0
  48. package/lib/cjs/utils/urlHelpers.js +102 -0
  49. package/lib/cjs/version.js +3 -0
  50. package/lib/mjs/components/Button/Button.css +61 -0
  51. package/lib/mjs/components/Button/Button.js +8 -0
  52. package/lib/mjs/components/Chat/AiMessage.css +35 -0
  53. package/lib/mjs/components/Chat/AiMessage.js +29 -0
  54. package/lib/mjs/components/Chat/Chat.css +103 -0
  55. package/lib/mjs/components/Chat/Chat.js +31 -0
  56. package/lib/mjs/components/Chat/ChatHeader.css +41 -0
  57. package/lib/mjs/components/Chat/ChatHeader.js +14 -0
  58. package/lib/mjs/components/Chat/ChatInput.css +83 -0
  59. package/lib/mjs/components/Chat/ChatInput.js +26 -0
  60. package/lib/mjs/components/Chat/ChatMessageList.css +23 -0
  61. package/lib/mjs/components/Chat/ChatMessageList.js +41 -0
  62. package/lib/mjs/components/Chat/TypingIndicator.css +51 -0
  63. package/lib/mjs/components/Chat/TypingIndicator.js +10 -0
  64. package/lib/mjs/components/Chat/UserMessage.css +25 -0
  65. package/lib/mjs/components/Chat/UserMessage.js +10 -0
  66. package/lib/mjs/components/Chat/WelcomeScreen.css +205 -0
  67. package/lib/mjs/components/Chat/WelcomeScreen.js +38 -0
  68. package/lib/mjs/components/CioAsaProvider/CioAsaProvider.js +19 -0
  69. package/lib/mjs/components/ResultsBlock/ResultsBlock.css +217 -0
  70. package/lib/mjs/components/ResultsBlock/ResultsBlock.js +76 -0
  71. package/lib/mjs/components/ResultsBlock/constants.js +8 -0
  72. package/lib/mjs/components/ResultsBlock/renderProductCard.js +17 -0
  73. package/lib/mjs/components/icons/ArrowRightIcon.js +5 -0
  74. package/lib/mjs/components/icons/ChatBubbleDarkIcon.js +5 -0
  75. package/lib/mjs/components/icons/ChatBubbleLightIcon.js +5 -0
  76. package/lib/mjs/components/icons/SendArrowIcon.js +5 -0
  77. package/lib/mjs/components/icons/SendPlaneIcon.js +5 -0
  78. package/lib/mjs/components/icons/index.js +5 -0
  79. package/lib/mjs/constants.js +3 -0
  80. package/lib/mjs/hooks/asaStreamHandlers.js +39 -0
  81. package/lib/mjs/hooks/useAsaResults.js +118 -0
  82. package/lib/mjs/hooks/useCioAsaContext.js +11 -0
  83. package/lib/mjs/hooks/useCioClient.js +23 -0
  84. package/lib/mjs/hooks/useFocusTrap.js +35 -0
  85. package/lib/mjs/hooks/useMessageInput.js +19 -0
  86. package/lib/mjs/hooks/useRequestConfigs.js +24 -0
  87. package/lib/mjs/index.js +11 -0
  88. package/lib/mjs/styles.css +34 -0
  89. package/lib/mjs/types.js +2 -0
  90. package/lib/mjs/utils/formatters.js +7 -0
  91. package/lib/mjs/utils/productNormalizer.js +15 -0
  92. package/lib/mjs/utils/translate.js +26 -0
  93. package/lib/mjs/utils/typeHelpers.js +1 -0
  94. package/lib/mjs/utils/urlHelpers.js +90 -0
  95. package/lib/mjs/version.js +1 -0
  96. package/lib/types/components/Button/Button.d.ts +12 -0
  97. package/lib/types/components/Chat/AiMessage.d.ts +12 -0
  98. package/lib/types/components/Chat/Chat.d.ts +38 -0
  99. package/lib/types/components/Chat/ChatHeader.d.ts +12 -0
  100. package/lib/types/components/Chat/ChatInput.d.ts +13 -0
  101. package/lib/types/components/Chat/ChatMessageList.d.ts +24 -0
  102. package/lib/types/components/Chat/TypingIndicator.d.ts +10 -0
  103. package/lib/types/components/Chat/UserMessage.d.ts +12 -0
  104. package/lib/types/components/Chat/WelcomeScreen.d.ts +16 -0
  105. package/lib/types/components/CioAsaProvider/CioAsaProvider.d.ts +3 -0
  106. package/lib/types/components/ResultsBlock/ResultsBlock.d.ts +32 -0
  107. package/lib/types/components/ResultsBlock/constants.d.ts +3 -0
  108. package/lib/types/components/ResultsBlock/renderProductCard.d.ts +12 -0
  109. package/lib/types/components/icons/ArrowRightIcon.d.ts +2 -0
  110. package/lib/types/components/icons/ChatBubbleDarkIcon.d.ts +2 -0
  111. package/lib/types/components/icons/ChatBubbleLightIcon.d.ts +2 -0
  112. package/lib/types/components/icons/SendArrowIcon.d.ts +2 -0
  113. package/lib/types/components/icons/SendPlaneIcon.d.ts +2 -0
  114. package/lib/types/components/icons/index.d.ts +5 -0
  115. package/lib/types/constants.d.ts +2 -0
  116. package/lib/types/hooks/asaStreamHandlers.d.ts +8 -0
  117. package/lib/types/hooks/useAsaResults.d.ts +2 -0
  118. package/lib/types/hooks/useCioAsaContext.d.ts +9 -0
  119. package/lib/types/hooks/useCioClient.d.ts +6 -0
  120. package/lib/types/hooks/useFocusTrap.d.ts +11 -0
  121. package/lib/types/hooks/useMessageInput.d.ts +15 -0
  122. package/lib/types/hooks/useRequestConfigs.d.ts +7 -0
  123. package/lib/types/index.d.ts +12 -0
  124. package/lib/types/types.d.ts +178 -0
  125. package/lib/types/utils/formatters.d.ts +1 -0
  126. package/lib/types/utils/productNormalizer.d.ts +14 -0
  127. package/lib/types/utils/translate.d.ts +2 -0
  128. package/lib/types/utils/typeHelpers.d.ts +4 -0
  129. package/lib/types/utils/urlHelpers.d.ts +8 -0
  130. package/lib/types/version.d.ts +2 -0
  131. package/package.json +150 -0
@@ -0,0 +1,205 @@
1
+ .cio-asa-welcome-screen {
2
+ display: flex;
3
+ flex-direction: column;
4
+ flex: 1;
5
+ padding: 20px;
6
+ position: relative;
7
+ }
8
+
9
+ .cio-asa-welcome-screen__close {
10
+ position: absolute;
11
+ top: 16px;
12
+ right: 20px;
13
+ background: none;
14
+ border: none;
15
+ cursor: pointer;
16
+ padding: 4px;
17
+ display: flex;
18
+ align-items: center;
19
+ justify-content: center;
20
+ color: #1a1a1a;
21
+ font-size: 20px;
22
+ line-height: 1;
23
+ z-index: 1;
24
+ }
25
+
26
+ .cio-asa-welcome-screen__close:hover {
27
+ opacity: 0.7;
28
+ }
29
+
30
+ .cio-asa-welcome-screen__content {
31
+ display: flex;
32
+ flex-direction: column;
33
+ align-items: center;
34
+ justify-content: center;
35
+ flex: 1;
36
+ width: 100%;
37
+ max-width: 504px;
38
+ margin: 0 auto;
39
+ }
40
+
41
+ @media (max-width: 768px) {
42
+ .cio-asa-welcome-screen__content {
43
+ max-width: 366px;
44
+ }
45
+ }
46
+
47
+ .cio-asa-welcome-screen__title {
48
+ font-weight: 400;
49
+ font-size: 26px;
50
+ line-height: 32px;
51
+ text-align: center;
52
+ letter-spacing: -0.005em;
53
+ font-feature-settings: 'tnum' on, 'lnum' on;
54
+ color: #000000;
55
+ margin: 0;
56
+ align-self: stretch;
57
+ }
58
+
59
+ .cio-asa-welcome-screen__input-row {
60
+ display: flex;
61
+ flex-direction: row;
62
+ align-items: center;
63
+ padding: 8px 8px 8px 12px;
64
+ gap: 12px;
65
+ width: 100%;
66
+ height: 40px;
67
+ margin-top: 32px;
68
+ background: #ffffff;
69
+ border: 1px solid #DEE0E3;
70
+ box-shadow: inset 1px 1px 2px rgba(18, 18, 105, 0.1), inset 0px 1px 4px rgba(18, 18, 105, 0.05), inset 1px 1px 1px rgba(18, 18, 105, 0.05);
71
+ border-radius: 4px;
72
+ box-sizing: border-box;
73
+ }
74
+
75
+ .cio-asa-welcome-screen__input {
76
+ flex: 1;
77
+ padding: 0;
78
+ border: none;
79
+ font-weight: 400;
80
+ font-size: 14px;
81
+ line-height: 16px;
82
+ letter-spacing: -0.005em;
83
+ color: #0F1324;
84
+ outline: none;
85
+ background: transparent;
86
+ }
87
+
88
+ .cio-asa-welcome-screen__input::placeholder {
89
+ color: rgba(15, 19, 36, 0.7);
90
+ }
91
+
92
+ /* Input states */
93
+ .cio-asa-welcome-screen__input-row:hover {
94
+ border-color: #C8CAD0;
95
+ }
96
+
97
+ .cio-asa-welcome-screen__input-row:focus-within {
98
+ border-color: #A980FF;
99
+ box-shadow: 0px 0px 0px 2px rgba(201, 176, 254, 0.7);
100
+ }
101
+
102
+ .cio-asa-welcome-screen__input-row:active {
103
+ border-color: #000000;
104
+ box-shadow: inset 0px 1px 4px rgba(18, 18, 105, 0.14), inset 2.1px 2px 2px rgba(18, 18, 105, 0.1), inset 0px 1.5px 3px rgba(18, 18, 105, 0.05);
105
+ }
106
+
107
+ .cio-asa-welcome-screen__input-row--disabled {
108
+ border-color: #E9EAEC;
109
+ box-shadow: none;
110
+ pointer-events: none;
111
+ }
112
+
113
+ .cio-asa-welcome-screen__input-row--disabled .cio-asa-welcome-screen__send-btn {
114
+ background: #E9EAEC;
115
+ box-shadow: none;
116
+ color: rgba(10, 15, 41, 0.25);
117
+ cursor: default;
118
+ }
119
+
120
+ .cio-asa-welcome-screen__input-row--disabled .cio-asa-welcome-screen__send-btn svg path {
121
+ fill: rgba(10, 15, 41, 0.25);
122
+ }
123
+
124
+ .cio-asa-welcome-screen__send-btn {
125
+ display: flex;
126
+ flex-direction: row;
127
+ justify-content: center;
128
+ align-items: center;
129
+ padding: 0 8px;
130
+ gap: 6px;
131
+ height: 24px;
132
+ background: #14151A;
133
+ box-shadow: 0px 0.4px 1px rgba(18, 18, 105, 0.13), 0px 0.9px 6px rgba(18, 18, 105, 0.05), 0px 1px 3px rgba(18, 18, 105, 0.05);
134
+ border-radius: 4px;
135
+ border: none;
136
+ cursor: pointer;
137
+ font-weight: 500;
138
+ font-size: 13px;
139
+ line-height: 16px;
140
+ letter-spacing: -0.005em;
141
+ font-feature-settings: 'tnum' on, 'lnum' on;
142
+ color: #ffffff;
143
+ white-space: nowrap;
144
+ flex-shrink: 0;
145
+ }
146
+
147
+ .cio-asa-welcome-screen__send-btn:hover {
148
+ background: #333;
149
+ }
150
+
151
+ .cio-asa-welcome-screen__suggestions {
152
+ display: grid;
153
+ grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
154
+ column-gap: 16px;
155
+ row-gap: 11px;
156
+ width: 100%;
157
+ margin-top: 20px;
158
+ animation: cio-asa-fade-in 0.5s ease 0.5s both;
159
+ }
160
+
161
+ .cio-asa-welcome-screen__suggestion-chip {
162
+ display: flex;
163
+ flex-direction: column;
164
+ justify-content: center;
165
+ align-items: center;
166
+ padding: 18px 16px;
167
+ background: #ffffff;
168
+ box-shadow: 0px 0.4px 1px rgba(18, 18, 105, 0.13), 0px 0.9px 6px rgba(18, 18, 105, 0.05), 0px 1px 3px rgba(18, 18, 105, 0.05);
169
+ border-radius: 12px;
170
+ border: 1px solid transparent;
171
+ cursor: pointer;
172
+ font-weight: 400;
173
+ font-size: 12px;
174
+ line-height: 20px;
175
+ text-align: center;
176
+ color: #343434;
177
+ box-sizing: border-box;
178
+ transition: background-color 0.2s, box-shadow 0.2s, border-color 0.2s;
179
+ }
180
+
181
+ .cio-asa-welcome-screen__suggestion-chip:hover {
182
+ background: #ffffff;
183
+ border-color: #ffffff;
184
+ box-shadow: 0px 6px 14px rgba(18, 18, 105, 0.11), 0px 2px 4px rgba(18, 18, 105, 0.0716748), 0px 1px 2px rgba(18, 18, 105, 0.055);
185
+ }
186
+
187
+ .cio-asa-welcome-screen__suggestion-chip:active {
188
+ background: #E0E3EB;
189
+ border-color: #DEE0E3;
190
+ box-shadow: inset 1px 1px 2px rgba(18, 18, 105, 0.1), inset 0px 1px 4px rgba(18, 18, 105, 0.05), inset 1px 1px 1px rgba(18, 18, 105, 0.05);
191
+ }
192
+
193
+ .cio-asa-welcome-screen__terms {
194
+ font-size: 11px;
195
+ color: #999;
196
+ text-align: center;
197
+ padding-top: 16px;
198
+ max-width: 504px;
199
+ margin: 0 auto;
200
+ }
201
+
202
+ .cio-asa-welcome-screen__terms a {
203
+ color: #666;
204
+ text-decoration: underline;
205
+ }
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import { RenderPropsWrapper } from '@constructor-io/constructorio-ui-components';
3
+ import { SendPlaneIcon } from '../icons';
4
+ import translate from '../../utils/translate';
5
+ import useMessageInput from '../../hooks/useMessageInput';
6
+ const DEFAULT_SUGGESTIONS = [];
7
+ export default function WelcomeScreen({ suggestions = DEFAULT_SUGGESTIONS, onSend, onClose, termsText, disabled = false, translations, componentOverrides, }) {
8
+ const { value: inputValue, setValue: setInputValue, handleSubmit, handleKeyDown, } = useMessageInput({ onSend, isDisabled: disabled });
9
+ const titleRenderProps = {
10
+ text: translate('CioAsa.welcome.title', translations),
11
+ };
12
+ const inputRenderProps = {
13
+ value: inputValue,
14
+ onChange: setInputValue,
15
+ onSubmit: handleSubmit,
16
+ placeholder: translate('CioAsa.welcome.placeholder', translations),
17
+ isDisabled: disabled,
18
+ };
19
+ const suggestionsRenderProps = {
20
+ suggestions,
21
+ onSuggestionClick: onSend,
22
+ };
23
+ return (React.createElement("div", { className: 'cio-asa-welcome-screen' },
24
+ onClose && (React.createElement("button", { type: 'button', className: 'cio-asa-welcome-screen__close', onClick: onClose, "aria-label": translate('CioAsa.header.close', translations) }, "\u2715")),
25
+ React.createElement("div", { className: 'cio-asa-welcome-screen__content' },
26
+ React.createElement(RenderPropsWrapper, { override: componentOverrides?.title?.reactNode, props: titleRenderProps },
27
+ React.createElement("h2", { id: 'cio-asa-chat-title', className: 'cio-asa-welcome-screen__title' }, titleRenderProps.text)),
28
+ React.createElement(RenderPropsWrapper, { override: componentOverrides?.input?.reactNode, props: inputRenderProps },
29
+ React.createElement("div", { className: `cio-asa-welcome-screen__input-row${disabled ? ' cio-asa-welcome-screen__input-row--disabled' : ''}` },
30
+ React.createElement("input", { type: 'text', className: 'cio-asa-welcome-screen__input', value: inputValue, onChange: (e) => setInputValue(e.target.value), onKeyDown: handleKeyDown, placeholder: inputRenderProps.placeholder, disabled: disabled, "aria-label": translate('CioAsa.welcome.inputAriaLabel', translations) }),
31
+ React.createElement("button", { type: 'button', className: 'cio-asa-welcome-screen__send-btn', onClick: handleSubmit, disabled: disabled || !inputValue.trim(), "aria-label": translate('CioAsa.welcome.sendAriaLabel', translations) },
32
+ translate('CioAsa.welcome.sendButton', translations),
33
+ React.createElement(SendPlaneIcon, null)))),
34
+ suggestions.length > 0 && (React.createElement(RenderPropsWrapper, { override: componentOverrides?.suggestedQuestions?.reactNode, props: suggestionsRenderProps },
35
+ React.createElement("nav", { className: 'cio-asa-welcome-screen__suggestions', "aria-label": translate('CioAsa.welcome.suggestionsAriaLabel', translations) }, suggestions.map((suggestion) => (React.createElement("button", { key: suggestion, type: 'button', className: 'cio-asa-welcome-screen__suggestion-chip', disabled: disabled, onClick: () => onSend(suggestion) }, suggestion))))))),
36
+ termsText && React.createElement("div", { className: 'cio-asa-welcome-screen__terms' }, termsText)));
37
+ }
38
+ WelcomeScreen.displayName = 'WelcomeScreen';
@@ -0,0 +1,19 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import useCioClient from '../../hooks/useCioClient';
3
+ import { AsaContext } from '../../hooks/useCioAsaContext';
4
+ import * as defaultFormatters from '../../utils/formatters';
5
+ import * as defaultUrlHelpers from '../../utils/urlHelpers';
6
+ export default function CioAsaProvider(props) {
7
+ const { apiKey, formatters, urlHelpers, staticRequestConfigs = { domain: 'chatbot' }, cioClient: customCioClient, children, } = props;
8
+ const [cioClientOptions, setCioClientOptions] = useState({});
9
+ const cioClient = useCioClient({ apiKey, cioClient: customCioClient, cioClientOptions });
10
+ const contextValue = useMemo(() => ({
11
+ cioClient,
12
+ cioClientOptions,
13
+ setCioClientOptions,
14
+ staticRequestConfigs,
15
+ formatters: { ...defaultFormatters, ...formatters },
16
+ urlHelpers: { ...defaultUrlHelpers, ...urlHelpers },
17
+ }), [cioClient, cioClientOptions, formatters, urlHelpers, staticRequestConfigs]);
18
+ return (React.createElement(AsaContext.Provider, { value: contextValue }, typeof children === 'function' ? children(contextValue) : children));
19
+ }
@@ -0,0 +1,217 @@
1
+ .cio-asa-results-block {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 20px;
5
+ width: 100%;
6
+ }
7
+
8
+ .cio-asa-results-group {
9
+ display: flex;
10
+ flex-direction: column;
11
+ gap: 12px;
12
+ }
13
+
14
+ .cio-asa-results-group__label {
15
+ font-size: 14px;
16
+ font-weight: 600;
17
+ color: #1a1a1a;
18
+ margin: 0;
19
+ }
20
+
21
+ /* Product Card - override ui-components defaults */
22
+ .cio-asa-product-card.cio-product-card {
23
+ display: flex;
24
+ flex-direction: column;
25
+ gap: 6px;
26
+ cursor: pointer;
27
+ width: 100%;
28
+ height: 100%;
29
+ min-width: unset;
30
+ max-width: unset;
31
+ border: none;
32
+ border-radius: 0;
33
+ box-shadow: none;
34
+ padding: 0;
35
+ background: transparent;
36
+ }
37
+
38
+ .cio-asa-product-card .cio-asa-product-card__image-wrapper.cio-product-card-image-section {
39
+ position: relative;
40
+ width: 100%;
41
+ aspect-ratio: var(--cio-asa-image-ratio, 3 / 4);
42
+ border-radius: 6px;
43
+ overflow: hidden;
44
+ background-color: #f3f4f6;
45
+ flex-shrink: 0;
46
+ }
47
+
48
+ .cio-asa-product-card .cio-asa-product-card__image-wrapper .cio-product-card-image {
49
+ width: 100%;
50
+ height: 100%;
51
+ object-fit: cover;
52
+ display: block;
53
+ min-height: unset;
54
+ border-radius: 0;
55
+ }
56
+
57
+ .cio-asa-product-card .cio-asa-product-card__badge {
58
+ position: absolute;
59
+ top: 8px;
60
+ left: 8px;
61
+ display: flex;
62
+ justify-content: center;
63
+ align-items: center;
64
+ padding: 0 4px;
65
+ min-width: 35px;
66
+ max-width: 120px;
67
+ height: 20px;
68
+ background: #dc2626;
69
+ color: #fff;
70
+ font-size: 13px;
71
+ font-weight: 500;
72
+ line-height: 16px;
73
+ text-align: center;
74
+ letter-spacing: -0.005em;
75
+ border-radius: 4px;
76
+ border: none;
77
+ z-index: 1;
78
+ overflow: hidden;
79
+ text-overflow: ellipsis;
80
+ white-space: nowrap;
81
+ }
82
+
83
+ .cio-asa-product-card .cio-asa-product-card__info.cio-product-card-content {
84
+ display: flex;
85
+ flex-direction: column;
86
+ gap: 2px;
87
+ flex: 1;
88
+ padding: 0;
89
+ }
90
+
91
+ .cio-asa-product-card .cio-asa-product-card__name.cio-product-card-title-section {
92
+ font-size: 12px;
93
+ line-height: 1.3;
94
+ color: #1a1a1a;
95
+ display: -webkit-box;
96
+ -webkit-line-clamp: 2;
97
+ -webkit-box-orient: vertical;
98
+ overflow: hidden;
99
+ margin: 0;
100
+ min-height: calc(2 * 12px * 1.3);
101
+ }
102
+
103
+ .cio-asa-product-card__description {
104
+ font-size: 11px;
105
+ line-height: 1.3;
106
+ color: #6b7280;
107
+ display: -webkit-box;
108
+ -webkit-line-clamp: 2;
109
+ -webkit-box-orient: vertical;
110
+ overflow: hidden;
111
+ }
112
+
113
+ .cio-asa-product-card .cio-asa-product-card__price.cio-product-card-price-section {
114
+ display: flex;
115
+ align-items: baseline;
116
+ gap: 4px;
117
+ }
118
+
119
+ .cio-asa-product-card .cio-asa-product-card__price.cio-product-card-price-section span {
120
+ word-spacing: -1ch;
121
+ }
122
+
123
+ /* Sale price (rendered first by library, displayed second) */
124
+ .cio-asa-product-card .cio-asa-product-card__price.cio-product-card-price-section span:first-child {
125
+ font-size: 14px;
126
+ font-weight: 700;
127
+ color: #1a1a1a;
128
+ }
129
+
130
+ .cio-asa-product-card .cio-asa-product-card__price.cio-product-card-price-section span:first-child:not(:only-child) {
131
+ color: #dc2626;
132
+ order: 2;
133
+ }
134
+
135
+ /* Original price (rendered second by library, displayed first) */
136
+ .cio-asa-product-card .cio-asa-product-card__price.cio-product-card-price-section span:last-child:not(:first-child) {
137
+ font-size: 12px;
138
+ color: #9ca3af;
139
+ text-decoration: line-through;
140
+ font-weight: normal;
141
+ order: 1;
142
+ }
143
+
144
+ /* Carousel overrides */
145
+ .cio-asa-results-group [data-slot="carousel-content"] {
146
+ padding: 0 !important;
147
+ }
148
+
149
+ .cio-asa-results-group [data-slot="carousel-item"] {
150
+ min-width: 0 !important;
151
+ align-self: stretch;
152
+ }
153
+
154
+ .cio-asa-results-group [data-slot="carousel-track"] {
155
+ padding-left: 0 !important;
156
+ }
157
+
158
+ /* Add to Cart (per card) */
159
+ .cio-asa-product-card .cio-asa-product-card__add-to-cart.cio-product-card-add-to-cart-btn {
160
+ display: flex;
161
+ flex-direction: row;
162
+ align-items: center;
163
+ justify-content: center;
164
+ gap: 10px;
165
+ padding: 6px 12px;
166
+ font-size: 14px;
167
+ font-weight: 500;
168
+ line-height: 16px;
169
+ letter-spacing: -0.005em;
170
+ color: #14151A;
171
+ background: #f3f4f6;
172
+ border: 1px solid #e5e7eb;
173
+ border-radius: 8px;
174
+ cursor: pointer;
175
+ width: 100%;
176
+ margin-top: auto;
177
+ padding-top: 4px;
178
+ transition: background-color 0.15s;
179
+ }
180
+
181
+ .cio-asa-product-card .cio-asa-product-card__add-to-cart.cio-product-card-add-to-cart-btn::before {
182
+ content: '';
183
+ display: inline-block;
184
+ width: 16px;
185
+ height: 16px;
186
+ flex-shrink: 0;
187
+ background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11.0311 8.66659C11.5311 8.66659 11.9711 8.39325 12.1977 7.97992L14.5844 3.65325C14.8311 3.21325 14.5111 2.66659 14.0044 2.66659H4.13772L3.51105 1.33325H1.33105V2.66659H2.66439L5.06439 7.72659L4.16439 9.35325C3.67772 10.2466 4.31772 11.3333 5.33105 11.3333H13.3311V9.99992H5.33105L6.06439 8.66659H11.0311ZM4.77105 3.99992H12.8711L11.0311 7.33325H6.35105L4.77105 3.99992ZM5.33105 11.9999C4.59772 11.9999 4.00439 12.5999 4.00439 13.3333C4.00439 14.0666 4.59772 14.6666 5.33105 14.6666C6.06439 14.6666 6.66439 14.0666 6.66439 13.3333C6.66439 12.5999 6.06439 11.9999 5.33105 11.9999ZM11.9977 11.9999C11.2644 11.9999 10.6711 12.5999 10.6711 13.3333C10.6711 14.0666 11.2644 14.6666 11.9977 14.6666C12.7311 14.6666 13.3311 14.0666 13.3311 13.3333C13.3311 12.5999 12.7311 11.9999 11.9977 11.9999Z' fill='%230F1324' fill-opacity='0.6'/%3E%3C/svg%3E");
188
+ background-repeat: no-repeat;
189
+ background-size: 16px 16px;
190
+ }
191
+
192
+ .cio-asa-product-card .cio-asa-product-card__add-to-cart.cio-product-card-add-to-cart-btn:hover {
193
+ background: #e5e7eb;
194
+ color: #14151A;
195
+ }
196
+
197
+ /* View More */
198
+ .cio-asa-results-group__view-more {
199
+ display: inline-flex;
200
+ align-items: center;
201
+ gap: 11px;
202
+ font-size: 13px;
203
+ color: #1a1a1a;
204
+ text-decoration: none;
205
+ cursor: pointer;
206
+ background: none;
207
+ border: none;
208
+ padding: 0;
209
+ font-family: inherit;
210
+ width: fit-content;
211
+ }
212
+
213
+ .cio-asa-results-group__view-more-text {
214
+ text-decoration: none;
215
+ border-bottom: 1px solid currentColor;
216
+ line-height: 1.2;
217
+ }
@@ -0,0 +1,76 @@
1
+ import React, { useRef, useState, useEffect } from 'react';
2
+ import { Carousel, RenderPropsWrapper } from '@constructor-io/constructorio-ui-components';
3
+ import { normalizeItemToProduct } from '../../utils/productNormalizer';
4
+ import { ArrowRightIcon } from '../icons';
5
+ import { PEEK_FRACTION, aspectRatioMap } from './constants';
6
+ import createProductCardRenderer from './renderProductCard';
7
+ import './ResultsBlock.css';
8
+ function PreviousButton() {
9
+ return null;
10
+ }
11
+ function NextButton() {
12
+ return null;
13
+ }
14
+ function ResultsBlock({ groups, aspectRatio = '3:4', minCardWidth = 150, gap = 12, showTitle = true, viewMoreText = 'View more products', addToCartText = 'Add to cart', saleBadgeText = 'Sale', currency, normalizeItem = normalizeItemToProduct, onProductClick, onAddToCart, onViewMore, componentOverrides, }) {
15
+ const containerRef = useRef(null);
16
+ const [slidesToShow, setSlidesToShow] = useState(3 + PEEK_FRACTION);
17
+ useEffect(() => {
18
+ const el = containerRef.current;
19
+ if (!el)
20
+ return undefined;
21
+ const compute = () => {
22
+ const width = el.clientWidth;
23
+ const count = Math.max(1, Math.floor(width / (minCardWidth + gap)));
24
+ setSlidesToShow(count + PEEK_FRACTION);
25
+ };
26
+ compute();
27
+ if (typeof ResizeObserver === 'undefined')
28
+ return undefined;
29
+ const ro = new ResizeObserver(compute);
30
+ ro.observe(el);
31
+ return () => ro.disconnect();
32
+ }, [minCardWidth, gap]);
33
+ if (!groups || groups.length === 0)
34
+ return null;
35
+ const renderProductCard = createProductCardRenderer({
36
+ currency,
37
+ addToCartText,
38
+ onProductClick,
39
+ onAddToCart,
40
+ componentOverrides: componentOverrides?.carousel?.item?.productCard,
41
+ });
42
+ return (React.createElement("div", { ref: containerRef, className: 'cio-asa-results-block', style: { '--cio-asa-image-ratio': aspectRatioMap[aspectRatio] } }, groups.map((groupData, index) => {
43
+ const label = groupData.group?.display_name || groupData.group?.value || '';
44
+ const groupKey = `${groupData.group?.value || label}-${index}`;
45
+ const products = groupData.searchResults.map((item) => normalizeItem(item, { saleBadgeText }));
46
+ const titleRenderProps = { label };
47
+ const viewMoreRenderProps = {
48
+ group: groupData.group,
49
+ onClick: () => onViewMore?.(groupData.group),
50
+ };
51
+ const userCarousel = componentOverrides?.carousel;
52
+ const carouselOverrides = {
53
+ previous: { reactNode: PreviousButton },
54
+ next: { reactNode: NextButton },
55
+ ...userCarousel,
56
+ item: {
57
+ ...userCarousel?.item,
58
+ productCard: {
59
+ reactNode: renderProductCard,
60
+ },
61
+ },
62
+ };
63
+ return (React.createElement("div", { className: 'cio-asa-results-group', key: groupKey },
64
+ showTitle && label && (React.createElement(RenderPropsWrapper, { override: componentOverrides?.groupTitle?.reactNode, props: titleRenderProps },
65
+ React.createElement("h3", { className: 'cio-asa-results-group__label' }, label))),
66
+ React.createElement(Carousel, { items: products, loop: false, responsive: {
67
+ 0: { gap, slidesToShow },
68
+ }, componentOverrides: carouselOverrides }),
69
+ onViewMore && (React.createElement(RenderPropsWrapper, { override: componentOverrides?.viewMore?.reactNode, props: viewMoreRenderProps },
70
+ React.createElement("button", { type: 'button', className: 'cio-asa-results-group__view-more', onClick: () => onViewMore(groupData.group) },
71
+ React.createElement("span", { className: 'cio-asa-results-group__view-more-text' }, viewMoreText),
72
+ React.createElement(ArrowRightIcon, null))))));
73
+ })));
74
+ }
75
+ ResultsBlock.displayName = 'ResultsBlock';
76
+ export default ResultsBlock;
@@ -0,0 +1,8 @@
1
+ export const PEEK_FRACTION = 0.3;
2
+ export const aspectRatioMap = {
3
+ '1:1': '1 / 1',
4
+ '3:4': '3 / 4',
5
+ '9:16': '9 / 16',
6
+ '4:3': '4 / 3',
7
+ '16:9': '16 / 9',
8
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { ProductCard } from '@constructor-io/constructorio-ui-components';
3
+ import { PLACEHOLDER_IMAGE } from '../../constants';
4
+ export default function createProductCardRenderer({ currency, addToCartText, onProductClick, onAddToCart, componentOverrides, }) {
5
+ const handleAddToCart = onAddToCart
6
+ ? (_e, product) => onAddToCart(product)
7
+ : undefined;
8
+ return function renderProductCard(renderProps) {
9
+ const product = renderProps.product;
10
+ return (React.createElement(ProductCard, { product: product, className: 'cio-asa-product-card', onProductClick: onProductClick, onAddToCart: handleAddToCart, addToCartText: addToCartText, componentOverrides: componentOverrides },
11
+ React.createElement(ProductCard.ImageSection, { className: 'cio-asa-product-card__image-wrapper', imageUrl: product.imageUrl || PLACEHOLDER_IMAGE }, product.badge && React.createElement("span", { className: 'cio-asa-product-card__badge' }, product.badge)),
12
+ React.createElement(ProductCard.Content, { className: 'cio-asa-product-card__info' },
13
+ React.createElement(ProductCard.TitleSection, { className: 'cio-asa-product-card__name' }),
14
+ currency && (React.createElement(ProductCard.PriceSection, { className: 'cio-asa-product-card__price', priceCurrency: currency })),
15
+ onAddToCart && (React.createElement(ProductCard.AddToCartButton, { className: 'cio-asa-product-card__add-to-cart' })))));
16
+ };
17
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export default function ArrowRightIcon() {
3
+ return (React.createElement("svg", { width: '10', height: '10', viewBox: '0 0 10 10', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
4
+ React.createElement("path", { fillRule: 'evenodd', clipRule: 'evenodd', d: 'M8.25979 4.20698L4.63903 0.72032L5.33267 -1.97313e-07L9.84668 4.34682L9.84668 5.06714L5.33267 9.41396L4.63903 8.69364L8.25979 5.20698L-0.000141371 5.20698L-0.000141328 4.20698L8.25979 4.20698Z', fill: 'currentColor' })));
5
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export default function ChatBubbleDarkIcon() {
3
+ return (React.createElement("svg", { className: 'cio-asa-button__icon', width: '14', height: '14', viewBox: '0 0 14 14', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-hidden": 'true' },
4
+ React.createElement("path", { d: 'M12.667 3.16699C12.7573 3.16717 12.8328 3.24274 12.833 3.33301V12.126L10.874 10.167H3.33301C3.24263 10.1668 3.16699 10.0904 3.16699 10V9.16699H11.833V3.16699H12.667ZM0.666992 0.5H9.33301C9.42353 0.5 9.5 0.576467 9.5 0.666992V6.66699C9.49982 6.75737 9.42342 6.83301 9.33301 6.83301H2.45996L0.5 8.79297V0.666992C0.5 0.576468 0.576468 0.5 0.666992 0.5ZM0.833008 7.9873L2.32031 6.5H9.16699V0.833008H0.833008V7.9873Z', fill: 'white', stroke: 'white' })));
5
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export default function ChatBubbleLightIcon() {
3
+ return (React.createElement("svg", { className: 'cio-asa-button__icon', width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-hidden": 'true' },
4
+ React.createElement("path", { d: 'M14 4.50024C14.0903 4.50043 14.1658 4.57599 14.166 4.66626V13.4592L12.207 11.5002H4.66602C4.57563 11.5001 4.5 11.4237 4.5 11.3333V10.5002H13.166V4.50024H14ZM2 1.83325H10.666C10.7565 1.83325 10.833 1.90972 10.833 2.00024V8.00024C10.8328 8.09063 10.7564 8.16626 10.666 8.16626H3.79297L1.83301 10.1262V2.00024C1.83301 1.90972 1.90948 1.83325 2 1.83325ZM2.16602 9.32056L3.65332 7.83325H10.5V2.16626H2.16602V9.32056Z', fill: 'black', stroke: 'black' })));
5
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export default function SendArrowIcon() {
3
+ return (React.createElement("svg", { width: '10', height: '11', viewBox: '0 0 10 11', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-hidden": 'true' },
4
+ React.createElement("path", { d: 'M0.5 5L5 0.5L9.5 5M5 1.125V10.25', stroke: '#0F1324', strokeOpacity: '0.7', strokeLinecap: 'round', strokeLinejoin: 'round' })));
5
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export default function SendPlaneIcon() {
3
+ return (React.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-hidden": 'true' },
4
+ React.createElement("path", { d: 'M14.8934 7.09539L14.8884 7.0932L1.54219 1.55758C1.42993 1.51059 1.30778 1.49217 1.18666 1.50395C1.06554 1.51573 0.949225 1.55734 0.848125 1.62508C0.741311 1.69507 0.653573 1.79052 0.592805 1.90283C0.532037 2.01515 0.500145 2.14081 0.5 2.26852V5.80883C0.50006 5.98341 0.561019 6.15249 0.67237 6.28695C0.783722 6.4214 0.938491 6.5128 1.11 6.54539L8.38906 7.89133C8.41767 7.89675 8.44348 7.91199 8.46205 7.93441C8.48062 7.95683 8.49078 7.98503 8.49078 8.01414C8.49078 8.04325 8.48062 8.07145 8.46205 8.09387C8.44348 8.11629 8.41767 8.13153 8.38906 8.13695L1.11031 9.48289C0.938851 9.51539 0.784092 9.60667 0.67269 9.741C0.561288 9.87534 0.500219 10.0443 0.5 10.2188V13.7598C0.499917 13.8817 0.530111 14.0018 0.587871 14.1092C0.645632 14.2166 0.729152 14.3079 0.830938 14.3751C0.953375 14.4564 1.09706 14.4999 1.24406 14.5001C1.34626 14.5 1.4474 14.4795 1.54156 14.4398L14.8875 8.9357L14.8934 8.93289C15.0731 8.85569 15.2262 8.72751 15.3337 8.56421C15.4413 8.40092 15.4986 8.20968 15.4986 8.01414C15.4986 7.81861 15.4413 7.62736 15.3337 7.46407C15.2262 7.30077 15.0731 7.1726 14.8934 7.09539Z', fill: 'white' })));
5
+ }
@@ -0,0 +1,5 @@
1
+ export { default as ChatBubbleDarkIcon } from './ChatBubbleDarkIcon';
2
+ export { default as ChatBubbleLightIcon } from './ChatBubbleLightIcon';
3
+ export { default as SendArrowIcon } from './SendArrowIcon';
4
+ export { default as SendPlaneIcon } from './SendPlaneIcon';
5
+ export { default as ArrowRightIcon } from './ArrowRightIcon';
@@ -0,0 +1,3 @@
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export const DEMO_API_KEY = 'key_fygjntHGW7usvxC8';
3
+ export const PLACEHOLDER_IMAGE = "data:image/svg+xml,%3Csvg width='200' height='200' viewBox='0 0 200 200' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='200' height='200' rx='12' fill='%23F3F4F6'/%3E%3Crect x='0.5' y='0.5' width='199' height='199' rx='11.5' stroke='%23E5E7EB'/%3E%3C/svg%3E";
@@ -0,0 +1,39 @@
1
+ function updateMessageById(setMessages, id, patch) {
2
+ setMessages((prev) => prev.map((msg) => (msg.id === id ? patch(msg) : msg)));
3
+ }
4
+ export function handleSearchResult(data, pendingGroup, assistantId, setMessages) {
5
+ const resolvedGroup = pendingGroup ?? {
6
+ display_name: data?.response?.search_request?.display_name ?? data?.title ?? '',
7
+ value: data?.response?.search_request?.search_term ?? data?.title ?? '',
8
+ };
9
+ const results = data?.response?.results ?? (data?.results ? data.results : [data]);
10
+ const newGroup = { group: resolvedGroup, searchResults: results };
11
+ updateMessageById(setMessages, assistantId, (msg) => ({
12
+ ...msg,
13
+ status: 'streaming',
14
+ groups: [...(msg.groups || []), newGroup],
15
+ }));
16
+ return null;
17
+ }
18
+ export function handleMessage(data, assistantId, setMessages) {
19
+ updateMessageById(setMessages, assistantId, (msg) => ({
20
+ ...msg,
21
+ status: 'streaming',
22
+ text: (msg.text || '') + (data?.text || ''),
23
+ }));
24
+ }
25
+ export function handleServerError(assistantId, setMessages) {
26
+ updateMessageById(setMessages, assistantId, (msg) => ({
27
+ ...msg,
28
+ status: 'error',
29
+ }));
30
+ }
31
+ export function handleStreamEnd(assistantId, setMessages) {
32
+ updateMessageById(setMessages, assistantId, (msg) => ({ ...msg, status: 'done' }));
33
+ }
34
+ export function handleStreamError(assistantId, setMessages) {
35
+ updateMessageById(setMessages, assistantId, (msg) => ({
36
+ ...msg,
37
+ status: 'error',
38
+ }));
39
+ }