@telia-ace/widget-conversation 1.1.2-rc.4 → 1.1.2-rc.6

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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),i=require("@emotion/styled"),n=require("@telia-ace/widget-ui"),C=require("@telia-ace/widget-utilities"),f=require("@emotion/react"),h=require("react"),Q=require("@telia-ace/widget-forms"),$=require("./index.js");require("@telia-ace/widget-core");require("@telia-ace/widget-services");require("@telia-ace/widget-plugins");const X=({className:t})=>{const[e,r]=h.useState(""),[o,a]=h.useState(!1),[l,d]=h.useState(0),[m,u]=h.useState(0),b=n.useIsTabbing(),p=n.useDispatch(),{inputPlaceholder:c="Type your message",inputHidden:g=!1,inputDisabled:j=!1,sendButtonLabel:L="Send message",inputMultiline:S=!0,secondaryAction:x}=n.useProperties(),[z,v]=n.useScroll(!0);h.useEffect(()=>{if(v.current){const{lineHeight:y,maxHeight:T}=getComputedStyle(v.current);if(y&&y.indexOf("px")>-1){const k=y.split("px"),G=parseInt(k[0],10);d(G);const J=T.split("px");u(parseInt(J[0],10))}}},[v.current]);const M=y=>{!y.shiftKey||!S?(y.preventDefault(),e&&e.length>0&&(p("user-submit",{text:e}),r(""),B(""))):e.length<1&&y.preventDefault()},_=y=>{x&&(y.preventDefault(),p("action",{actionKey:x.action,...x}))},Y=y=>{if(S&&v.current){const T=v.current.scrollHeight;if(T>l){v.current.style.height="auto";let k=T;y.length<1&&(k=l),v.current.style.height=`${k}px`,k>=m?v.current.style.overflowY="scroll":v.current.style.overflowY="hidden"}}},B=y=>{Y(y),r(y),y&&y.length>0&&p("user-typing",{textLength:y.length})};return g?null:s.jsxs(se,{grow:S,className:C.appendClassNames("humany-conversation-input",t),"data-has-focus":o,scrollableCss:z,isTabbing:b,children:[x&&s.jsx(te,{disabled:j,onClick:_,title:x.label,"aria-label":x.label,children:s.jsx(n.SymbolBadge,{size:24,symbol:{type:"Svg",content:x.icon||"browse"}})}),S?s.jsx(Z,{value:e,onChange:B,onEnter:M,disabled:j,"aria-label":c,placeholder:c,onFocusChange:a,type:"textarea",rows:1,ref:v}):s.jsx(ee,{value:e,onChange:B,onEnter:M,disabled:j,"aria-label":c,placeholder:c,onFocusChange:a}),s.jsx(F,{disabled:!1,onClick:M,title:L,"aria-label":L,children:s.jsx(ne,{size:22,symbol:{type:"Svg",content:"send"},hasContent:!!e&&!!e.length})})]})},Z=i(n.Input)`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),i=require("@emotion/styled"),n=require("@telia-ace/widget-ui"),C=require("@telia-ace/widget-utilities"),b=require("@emotion/react"),y=require("react"),G=require("@telia-ace/widget-forms"),v=require("./index.js");require("@telia-ace/widget-core");require("@telia-ace/widget-services");require("@telia-ace/widget-plugins");const J=({className:t})=>{const[e,r]=y.useState(""),[o,a]=y.useState(0),[l,d]=y.useState(0),m=n.useIsTabbing(),u=n.useDispatch(),{inputPlaceholder:f="Type your message",inputHidden:j=!1,inputDisabled:c=!1,sendButtonLabel:h="Send message",inputMultiline:x=!0,secondaryAction:$}=n.useProperties(),[L,p]=n.useScroll(!0);y.useEffect(()=>{if(p.current){const{lineHeight:g,maxHeight:z}=getComputedStyle(p.current);if(g&&g.indexOf("px")>-1){const k=g.split("px"),_=parseInt(k[0],10);a(_);const Y=z.split("px");d(parseInt(Y[0],10))}}},[p.current]);const w=g=>{!g.shiftKey||!x?(g.preventDefault(),e&&e.length>0&&(u("user-submit",{text:e}),r(""),I(""))):e.length<1&&g.preventDefault()},U=g=>{$&&(g.preventDefault(),u("action",{actionKey:$.action,...$}))},V=g=>{if(x&&p.current){const z=p.current.scrollHeight;if(z>o){p.current.style.height="auto";let k=z;g.length<1&&(k=o),p.current.style.height=`${k}px`,k>=l?p.current.style.overflowY="scroll":p.current.style.overflowY="hidden"}}},I=g=>{V(g),r(g),g&&g.length>0&&u("user-typing",{textLength:g.length})};return j?null:s.jsxs(ee,{grow:x,className:C.appendClassNames("humany-conversation-input",t),scrollableCss:L,isTabbing:m,children:[$&&s.jsx(Z,{disabled:c,onClick:U,title:$.label,"aria-label":$.label,children:s.jsx(n.SymbolBadge,{size:24,symbol:{type:"Svg",content:$.icon||"browse"}})}),x?s.jsx(Q,{value:e,onChange:I,onEnter:w,disabled:c,"aria-label":f,placeholder:f,type:"textarea",rows:1,ref:p}):s.jsx(X,{value:e,onChange:I,onEnter:w,disabled:c,"aria-label":f,placeholder:f}),s.jsx(P,{disabled:!1,onClick:w,title:h,"aria-label":h,children:s.jsx(te,{size:22,symbol:{type:"Svg",content:"send"},hasContent:!!e&&!!e.length})})]})},Q=i(n.Input)`
2
2
  resize: none;
3
3
  flex: 1;
4
4
  flex-shrink: 1;
@@ -12,7 +12,11 @@
12
12
  border: none;
13
13
  transition: height 200ms linear;
14
14
  outline: none;
15
- `,ee=i(n.Input)`
15
+ &:focus-visible {
16
+ ${n.borderTabStyle};
17
+ outline-offset: 12px;
18
+ }
19
+ `,X=i(n.Input)`
16
20
  flex: 1;
17
21
  border: none;
18
22
  background-color: transparent;
@@ -26,7 +30,7 @@
26
30
  color: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.textLight}};
27
31
  font-style: italic;
28
32
  }
29
- `,F=i(n.Button)`
33
+ `,P=i(n.Button)`
30
34
  flex: 0 0 50px;
31
35
  align-self: stretch;
32
36
  background-color: transparent;
@@ -38,14 +42,14 @@
38
42
  &:focus-visible {
39
43
  ${n.borderTabStyle};
40
44
  }
41
- `,te=i(F)`
45
+ `,Z=i(P)`
42
46
  border-right: ${t=>t.theme.border};
43
47
  margin: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}} 0;
