@asgard-js/react 0.0.1 → 0.0.3

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 (35) hide show
  1. package/dist/components/chatbot/chatbot-body.d.ts.map +1 -1
  2. package/dist/components/chatbot/chatbot-footer.d.ts.map +1 -1
  3. package/dist/components/chatbot/chatbot-header.d.ts +5 -1
  4. package/dist/components/chatbot/chatbot-header.d.ts.map +1 -1
  5. package/dist/components/chatbot/chatbot.d.ts +8 -3
  6. package/dist/components/chatbot/chatbot.d.ts.map +1 -1
  7. package/dist/components/chatbot/profile-icon.d.ts +8 -0
  8. package/dist/components/chatbot/profile-icon.d.ts.map +1 -0
  9. package/dist/components/conversation-message-renderer/conversation-message-renderer.d.ts +1 -1
  10. package/dist/components/conversation-message-renderer/conversation-message-renderer.d.ts.map +1 -1
  11. package/dist/components/templates/avatar/avatar.d.ts.map +1 -1
  12. package/dist/components/templates/bot-typing-box/bot-typing-box.d.ts +6 -1
  13. package/dist/components/templates/bot-typing-box/bot-typing-box.d.ts.map +1 -1
  14. package/dist/components/templates/button-template/button-template.d.ts +1 -1
  15. package/dist/components/templates/button-template/button-template.d.ts.map +1 -1
  16. package/dist/components/templates/carousel-template/carousel-template.d.ts +1 -1
  17. package/dist/components/templates/carousel-template/carousel-template.d.ts.map +1 -1
  18. package/dist/components/templates/hint-template/hint-template.d.ts +1 -1
  19. package/dist/components/templates/hint-template/hint-template.d.ts.map +1 -1
  20. package/dist/components/templates/quick-replies/quick-replies.d.ts.map +1 -1
  21. package/dist/components/templates/text-template/text-template.d.ts +1 -1
  22. package/dist/components/templates/text-template/text-template.d.ts.map +1 -1
  23. package/dist/context/asgard-service-context.d.ts +13 -5
  24. package/dist/context/asgard-service-context.d.ts.map +1 -1
  25. package/dist/hooks/index.d.ts +0 -1
  26. package/dist/hooks/index.d.ts.map +1 -1
  27. package/dist/hooks/use-channel.d.ts +10 -20
  28. package/dist/hooks/use-channel.d.ts.map +1 -1
  29. package/dist/index.js +391 -344
  30. package/dist/style.css +1 -1
  31. package/package.json +1 -1
  32. package/dist/components/message-box/message-box.d.ts +0 -9
  33. package/dist/components/message-box/message-box.d.ts.map +0 -1
  34. package/dist/hooks/use-chatbot-typing.d.ts +0 -11
  35. package/dist/hooks/use-chatbot-typing.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,283 +1,306 @@