44
- `,se=i.div`
45
- ${t=>t.grow?f.css`
48
+ `,ee=i.div`
49
+ ${t=>t.grow?b.css`
46
50
  min-height: 50px;
47
51
  max-height: 150px;
48
- `:f.css`
52
+ `:b.css`
49
53
  height: 50px;
50
54
  `}
51
55
  flex: 0 0 auto;
@@ -57,13 +61,13 @@
57
61
  textarea {
58
62
  ${t=>!!t.scrollableCss&&t.scrollableCss}
59
63
  }
60
- `,ne=i(({hasContent:t,...e})=>s.jsx(n.SymbolBadge,{...e}))`
64
+ `,te=i(({hasContent:t,...e})=>s.jsx(n.SymbolBadge,{...e}))`
61
65
  line,
62
66
  path {
63
67
  stroke: ${t=>{var e;return t.hasContent?(e=t.theme.colors)==null?void 0:e.primary:"#a6a6a6"}};
64
68
  fill: ${t=>{var e;return t.hasContent?(e=t.theme.colors)==null?void 0:e.primary:"#a6a6a6"}};
65
69
  }
66
- `,re=i.div`
70
+ `,se=i.div`
67
71
  width: ${t=>t.avatarSize||"32px"};
68
72
  height: ${t=>t.avatarSize||"32px"};
69
73
  border-radius: 50%;
@@ -98,7 +102,7 @@
98
102
  stroke: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.text}};
99
103
  }
100
104
  }
101
- `,oe=f.keyframes`
105
+ `,ne=b.keyframes`
102
106
  0% {
103
107
  opacity: 0;
104
108
  }
@@ -108,7 +112,7 @@
108
112
  100% {
109
113
  opacity: 0;
110
114
  }
111
- `,ae=i.div`
115
+ `,re=i.div`
112
116
  display: flex;
113
117
  justify-content: center;
114
118
  > div {
@@ -117,7 +121,7 @@
117
121
  border-radius: 50%;
118
122
  margin: 5px;
119
123
  background-color: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.text}};
120
- animation: ${oe} 1s infinite;
124
+ animation: ${ne} 1s infinite;
121
125
  }
122
126
  > div:nth-of-type(2) {
123
127
  animation-delay: 100ms;
@@ -125,23 +129,23 @@
125
129
  > div:nth-of-type(3) {
126
130
  animation-delay: 200ms;
127
131
  }
128
- `,R=i.div`
132
+ `,H=i.div`
129
133
  grid-area: content;
130
134
  max-width: 100%;
131
135
  overflow: hidden;
132
- `,ie=i(n.Typography)`
136
+ `,oe=i(n.Typography)`
133
137
  font-size: ${t=>{var e;return(e=t.theme.fonts)==null?void 0:e.normal}};
134
138
  font-weight: normal;
135
139
  margin: 0;
136
- `,O=i.div`
140
+ `,A=i.div`
137
141
  display: flex;
138
142
  ${t=>t.left&&"justify-content: start;"};
139
143
  ${t=>t.center&&"justify-content: center;"};
140
144
  ${t=>t.right&&"justify-content: end;"};
141
- `,K=i.div`
145
+ `,R=i.div`
142
146
  ${t=>{var e;return t.padded&&`padding: ${(e=t.theme.sizes)==null?void 0:e.medium};`}}
143
- ${t=>!t.user&&t.stacked&&le(t.stacked,t.theme)}
144
- ${t=>t.user&&t.stacked&&ce(t.stacked,t.theme)}
147
+ ${t=>!t.user&&t.stacked&&ae(t.stacked,t.theme)}
148
+ ${t=>t.user&&t.stacked&&ie(t.stacked,t.theme)}
145
149
 
146
150
  display: inline-block;
147
151
  margin-top: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}};
@@ -154,11 +158,11 @@
154
158
  }
155
159
  max-width: 100%;
156
160
  ${t=>t.fullWidth&&"width: 100%;"}
157
- `,le=(t,e)=>{var o,a;const r=f.css`
161
+ `,ae=(t,e)=>{var o,a;const r=b.css`
158
162
  background-color: ${(o=e.colors)==null?void 0:o.accent};
159
163
  color: ${(a=e.colors)==null?void 0:a.text};
160
164
  ${e.border&&`border: ${e.border};`};
161
- `;return e.borderRadius?f.css`
165
+ `;return e.borderRadius?b.css`
162
166
  ${r}
163
167
 
164
168
  border-top-right-radius: ${e.borderRadius};
@@ -171,10 +175,10 @@
171
175
  ${t==="last"&&`
172
176
  border-bottom-left-radius: ${e.borderRadius};
173
177
  `}
174
- `:r},ce=(t,e)=>{var o,a;const r=f.css`
178
+ `:r},ie=(t,e)=>{var o,a;const r=b.css`
175
179
  background-color: ${(o=e.colors)==null?void 0:o.primary};
176
180
  color: ${(a=e.colors)==null?void 0:a.accent};
177
- `;return e.borderRadius?f.css`
181
+ `;return e.borderRadius?b.css`
178
182
  ${r}
179
183
 
180
184
  border-top-left-radius: ${e.borderRadius};
@@ -187,15 +191,15 @@
187
191
  ${t==="last"&&`
188
192
  border-bottom-right-radius: ${e.borderRadius};
189
193
  `}
190
- `:r},I=i.div`
194
+ `:r},T=i.div`
191
195
  margin-bottom: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}};
192
196
  &:last-child {
193
197
  margin-bottom: 0;
194
198
  }
195
- `,w=t=>{var e,r;return f.css`
199
+ `,S=t=>{var e,r;return b.css`
196
200
  margin: ${(e=t.theme.sizes)==null?void 0:e.medium} 0;
197
201
  padding: 0 ${(r=t.theme.sizes)==null?void 0:r.medium};
198
- `},de=i(Q.FormComponent)`
202
+ `},le=i(G.FormComponent)`
199
203
  & button.humany-form-component-button {
200
204
  ${t=>{var e,r,o,a;return((e=t.theme.colors)==null?void 0:e.primary)&&((r=t.theme.colors)==null?void 0:r.accent)&&n.invertedHoverButton({active:!1,primaryColor:(o=t.theme.colors)==null?void 0:o.primary,secondaryColor:(a=t.theme.colors)==null?void 0:a.accent,theme:t.theme})}};
201
205
  display: block;
@@ -209,7 +213,7 @@
209
213
  margin-bottom: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}};
210
214
  }
211
215
  }
212
- `,me=i(n.Html)`
216
+ `,ce=i(n.Html)`
213
217
  white-space: pre-wrap;
214
218
  a {
215
219
  color: ${t=>t.theme.colors.link};
@@ -217,14 +221,14 @@
217
221
  ${t=>{var e;return((e=t.theme.accessibility)==null?void 0:e.isTabbing)&&n.borderTabStyle}};
218
222
  }
219
223
  }
220
- `,ue=i(n.List)`
224
+ `,de=i(n.List)`
221
225
  padding: 0;
222
226
  list-style: none;
223
227
  margin: 0 -${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}};
224
228
  > li {
225
229
  margin: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}};
226
230
  }
227
- `,he=i.button`
231
+ `,me=i.button`
228
232
  ${t=>n.buttonCss(t)};
229
233
  display: block;
230
234
  background-color: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.primary}};
@@ -234,7 +238,7 @@
234
238
  ${n.borderTabStyle}
235
239
  background-color: transparent;
236
240
  }
237
- `,D=h.forwardRef(({boxed:t,className:e,agentData:r},o)=>s.jsx(R,{ref:o,children:s.jsx(O,{left:t,center:!t,children:s.jsx(K,{padded:!!t,stacked:t?"first":void 0,children:s.jsxs(ae,{children:[s.jsx("div",{}),s.jsx("div",{}),s.jsx("div",{})]})})})})),W=h.createContext(null),ge=i.p`
241
+ `,K=y.forwardRef(({boxed:t,className:e,agentData:r},o)=>s.jsx(H,{ref:o,children:s.jsx(A,{left:t,center:!t,children:s.jsx(R,{padded:!!t,stacked:t?"first":void 0,children:s.jsxs(re,{children:[s.jsx("div",{}),s.jsx("div",{}),s.jsx("div",{})]})})})})),E=y.createContext(null),ue=i.p`
238
242
  && {
239
243
  font-size: ${t=>{var e;return(e=t.theme.fonts)==null?void 0:e.small}};
240
244
  font-weight: 300;
@@ -243,28 +247,28 @@
243
247
  line-height: 1.5em;
244
248
  grid-area: info;
245
249
  color: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.text}};
246
- `,P=(t,e)=>new Date(t).toLocaleTimeString(e||[],{hour:"2-digit",minute:"2-digit"}),N=({className:t,name:e,timestamp:r})=>{const o=h.useContext(W);if(!e&&!r)return null;let a="";return e?r?a=`${e}: ${P(r,o)}`:a=e:r&&(a=P(r,o)),s.jsx(ge,{children:a})},U=({className:t,children:e,sender:r,timestamp:o})=>{const{avatar:a,name:l}=r,{avatarSize:d}=n.useProperties();return s.jsxs(ye,{hasAvatar:!!a,className:C.appendClassNames(t,"humany-conversation-agent-message"),children:[a&&s.jsx(re,{avatarSize:d,children:typeof a=="string"?s.jsx("img",{src:a}):s.jsx(n.SymbolBadge,{symbol:a})}),e,s.jsx(N,{name:l,timestamp:o})]})},ye=i.div`
250
+ `,q=(t,e)=>new Date(t).toLocaleTimeString(e||[],{hour:"numeric",minute:"2-digit"}),N=({className:t,name:e,timestamp:r})=>{const o=y.useContext(E);if(!e&&!r)return null;let a="";return e?r?a=`${e}: ${q(r,o)}`:a=e:r&&(a=q(r,o)),s.jsx(ue,{children:a})},F=({className:t,children:e,sender:r,timestamp:o})=>{const{avatar:a,name:l}=r,{avatarSize:d}=n.useProperties();return s.jsxs(he,{hasAvatar:!!a,className:C.appendClassNames(t,"humany-conversation-agent-message"),children:[a&&s.jsx(se,{avatarSize:d,children:typeof a=="string"?s.jsx("img",{src:a}):s.jsx(n.SymbolBadge,{symbol:a})}),e,s.jsx(N,{name:l,timestamp:o})]})},he=i.div`
247
251
  display: grid;
248
252
  margin-right: 10%;
249
253
  width: 90%;
250
- ${t=>t.hasAvatar?f.css`
254
+ ${t=>t.hasAvatar?b.css`
251
255
  grid-template-columns: auto 1fr;
252
256
  grid-template-rows: 1fr auto;
253
257
  grid-template-areas:
254
258
  'avatar content'
255
259
  '. info';
256
- `:f.css`
260
+ `:b.css`
257
261
  grid-template-columns: 1fr;
258
262
  grid-template-rows: 1fr auto;
259
263
  grid-template-areas:
260
264
  'content'
261
265
  'info';
262
266
  `};
263
- `,fe=h.forwardRef(({className:t,children:e,timestamp:r,discrete:o,fullWidth:a},l)=>s.jsx(be,{ref:l,className:C.appendClassNames(t,"humany-conversation-system-message"),fullWidth:a,children:o?s.jsxs(pe,{className:"humany-conversation-discrete-message",children:[e,s.jsx(N,{timestamp:r})]}):s.jsxs(s.Fragment,{children:[e,s.jsx(N,{timestamp:r})]})})),be=i.div`
267
+ `,ge=y.forwardRef(({className:t,children:e,timestamp:r,discrete:o,fullWidth:a},l)=>s.jsx(ye,{ref:l,className:C.appendClassNames(t,"humany-conversation-system-message"),fullWidth:a,children:o?s.jsxs(fe,{className:"humany-conversation-discrete-message",children:[e,s.jsx(N,{timestamp:r})]}):s.jsxs(s.Fragment,{children:[e,s.jsx(N,{timestamp:r})]})})),ye=i.div`
264
268
  ${t=>t.fullWidth&&"width: 100%"};
265
269
  padding: 0 ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.large}};
266
270
  overflow: auto;
267
- `,pe=i.div`
271
+ `,fe=i.div`
268
272
  text-align: center;
269
273
  word-wrap: break-word;
270
274
  font-size: ${t=>{var e;return(e=t.theme.fonts)==null?void 0:e.normal}};
@@ -272,13 +276,13 @@
272
276
  > p {
273
277
  margin: 0;
274
278
  }
275
- `,xe=({className:t,children:e,timestamp:r})=>{const{userLabel:o=""}=n.useProperties();return s.jsxs(ve,{className:C.appendClassNames(t,"humany-conversation-user-message"),children:[e,s.jsx(N,{name:o,timestamp:r})]})},ve=i.div`
279
+ `,be=({className:t,children:e,timestamp:r})=>{const{userLabel:o=""}=n.useProperties();return s.jsxs(pe,{className:C.appendClassNames(t,"humany-conversation-user-message"),children:[e,s.jsx(N,{name:o,timestamp:r})]})},pe=i.div`
276
280
  margin-left: 10%;
277
281
  width: 90%;
278
282
  display: flex;
279
283
  flex-direction: column;
280
284
  align-items: flex-end;
281
- `,q=t=>Array.isArray(t)?t:Object.keys(t).map(e=>({label:t[e],actionKey:e})),$e=({header:t,actions:e,dispatch:r})=>s.jsx(je,{className:"humany-conversation-button-list",header:t,items:q(e),renderItem:o=>{var l;const a=!!((l=o==null?void 0:o.data)!=null&&l.href);return s.jsx("li",{children:a?s.jsxs(Se,{onClick:()=>{r("action",o)},href:o.data.href,target:o.data.target,"aria-label":o.label,title:o.label,children:[s.jsx(n.SymbolBadge,{symbol:o.symbol}),o.label]}):s.jsxs(we,{onClick:()=>{r("action",o)},"aria-label":o.label,title:o.label,children:[s.jsx(n.SymbolBadge,{symbol:o.symbol}),o.label]})},o.actionKey)}}),je=i(n.ItemList)`
285
+ `,O=t=>Array.isArray(t)?t:Object.keys(t).map(e=>({label:t[e],actionKey:e})),xe=({header:t,actions:e,dispatch:r})=>s.jsx(ve,{className:"humany-conversation-button-list",header:t,items:O(e),renderItem:o=>{var l;const a=!!((l=o==null?void 0:o.data)!=null&&l.href);return s.jsx("li",{children:a?s.jsxs($e,{onClick:()=>{r("action",o)},href:o.data.href,target:o.data.target,"aria-label":o.label,title:o.label,children:[s.jsx(n.SymbolBadge,{symbol:o.symbol}),o.label]}):s.jsxs(je,{onClick:()=>{r("action",o)},"aria-label":o.label,title:o.label,children:[s.jsx(n.SymbolBadge,{symbol:o.symbol}),o.label]})},o.actionKey)}}),ve=i(n.ItemList)`
282
286
  ${n.itemList}
283
287
  > ul {
284
288
  display: flex;
@@ -288,8 +292,8 @@
288
292
  margin: 0;
289
293
  }
290
294
  }
291
- ${w}
292
- `,Se=i(n.Link)`
295
+ ${S}
296
+ `,$e=i(n.Link)`
293
297
  ${n.buttonCss};
294
298
 
295
299
  display: block;
@@ -308,7 +312,7 @@
308
312
  svg {
309
313
  margin-right: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.small}};
310
314
  }
311
- `,we=i(n.Button)`
315
+ `,je=i(n.Button)`
312
316
  ${n.buttonCss};
313
317
 
314
318
  display: block;
@@ -327,22 +331,22 @@
327
331
  svg {
328
332
  margin-right: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.small}};
329
333
  }
330
- `,Ce=({type:t,content:e={}})=>{const r=n.useComponent(t);return!r||!t?null:s.jsx(h.Suspense,{fallback:null,children:s.jsx(r,{...e})})},ke=({body:t})=>s.jsx(Le,{html:t}),Le=i(n.Html)`
334
+ `,Se=({type:t,content:e={}})=>{const r=n.useComponent(t);return!r||!t?null:s.jsx(y.Suspense,{fallback:null,children:s.jsx(r,{...e})})},we=({body:t})=>s.jsx(Ce,{html:t}),Ce=i(n.Html)`
331
335
  ${n.genericHtml}
332
336
  color: inherit;
333
337
  white-space: pre-wrap;
334
- ${w}
338
+ ${S}
335
339
  a {
336
340
  color: ${t=>t.theme.colors.link};
337
341
  &:focus-visible {
338
342
  ${n.borderTabStyle};
339
343
  }
340
344
  }
341
- `,ze=({header:t,actions:e,dispatch:r})=>s.jsx(Te,{className:"humany-conversation-item-list",header:t,items:q(e),renderItem:o=>{var a;return s.jsx("li",{children:s.jsxs(Ie,{children:[((a=o.symbol)==null?void 0:a.content)&&s.jsx("div",{className:"item-icon",children:s.jsx(n.SymbolBadge,{size:22,symbol:{type:o.symbol.type,content:o.symbol.content}})}),s.jsxs("div",{className:"item-body",children:[s.jsx(n.Button,{onClick:()=>{r("action",o)},"aria-label":o.label,title:o.label,children:o.label}),o.description&&s.jsx("p",{children:o.description})]})]})},o.actionKey)}}),Te=i(n.ItemList)`
345
+ `,ke=({header:t,actions:e,dispatch:r})=>s.jsx(Le,{className:"humany-conversation-item-list",header:t,items:O(e),renderItem:o=>{var a;return s.jsx("li",{children:s.jsxs(ze,{children:[((a=o.symbol)==null?void 0:a.content)&&s.jsx("div",{className:"item-icon",children:s.jsx(n.SymbolBadge,{size:22,symbol:{type:o.symbol.type,content:o.symbol.content}})}),s.jsxs("div",{className:"item-body",children:[s.jsx(n.Button,{onClick:()=>{r("action",o)},"aria-label":o.label,title:o.label,children:o.label}),o.description&&s.jsx("p",{children:o.description})]})]})},o.actionKey)}}),Le=i(n.ItemList)`
342
346
  ${n.itemList}