1
- import { jsx as o, jsxs as i } from "react/jsx-runtime";
2
- import { useRef as q, useEffect as m, useState as C, useCallback as h, createContext as Q, useMemo as A, useContext as W } from "react";
3
- import { AsgardServiceClient as X, FetchSSEAction as z, EventType as S, MessageTemplateType as w } from "@asgard-js/core";
4
- function J(n) {
5
- const { config: t } = n, e = q(null);
6
- return e.current || (e.current = new X(t)), m(() => () => {
1
+ import { jsx as n, jsxs as a } from "react/jsx-runtime";
2
+ import { useRef as R, useEffect as T, useState as w, useCallback as f, useMemo as N, createContext as W, useContext as X } from "react";
3
+ import { AsgardServiceClient as G, Conversation as J, MessageTemplateType as y } from "@asgard-js/core";
4
+ function P(o) {
5
+ var t, e, s = "";
6
+ if (typeof o == "string" || typeof o == "number") s += o;
7
+ else if (typeof o == "object") if (Array.isArray(o)) {
8
+ var c = o.length;
9
+ for (t = 0; t < c; t++) o[t] && (e = P(o[t])) && (s && (s += " "), s += e);
10
+ } else for (e in o) o[e] && (s && (s += " "), s += e);
11
+ return s;
12
+ }
13
+ function u() {
14
+ for (var o, t, e = 0, s = "", c = arguments.length; e < c; e++) (o = arguments[e]) && (t = P(o)) && (s && (s += " "), s += t);
15
+ return s;
16
+ }
17
+ function Y(o) {
18
+ const { config: t } = o, e = R(null);
19
+ return e.current || (e.current = new G(t)), T(() => () => {
7
20
  e.current && (e.current.close(), e.current = null);
8
21
  }, [t]), e.current;
9
22
  }
10
- function Y(n) {
11
- const {
12
- client: t,
13
- customChannelId: e,
14
- initConversation: s,
15
- onResetChannelInit: c,
16
- startTyping: l,
17
- onTyping: r,
18
- stopTyping: a
19
- } = n;
23
+ function tt(o) {
24
+ const { client: t, customChannelId: e, initMessages: s, options: c } = o;
20
25
  if (!t)
21
26
  throw new Error("Client instance is required");
22
27
  if (!e)
23
28
  throw new Error("Custom channel id is required");
24
- const [_, u] = C(!1), [p, v] = C(
25
- s ?? []
29
+ const [r, _] = w(!1), [i, l] = w(
30
+ new J({
31
+ messages: new Map(
32
+ s == null ? void 0 : s.map((h) => [h.messageId, h])
33
+ ),
34
+ typingMessages: null
35
+ })
26
36
  );
27
- m(() => {
28
- console.log("conversation", p);
29
- }, [p]), m(() => {
30
- t.setChannel(
31
- {
32
- customChannelId: e,
33
- customMessageId: "",
34
- text: ""
35
- },
36
- {
37
- onStart: () => u(!0),
38
- onCompleted: () => u(!1)
39
- }
40
- );
37
+ T(() => {
38
+ t.setChannel({
39
+ customChannelId: e,
40
+ customMessageId: ""
41
+ });
41
42
  }, [t, e]);
42
- const B = h(
43
- (d, g) => {
44
- v(
45
- (b) => b.concat({
46
- type: "user",
47
- customMessageId: g,
48
- text: d,
49
- time: /* @__PURE__ */ new Date()
50
- })
51
- ), t.sendMessage(
52
- {
53
- customChannelId: e,
54
- customMessageId: g,
55
- text: d
56
- },
57
- {
58
- onStart: () => u(!0),
59
- onCompleted: () => u(!1)
60
- }
61
- );
43
+ const d = f(
44
+ (h, b) => {
45
+ _(!0), l((C) => {
46
+ const x = C.pushMessage(
47
+ C,
48
+ {
49
+ type: "user",
50
+ messageId: b ?? crypto.randomUUID(),
51
+ text: h,
52
+ time: /* @__PURE__ */ new Date()
53
+ }
54
+ );
55
+ return t.sendMessage(
56
+ {
57
+ customChannelId: e,
58
+ customMessageId: b,
59
+ text: h
60
+ },
61
+ {
62
+ onSseMessage: (z) => {
63
+ l(
64
+ (j) => x.onMessage(j, z, {
65
+ showDebugMessage: c == null ? void 0 : c.showDebugMessage
66
+ })
67
+ );
68
+ },
69
+ onSseCompleted: () => {
70
+ _(!1);
71
+ }
72
+ }
73
+ ), x;
74
+ });
62
75
  },
63
- [t, e]
76
+ [t, e, c]
77
+ );
78
+ return N(
79
+ () => ({
80
+ isConnecting: r,
81
+ messages: i.messages,
82
+ typingMessages: i.typingMessages,
83
+ sendMessage: d
84
+ }),
85
+ [i, r, d]
64
86
  );
65
- return m(() => {
66
- c && t.on(z.RESET_CHANNEL, S.INIT, c);
67
- }, [t, c]), m(() => {
68
- t.on(z.NONE, S.MESSAGE_START, (d) => {
69
- l(d.fact.messageStart.message);
70
- });
71
- }, [t, l]), m(() => {
72
- t.on(z.NONE, S.MESSAGE_DELTA, (d) => {
73
- r(d.fact.messageDelta.message);
74
- });
75
- }, [t, r]), m(() => {
76
- t.on(z.NONE, S.MESSAGE_COMPLETE, (d) => {
77
- const { eventType: g, fact: b } = d, T = b.messageComplete.message;
78
- T.isDebug || v(
79
- (E) => E.concat({
80
- type: "bot",
81
- eventType: g,
82
- message: T,
83
- time: /* @__PURE__ */ new Date()
84
- })
85
- ), a();
86
- });
87
- }, [t, a]), {
88
- conversation: p,
89
- sendMessage: B,
90
- isConnectionProcessing: _
91
- };
92
87
  }
93
- function tt(n, t) {
94
- const [e, s] = C(n);
95
- return m(() => {
88
+ function et(o, t) {
89
+ const [e, s] = w(o);
90
+ return T(() => {
96
91
  const c = window.setTimeout(() => {
97
- s(n);
92
+ s(o);
98
93
  }, t ?? 300);
99
94
  return () => clearTimeout(c);
100
- }, [n, t]), e;
101
- }
102
- function et() {
103
- const [n, t] = C(!1), [e, s] = C(null), c = h(() => t(!0), [t]), l = h((_) => {
104
- s((u) => (u ?? "") + _.text);
105
- }, []), r = h(() => {
106
- t(!1), s(null);
107
- }, [t]);
108
- return {
109
- isTyping: tt(n, 500),
110
- displayText: e,
111
- startTyping: c,
112
- onTyping: l,
113
- stopTyping: r
114
- };
95
+ }, [o, t]), e;
115
96
  }
116
- const U = Q({
97
+ const L = W({
98
+ avatar: void 0,
117
99
  client: null,
118
- isTyping: !1,
119
- displayText: null,
100
+ isConnecting: !1,
101
+ messages: null,
102
+ typingMessages: null,
120
103
  messageBoxBottomRef: { current: null },
121
- isConnectionProcessing: !1,
122
- conversation: [],
123
104
  sendMessage: () => {
124
105
  }
125
106
  });
126
- function nt(n) {
107
+ function ot(o) {
127
108
  const {
128
- children: t,
129
- config: e,
130
- customChannelId: s,
131
- customMessageId: c,
132
- delayTime: l,
133
- initConversation: r,
134
- ...a
135
- } = n, _ = q(null), u = J({ config: e }), { isTyping: p, displayText: v, startTyping: B, onTyping: d, stopTyping: g } = et(), { sendMessage: b, conversation: T, isConnectionProcessing: E } = Y({
136
- client: u,
137
- customChannelId: s,
138
- startTyping: B,
139
- onTyping: d,
140
- stopTyping: g,
141
- initConversation: r
142
- }), K = A(
109
+ avatar: t,
110
+ children: e,
111
+ config: s,
112
+ customChannelId: c,
113
+ customMessageId: r,
114
+ delayTime: _,
115
+ initMessages: i,
116
+ options: l,
117
+ ...d
118
+ } = o, h = R(null), b = Y({ config: s }), { messages: C, typingMessages: x, sendMessage: z, isConnecting: j } = tt({
119
+ client: b,
120
+ customChannelId: c,
121
+ initMessages: i,
122
+ options: l
123
+ }), Q = N(
143
124
  () => ({
144
- client: u,
145
- isTyping: p,
146
- displayText: v,
147
- messageBoxBottomRef: _,
148
- isConnectionProcessing: E,
149
- conversation: T,
150
- sendMessage: b
125
+ avatar: t,
126
+ client: b,
127
+ isConnecting: j,
128
+ messages: C,
129
+ typingMessages: x,
130
+ sendMessage: z,
131
+ messageBoxBottomRef: h
151
132
  }),
152
- [
153
- u,
154
- T,
155
- v,
156
- _,
157
- E,
158
- p,
159
- b
160
- ]
133
+ [t, b, j, C, z, x]
161
134
  );
162
- return /* @__PURE__ */ o(U.Provider, { value: K, children: /* @__PURE__ */ o("div", { ...a, children: t }) });
135
+ return /* @__PURE__ */ n(L.Provider, { value: Q, children: /* @__PURE__ */ n("div", { ...d, children: e }) });
163
136
  }
164
- function k() {
165
- return W(U);
137
+ function m() {
138
+ return X(L);
166
139
  }
167
- const ot = "_chatbot_header_uinpm_1", st = {
168
- chatbot_header: ot
140
+ const nt = "_chatbot_header_1xj9n_1", st = "_chatbot_header__content_1xj9n_1", ct = "_chatbot_header__title_1xj9n_9", rt = "_chatbot_header__extra_1xj9n_20", k = {
141
+ chatbot_header: nt,
142
+ chatbot_header__content: st,
143
+ chatbot_header__title: ct,
144
+ chatbot_header__extra: rt
169
145
  };
170
- function ct() {
171
- return /* @__PURE__ */ o("div", { className: st.chatbot_header, children: "Header" });
146
+ function at(o) {
147
+ const { avatar: t } = o;
148
+ return t ? /* @__PURE__ */ n(
149
+ "img",
150
+ {
151
+ src: t,
152
+ alt: "avatar",
153
+ style: {
154
+ width: 33,
155
+ height: 32,
156
+ borderRadius: "50%"
157
+ }
158
+ }
159
+ ) : /* @__PURE__ */ a(
160
+ "svg",
161
+ {
162
+ width: "33",
163
+ height: "32",
164
+ viewBox: "0 0 33 32",
165
+ fill: "none",
166
+ xmlns: "http://www.w3.org/2000/svg",
167
+ children: [
168
+ /* @__PURE__ */ a("g", { "clip-path": "url(#clip0_3084_29383)", children: [
169
+ /* @__PURE__ */ n(
170
+ "path",
171
+ {
172
+ d: "M0.410645 16C0.410645 7.16344 7.57409 0 16.4106 0C25.2472 0 32.4106 7.16344 32.4106 16C32.4106 24.8366 25.2472 32 16.4106 32C7.57409 32 0.410645 24.8366 0.410645 16Z",
173
+ fill: "#333333"
174
+ }
175
+ ),
176
+ /* @__PURE__ */ n(
177
+ "path",
178
+ {
179
+ "fill-rule": "evenodd",
180
+ "clip-rule": "evenodd",
181
+ d: "M16.5788 6.33398C19.8925 6.33398 22.5788 9.02028 22.5788 12.334C22.5788 14.2211 21.7075 15.9048 20.3453 17.0047C23.6487 18.3735 26.0607 21.6974 26.4106 25.6673H24.4569C24.0206 21.6274 20.9742 18.4911 17.2591 18.3397L16.9776 18.334H16.5788H15.8437C12.0019 18.334 8.81164 21.5258 8.36437 25.6673H6.41064C6.76857 21.607 9.28344 18.2225 12.7029 16.9143C11.4036 15.8137 10.5788 14.1701 10.5788 12.334C10.5788 9.02028 13.265 6.33398 16.5788 6.33398ZM16.5788 16.334C18.7879 16.334 20.5788 14.5431 20.5788 12.334C20.5788 10.1248 18.7879 8.33398 16.5788 8.33398C14.3696 8.33398 12.5788 10.1248 12.5788 12.334C12.5788 14.5431 14.3696 16.334 16.5788 16.334Z",
182
+ fill: "#8C8C8C"
183
+ }
184
+ )
185
+ ] }),
186
+ /* @__PURE__ */ n("defs", { children: /* @__PURE__ */ n("clipPath", { id: "clip0_3084_29383", children: /* @__PURE__ */ n(
187
+ "path",
188
+ {
189
+ d: "M0.410645 16C0.410645 7.16344 7.57409 0 16.4106 0C25.2472 0 32.4106 7.16344 32.4106 16C32.4106 24.8366 25.2472 32 16.4106 32C7.57409 32 0.410645 24.8366 0.410645 16Z",
190
+ fill: "white"
191
+ }
192
+ ) }) })
193
+ ]
194
+ }
195
+ );
172
196
  }
173
- const rt = "_chatbot_body_okhax_1", it = {
174
- chatbot_body: rt
175
- }, at = "_template_box_1ozig_1", f = {
176
- template_box: at,
197
+ function it(o) {
198
+ const { title: t } = o, { avatar: e } = m();
199
+ return /* @__PURE__ */ n("div", { className: k.chatbot_header, children: /* @__PURE__ */ a("div", { className: k.chatbot_header__content, children: [
200
+ /* @__PURE__ */ a("div", { className: k.chatbot_header__title, children: [
201
+ /* @__PURE__ */ n(at, { avatar: e }),
202
+ /* @__PURE__ */ n("h4", { children: t })
203
+ ] }),
204
+ /* @__PURE__ */ n("div", { className: k.chatbot_header__extra })
205
+ ] }) });
206
+ }
207
+ const lt = "_chatbot_body_1f0gq_1", _t = "_chatbot_body__content_1f0gq_7", S = {
208
+ chatbot_body: lt,
209
+ chatbot_body__content: _t
210
+ }, dt = "_template_box_1ozig_1", g = {
211
+ template_box: dt,
177
212
  "template_box--bot": "_template_box--bot_1ozig_7",
178
213
  "template_box--horizontal": "_template_box--horizontal_1ozig_7",
179
214
  "template_box--vertical": "_template_box--vertical_1ozig_10",
180
215
  "template_box--user": "_template_box--user_1ozig_14"
181
216
  };
182
- function L(n) {
183
- var t, e, s = "";
184
- if (typeof n == "string" || typeof n == "number") s += n;
185
- else if (typeof n == "object") if (Array.isArray(n)) {
186
- var c = n.length;
187
- for (t = 0; t < c; t++) n[t] && (e = L(n[t])) && (s && (s += " "), s += e);
188
- } else for (e in n) n[e] && (s && (s += " "), s += e);
189
- return s;
190
- }
191
- function x() {
192
- for (var n, t, e = 0, s = "", c = arguments.length; e < c; e++) (n = arguments[e]) && (t = L(n)) && (s && (s += " "), s += t);
193
- return s;
194
- }
195
- function M(n) {
196
- const { type: t, direction: e = "horizontal", children: s } = n, c = A(() => {
217
+ function M(o) {
218
+ const { type: t, direction: e = "horizontal", children: s } = o, c = N(() => {
197
219
  switch (t) {
198
220
  case "user":
199
- return x(f.template_box, f["template_box--user"]);
221
+ return u(g.template_box, g["template_box--user"]);
200
222
  case "bot":
201
223
  default:
202
- return x(
203
- f.template_box,
204
- f["template_box--bot"],
205
- e === "horizontal" ? f["template_box--horizontal"] : f["template_box--vertical"]
224
+ return u(
225
+ g.template_box,
226
+ g["template_box--bot"],
227
+ e === "horizontal" ? g["template_box--horizontal"] : g["template_box--vertical"]
206
228
  );
207
229
  }
208
230
  }, [e, t]);
209
- return /* @__PURE__ */ o("div", { className: c, children: s });
231
+ return /* @__PURE__ */ n("div", { className: c, children: s });
210
232
  }
211
- const lt = "_template_box_content_12ojl_1", _t = "_content_12ojl_7", D = {
212
- template_box_content: lt,
213
- content: _t
214
- }, ut = "_quick_replies_box_19pe0_1", dt = "_quick_reply_19pe0_7", V = {
215
- quick_replies_box: ut,
216
- quick_reply: dt
233
+ const ht = "_template_box_content_12ojl_1", ut = "_content_12ojl_7", A = {
234
+ template_box_content: ht,
235
+ content: ut
236
+ }, mt = "_quick_replies_box_zoq7y_1", bt = "_quick_reply_zoq7y_7", Z = {
237
+ quick_replies_box: mt,
238
+ quick_reply: bt
217
239
  };
218
- function mt(n) {
219
- const { quickReplies: t } = n, { sendMessage: e } = k(), s = h(
220
- (c) => {
221
- e(c);
240
+ function gt(o) {
241
+ const { quickReplies: t } = o, { sendMessage: e, isConnecting: s } = m(), c = f(
242
+ (r) => {
243
+ e(r);
222
244
  },
223
245
  [e]
224
246
  );
225
- return t != null && t.length ? /* @__PURE__ */ o("div", { className: V.quick_replies_box, children: t.map((c) => /* @__PURE__ */ o(
226
- "div",
247
+ return t != null && t.length ? /* @__PURE__ */ n("div", { className: Z.quick_replies_box, children: t.map((r) => /* @__PURE__ */ n(
248
+ "button",
227
249
  {
228
- className: V.quick_reply,
229
- onClick: () => s(c.text),
230
- children: c.text
250
+ className: Z.quick_reply,
251
+ disabled: s,
252
+ onClick: () => c(r.text),
253
+ children: r.text
231
254
  },
232
- c.text
255
+ r.text
233
256
  )) }) : null;
234
257
  }
235
- function F(n) {
236
- return n.toLocaleTimeString("zh-TW", {
258
+ function F(o) {
259
+ return o.toLocaleTimeString("zh-TW", {
237
260
  timeZone: "Asia/Taipei",
238
261
  hour: "2-digit",
239
262
  minute: "2-digit",
240
263
  hour12: !1
241
264
  });
242
265
  }
243
- const ht = "_time_rgg92_1", pt = {
244
- time: ht
266
+ const pt = "_time_rgg92_1", ft = {
267
+ time: pt
245
268
  };
246
- function $(n) {
247
- const { time: t, className: e } = n;
248
- return t ? /* @__PURE__ */ o("div", { className: x(pt.time, e), children: F(t) }) : null;
269
+ function q(o) {
270
+ const { time: t, className: e } = o;
271
+ return t ? /* @__PURE__ */ n("div", { className: u(ft.time, e), children: F(t) }) : null;
249
272
  }
250
- function H(n) {
251
- const { quickReplies: t, time: e, children: s } = n;
252
- return /* @__PURE__ */ i("div", { className: D.template_box_content, children: [
253
- /* @__PURE__ */ i("div", { className: D.content, children: [
273
+ function $(o) {
274
+ const { quickReplies: t, time: e, children: s } = o;
275
+ return /* @__PURE__ */ a("div", { className: A.template_box_content, children: [
276
+ /* @__PURE__ */ a("div", { className: A.content, children: [
254
277
  s,
255
- /* @__PURE__ */ o($, { time: e })
278
+ /* @__PURE__ */ n(q, { time: e })
256
279
  ] }),
257
- !!(t != null && t.length) && /* @__PURE__ */ o(mt, { quickReplies: t })
280
+ !!(t != null && t.length) && /* @__PURE__ */ n(gt, { quickReplies: t })
258
281
  ] });
259
282
  }
260
- const gt = "_bot_avatar_14r1r_1", bt = {
261
- bot_avatar: gt
283
+ const Ct = "_bot_avatar_xrs9x_1", U = {
284
+ bot_avatar: Ct
262
285
  };
263
- function I() {
264
- return /* @__PURE__ */ o("div", { className: bt.bot_avatar, children: /* @__PURE__ */ i(
286
+ function H() {
287
+ const { avatar: o } = m();
288
+ return o ? /* @__PURE__ */ n("img", { src: o, alt: "Bot Avatar", className: U.bot_avatar }) : /* @__PURE__ */ n("div", { className: U.bot_avatar, children: /* @__PURE__ */ a(
265
289
  "svg",
266
290
  {
267
- width: "25",
268
- height: "24",
291
+ style: { width: "100%", height: "100%" },
269
292
  viewBox: "0 0 25 24",
270
293
  fill: "none",
271
294
  xmlns: "http://www.w3.org/2000/svg",
272
295
  children: [
273
- /* @__PURE__ */ o(
296
+ /* @__PURE__ */ n(
274
297
  "path",
275
298
  {
276
299
  d: "M0.40625 12C0.40625 5.37258 5.77883 0 12.4062 0C19.0337 0 24.4062 5.37258 24.4062 12C24.4062 18.6274 19.0337 24 12.4062 24C5.77883 24 0.40625 18.6274 0.40625 12Z",
277
300
  fill: "#585858"
278
301
  }
279
302
  ),
280
- /* @__PURE__ */ o(
303
+ /* @__PURE__ */ n(
281
304
  "path",
282
305
  {
283
306
  d: "M6.40625 18.75V15C6.40625 14.5875 6.55313 14.2344 6.84688 13.9406C7.14063 13.6469 7.49375 13.5 7.90625 13.5H16.9062C17.3188 13.5 17.6719 13.6469 17.9656 13.9406C18.2594 14.2344 18.4062 14.5875 18.4062 15V18.75H6.40625ZM10.1562 12.75C9.11875 12.75 8.23438 12.3844 7.50312 11.6531C6.77187 10.9219 6.40625 10.0375 6.40625 9C6.40625 7.9625 6.77187 7.07812 7.50312 6.34687C8.23438 5.61562 9.11875 5.25 10.1562 5.25H14.6562C15.6938 5.25 16.5781 5.61562 17.3094 6.34687C18.0406 7.07812 18.4062 7.9625 18.4062 9C18.4062 10.0375 18.0406 10.9219 17.3094 11.6531C16.5781 12.3844 15.6938 12.75 14.6562 12.75H10.1562ZM7.90625 17.25H16.9062V15H7.90625V17.25ZM10.1562 11.25H14.6562C15.2812 11.25 15.8125 11.0312 16.25 10.5938C16.6875 10.1562 16.9062 9.625 16.9062 9C16.9062 8.375 16.6875 7.84375 16.25 7.40625C15.8125 6.96875 15.2812 6.75 14.6562 6.75H10.1562C9.53125 6.75 9 6.96875 8.5625 7.40625C8.125 7.84375 7.90625 8.375 7.90625 9C7.90625 9.625 8.125 10.1562 8.5625 10.5938C9 11.0312 9.53125 11.25 10.1562 11.25ZM10.1562 9.75C10.3688 9.75 10.5469 9.67812 10.6906 9.53438C10.8344 9.39062 10.9062 9.2125 10.9062 9C10.9062 8.7875 10.8344 8.60938 10.6906 8.46562C10.5469 8.32187 10.3688 8.25 10.1562 8.25C9.94375 8.25 9.76562 8.32187 9.62187 8.46562C9.47812 8.60938 9.40625 8.7875 9.40625 9C9.40625 9.2125 9.47812 9.39062 9.62187 9.53438C9.76562 9.67812 9.94375 9.75 10.1562 9.75ZM14.6562 9.75C14.8687 9.75 15.0469 9.67812 15.1906 9.53438C15.3344 9.39062 15.4062 9.2125 15.4062 9C15.4062 8.7875 15.3344 8.60938 15.1906 8.46562C15.0469 8.32187 14.8687 8.25 14.6562 8.25C14.4438 8.25 14.2656 8.32187 14.1219 8.46562C13.9781 8.60938 13.9062 8.7875 13.9062 9C13.9062 9.2125 13.9781 9.39062 14.1219 9.53438C14.2656 9.67812 14.4438 9.75 14.6562 9.75Z",
@@ -288,54 +311,54 @@ function I() {
288
311
  }
289
312
  ) });
290
313
  }
291
- const ft = "_text_1b4yq_1", yt = "_dot_1b4yq_18", Ct = "_blink_1b4yq_1", y = {
292
- text: ft,
293
- "text--bot": "_text--bot_1b4yq_7",
294
- "typing-indicator": "_typing-indicator_1b4yq_13",
295
- dot: yt,
296
- blink: Ct
314
+ const xt = "_text_1djgp_1", vt = "_dot_1djgp_18", yt = "_blink_1djgp_1", p = {
315
+ text: xt,
316
+ "text--bot": "_text--bot_1djgp_7",
317
+ "typing-indicator": "_typing-indicator_1djgp_13",
318
+ dot: vt,
319
+ blink: yt
297
320
  };
298
- function xt(n) {
299
- const { children: t, onResize: e } = n, s = q(null);
300
- return m(() => {
301
- const c = new ResizeObserver((l) => {
302
- for (const r of l) {
303
- const { width: a, height: _ } = r.contentRect;
304
- e(a, _);
321
+ function wt(o) {
322
+ const { children: t, onResize: e } = o, s = R(null);
323
+ return T(() => {
324
+ const c = new ResizeObserver((r) => {
325
+ for (const _ of r) {
326
+ const { width: i, height: l } = _.contentRect;
327
+ e(i, l);
305
328
  }
306
329
  });
307
330
  return s.current && c.observe(s.current), () => {
308
331
  c.disconnect();
309
332
  };
310
- }, [s, e]), /* @__PURE__ */ o("div", { ref: s, children: t });
333
+ }, [s, e]), /* @__PURE__ */ n("div", { ref: s, children: t });
311
334
  }
312
- function vt() {
313
- const { isTyping: n, displayText: t, messageBoxBottomRef: e } = k(), s = h(() => {
314
- var c;
315
- (c = e.current) == null || c.scrollIntoView({ behavior: "smooth" });
316
- }, [e]);
317
- return n ? /* @__PURE__ */ i(M, { type: "bot", direction: "horizontal", children: [
318
- /* @__PURE__ */ o(I, {}),
319
- /* @__PURE__ */ o(H, { time: /* @__PURE__ */ new Date(), children: /* @__PURE__ */ o("div", { className: x(y.text, y["text--bot"]), children: /* @__PURE__ */ i(xt, { onResize: s, children: [
320
- /* @__PURE__ */ o("span", { children: t ?? "" }),
321
- n && /* @__PURE__ */ i("span", { className: y["typing-indicator"], children: [
322
- /* @__PURE__ */ o("div", { className: y.dot }),
323
- /* @__PURE__ */ o("div", { className: y.dot }),
324
- /* @__PURE__ */ o("div", { className: y.dot })
335
+ function Nt(o) {
336
+ const { typingMessage: t } = o, { messageBoxBottomRef: e } = m(), s = f(() => {
337
+ var r;
338
+ (r = e.current) == null || r.scrollIntoView({ behavior: "smooth" });
339
+ }, [e]), c = et(t == null ? void 0 : t.isTyping, 500);
340
+ return c ? /* @__PURE__ */ a(M, { type: "bot", direction: "horizontal", children: [
341
+ /* @__PURE__ */ n(H, {}),
342
+ /* @__PURE__ */ n($, { time: /* @__PURE__ */ new Date(), children: /* @__PURE__ */ n("div", { className: u(p.text, p["text--bot"]), children: /* @__PURE__ */ a(wt, { onResize: s, children: [
343
+ /* @__PURE__ */ n("span", { children: (t == null ? void 0 : t.typingText) ?? "" }),
344
+ c && /* @__PURE__ */ a("span", { className: p["typing-indicator"], children: [
345
+ /* @__PURE__ */ n("div", { className: p.dot }),
346
+ /* @__PURE__ */ n("div", { className: p.dot }),
347
+ /* @__PURE__ */ n("div", { className: p.dot })
325
348
  ] })
326
349
  ] }) }) })
327
350
  ] }) : null;
328
351
  }
329
- const Tt = "_card_root_1ygom_1", Nt = "_card_content_1ygom_10", wt = "_card_title_1ygom_17", Mt = "_card_description_1ygom_23", kt = "_card_actions_1ygom_37", N = {
330
- card_root: Tt,
331
- card_content: Nt,
332
- card_title: wt,
333
- card_description: Mt,
352
+ const Mt = "_card_root_1ygom_1", Tt = "_card_content_1ygom_10", zt = "_card_title_1ygom_17", jt = "_card_description_1ygom_23", kt = "_card_actions_1ygom_37", v = {
353
+ card_root: Mt,
354
+ card_content: Tt,
355
+ card_title: zt,
356
+ card_description: jt,
334
357
  card_actions: kt
335
358
  };
336
- function G(n) {
337
- var r;
338
- const { template: t } = n, { sendMessage: e } = k(), s = A(() => (t == null ? void 0 : t.thumbnailImageUrl.replace(/^http:/, "").replace(/^https:/, "")) || "https://via.assets.so/img.jpg?w=200&h=270&tc=white&bg=#eeeeee", [t]), c = A(() => {
359
+ function K(o) {
360
+ var _;
361
+ const { template: t } = o, { sendMessage: e } = m(), s = N(() => (t == null ? void 0 : t.thumbnailImageUrl.replace(/^http:/, "").replace(/^https:/, "")) || "https://via.assets.so/img.jpg?w=200&h=270&tc=white&bg=#eeeeee", [t]), c = N(() => {
339
362
  switch (t == null ? void 0 : t.imageAspectRatio) {
340
363
  case "square":
341
364
  return "1 / 1";
@@ -343,21 +366,21 @@ function G(n) {
343
366
  default:
344
367
  return "1.51 / 1";
345
368
  }
346
- }, [t]), l = h(
347
- (a) => function() {
348
- switch (a.type) {
369
+ }, [t]), r = f(
370
+ (i) => function() {
371
+ switch (i.type) {
349
372
  case "message":
350
- e(a.text);
373
+ e(i.text);
351
374
  return;
352
375
  case "uri":
353
- window.open(a.uri, "_blank");
376
+ window.open(i.uri, "_blank");
354
377
  return;
355
378
  }
356
379
  },
357
380
  [e]
358
381
  );
359
- return /* @__PURE__ */ i("div", { className: N.card_root, children: [
360
- (t == null ? void 0 : t.thumbnailImageUrl) && /* @__PURE__ */ o(
382
+ return /* @__PURE__ */ a("div", { className: v.card_root, children: [
383
+ (t == null ? void 0 : t.thumbnailImageUrl) && /* @__PURE__ */ n(
361
384
  "img",
362
385
  {
363
386
  alt: t == null ? void 0 : t.title,
@@ -370,164 +393,188 @@ function G(n) {
370
393
  }
371
394
  }
372
395
  ),
373
- /* @__PURE__ */ i("div", { className: N.card_content, children: [
374
- /* @__PURE__ */ o("h5", { className: N.card_title, children: t == null ? void 0 : t.title }),
375
- /* @__PURE__ */ o("div", { className: N.card_description, children: t == null ? void 0 : t.text }),
376
- /* @__PURE__ */ o("div", { className: N.card_actions, children: (r = t == null ? void 0 : t.buttons) == null ? void 0 : r.map((a, _) => /* @__PURE__ */ o("button", { onClick: l(a.action), children: a.label }, _)) })
396
+ /* @__PURE__ */ a("div", { className: v.card_content, children: [
397
+ /* @__PURE__ */ n("h5", { className: v.card_title, children: t == null ? void 0 : t.title }),
398
+ /* @__PURE__ */ n("div", { className: v.card_description, children: t == null ? void 0 : t.text }),
399
+ /* @__PURE__ */ n("div", { className: v.card_actions, children: (_ = t == null ? void 0 : t.buttons) == null ? void 0 : _.map((i, l) => /* @__PURE__ */ n("button", { onClick: r(i.action), children: i.label }, l)) })
377
400
  ] })
378
401
  ] });
379
402
  }
380
- function Et(n) {
381
- const { conversationMessage: t } = n, e = t.message.template;
382
- return /* @__PURE__ */ i(M, { type: "bot", direction: "horizontal", children: [
383
- /* @__PURE__ */ o(I, {}),
384
- /* @__PURE__ */ o(
385
- H,
403
+ function Bt(o) {
404
+ const { conversationMessage: t } = o, e = t.message.template;
405
+ return /* @__PURE__ */ a(M, { type: "bot", direction: "horizontal", children: [
406
+ /* @__PURE__ */ n(H, {}),
407
+ /* @__PURE__ */ n(
408
+ $,
386
409
  {
387
410
  time: t.time,
388
411
  quickReplies: e == null ? void 0 : e.quickReplies,
389
- children: /* @__PURE__ */ o(G, { template: e })
412
+ children: /* @__PURE__ */ n(K, { template: e })
390
413
  }
391
414
  )
392
415
  ] });
393
416
  }
394
- const zt = "_text_1p20y_1", St = "_content_1p20y_19", R = {
395
- text: zt,
396
- "text--user": "_text--user_1p20y_7",
397
- "text--bot": "_text--bot_1p20y_13",
398
- content: St
417
+ const Ht = "_text_sbjtw_1", It = "_content_sbjtw_19", B = {
418
+ text: Ht,
419
+ "text--user": "_text--user_sbjtw_7",
420
+ "text--bot": "_text--bot_sbjtw_13",
421
+ content: It
399
422
  };
400
- function O(n) {
423
+ function D(o) {
401
424
  var e;
402
- const { conversationMessage: t } = n;
403
- return t.type === "user" ? /* @__PURE__ */ i(M, { type: "user", direction: "horizontal", children: [
404
- /* @__PURE__ */ o("div", { className: x(R.text, R["text--user"]), children: t.text }),
405
- /* @__PURE__ */ o($, { time: t.time })
406
- ] }) : /* @__PURE__ */ i(M, { type: "bot", direction: "horizontal", children: [
407
- /* @__PURE__ */ o(I, {}),
408
- /* @__PURE__ */ o(
409
- H,
425
+ const { conversationMessage: t } = o;
426
+ return t.type === "user" ? /* @__PURE__ */ a(M, { type: "user", direction: "horizontal", children: [
427
+ /* @__PURE__ */ n("div", { className: u(B.text, B["text--user"]), children: t.text }),
428
+ /* @__PURE__ */ n(q, { time: t.time })
429
+ ] }) : /* @__PURE__ */ a(M, { type: "bot", direction: "horizontal", children: [
430
+ /* @__PURE__ */ n(H, {}),
431
+ /* @__PURE__ */ n(
432
+ $,
410
433
  {
411
434
  time: t.time,
412
435
  quickReplies: (e = t.message.template) == null ? void 0 : e.quickReplies,
413
- children: /* @__PURE__ */ o("div", { className: x(R.text, R["text--bot"]), children: t.message.text })
436
+ children: /* @__PURE__ */ n("div", { className: u(B.text, B["text--bot"]), children: t.message.text })
414
437
  }
415
438
  )
416
439
  ] });
417
440
  }
418
- const Rt = "_carousel_root_sv1hc_1", At = "_carousel_time_sv1hc_12", P = {
441
+ const Rt = "_carousel_root_sv1hc_1", qt = "_carousel_time_sv1hc_12", V = {
419
442
  carousel_root: Rt,
420
- carousel_time: At
443
+ carousel_time: qt
421
444
  };
422
- function It(n) {
445
+ function $t(o) {
423
446
  var s;
424
- const { conversationMessage: t } = n, e = t.message.template;
425
- return /* @__PURE__ */ i(M, { type: "bot", direction: "vertical", children: [
426
- /* @__PURE__ */ o(I, {}),
427
- /* @__PURE__ */ o("div", { className: P.carousel_root, children: (s = e.columns) == null ? void 0 : s.map((c, l) => /* @__PURE__ */ o(G, { template: c }, l)) }),
428
- /* @__PURE__ */ o($, { className: P.carousel_time, time: t.time })
447
+ const { conversationMessage: t } = o, e = t.message.template;
448
+ return /* @__PURE__ */ a(M, { type: "bot", direction: "vertical", children: [
449
+ /* @__PURE__ */ n(H, {}),
450
+ /* @__PURE__ */ n("div", { className: V.carousel_root, children: (s = e.columns) == null ? void 0 : s.map((c, r) => /* @__PURE__ */ n(K, { template: c }, r)) }),
451
+ /* @__PURE__ */ n(q, { className: V.carousel_time, time: t.time })
429
452
  ] });
430
453
  }
431
- const Bt = "_hint_root_4opfe_1", qt = "_time_4opfe_15", Z = {
432
- hint_root: Bt,
433
- time: qt
454
+ const St = "_hint_root_g119q_1", At = "_time_g119q_14", E = {
455
+ hint_root: St,
456
+ time: At
434
457
  };
435
- function $t(n) {
436
- const { conversationMessage: t } = n;
458
+ function Zt(o) {
459
+ const { conversationMessage: t } = o;
437
460
  if (t.type === "user") return null;
438
461
  const e = t.message.template;
439
- return e.type !== w.HINT ? null : /* @__PURE__ */ i("div", { className: Z.hint_root, children: [
440
- /* @__PURE__ */ o("div", { className: Z.time, children: F(t.time) }),
462
+ return e.type !== y.HINT ? null : /* @__PURE__ */ a("div", { className: E.hint_root, children: [
463
+ /* @__PURE__ */ n("div", { className: E.time, children: F(t.time) }),
441
464
  e.text
442
465
  ] });
443
466
  }
444
- function Ht(n) {
445
- const { conversationMessage: t } = n;
467
+ function Ut(o) {
468
+ const { conversationMessage: t } = o;
446
469
  if (t.type === "user")
447
- return /* @__PURE__ */ o(O, { conversationMessage: t });
470
+ return /* @__PURE__ */ n(D, { conversationMessage: t });
448
471
  const e = t.message.template;
449
472
  switch (e == null ? void 0 : e.type) {
450
- case w.TEXT:
451
- return /* @__PURE__ */ o(O, { conversationMessage: t });
452
- case w.HINT:
453
- return /* @__PURE__ */ o($t, { conversationMessage: t });
454
- case w.BUTTON:
455
- return /* @__PURE__ */ o(Et, { conversationMessage: t });
456
- case w.CAROUSEL:
457
- return /* @__PURE__ */ o(It, { conversationMessage: t });
473
+ case y.TEXT:
474
+ return /* @__PURE__ */ n(D, { conversationMessage: t });
475
+ case y.HINT:
476
+ return /* @__PURE__ */ n(Zt, { conversationMessage: t });
477
+ case y.BUTTON:
478
+ return /* @__PURE__ */ n(Bt, { conversationMessage: t });
479
+ case y.CAROUSEL:
480
+ return /* @__PURE__ */ n($t, { conversationMessage: t });
458
481
  default:
459
- return /* @__PURE__ */ o("div", { children: "Unknown template" });
482
+ return /* @__PURE__ */ n("div", { children: "Unknown template" });
460
483
  }
461
484
  }
462
485
  function Dt() {
463
- const { conversation: n, messageBoxBottomRef: t } = k();
464
- return m(() => {
465
- var e;
466
- (e = t.current) == null || e.scrollIntoView({ behavior: "smooth" });
467
- }, [n, t]), /* @__PURE__ */ i("div", { className: it.chatbot_body, children: [
468
- n.map((e) => /* @__PURE__ */ o(
469
- Ht,
486
+ const { messages: o, typingMessages: t, messageBoxBottomRef: e } = m();
487
+ return T(() => {
488
+ var s;
489
+ (s = e.current) == null || s.scrollIntoView({ behavior: "smooth" });
490
+ }, [o, e]), /* @__PURE__ */ n("div", { className: S.chatbot_body, children: /* @__PURE__ */ a("div", { className: S.chatbot_body__content, children: [
491
+ Array.from((o == null ? void 0 : o.values()) ?? []).map((s) => /* @__PURE__ */ n(
492
+ Ut,
470
493
  {
471
- conversationMessage: e
494
+ conversationMessage: s
472
495
  },
473
496
  crypto.randomUUID()
474
497
  )),
475
- /* @__PURE__ */ o(vt, {}),
476
- /* @__PURE__ */ o("div", { ref: t })
477
- ] });
498
+ Array.from((t == null ? void 0 : t.values()) ?? []).map((s) => /* @__PURE__ */ n(
499
+ Nt,
500
+ {
501
+ typingMessage: s
502
+ },
503
+ crypto.randomUUID()
504
+ )),
505
+ /* @__PURE__ */ n("div", { ref: e })
506
+ ] }) });
478
507
  }
479
- const Vt = "_chatbot_footer_1i661_1", Ot = "_chatbot_input_1i661_5", j = {
508
+ const Vt = "_chatbot_footer_3box0_1", Et = "_chatbot_footer__content_3box0_1", Ot = "_chatbot_textarea_3box0_8", I = {
480
509
  chatbot_footer: Vt,
481
- chatbot_input: Ot
510
+ chatbot_footer__content: Et,
511
+ chatbot_textarea: Ot
482
512
  };
483
513
  function Pt() {
484
- const { sendMessage: n, isConnectionProcessing: t } = k(), [e, s] = C(""), c = h(
485
- (r) => {
486
- s(r.target.value);
514
+ const { sendMessage: o, isConnecting: t } = m(), [e, s] = w(""), [c, r] = w(!1), _ = f(
515
+ (l) => {
516
+ const d = l.target, h = d.value;
517
+ d.style.height = "20px", h && (d.style.height = `${d.scrollHeight - 16}px`), s(l.target.value);
487
518
  },
488
519
  []
489
- ), l = h(
490
- (r) => {
491
- r.key === "Enter" && (n(e), s(""));
520
+ ), i = f(
521
+ (l) => {
522
+ l.key === "Enter" && !c && !t && (o(e), s(""));
492
523
  },
493
- [n, e]
524
+ [c, t, o, e]
494
525
  );
495
- return /* @__PURE__ */ o("div", { className: j.chatbot_footer, children: /* @__PURE__ */ o(
496
- "input",
526
+ return /* @__PURE__ */ n("div", { className: I.chatbot_footer, children: /* @__PURE__ */ n("div", { className: I.chatbot_footer__content, children: /* @__PURE__ */ n(
527
+ "textarea",
497
528
  {
498
- className: j.chatbot_input,
529
+ className: I.chatbot_textarea,
499
530
  disabled: t,
531
+ cols: 40,
500
532
  value: e,
501
533
  placeholder: "Enter message",
502
- onChange: c,
503
- onKeyDown: l
534
+ onChange: _,
535
+ onKeyDown: i,
536
+ onCompositionStart: () => r(!0),
537
+ onCompositionEnd: () => r(!1)
504
538
  }
505
- ) });
539
+ ) }) });
506
540
  }
507
- const Zt = "_chatbot_root_1tkt9_1", jt = {
508
- chatbot_root: Zt
541
+ const Lt = "_chatbot_root_1jllh_1", Ft = "_chatbot_root__fullScreen_1jllh_12", O = {
542
+ chatbot_root: Lt,
543
+ chatbot_root__fullScreen: Ft
509
544
  };
510
- function Gt(n) {
511
- const { config: t, customChannelId: e, initConversation: s } = n;
512
- return /* @__PURE__ */ i(
513
- nt,
545
+ function Xt(o) {
546
+ const {
547
+ title: t,
548
+ config: e,
549
+ customChannelId: s,
550
+ initMessages: c,
551
+ fullScreen: r = !1,
552
+ avatar: _,
553
+ options: i
554
+ } = o;
555
+ return /* @__PURE__ */ a(
556
+ ot,
514
557
  {
515
- className: jt.chatbot_root,
516
- config: t,
517
- customChannelId: e,
518
- initConversation: s,
558
+ className: u(
559
+ O.chatbot_root,
560
+ r && O.chatbot_root__fullScreen
561
+ ),
562
+ avatar: _,
563
+ config: e,
564
+ customChannelId: s,
565
+ initMessages: c,
566
+ options: i,
519
567
  children: [
520
- /* @__PURE__ */ o(ct, {}),
521
- /* @__PURE__ */ o(Dt, {}),
522
- /* @__PURE__ */ o(Pt, {})
568
+ /* @__PURE__ */ n(it, { title: t }),
569
+ /* @__PURE__ */ n(Dt, {}),
570
+ /* @__PURE__ */ n(Pt, {})
523
571
  ]
524
572
  }
525
573
  );
526
574
  }
527
575
  export {
528
- Gt as Chatbot,
529
- J as useAsgardServiceClient,
530
- Y as useChannel,
531
- et as useChatbotTyping,
532
- tt as useDebounce
576
+ Xt as Chatbot,
577
+ Y as useAsgardServiceClient,
578
+ tt as useChannel,
579
+ et as useDebounce
533
580
  };