343
347
 
344
348
  > .humany-paragraph {
345
- ${w}
349
+ ${S}
346
350
  margin-bottom: 0;
347
351
 
348
352
  h1 {
@@ -350,7 +354,7 @@
350
354
  }
351
355
  }
352
356
 
353
- ${t=>n.headingElement(t)("h1",f.css`
357
+ ${t=>n.headingElement(t)("h1",b.css`
354
358
  white-space: normal;
355
359
  `)}
356
360
 
@@ -370,10 +374,10 @@
370
374
  border-bottom: none;
371
375
  }
372
376
  }
373
- `,Ie=i.div`
377
+ `,ze=i.div`
374
378
  display: flex;
375
379
  gap: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.medium}};
376
- ${w}
380
+ ${S}
377
381
 
378
382
  .item-icon {
379
383
  }
@@ -407,11 +411,11 @@
407
411
  }
408
412
  }
409
413
  }
410
- `,Ne=({header:t,actions:e,dispatch:r})=>{const o=n.usePrevious(e),a=h.useRef(),l=n.useIsTabbing();return h.useEffect(()=>{if(o&&Array.isArray(e)&&Array.isArray(o)&&o.length<e.length&&a.current){const d=a.current.querySelectorAll(".humany-conversation-link-list > ul > li"),m=d[o.length];if(d.length===e.length&&o.length){const u=d[o.length-1];if(u){const b=u.querySelector(".humany-button");b&&b.focus()}}else m&&new MutationObserver((b,p)=>{b.forEach(c=>{if(c.addedNodes){const g=Array.from(c.addedNodes).find(j=>j.tagName==="BUTTON");g&&C.htmlParentContains(a.current,document.activeElement)&&(l&&g.focus(),p.disconnect())}})}).observe(m,{attributes:!1,characterData:!1,childList:!0,subtree:!0,attributeOldValue:!1,characterDataOldValue:!1})}}),s.jsx(Me,{ref:a,className:"humany-conversation-link-list",header:t,items:q(e),renderItem:d=>s.jsx("li",{children:s.jsxs(Be,{help:d.actionKey==="help",onClick:()=>{r("action",d)},"aria-label":d.label,title:d.label,children:[d.label,d.actionKey==="help"&&s.jsx(n.SymbolBadge,{size:14,symbol:{type:"Svg",content:"caret-down"}})]})},d.actionKey)})},Me=i(n.ItemList)`
414
+ `,Te=({header:t,actions:e,dispatch:r})=>{const o=n.usePrevious(e),a=y.useRef(),l=n.useIsTabbing();return y.useEffect(()=>{if(o&&Array.isArray(e)&&Array.isArray(o)&&o.length<e.length&&a.current){const d=a.current.querySelectorAll(".humany-conversation-link-list > ul > li"),m=d[o.length];if(d.length===e.length&&o.length){const u=d[o.length-1];if(u){const f=u.querySelector(".humany-button");f&&f.focus()}}else m&&new MutationObserver((f,j)=>{f.forEach(c=>{if(c.addedNodes){const h=Array.from(c.addedNodes).find(x=>x.tagName==="BUTTON");h&&C.htmlParentContains(a.current,document.activeElement)&&(l&&h.focus(),j.disconnect())}})}).observe(m,{attributes:!1,characterData:!1,childList:!0,subtree:!0,attributeOldValue:!1,characterDataOldValue:!1})}}),s.jsx(Ne,{ref:a,className:"humany-conversation-link-list",header:t,items:O(e),renderItem:d=>s.jsx("li",{children:s.jsxs(Ie,{help:d.actionKey==="help",onClick:()=>{r("action",d)},"aria-label":d.label,title:d.label,children:[d.label,d.actionKey==="help"&&s.jsx(n.SymbolBadge,{size:14,symbol:{type:"Svg",content:"caret-down"}})]})},d.actionKey)})},Ne=i(n.ItemList)`
411
415
  ${n.itemList}
412
- ${w}
416
+ ${S}
413
417
 
414
- ${t=>n.headingElement(t)("h1",f.css`
418
+ ${t=>n.headingElement(t)("h1",b.css`
415
419
  white-space: normal;
416
420
  `)}
417
421
 
@@ -423,7 +427,7 @@
423
427
  margin: 0;
424
428
  }
425
429
  }
426
- `,Be=i(n.Button)`
430
+ `,Ie=i(n.Button)`
427
431
  display: block;
428
432
  text-align: left;
429
433
  font-weight: 300;
@@ -432,7 +436,7 @@
432
436
  text-overflow: ellipsis;
433
437
  overflow: hidden;
434
438
 
435
- ${t=>{var e,r;return t.help&&f.css`
439
+ ${t=>{var e,r;return t.help&&b.css`
436
440
  color: ${(e=t.theme.colors)==null?void 0:e.text};
437
441
  text-decoration: underline;
438
442
 
@@ -449,12 +453,12 @@
449
453
  text-decoration: underline;
450
454
  }
451
455
  }
452
- `,He=()=>s.jsx(Ae,{className:"humany-conversation-separator"}),Ae=i.div`
456
+ `,Me=()=>s.jsx(Be,{className:"humany-conversation-separator"}),Be=i.div`
453
457
  ${t=>t.theme.border&&`border-bottom: ${t.theme.border};`}
454
458
  width: 100%;
455
- `,Re=({text:t})=>s.jsx(Oe,{className:"humany-conversation-text",variant:"span",children:t}),Oe=i(n.Typography)`
456
- ${w}
457
- `,Ke=({header:t="Video call",acceptLabel:e="Accept",declineLabel:r="Decline",dispatch:o})=>{const a=h.useMemo(()=>[{label:e,actionKey:"accept-video-call",symbol:{type:"Svg",content:"video"}},{label:r,actionKey:"decline-video-call",symbol:{type:"Svg",content:"close"}}],[e,r]);return s.jsx(qe,{className:"humany-conversation-video-request",header:t,items:a,renderItem:l=>{const d=l.actionKey==="accept-video-call"?"#70c48e":"#da5c85";return s.jsx("li",{children:s.jsx(De,{onClick:()=>{o("action",l)},"aria-label":l.label,title:l.label,bgColor:d,children:s.jsx(n.SymbolBadge,{symbol:l.symbol,size:25})})},l.actionKey)}})},qe=i(n.ItemList)`
459
+ `,He=({text:t})=>s.jsx(Ae,{className:"humany-conversation-text",variant:"span",children:t}),Ae=i(n.Typography)`
460
+ ${S}
461
+ `,Re=({header:t="Video call",acceptLabel:e="Accept",declineLabel:r="Decline",dispatch:o})=>{const a=y.useMemo(()=>[{label:e,actionKey:"accept-video-call",symbol:{type:"Svg",content:"video"}},{label:r,actionKey:"decline-video-call",symbol:{type:"Svg",content:"close"}}],[e,r]);return s.jsx(Oe,{className:"humany-conversation-video-request",header:t,items:a,renderItem:l=>{const d=l.actionKey==="accept-video-call"?"#70c48e":"#da5c85";return s.jsx("li",{children:s.jsx(Ke,{onClick:()=>{o("action",l)},"aria-label":l.label,title:l.label,bgColor:d,children:s.jsx(n.SymbolBadge,{symbol:l.symbol,size:25})})},l.actionKey)}})},Oe=i(n.ItemList)`
458
462
  ${t=>n.itemList(t)}
459
463
  > ul {
460
464
  display: flex;
@@ -464,8 +468,8 @@
464
468
  margin: 0;
465
469
  }
466
470
  }
467
- ${t=>w(t)}
468
- `,De=i(n.Button)`
471
+ ${t=>S(t)}
472
+ `,Ke=i(n.Button)`
469
473
  ${n.buttonCss};
470
474
 
471
475
  background-color: ${t=>t.bgColor};
@@ -499,20 +503,20 @@
499
503
  stroke: #fff;
500
504
  }
501
505
  }
502
- `,Pe=([t,e])=>({type:t,content:e}),Ee=({items:t,dispatch:e})=>s.jsx(Fe,{role:"none",className:"humany-message-list",items:t.map(Pe),renderLi:!0,renderItem:r=>{switch(r.type){case $.ConversationMessageListItemType.Text:return s.jsx(Re,{text:r.content});case $.ConversationMessageListItemType.HTML:return s.jsx(ke,{...r.content});case $.ConversationMessageListItemType.Separator:return s.jsx(He,{...r.content});case $.ConversationMessageListItemType.ItemList:return s.jsx(ze,{...r.content,dispatch:e});case $.ConversationMessageListItemType.LinkList:return s.jsx(Ne,{...r.content,dispatch:e});case $.ConversationMessageListItemType.ButtonList:return s.jsx($e,{...r.content,dispatch:e});case $.ConversationMessageListItemType.VideoRequest:return s.jsx(Ke,{...r.content,dispatch:e});default:return s.jsx(Ce,{type:r.type,content:r.content})}}}),Fe=i(n.List)`
506
+ `,qe=([t,e])=>({type:t,content:e}),De=({items:t,dispatch:e})=>s.jsx(Pe,{role:"none",className:"humany-message-list",items:t.map(qe),renderLi:!0,renderItem:r=>{switch(r.type){case v.ConversationMessageListItemType.Text:return s.jsx(He,{text:r.content});case v.ConversationMessageListItemType.HTML:return s.jsx(we,{...r.content});case v.ConversationMessageListItemType.Separator:return s.jsx(Me,{...r.content});case v.ConversationMessageListItemType.ItemList:return s.jsx(ke,{...r.content,dispatch:e});case v.ConversationMessageListItemType.LinkList:return s.jsx(Te,{...r.content,dispatch:e});case v.ConversationMessageListItemType.ButtonList:return s.jsx(xe,{...r.content,dispatch:e});case v.ConversationMessageListItemType.VideoRequest:return s.jsx(Re,{...r.content,dispatch:e});default:return s.jsx(Se,{type:r.type,content:r.content})}}}),Pe=i(n.List)`
503
507
  ${n.list}
504
508
 
505
509
  > li {
506
510
  margin: 0;
507
511
  }
508
- `,We=h.forwardRef(({className:t,timestamp:e,sender:r,type:o,content:a},l)=>{const d=h.useCallback(c=>{let g="first";return a.length>1&&(g=c===0?"first":c+1===a.length?"last":"middle"),g},[a]),{userLabel:m=""}=n.useProperties(),u=()=>s.jsx(s.Fragment,{children:a.map(c=>{const{key:g,body:j,title:L,form:S,actions:x}=c,z=!!j&&!L&&!S&&!x;return s.jsx(fe,{className:t,discrete:z,ref:l,timestamp:e,fullWidth:!!S||!!x,children:z&&j?s.jsx(n.Html,{html:j}):s.jsx(H,{isSystem:!0,content:c})},g)})}),b=()=>s.jsxs(s.Fragment,{children:[s.jsxs(E,{className:"humany-sr-only",children:[r==null?void 0:r.name,":"]}),s.jsx(U,{sender:r,timestamp:e,className:t,children:s.jsx(R,{className:"humany-message-content-bundle",children:a.map((c,g)=>s.jsx(O,{className:"humany-message-container",left:!0,ref:l,children:s.jsx(H,{content:c,stacked:d(g)})},c.key))})})]}),p=()=>s.jsxs(s.Fragment,{children:[s.jsxs(E,{className:"humany-sr-only",children:[m,":"]}),s.jsx(xe,{timestamp:e,className:t,children:s.jsx(R,{className:"humany-message-content-bundle",children:a.map((c,g)=>s.jsx(O,{className:"humany-message-container",right:!0,ref:l,children:s.jsx(H,{isUser:!0,content:c,stacked:d(g)})},c.key))})})]});switch(o){case $.ConversationMessageType.System:return u();case $.ConversationMessageType.Agent:return b();case $.ConversationMessageType.User:return p();default:return null}}),H=({content:t,isUser:e,isSystem:r,stacked:o})=>{const a=n.useDispatch(),{title:l,body:d,actions:m,form:u,items:b}=t;return b?s.jsx(K,{className:"humany-message-content",user:!!e,stacked:o,children:s.jsx(Ee,{items:b,dispatch:a})}):s.jsxs(K,{className:"humany-message-content",padded:!r,user:!!e,stacked:o,fullWidth:!!u||!!m,children:[l&&s.jsx(I,{children:s.jsx(ie,{variant:"h2",children:l})}),d&&s.jsx(I,{children:s.jsx(me,{html:d})}),u&&s.jsx(I,{children:s.jsx(de,{...u,onChange:(c,g)=>{a("form",{data:g,formKey:u.schema.id,actionKey:c})}})}),m&&s.jsx(I,{children:s.jsx(ue,{items:Object.keys(m).map(c=>({label:m[c],actionKey:c})),renderItem:c=>s.jsx("li",{children:s.jsx(he,{onClick:()=>{a("action",c.actionKey)},children:c.label})},c.actionKey)})})]})},E=i.div`
512
+ `,Ee=y.forwardRef(({className:t,timestamp:e,sender:r,type:o,content:a},l)=>{const d=y.useCallback(c=>{let h="first";return a.length>1&&(h=c===0?"first":c+1===a.length?"last":"middle"),h},[a]),{userLabel:m=""}=n.useProperties(),u=()=>s.jsx(s.Fragment,{children:a.map(c=>{const{key:h,body:x,title:$,form:L,actions:p}=c,w=!!x&&!$&&!L&&!p;return s.jsx(ge,{className:t,discrete:w,ref:l,timestamp:e,fullWidth:!!L||!!p,children:w&&x?s.jsx(n.Html,{html:x}):s.jsx(M,{isSystem:!0,content:c})},h)})}),f=()=>s.jsxs(s.Fragment,{children:[s.jsxs(D,{className:"humany-sr-only",children:[r==null?void 0:r.name,":"]}),s.jsx(F,{sender:r,timestamp:e,className:t,children:s.jsx(H,{className:"humany-message-content-bundle",children:a.map((c,h)=>s.jsx(A,{className:"humany-message-container",left:!0,ref:l,children:s.jsx(M,{content:c,stacked:d(h)})},c.key))})})]}),j=()=>s.jsxs(s.Fragment,{children:[s.jsxs(D,{className:"humany-sr-only",children:[m,":"]}),s.jsx(be,{timestamp:e,className:t,children:s.jsx(H,{className:"humany-message-content-bundle",children:a.map((c,h)=>s.jsx(A,{className:"humany-message-container",right:!0,ref:l,children:s.jsx(M,{isUser:!0,content:c,stacked:d(h)})},c.key))})})]});switch(o){case v.ConversationMessageType.System:return u();case v.ConversationMessageType.Agent:return f();case v.ConversationMessageType.User:return j();default:return null}}),M=({content:t,isUser:e,isSystem:r,stacked:o})=>{const a=n.useDispatch(),{title:l,body:d,actions:m,form:u,items:f}=t;return f?s.jsx(R,{className:"humany-message-content",user:!!e,stacked:o,children:s.jsx(De,{items:f,dispatch:a})}):s.jsxs(R,{className:"humany-message-content",padded:!r,user:!!e,stacked:o,fullWidth:!!u||!!m,children:[l&&s.jsx(T,{children:s.jsx(oe,{variant:"h2",children:l})}),d&&s.jsx(T,{children:s.jsx(ce,{html:d})}),u&&s.jsx(T,{children:s.jsx(le,{...u,onChange:(c,h)=>{a("form",{data:h,formKey:u.schema.id,actionKey:c})}})}),m&&s.jsx(T,{children:s.jsx(de,{items:Object.keys(m).map(c=>({label:m[c],actionKey:c})),renderItem:c=>s.jsx("li",{children:s.jsx(me,{onClick:()=>{a("action",c.actionKey)},children:c.label})},c.actionKey)})})]})},D=i.div`
509
513
  position: absolute;
510
514
  left: -10000px;
511
515
  top: auto;
512
516
  width: 1px;
513
517
  height: 1px;
514
518
  overflow: hidden;
515
- `,V=()=>{const t=h.useCallback(m=>{m&&setTimeout(()=>{m.scrollIntoView({block:"start",behavior:"smooth"})},250)},[]),[e,r]=n.useScroll(!0),{messages:o,loading:a,typingActors:l=[]}=n.useProperties(),d=()=>l&&l.length?l.map((m,u)=>s.jsx(A,{id:`typing_${m.name}`,children:s.jsx(U,{timestamp:Date.now(),sender:m,children:s.jsx(D,{boxed:!0,ref:t})})},`typing_${m.name}`)):null;return s.jsxs(s.Fragment,{children:[s.jsxs(Ue,{tabIndex:0,scrollableCss:e,ref:r,children:[o&&o.length?o.map((m,u)=>{const{type:b,timestamp:p,sender:c,content:g}=m;return s.jsx(A,{className:"humany-conversation-entry",tabIndex:-1,children:s.jsx(We,{...m,ref:t})},`${b}_${c==null?void 0:c.name}_${p}_${g[0].key}`)}):null,d(),a&&s.jsx(A,{children:s.jsx(D,{ref:t})})]}),s.jsx(X,{})]})},Ue=i.div`
519
+ `,W=()=>{const t=y.useCallback(m=>{m&&setTimeout(()=>{m.scrollIntoView({block:"start",behavior:"smooth"})},250)},[]),[e,r]=n.useScroll(!0),{messages:o,loading:a,typingActors:l=[]}=n.useProperties(),d=()=>l&&l.length?l.map((m,u)=>s.jsx(B,{id:`typing_${m.name}`,children:s.jsx(F,{timestamp:Date.now(),sender:m,children:s.jsx(K,{boxed:!0,ref:t})})},`typing_${m.name}`)):null;return s.jsxs(s.Fragment,{children:[s.jsxs(Fe,{tabIndex:0,scrollableCss:e,ref:r,children:[o&&o.length?o.map((m,u)=>{const{type:f,timestamp:j,sender:c,content:h}=m;return s.jsx(B,{className:"humany-conversation-entry",tabIndex:-1,children:s.jsx(Ee,{...m,ref:t})},`${f}_${c==null?void 0:c.name}_${j}_${h[0].key}`)}):null,d(),a&&s.jsx(B,{children:s.jsx(K,{ref:t})})]}),s.jsx(J,{})]})},Fe=i.div`
516
520
  display: flex;
517
521
  flex-direction: column;
518
522
  align-items: stretch;
@@ -522,7 +526,7 @@
522
526
  &:focus-visible {
523
527
  ${t=>n.borderTabStyle(t)};
524
528
  }
525
- `,A=i.div`
529
+ `,B=i.div`
526
530
  margin: 0;
527
531
  margin-bottom: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.medium}};
528
532
 
@@ -545,10 +549,10 @@
545
549
  h1 {
546
550
  font-weight: normal;
547
551
  }
548
- ${t=>n.headingElement(t)("h1",f.css`
552
+ ${t=>n.headingElement(t)("h1",b.css`
549
553
  font-weight: normal;
550
554
  `)}
551
- `,Ve=({dispatch:t})=>{const e=h.useRef(null);return h.useEffect(()=>{e.current&&e.current.parentNode&&t("overlay-mounted",e.current)},[e]),s.jsx(n.WidgetOverlayOutlet,{portalId:"humany-conversation-overlay-portal",className:"humany-conversation-overlay-outlet",ref:e})},_e=({dispatch:t,header:e,buttonLabel:r})=>s.jsxs(Ye,{portalId:"humany-conversation-portal",className:"humany-conversation-outlet",children:[s.jsxs(Ge,{className:"humany-conversation-outlet-head",children:[s.jsx(Qe,{className:"humany-conversation-outlet-head-button","aria-label":r,title:r,onClick:()=>t("hide-overlay-conversation"),children:s.jsx(n.SymbolBadge,{symbol:{type:"Svg",content:"caret-down"},size:20})}),e&&s.jsx(Je,{className:"humany-conversation-outlet-header",variant:"h1",children:e})]}),s.jsx(V,{})]}),Ye=i(n.WidgetOverlayOutlet)`
555
+ `,We=({dispatch:t})=>{const e=y.useRef(null);return y.useEffect(()=>{e.current&&e.current.parentNode&&t("overlay-mounted",e.current)},[e]),s.jsx(n.WidgetOverlayOutlet,{portalId:"humany-conversation-overlay-portal",className:"humany-conversation-overlay-outlet",ref:e})},Ue=({dispatch:t,header:e,buttonLabel:r})=>s.jsxs(Ve,{portalId:"humany-conversation-portal",className:"humany-conversation-outlet",children:[s.jsxs(_e,{className:"humany-conversation-outlet-head",children:[s.jsx(Ge,{className:"humany-conversation-outlet-head-button","aria-label":r,title:r,onClick:()=>t("hide-overlay-conversation"),children:s.jsx(n.SymbolBadge,{symbol:{type:"Svg",content:"caret-down"},size:20})}),e&&s.jsx(Ye,{className:"humany-conversation-outlet-header",variant:"h1",children:e})]}),s.jsx(W,{})]}),Ve=i(n.WidgetOverlayOutlet)`
552
556
  z-index: 11;
553
557
  top: auto;
554
558
  height: 65%;
@@ -557,7 +561,7 @@
557
561
  flex-direction: column;
558
562
  border-top-right-radius: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.large}};
559
563
  border-top-left-radius: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.large}};
560
- `,Ge=i.div`
564
+ `,_e=i.div`
561
565
  display: flex;
562
566
  flex-direction: column;
563
567
  justify-content: center;
@@ -565,11 +569,11 @@
565
569
  gap: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}};
566
570
  padding: ${t=>{var e;return(e=t.theme.sizes)==null?void 0:e.normal}};
567
571
  ${t=>t.theme.border&&`border-bottom: ${t.theme.border};`}
568
- `,Je=i(n.Typography)`
572
+ `,Ye=i(n.Typography)`
569
573
  font-size: ${t=>{var e;return(e=t.theme.fonts)==null?void 0:e.medium}};
570
574
  color: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.text}};
571
575
  margin: 0;
572
- `,Qe=i(n.Button)`
576
+ `,Ge=i(n.Button)`
573
577
  display: flex;
574
578
  align-items: center;
575
579
  justify-content: center;
@@ -583,7 +587,7 @@
583
587
  svg line {
584
588
  stroke: ${t=>{var e;return(e=t.theme.colors)==null?void 0:e.text}};
585
589
  }
586
- `,Xe=({className:t,...e})=>{const{overlay:r,overlayConversationHeader:o,overlayConversationCloseLabel:a,conversationControllerId:l}=n.useProperties(),d=n.useDispatch(),u=n.useContainer().get("$settings");return s.jsx(n.ConversationContext.Provider,{value:l?{id:l}:null,children:s.jsxs(W.Provider,{value:u==null?void 0:u.language,children:[s.jsx(Ze,{"aria-live":"assertive",...e,className:C.appendClassNames(t,"humany-conversation-component"),children:s.jsx(V,{})}),r&&s.jsxs(s.Fragment,{children:[s.jsx(Ve,{dispatch:d}),r.conversation&&s.jsx(_e,{dispatch:d,header:o,buttonLabel:a})]})]})})},Ze=i.div`
590
+ `,Je=({className:t,...e})=>{const{overlay:r,overlayConversationHeader:o,overlayConversationCloseLabel:a,conversationControllerId:l}=n.useProperties(),d=n.useDispatch(),u=n.useContainer().get("$settings");return s.jsx(n.ConversationContext.Provider,{value:l?{id:l}:null,children:s.jsxs(E.Provider,{value:u==null?void 0:u.language,children:[s.jsx(Qe,{"aria-live":"assertive",...e,className:C.appendClassNames(t,"humany-conversation-component"),children:s.jsx(W,{})}),r&&s.jsxs(s.Fragment,{children:[s.jsx(We,{dispatch:d}),r.conversation&&s.jsx(Ue,{dispatch:d,header:o,buttonLabel:a})]})]})})},Qe=i.div`
587
591
  position: absolute;
588
592
  right: 0;
589
593
  left: 0;
@@ -592,4 +596,4 @@
592
596
  overflow: hidden;
593
597
  display: flex;
594
598
  flex-direction: column;
595
- `;exports.default=Xe;
599
+ `;exports.default=Je;
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";var $=Object.defineProperty;var q=(o,e,t)=>e in o?$(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var d=(o,e,t)=>(q(o,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("@telia-ace/widget-core"),p=require("@telia-ace/widget-services"),E=require("@telia-ace/widget-utilities"),L=require("@telia-ace/widget-forms"),M=require("@telia-ace/widget-plugins"),N=require("@telia-ace/widget-ui"),z=require("react");class U{constructor(e){d(this,"cache",new Map);d(this,"subscriptions",[]);this.controller=e;const{events:t}=e.container.get("$widget"),s=t.subscribe("data-client:fetched",(r,n)=>{n.type==="contact-method"&&this.cache.set(n.response.id,n.response)});this.subscriptions.push(s)}getConversationLogs(){return this.controller.messages.reduce((t,s)=>{const r=k(s),{key:n,content:a,type:i,sender:c,timestamp:h}=r.content,u=this.parseEntry(a,i,c,h);return u&&t.push(u),t},[])}parseEntry(e,t,s,r){const n=h=>{let u=[],l=[],m;if(Array.isArray(h)){const[g,f]=h;m=f}else m=h;return this.createMessageContent(m).length&&(l=[...l,this.createMessageContent(m)]),u=[...u,...this.createMessageOptions(m)],{messagesAsList:l,options:u}};let a=[],i=[];if(Array.isArray(e.items)){const{items:h}=e;h.forEach(u=>{const l=n(u);a=[...a,...l.options],i=[...i,...l.messagesAsList]})}else{const h=n(e);a=[...a,...h.options],i=[...i,...h.messagesAsList]}return{options:a,message:i.length?i.join(`
2
2
  `):void 0,source:this.createMessageSource(t),alias:this.createAlias(t,s),timestamp:r}}createMessageSource(e){return e}createAlias(e,t){return e===y.System?"system":(t==null?void 0:t.name)||"Me"}handleContactMethod(e){if(!this.cache.has(e))return;const t=this.cache.get(e);let s="";return s=this.appendText(s,`${t.clientName}:`),s=this.appendText(s,t.title),t.description&&(s=this.appendText(s,t.title)),s}getDetails(e,t=!0){if(!e)return"";const{header:s,title:r,label:n,description:a,text:i,html:c,body:h,contactMethodId:u}=e;let l="";if(u){const m=this.handleContactMethod(u.toString());m&&(l=this.appendText(l,m,t))}return s&&(l=this.appendText(l,s,t)),r&&(l=this.appendText(l,r,t)),a&&(l=this.appendText(l,a,t)),i&&(l=this.appendText(l,i,t)),n&&(l=this.appendText(l,n,t)),c&&(l=this.appendText(l,c,t)),h&&typeof h=="string"&&(l=this.appendText(l,h,t)),l}createMessageContent(e){let t="";return t=this.getDetails(e),t}createMessageOptions(e){let t=[],s=[];return Array.isArray(e==null?void 0:e.actions)?s=e.actions:typeof(e==null?void 0:e.actions)=="object"&&(s=Object.entries(e.actions).map(([r,n])=>({actionKey:r,label:n}))),s.length&&(t=s.map(r=>this.getDetails(r,!1))),t}appendText(e,t,s=!0){return s&&e.length?`${e}
3
- ${t}`:e.length?`${e} ${t}`:t}dispose(){this.subscriptions.forEach(e=>{e()})}}class P{constructor(e,t){d(this,"id");d(this,"name");d(this,"avatar");d(this,"print",(e,t,s=null)=>{const r={name:this.name,avatar:this.avatar,id:this.id},n=k(e,t);return s=s??n.timestamp,this.provider.createEntry(n.key,n.content,y.Agent,r,s)});d(this,"typing",()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}));this.provider=e,this.id=t.id||E.uuid(),this.name=t.name,this.avatar=t.avatar}update(e){var r;const{name:t,avatar:s}=e;s===null?this.avatar=void 0:s&&(this.avatar=s),t===null?this.name=void 0:t&&(this.name=t),(r=this.provider.controller)==null||r.events.dispatch("conversation:agent-updated",{agent:this})}}class A{constructor(e,t,s){d(this,"subscriptions",[]);d(this,"options");d(this,"user");this.name=e,this.container=t,this.controller=s,this.user=s==null?void 0:s.user,this.options={silent:!1}}static create(e,t,s){return new A(e,t,s)}createAgent(e={}){var t;if(this.controller){const s=this.controller.getAgentById(e.id),r=s?new P(this,{...s,...e}):new P(this,e);return s||(t=this.controller)==null||t.events.dispatch("conversation:agent-created",{agent:r}),r}}print(e){var t;return(t=this.controller)==null?void 0:t.print(e)}setTypingState(e,t){var s;return(s=this.controller)==null?void 0:s.setTypingState(e,t)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(e,t,s,r,n){var a;return(a=this.controller)==null?void 0:a.createEntry(e,t,s,r,n)}dispose(){var e;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(e=this.controller)==null||e.disposeProvider(this),this.controller=null,this.subscriptions.forEach(t=>t())}isRehydrated(){var e;return((e=this.controller)==null?void 0:e.isRehydrated())||Promise.resolve(!1)}getHistory(){var e;return((e=this.controller)==null?void 0:e.getHistory())||[]}complete(){var e;(e=this.controller)==null||e.onCompleteProvider()}setOptions(e={silent:!1}){this.options=e}onUnreadMessage(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.onUnreadMessage(e);return this.subscriptions.push(s),()=>{s()}}}onMounted(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.events.subscribe("conversation:component-mount-changed",e);return this.subscriptions.push(s),e({},this.controller.getComponentMountedState()),()=>{s()}}}}const O=o=>`conversation-${o}`;class K{constructor(){d(this,"_locking",Promise.resolve());d(this,"_locks",0)}isLocked(){return this._locks>0}lock(){this._locks+=1;let e;const t=new Promise(r=>e=()=>{this._locks-=1,r()}),s=this._locking.then(()=>e);return this._locking=this._locking.then(()=>t),s}}class Q{constructor(e,t,s){d(this,"sessionStorageKey");d(this,"locker",new K);d(this,"initialStoredAgents",[]);this.container=e,this.conversation=t,this.enabled=s,this.sessionStorageKey=O(t.id),t.onStarted(async()=>{if(t.messages.length>0)return;const{agents:r}=await this.read(),n=[];r&&r.forEach(i=>{const c=t.providerIndex(i.providerName),h=c>-1?t.registeredProviders[c]:t.createProvider(i.providerName),u=new P(h,{name:i.name,avatar:i.avatar,id:i.id});n.push(u)});const{messages:a}=await this.read();a.forEach(i=>{switch(i.type){case"agent":{const c=n.find(h=>{var u;return h.id===((u=i.sender)==null?void 0:u.id)});c&&c.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"user":{t.user.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"system":default:t.print(i.content.items||i.content,i.timestamp)}})}),t.onMessageCreated(async(r,n)=>{this.write(n.message,"messages")}),t.events.subscribe("conversation:agent-created",async(r,n)=>{const a={id:n.agent.id,name:n.agent.name,avatar:n.agent.avatar,providerName:n.agent.provider.name};await this.write(a,"agents")}),t.events.subscribe("conversation:agent-updated",async(r,n)=>{const{agents:a}=await this.read();await this.write([...a.map(i=>i.id===n.agent.id?{...i,name:n.agent.name,avatar:n.agent.avatar}:i)],"agents","update")})}setInitialData(e){this.initialStoredAgents=e.agents}async isRehydrated(){const{messages:e}=await this.read();return e.length>0}getStoredAgent(e){if(this.enabled)return this.initialStoredAgents.find(t=>t.id===e)}async write(e,t,s="add"){if(!this.enabled)return;const r=await this.locker.lock();return p.createStorageWriter(this.container,this.sessionStorageKey,p.StorageCategory.Necessary).then(async n=>{if(s==="add"){const a=await this.read();if(t==="messages"&&a.messages.findIndex(c=>c.key===e.key)>-1){r();return}const i={...a};return t==="messages"?i.messages=[...i.messages,e]:t==="agents"&&(i.agents=[...i.agents,e]),n({...a,...i}).then(()=>{r()})}if(s==="update"&&t==="agents"){const a=await this.read();return n({...a,agents:e}).then(()=>{r()})}return n(e).then(()=>{r()})})}async read(){return p.readStorage(this.container,this.sessionStorageKey).then(e=>e||{messages:[],agents:[]})}}class j{constructor(e){d(this,"print",(e,t,s=null)=>{const r=k(e,t);return s=s??r.timestamp,this.controller.createEntry(r.key,r.content,y.User,void 0,s)});this.controller=e}}const x=async(o,e,t)=>{const s=await o.getAsync("conversation"),r=await o.getAsync("components"),n=s.controllers.find(a=>a.conversation.id===e);if(n){const a=[...n.conversation.providers];a.forEach(c=>{n.conversation.setProviderOptions(c,{silent:!0})}),n.conversation.queueProviders(a),n.conversation.setProviders([t]);const i=r.components().ofType("conversation");r.write({key:"setConversationProvider",attributes:{properties:{providers:[t]}},target:i,provider:"localStorage"})}};class H{constructor(e){this.writer=e}update(e){const t=this.getNormalizedSettings(e);this.writer(t)}remove(){this.writer(null)}getNormalizedSettings(e){return typeof e=="string"?{body:e}:e.length>-1&&typeof e=="object"?{items:e}:e}}var y=(o=>(o.User="user",o.Agent="agent",o.System="system",o))(y||{});const k=(o,e)=>{let t,s=(e==null?void 0:e.key)||E.uuid(),r=Date.now();if(Array.isArray(o)&&o.length>-1)typeof o[0]=="string"?t={items:[o]}:t={items:o};else if(typeof o=="string")t={body:o};else if(o=o||{},o.type)t={...o};else{if(t={body:o.body,actions:o.actions,title:o.title},o.key&&(s=o.key),o.timestamp&&(r=o.timestamp),typeof o.form=="function"){const n=L.FormBuilder.create(s);o.form(n);const a=n.get();t.form=a}o.timestamp===null&&(r=null)}return{content:t,key:s,timestamp:r}},W=(o,e)=>{if(!e)return;const t=JSON.stringify(e),s=o.findIndex(r=>t===JSON.stringify(r));if(s>-1)return o.splice(s,1)};class B{constructor(e,t,s){d(this,"formHandlers",{});d(this,"user",new j(this));d(this,"events");d(this,"providers",[]);d(this,"active",!1);d(this,"queuedProviders",[]);d(this,"registeredProviders",[]);d(this,"loaders",0);d(this,"componentMounted",!1);d(this,"store");d(this,"messages",[]);d(this,"typingActors",[]);d(this,"conversationHistory");d(this,"print",(e,t=null)=>{const s=k(e);return t=t??s.timestamp,this.createEntry(s.key,s.content,"system",void 0,t)});this.container=e,this.id=t;const r=e.get("$widget");this.events=r.events.createChild(this),this.store=new Q(e,this,s.rehydrate),this.conversationHistory=new U(this)}setInitialStorage(e){this.store.setInitialData(e)}setProviders(e){const t=[],s=[];this.providers.reduce((r,n)=>(e.indexOf(n)===-1&&r.push(n),r),[]).forEach(r=>{const n=this.providers.indexOf(r);n>-1&&(t.push(r),this.providers.splice(n,1))}),e.forEach(r=>{this.providers.indexOf(r)===-1&&(s.push(r),this.providers.push(r))}),(s.length||t.length)&&this.events.dispatch("conversation:providers-changed",{added:s,removed:t})}createProvider(e){const t=this.providerIndex(e);if(t>-1)return this.registeredProviders[t];const s=A.create(e,this.container,this);return this.registeredProviders.push(s),s}providerIndex(e){return this.registeredProviders.findIndex(t=>t.name===e)}getAgentById(e){if(e)return this.store.getStoredAgent(e)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(e=>e.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(e){return this.events.subscribe("conversation:controller-disposed",e)}onStarted(e){return this.events.subscribe("conversation:started",e)}onMessageCreated(e){return this.events.subscribe("conversation:message-created",e)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(e){const t=this.providerIndex(e.name);t>-1&&this.registeredProviders.splice(t,1),this.events.dispatch("conversation:providers-changed",{removed:[e.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(e){return this.events.subscribe("conversation:providers-changed",e)}setComponentMountedState(e){this.componentMounted!==e&&(this.componentMounted=e,e&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",e))}setProviderOptions(e,t){const s=this.providerIndex(e);s>-1&&this.registeredProviders[s].setOptions(t)}changeProvider(e){this.registeredProviders.find(s=>s.name===e)&&x(this.container,this.id,e)}queueProviders(e){this.queuedProviders=e}onCompleteProvider(){const e=this.queuedProviders.pop();e&&x(this.container,this.id,e)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(e){return this.events.subscribe("conversation:unread-message",e)}createEntry(e,t,s,r,n){const a={key:e,content:t,type:s,sender:r||null,timestamp:n||n===null?n:Date.now()};this.messages.push(a),a.type==="agent"&&W(this.typingActors,r);const i=new H(c=>{if(c!==null){const{timestamp:h=void 0,...u}=c;a.content=u,h&&(a.timestamp=h)}else{const h=this.messages.indexOf(a);a.content=null,h>-1&&this.messages.splice(h,1)}this.events.dispatch("conversation:message-updated",{message:a}),this.update()});return this.events.dispatch("conversation:message-created",{message:a}),this.update(),this.componentMounted||this.events.dispatch("conversation:unread-message",!0),i}update(){this.events.dispatch("conversation:updated",{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors})}getMessageStream(){return{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors}}setTypingState(e,t){return this.typingActors.indexOf(e)===-1&&(this.typingActors.push(e),this.update()),()=>{W(this.typingActors,e),this.update()}}loader(){this.loaders=this.loaders+1;let e=!1;return this.loaders===1&&this.update(),()=>{e||(e=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(e,t){this.formHandlers[e]={...this.formHandlers[e],submit:t}}validateForm(e,t){this.formHandlers[e]={...this.formHandlers[e],validate:t}}getHistory(){return this.conversationHistory.getConversationLogs()}}const F=(o,e)=>{const t=o.split("_contact");return e.widgets.get(t[0])},I=o=>{const e=o.get("$widget"),{name:t,implementation:s}=o.get("$widget"),r=t.indexOf("_contact")>-1?F(t,s):e,{data:n}=o.get("$settings"),{trigger:a}=r.container.get("$settings"),i=`${t.replace("_contact-method","").replace("_contact","")}_contact-method`,c=s.widgets.get(i);return c&&!a?{chatWidget:c,mainWidget:r,data:n}:{mainWidget:r,data:n}},G=o=>{const{chatWidget:e}=I(o);return!!e},R=(o,e,t)=>{const{mainWidget:s,data:r,chatWidget:n}=I(o);return n?n.state==="activated"?n.invoke("open").then(()=>{n.container.getAsync("conversation").then(a=>{a.navigateToConversationIfActive(e.id).then(()=>M.closeAllModals(o))})}):n.activate().then(()=>{const{trigger:a}=n.container.get("$settings");return a.action="hide",n.invoke("setSettings",()=>({data:r,trigger:a,activate:!0})).then(()=>n.container.getAsync("components").then(i=>{const c=i.components().ofType("contact-method");i.write({key:"setContactMethodId",attributes:{properties:{id:e.id,guideId:e.guideId}},target:c,provider:"localStorage"});const h=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,provider:"localStorage"})}))}).then(()=>n.invoke("attach",{key:"contact-method",triggerDOMElement:t,withRenderState:"open"})).then(()=>(p.createStorageWriter(n.container,"activeStickyWidget",p.StorageCategory.Necessary,{medium:p.StorageMedium.Local,scope:p.StorageScope.Implementation}).then(a=>a(n.name)),n.container.getAsync("conversation").then(a=>{a.setConversationEndedBehavior(S.Deactivate)}).then(()=>M.closeAllModals(o)).then(()=>!1))):(s.container.getAsync("conversation").then(a=>a.navigateToConversationIfActive(e.id).then(()=>a.setConversationEndedBehavior(S.Navigate))),!n)},J=(o,e,t="conversation")=>{const{mainWidget:s,chatWidget:r}=I(o);return r?r.container.getAsync("router").then(n=>{n.navigate(t,{id:e.id})}):s.container.getAsync("conversation").then(n=>{var a;(a=n.setConversationEndedBehavior(S.Navigate))==null||a.then(()=>{s.container.getAsync("router").then(i=>{s.container.getAsync("components").then(c=>{const h=c.components().ofType("conversation");c.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,provider:"localStorage"})}).then(()=>{i.navigate(t,{id:e.id})})})})})},b="conversations";var S=(o=>(o.Deactivate="deactivate",o.Navigate="navigate",o.None="none",o))(S||{});class w{constructor(e,t){d(this,"events");d(this,"controllers",[]);d(this,"providers",[]);d(this,"disposeProviders",{});d(this,"subscriptions",[]);d(this,"storageWriter",null);d(this,"router",null);d(this,"buttonQuery",null);d(this,"sessionInfo",null);this.container=e,this.components=t;const s=e.get("$widget");this.events=s.events.createChild(this)}initialize(){p.createStorageWriter(this.container,b,p.StorageCategory.Necessary,{medium:p.StorageMedium.Local}).then(e=>this.storageWriter=e),p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),e&&(this.sessionInfo=e,e.id&&e.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.container.getAsync("router").then(e=>this.router=e),this.events.subscribe("conversation:ended",(e,t)=>{var s,r,n;switch((s=this.sessionInfo)==null?void 0:s.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break;case"navigate":const i=(r=this.router)==null?void 0:r.getInitialRoute();i&&((n=this.router)==null||n.navigate(i.name));break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(e){this.subscriptions.push(e)}static getInstance(e,t="conversation"){return E.lock(e)(()=>e.getAsync(t).then(s=>{let r=s;return r||D.ComponentPlatform.getInstance(e).then(n=>(r=new w(e,n),r.initialize(),e.registerAsync(t,()=>r),r))}))}navigateToConversationIfActive(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{var s;if(t&&t.id===e&&t.route){const{name:r,params:n}=t.route;(s=this.router)==null||s.navigate(r,n)}})}setConversationEndedBehavior(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{let s=t;return s?s.conversationEndedBehavior=e:s={conversationEndedBehavior:e},this.sessionInfo=s,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(e,t){const s=O(e),{agents:r}=await p.readStorage(this.container,s)||{agents:[]},n=this.controllers.findIndex(i=>i.conversation.id===e);let a;return n>-1?a=this.controllers[n].conversation:a=new B(this.container,e,t),a.setInitialStorage({agents:r||[]}),a}registerProvider(e,t){const s={name:e,handler:t};this.providers.push(s),this.controllers.filter(r=>r.conversation.providers.indexOf(e)>-1).forEach(r=>{this.invokeHandler(s,r)})}registerController(e,t){const s=this.controllers.findIndex(n=>n.conversation.id===e.id);let r;if(s<0){r={conversation:e,component:t},this.controllers.push(r);const n=a=>{a&&this.providers.filter(i=>a.indexOf(i.name)>-1).forEach(i=>{this.invokeHandler(i,r)})};return this.subscriptions.push(e.onDispose((a,i)=>{const c=this.controllers.findIndex(h=>h.conversation===i);c>-1&&this.controllers.splice(c,1),this.components.components().ofType("conversation-return-button").select().writeProperties({active:!1}),this.events.dispatch("conversation:ended",{},{bubbles:!0})})),this.subscriptions.push(e.onProvidersChange((a,i)=>{const{added:c,removed:h=[]}=i;h.forEach(u=>{(this.disposeProviders[u]||[]).forEach(l=>{l()})}),n(c)})),this.subscriptions.push(e.onStarted((a,i)=>{var h,u;const c={id:e.id,route:(h=this.router)==null?void 0:h.getRouteData(),conversationEndedBehavior:(u=this.sessionInfo)==null?void 0:u.conversationEndedBehavior};this.sessionInfo=c,this.storageWriter&&this.storageWriter(c),this.writeToComponents({active:i})})),this.subscriptions.push(e.onUnreadMessage((a,i)=>{this.events.dispatch("conversation:unread-message",i),this.writeToComponents({alert:{show:i}})})),n(e.providers),!0}return r=this.controllers[s],!1}writeToComponents(e,t="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:e},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(e,t){const s=e.handler(t.conversation.createProvider(e.name),t.component);s&&(this.disposeProviders[e.name]||(this.disposeProviders[e.name]=[]),this.disposeProviders[e.name].push(s))}getComponentRoute(){return p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>e==null?void 0:e.route)}dispose(){Object.keys(this.disposeProviders).forEach(e=>{this.disposeProviders[e].forEach(t=>{t()})}),this.subscriptions.forEach(e=>{e()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(e,t,s,r){if(G(t)){e.preventDefault();let n=document.getElementById("humany-dynamic-anchor");n||(n=document.createElement("a"),n.setAttribute("href","#"),n.id="humany-dynamic-anchor",document.body.appendChild(n)),R(t,s,n)}R(t,s)}static async handleContactMethodSubmit(e,t){var s,r;return(r=(s=t==null?void 0:t.body.form.meta)==null?void 0:s.conversation)!=null&&r.id?x(e,t.body.form.meta.conversation.id,t.clientName):J(e,t)}}const V=(o,e)=>o.reduce((t,s,r)=>{var a,i;const n={...s,content:[{...s.content,key:s.key}]};if(t.length>0&&s.type!==y.System){const c=t[t.length-1];if((!e&&e!==0||Math.abs(c.timestamp-s.timestamp)<e)&&((a=c.sender)==null?void 0:a.name)===((i=s.sender)==null?void 0:i.name)&&c.type===s.type)return c.timestamp=s.timestamp,c.content.push({...s.content,key:s.key}),t}return t.push(n),t},[]),Y=o=>Promise.all([w.getInstance(o),o.getAsync("router")]).then(([e,t])=>N.createReactComponent(o,"conversation",Promise.resolve().then(()=>require("./conversation-fa30b867.js")),async s=>{const{rehydrate:r=!1}=s.properties(),a=t.getRouteData().params.id||s.node.name||"component",i=await e.createController(a,{rehydrate:r}),c=e.registerController(i,s),h=3*60*1e3,u=v=>{const{providers:g=[]}=v;if(g){const f=Array.isArray(g)?g:[g];return i.setProviders(f),f}};u(s.properties(u)),i.setComponentMountedState(!0);const l=v=>{const{loading:g,typingActors:f,messages:C}=v;s.writeProperties({loading:g,typingActors:f,messages:V(C,h)})};l(i.getMessageStream()),c&&(s.writeProperties({conversationControllerId:i.id}),s.actions.create("user-submit",(v,g)=>{if(g){const{preventDefault:f,validationPromise:C}=g;if(f){C&&C().then(T=>{T&&i.user.print(T)});return}}i.user.print(v.text)}),s.actions.create("user-typing",(v,g)=>{}),s.actions.create("form",(v,g)=>{}),s.actions.create("action",(v,g)=>{}),s.actions.create("overlay-mounted",(v,g)=>{}),s.actions.create("show-overlay",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}),s.actions.create("hide-overlay",(v,g)=>{s.writeProperties({overlay:null})}),s.actions.create("show-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!0,secondary:!1}})}),s.actions.create("hide-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}));const m=i.events.subscribe("conversation:updated",(v,g)=>{l(g)});return()=>{i.setComponentMountedState(!1),m(),i.active||l({messages:[],typingActors:[],loading:!1})}},{reuseController:!0})),X=o=>Promise.all([D.ComponentPlatform.getInstance(o),w.getInstance(o),o.getAsync("router")]).then(([e,t,s])=>N.createReactComponent(o,"conversation-return-button",Promise.resolve().then(()=>require("./return-button-f1f43984.js")),r=>{r.actions.create("toggle",(n={})=>{var a;(a=t.getComponentRoute())==null||a.then(i=>{i&&s.navigate(i.name,i.params)})})}));var _=(o=>(o.LinkList="link-list",o.Separator="separator",o.ButtonList="button-list",o.ItemList="item-list",o.Text="text",o.HTML="html",o.VideoRequest="video-request",o))(_||{});const Z=(o,e,t)=>o.getAsync("componentResolver").then(async s=>{(await w.getInstance(o)).addSubscription(s.registerComponent(e,z.lazy(()=>t)))});exports.Agent=P;exports.ConversationComponent=Y;exports.ConversationController=B;exports.ConversationEndedBehavior=S;exports.ConversationEntry=H;exports.ConversationMessageListItemType=_;exports.ConversationMessageType=y;exports.ConversationPlatform=w;exports.ConversationProvider=A;exports.ConversationReturnButtonComponent=X;exports.registerCustomMessageComponent=Z;
3
+ ${t}`:e.length?`${e} ${t}`:t}dispose(){this.subscriptions.forEach(e=>{e()})}}class P{constructor(e,t){d(this,"id");d(this,"name");d(this,"avatar");d(this,"print",(e,t,s=null)=>{const r={name:this.name,avatar:this.avatar,id:this.id},n=k(e,t);return s=s??n.timestamp,this.provider.createEntry(n.key,n.content,y.Agent,r,s)});d(this,"typing",()=>this.provider.setTypingState({name:this.name,avatar:this.avatar}));this.provider=e,this.id=t.id||E.uuid(),this.name=t.name,this.avatar=t.avatar}update(e){var r;const{name:t,avatar:s}=e;s===null?this.avatar=void 0:s&&(this.avatar=s),t===null?this.name=void 0:t&&(this.name=t),(r=this.provider.controller)==null||r.events.dispatch("conversation:agent-updated",{agent:this})}}class A{constructor(e,t,s){d(this,"subscriptions",[]);d(this,"options");d(this,"user");this.name=e,this.container=t,this.controller=s,this.user=s==null?void 0:s.user,this.options={silent:!1}}static create(e,t,s){return new A(e,t,s)}createAgent(e={}){var t;if(this.controller){const s=this.controller.getAgentById(e.id),r=s?new P(this,{...s,...e}):new P(this,e);return s||(t=this.controller)==null||t.events.dispatch("conversation:agent-created",{agent:r}),r}}print(e){var t;return(t=this.controller)==null?void 0:t.print(e)}setTypingState(e,t){var s;return(s=this.controller)==null?void 0:s.setTypingState(e,t)}loading(){return this.controller?this.controller.loader():()=>()=>{}}createEntry(e,t,s,r,n){var a;return(a=this.controller)==null?void 0:a.createEntry(e,t,s,r,n)}dispose(){var e;process.env.NODE_ENV!=="production"&&console.log(`conversation-provider: dispose (${this.name})`),(e=this.controller)==null||e.disposeProvider(this),this.controller=null,this.subscriptions.forEach(t=>t())}isRehydrated(){var e;return((e=this.controller)==null?void 0:e.isRehydrated())||Promise.resolve(!1)}getHistory(){var e;return((e=this.controller)==null?void 0:e.getHistory())||[]}complete(){var e;(e=this.controller)==null||e.onCompleteProvider()}setOptions(e={silent:!1}){this.options=e}onUnreadMessage(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.onUnreadMessage(e);return this.subscriptions.push(s),()=>{s()}}}onMounted(e){var t;if(this.controller){const s=(t=this.controller)==null?void 0:t.events.subscribe("conversation:component-mount-changed",e);return this.subscriptions.push(s),e({},this.controller.getComponentMountedState()),()=>{s()}}}}const O=o=>`conversation-${o}`;class K{constructor(){d(this,"_locking",Promise.resolve());d(this,"_locks",0)}isLocked(){return this._locks>0}lock(){this._locks+=1;let e;const t=new Promise(r=>e=()=>{this._locks-=1,r()}),s=this._locking.then(()=>e);return this._locking=this._locking.then(()=>t),s}}class Q{constructor(e,t,s){d(this,"sessionStorageKey");d(this,"locker",new K);d(this,"initialStoredAgents",[]);this.container=e,this.conversation=t,this.enabled=s,this.sessionStorageKey=O(t.id),t.onStarted(async()=>{if(t.messages.length>0)return;const{agents:r}=await this.read(),n=[];r&&r.forEach(i=>{const c=t.providerIndex(i.providerName),h=c>-1?t.registeredProviders[c]:t.createProvider(i.providerName),u=new P(h,{name:i.name,avatar:i.avatar,id:i.id});n.push(u)});const{messages:a}=await this.read();a.forEach(i=>{switch(i.type){case"agent":{const c=n.find(h=>{var u;return h.id===((u=i.sender)==null?void 0:u.id)});c&&c.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"user":{t.user.print(i.content.items||i.content,{key:i.key},i.timestamp);return}case"system":default:t.print(i.content.items||i.content,i.timestamp)}})}),t.onMessageCreated(async(r,n)=>{this.write(n.message,"messages")}),t.events.subscribe("conversation:agent-created",async(r,n)=>{const a={id:n.agent.id,name:n.agent.name,avatar:n.agent.avatar,providerName:n.agent.provider.name};await this.write(a,"agents")}),t.events.subscribe("conversation:agent-updated",async(r,n)=>{const{agents:a}=await this.read();await this.write([...a.map(i=>i.id===n.agent.id?{...i,name:n.agent.name,avatar:n.agent.avatar}:i)],"agents","update")})}setInitialData(e){this.initialStoredAgents=e.agents}async isRehydrated(){const{messages:e}=await this.read();return e.length>0}getStoredAgent(e){if(this.enabled)return this.initialStoredAgents.find(t=>t.id===e)}async write(e,t,s="add"){if(!this.enabled)return;const r=await this.locker.lock();return p.createStorageWriter(this.container,this.sessionStorageKey,p.StorageCategory.Necessary).then(async n=>{if(s==="add"){const a=await this.read();if(t==="messages"&&a.messages.findIndex(c=>c.key===e.key)>-1){r();return}const i={...a};return t==="messages"?i.messages=[...i.messages,e]:t==="agents"&&(i.agents=[...i.agents,e]),n({...a,...i}).then(()=>{r()})}if(s==="update"&&t==="agents"){const a=await this.read();return n({...a,agents:e}).then(()=>{r()})}return n(e).then(()=>{r()})})}async read(){return p.readStorage(this.container,this.sessionStorageKey).then(e=>e||{messages:[],agents:[]})}}class j{constructor(e){d(this,"print",(e,t,s=null)=>{const r=k(e,t);return s=s??r.timestamp,this.controller.createEntry(r.key,r.content,y.User,void 0,s)});this.controller=e}}const x=async(o,e,t)=>{const s=await o.getAsync("conversation"),r=await o.getAsync("components"),n=s.controllers.find(a=>a.conversation.id===e);if(n){const a=[...n.conversation.providers];a.forEach(c=>{n.conversation.setProviderOptions(c,{silent:!0})}),n.conversation.queueProviders(a),n.conversation.setProviders([t]);const i=r.components().ofType("conversation");r.write({key:"setConversationProvider",attributes:{properties:{providers:[t]}},target:i,provider:"localStorage"})}};class H{constructor(e){this.writer=e}update(e){const t=this.getNormalizedSettings(e);this.writer(t)}remove(){this.writer(null)}getNormalizedSettings(e){return typeof e=="string"?{body:e}:e.length>-1&&typeof e=="object"?{items:e}:e}}var y=(o=>(o.User="user",o.Agent="agent",o.System="system",o))(y||{});const k=(o,e)=>{let t,s=(e==null?void 0:e.key)||E.uuid(),r=Date.now();if(Array.isArray(o)&&o.length>-1)typeof o[0]=="string"?t={items:[o]}:t={items:o};else if(typeof o=="string")t={body:o};else if(o=o||{},o.type)t={...o};else{if(t={body:o.body,actions:o.actions,title:o.title},o.key&&(s=o.key),o.timestamp&&(r=o.timestamp),typeof o.form=="function"){const n=L.FormBuilder.create(s);o.form(n);const a=n.get();t.form=a}o.timestamp===null&&(r=null)}return{content:t,key:s,timestamp:r}},W=(o,e)=>{if(!e)return;const t=JSON.stringify(e),s=o.findIndex(r=>t===JSON.stringify(r));if(s>-1)return o.splice(s,1)};class B{constructor(e,t,s){d(this,"formHandlers",{});d(this,"user",new j(this));d(this,"events");d(this,"providers",[]);d(this,"active",!1);d(this,"queuedProviders",[]);d(this,"registeredProviders",[]);d(this,"loaders",0);d(this,"componentMounted",!1);d(this,"store");d(this,"messages",[]);d(this,"typingActors",[]);d(this,"conversationHistory");d(this,"print",(e,t=null)=>{const s=k(e);return t=t??s.timestamp,this.createEntry(s.key,s.content,"system",void 0,t)});this.container=e,this.id=t;const r=e.get("$widget");this.events=r.events.createChild(this),this.store=new Q(e,this,s.rehydrate),this.conversationHistory=new U(this)}setInitialStorage(e){this.store.setInitialData(e)}setProviders(e){const t=[],s=[];this.providers.reduce((r,n)=>(e.indexOf(n)===-1&&r.push(n),r),[]).forEach(r=>{const n=this.providers.indexOf(r);n>-1&&(t.push(r),this.providers.splice(n,1))}),e.forEach(r=>{this.providers.indexOf(r)===-1&&(s.push(r),this.providers.push(r))}),(s.length||t.length)&&this.events.dispatch("conversation:providers-changed",{added:s,removed:t})}createProvider(e){const t=this.providerIndex(e);if(t>-1)return this.registeredProviders[t];const s=A.create(e,this.container,this);return this.registeredProviders.push(s),s}providerIndex(e){return this.registeredProviders.findIndex(t=>t.name===e)}getAgentById(e){if(e)return this.store.getStoredAgent(e)}dispose(){this.conversationHistory.dispose(),this.registeredProviders.forEach(e=>e.dispose()),this.messages=[],this.events.dispatch("conversation:controller-disposed",this),this.active=!1}onDispose(e){return this.events.subscribe("conversation:controller-disposed",e)}onStarted(e){return this.events.subscribe("conversation:started",e)}onMessageCreated(e){return this.events.subscribe("conversation:message-created",e)}isRehydrated(){return this.store.isRehydrated()}disposeProvider(e){const t=this.providerIndex(e.name);t>-1&&this.registeredProviders.splice(t,1),this.events.dispatch("conversation:providers-changed",{removed:[e.name]}),this.registeredProviders.length||this.dispose()}onProvidersChange(e){return this.events.subscribe("conversation:providers-changed",e)}setComponentMountedState(e){this.componentMounted!==e&&(this.componentMounted=e,e&&(this.events.dispatch("conversation:unread-message",!1),this.events.dispatch("conversation:started",!0),this.active=!0),this.events.dispatch("conversation:component-mount-changed",e))}setProviderOptions(e,t){const s=this.providerIndex(e);s>-1&&this.registeredProviders[s].setOptions(t)}changeProvider(e){this.registeredProviders.find(s=>s.name===e)&&x(this.container,this.id,e)}queueProviders(e){this.queuedProviders=e}onCompleteProvider(){const e=this.queuedProviders.pop();e&&x(this.container,this.id,e)}getComponentMountedState(){return this.componentMounted}onUnreadMessage(e){return this.events.subscribe("conversation:unread-message",e)}createEntry(e,t,s,r,n){const a={key:e,content:t,type:s,sender:r||null,timestamp:n||n===null?n:Date.now()};this.messages.push(a),a.type==="agent"&&W(this.typingActors,r);const i=new H(c=>{if(c!==null){const{timestamp:h=void 0,...u}=c;a.content=u,h&&(a.timestamp=h)}else{const h=this.messages.indexOf(a);a.content=null,h>-1&&this.messages.splice(h,1)}this.events.dispatch("conversation:message-updated",{message:a}),this.update()});return this.events.dispatch("conversation:message-created",{message:a}),this.update(),this.componentMounted||this.events.dispatch("conversation:unread-message",!0),i}update(){this.events.dispatch("conversation:updated",{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors})}getMessageStream(){return{messages:this.messages,loading:this.loaders>0,typingActors:this.typingActors}}setTypingState(e,t){return this.typingActors.indexOf(e)===-1&&(this.typingActors.push(e),this.update()),()=>{W(this.typingActors,e),this.update()}}loader(){this.loaders=this.loaders+1;let e=!1;return this.loaders===1&&this.update(),()=>{e||(e=!0,this.loaders=this.loaders-1,this.loaders===0&&this.update())}}submitForm(e,t){this.formHandlers[e]={...this.formHandlers[e],submit:t}}validateForm(e,t){this.formHandlers[e]={...this.formHandlers[e],validate:t}}getHistory(){return this.conversationHistory.getConversationLogs()}}const F=(o,e)=>{const t=o.split("_contact");return e.widgets.get(t[0])},I=o=>{const e=o.get("$widget"),{name:t,implementation:s}=o.get("$widget"),r=t.indexOf("_contact")>-1?F(t,s):e,{data:n}=o.get("$settings"),{trigger:a}=r.container.get("$settings"),i=`${t.replace("_contact-method","").replace("_contact","")}_contact-method`,c=s.widgets.get(i);return c&&!a?{chatWidget:c,mainWidget:r,data:n}:{mainWidget:r,data:n}},G=o=>{const{chatWidget:e}=I(o);return!!e},R=(o,e,t)=>{const{mainWidget:s,data:r,chatWidget:n}=I(o);return n?n.state==="activated"?n.invoke("open").then(()=>{n.container.getAsync("conversation").then(a=>{a.navigateToConversationIfActive(e.id).then(()=>M.closeAllModals(o))})}):n.activate().then(()=>{const{trigger:a}=n.container.get("$settings");return a.action="hide",n.invoke("setSettings",()=>({data:r,trigger:a,activate:!0})).then(()=>n.container.getAsync("components").then(i=>{const c=i.components().ofType("contact-method");i.write({key:"setContactMethodId",attributes:{properties:{id:e.id,guideId:e.guideId}},target:c,provider:"localStorage"});const h=i.components().ofType("conversation");i.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,provider:"localStorage"})}))}).then(()=>n.invoke("attach",{key:"contact-method",triggerDOMElement:t,withRenderState:"open"})).then(()=>(p.createStorageWriter(n.container,"activeStickyWidget",p.StorageCategory.Necessary,{medium:p.StorageMedium.Local,scope:p.StorageScope.Implementation}).then(a=>a(n.name)),n.container.getAsync("conversation").then(a=>{a.setConversationEndedBehavior(S.Deactivate)}).then(()=>M.closeAllModals(o)).then(()=>!1))):(s.container.getAsync("conversation").then(a=>a.navigateToConversationIfActive(e.id).then(()=>a.setConversationEndedBehavior(S.Navigate))),!n)},J=(o,e,t="conversation")=>{const{mainWidget:s,chatWidget:r}=I(o);return r?r.container.getAsync("router").then(n=>{n.navigate(t,{id:e.id})}):s.container.getAsync("conversation").then(n=>{var a;(a=n.setConversationEndedBehavior(S.Navigate))==null||a.then(()=>{s.container.getAsync("router").then(i=>{s.container.getAsync("components").then(c=>{const h=c.components().ofType("conversation");c.write({key:"setConversationProvider",attributes:{properties:{providers:[e.clientName]}},target:h,provider:"localStorage"})}).then(()=>{i.navigate(t,{id:e.id})})})})})},b="conversations";var S=(o=>(o.Deactivate="deactivate",o.Navigate="navigate",o.None="none",o))(S||{});class w{constructor(e,t){d(this,"events");d(this,"controllers",[]);d(this,"providers",[]);d(this,"disposeProviders",{});d(this,"subscriptions",[]);d(this,"storageWriter",null);d(this,"router",null);d(this,"buttonQuery",null);d(this,"sessionInfo",null);this.container=e,this.components=t;const s=e.get("$widget");this.events=s.events.createChild(this)}initialize(){p.createStorageWriter(this.container,b,p.StorageCategory.Necessary,{medium:p.StorageMedium.Local}).then(e=>this.storageWriter=e),p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>{this.buttonQuery=this.components.components().ofType("conversation-return-button"),e&&(this.sessionInfo=e,e.id&&e.route&&this.writeToComponents({active:!0,alert:{show:!1}}))}),this.container.getAsync("router").then(e=>this.router=e),this.events.subscribe("conversation:ended",(e,t)=>{var s,r,n;switch((s=this.sessionInfo)==null?void 0:s.conversationEndedBehavior){case"deactivate":this.container.get("$widget").deactivate();break;case"navigate":const i=(r=this.router)==null?void 0:r.getInitialRoute();i&&((n=this.router)==null||n.navigate(i.name));break}this.writeToComponents({active:!1}),this.sessionInfo=null,this.storageWriter&&this.storageWriter()})}addSubscription(e){this.subscriptions.push(e)}static getInstance(e,t="conversation"){return E.lock(e)(()=>e.getAsync(t).then(s=>{let r=s;return r||D.ComponentPlatform.getInstance(e).then(n=>(r=new w(e,n),r.initialize(),e.registerAsync(t,()=>r),r))}))}navigateToConversationIfActive(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{var s;if(t&&t.id===e&&t.route){const{name:r,params:n}=t.route;(s=this.router)==null||s.navigate(r,n)}})}setConversationEndedBehavior(e){return p.readStorage(this.container,b,p.StorageMedium.Local).then(t=>{let s=t;return s?s.conversationEndedBehavior=e:s={conversationEndedBehavior:e},this.sessionInfo=s,this.storageWriter&&this.storageWriter(this.sessionInfo)||Promise.resolve()})}async createController(e,t){const s=O(e),{agents:r}=await p.readStorage(this.container,s)||{agents:[]},n=this.controllers.findIndex(i=>i.conversation.id===e);let a;return n>-1?a=this.controllers[n].conversation:a=new B(this.container,e,t),a.setInitialStorage({agents:r||[]}),a}registerProvider(e,t){const s={name:e,handler:t};this.providers.push(s),this.controllers.filter(r=>r.conversation.providers.indexOf(e)>-1).forEach(r=>{this.invokeHandler(s,r)})}registerController(e,t){const s=this.controllers.findIndex(n=>n.conversation.id===e.id);let r;if(s<0){r={conversation:e,component:t},this.controllers.push(r);const n=a=>{a&&this.providers.filter(i=>a.indexOf(i.name)>-1).forEach(i=>{this.invokeHandler(i,r)})};return this.subscriptions.push(e.onDispose((a,i)=>{const c=this.controllers.findIndex(h=>h.conversation===i);c>-1&&this.controllers.splice(c,1),this.components.components().ofType("conversation-return-button").select().writeProperties({active:!1}),this.events.dispatch("conversation:ended",{},{bubbles:!0})})),this.subscriptions.push(e.onProvidersChange((a,i)=>{const{added:c,removed:h=[]}=i;h.forEach(u=>{(this.disposeProviders[u]||[]).forEach(l=>{l()})}),n(c)})),this.subscriptions.push(e.onStarted((a,i)=>{var h,u;const c={id:e.id,route:(h=this.router)==null?void 0:h.getRouteData(),conversationEndedBehavior:(u=this.sessionInfo)==null?void 0:u.conversationEndedBehavior};this.sessionInfo=c,this.storageWriter&&this.storageWriter(c),this.writeToComponents({active:i})})),this.subscriptions.push(e.onUnreadMessage((a,i)=>{this.events.dispatch("conversation:unread-message",i),this.writeToComponents({alert:{show:i}})})),n(e.providers),!0}return r=this.controllers[s],!1}writeToComponents(e,t="conversationReturnButtonState"){this.buttonQuery&&this.components.write({key:"conversationReturnButtonState",attributes:{properties:e},target:this.buttonQuery,provider:"localStorage"})}invokeHandler(e,t){const s=e.handler(t.conversation.createProvider(e.name),t.component);s&&(this.disposeProviders[e.name]||(this.disposeProviders[e.name]=[]),this.disposeProviders[e.name].push(s))}getComponentRoute(){return p.readStorage(this.container,b,p.StorageMedium.Local).then(e=>e==null?void 0:e.route)}dispose(){Object.keys(this.disposeProviders).forEach(e=>{this.disposeProviders[e].forEach(t=>{t()})}),this.subscriptions.forEach(e=>{e()}),this.controllers=[],this.providers=[]}static async handleContactMethodClick(e,t,s,r){if(G(t)){e.preventDefault();let n=document.getElementById("humany-dynamic-anchor");n||(n=document.createElement("a"),n.setAttribute("href","#"),n.id="humany-dynamic-anchor",document.body.appendChild(n)),R(t,s,n)}R(t,s)}static async handleContactMethodSubmit(e,t){var s,r;return(r=(s=t==null?void 0:t.body.form.meta)==null?void 0:s.conversation)!=null&&r.id?x(e,t.body.form.meta.conversation.id,t.clientName):J(e,t)}}const V=(o,e)=>o.reduce((t,s,r)=>{var a,i;const n={...s,content:[{...s.content,key:s.key}]};if(t.length>0&&s.type!==y.System){const c=t[t.length-1];if((!e&&e!==0||Math.abs(c.timestamp-s.timestamp)<e)&&((a=c.sender)==null?void 0:a.name)===((i=s.sender)==null?void 0:i.name)&&c.type===s.type)return c.timestamp=s.timestamp,c.content.push({...s.content,key:s.key}),t}return t.push(n),t},[]),Y=o=>Promise.all([w.getInstance(o),o.getAsync("router")]).then(([e,t])=>N.createReactComponent(o,"conversation",Promise.resolve().then(()=>require("./conversation-9e421db3.js")),async s=>{const{rehydrate:r=!1}=s.properties(),a=t.getRouteData().params.id||s.node.name||"component",i=await e.createController(a,{rehydrate:r}),c=e.registerController(i,s),h=3*60*1e3,u=v=>{const{providers:g=[]}=v;if(g){const f=Array.isArray(g)?g:[g];return i.setProviders(f),f}};u(s.properties(u)),i.setComponentMountedState(!0);const l=v=>{const{loading:g,typingActors:f,messages:C}=v;s.writeProperties({loading:g,typingActors:f,messages:V(C,h)})};l(i.getMessageStream()),c&&(s.writeProperties({conversationControllerId:i.id}),s.actions.create("user-submit",(v,g)=>{if(g){const{preventDefault:f,validationPromise:C}=g;if(f){C&&C().then(T=>{T&&i.user.print(T)});return}}i.user.print(v.text)}),s.actions.create("user-typing",(v,g)=>{}),s.actions.create("form",(v,g)=>{}),s.actions.create("action",(v,g)=>{}),s.actions.create("overlay-mounted",(v,g)=>{}),s.actions.create("show-overlay",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}),s.actions.create("hide-overlay",(v,g)=>{s.writeProperties({overlay:null})}),s.actions.create("show-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!0,secondary:!1}})}),s.actions.create("hide-overlay-conversation",(v,g)=>{s.writeProperties({overlay:{conversation:!1,secondary:!1}})}));const m=i.events.subscribe("conversation:updated",(v,g)=>{l(g)});return()=>{i.setComponentMountedState(!1),m(),i.active||l({messages:[],typingActors:[],loading:!1})}},{reuseController:!0})),X=o=>Promise.all([D.ComponentPlatform.getInstance(o),w.getInstance(o),o.getAsync("router")]).then(([e,t,s])=>N.createReactComponent(o,"conversation-return-button",Promise.resolve().then(()=>require("./return-button-f1f43984.js")),r=>{r.actions.create("toggle",(n={})=>{var a;(a=t.getComponentRoute())==null||a.then(i=>{i&&s.navigate(i.name,i.params)})})}));var _=(o=>(o.LinkList="link-list",o.Separator="separator",o.ButtonList="button-list",o.ItemList="item-list",o.Text="text",o.HTML="html",o.VideoRequest="video-request",o))(_||{});const Z=(o,e,t)=>o.getAsync("componentResolver").then(async s=>{(await w.getInstance(o)).addSubscription(s.registerComponent(e,z.lazy(()=>t)))});exports.Agent=P;exports.ConversationComponent=Y;exports.ConversationController=B;exports.ConversationEndedBehavior=S;exports.ConversationEntry=H;exports.ConversationMessageListItemType=_;exports.ConversationMessageType=y;exports.ConversationPlatform=w;exports.ConversationProvider=A;exports.ConversationReturnButtonComponent=X;exports.registerCustomMessageComponent=Z;
package/index.mjs CHANGED
@@ -939,7 +939,7 @@ const ee = (o, e) => o.reduce((t, s, r) => {
939
939
  ]).then(([e, t]) => _(
940
940
  o,
941
941
  "conversation",
942
- import("./conversation-3b72a8bd.mjs"),
942
+ import("./conversation-5f3a00de.mjs"),
943
943
  async (s) => {
944
944
  const { rehydrate: r = !1 } = s.properties(), a = t.getRouteData().params.id || s.node.name || "component", i = await e.createController(a, {
945
945
  rehydrate: r