@asgard-js/react 0.0.3 → 0.0.4

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 (79) hide show
  1. package/dist/index.js +532 -349
  2. package/dist/style.css +1 -1
  3. package/package.json +5 -1
  4. package/dist/components/chatbot/chatbot-body.d.ts +0 -4
  5. package/dist/components/chatbot/chatbot-body.d.ts.map +0 -1
  6. package/dist/components/chatbot/chatbot-footer.d.ts +0 -4
  7. package/dist/components/chatbot/chatbot-footer.d.ts.map +0 -1
  8. package/dist/components/chatbot/chatbot-header.d.ts +0 -8
  9. package/dist/components/chatbot/chatbot-header.d.ts.map +0 -1
  10. package/dist/components/chatbot/chatbot.d.ts +0 -17
  11. package/dist/components/chatbot/chatbot.d.ts.map +0 -1
  12. package/dist/components/chatbot/profile-icon.d.ts +0 -8
  13. package/dist/components/chatbot/profile-icon.d.ts.map +0 -1
  14. package/dist/components/conversation-message-renderer/conversation-message-renderer.d.ts +0 -9
  15. package/dist/components/conversation-message-renderer/conversation-message-renderer.d.ts.map +0 -1
  16. package/dist/components/conversation-message-renderer/index.d.ts +0 -2
  17. package/dist/components/conversation-message-renderer/index.d.ts.map +0 -1
  18. package/dist/components/index.d.ts +0 -2
  19. package/dist/components/index.d.ts.map +0 -1
  20. package/dist/components/templates/avatar/avatar.d.ts +0 -4
  21. package/dist/components/templates/avatar/avatar.d.ts.map +0 -1
  22. package/dist/components/templates/avatar/index.d.ts +0 -2
  23. package/dist/components/templates/avatar/index.d.ts.map +0 -1
  24. package/dist/components/templates/bot-typing-box/bot-typing-box.d.ts +0 -9
  25. package/dist/components/templates/bot-typing-box/bot-typing-box.d.ts.map +0 -1
  26. package/dist/components/templates/bot-typing-box/index.d.ts +0 -2
  27. package/dist/components/templates/bot-typing-box/index.d.ts.map +0 -1
  28. package/dist/components/templates/bot-typing-box/resize-observer-box.d.ts +0 -9
  29. package/dist/components/templates/bot-typing-box/resize-observer-box.d.ts.map +0 -1
  30. package/dist/components/templates/button-template/button-template.d.ts +0 -9
  31. package/dist/components/templates/button-template/button-template.d.ts.map +0 -1
  32. package/dist/components/templates/button-template/card.d.ts +0 -9
  33. package/dist/components/templates/button-template/card.d.ts.map +0 -1
  34. package/dist/components/templates/button-template/index.d.ts +0 -2
  35. package/dist/components/templates/button-template/index.d.ts.map +0 -1
  36. package/dist/components/templates/carousel-template/carousel-template.d.ts +0 -9
  37. package/dist/components/templates/carousel-template/carousel-template.d.ts.map +0 -1
  38. package/dist/components/templates/carousel-template/index.d.ts +0 -2
  39. package/dist/components/templates/carousel-template/index.d.ts.map +0 -1
  40. package/dist/components/templates/hint-template/hint-template.d.ts +0 -9
  41. package/dist/components/templates/hint-template/hint-template.d.ts.map +0 -1
  42. package/dist/components/templates/hint-template/index.d.ts +0 -2
  43. package/dist/components/templates/hint-template/index.d.ts.map +0 -1
  44. package/dist/components/templates/index.d.ts +0 -8
  45. package/dist/components/templates/index.d.ts.map +0 -1
  46. package/dist/components/templates/quick-replies/index.d.ts +0 -2
  47. package/dist/components/templates/quick-replies/index.d.ts.map +0 -1
  48. package/dist/components/templates/quick-replies/quick-replies.d.ts +0 -10
  49. package/dist/components/templates/quick-replies/quick-replies.d.ts.map +0 -1
  50. package/dist/components/templates/template-box/index.d.ts +0 -3
  51. package/dist/components/templates/template-box/index.d.ts.map +0 -1
  52. package/dist/components/templates/template-box/template-box-content.d.ts +0 -12
  53. package/dist/components/templates/template-box/template-box-content.d.ts.map +0 -1
  54. package/dist/components/templates/template-box/template-box.d.ts +0 -14
  55. package/dist/components/templates/template-box/template-box.d.ts.map +0 -1
  56. package/dist/components/templates/text-template/index.d.ts +0 -2
  57. package/dist/components/templates/text-template/index.d.ts.map +0 -1
  58. package/dist/components/templates/text-template/text-template.d.ts +0 -9
  59. package/dist/components/templates/text-template/text-template.d.ts.map +0 -1
  60. package/dist/components/templates/time/index.d.ts +0 -2
  61. package/dist/components/templates/time/index.d.ts.map +0 -1
  62. package/dist/components/templates/time/time.d.ts +0 -9
  63. package/dist/components/templates/time/time.d.ts.map +0 -1
  64. package/dist/context/asgard-service-context.d.ts +0 -30
  65. package/dist/context/asgard-service-context.d.ts.map +0 -1
  66. package/dist/hooks/index.d.ts +0 -4
  67. package/dist/hooks/index.d.ts.map +0 -1
  68. package/dist/hooks/use-asgard-service-client.d.ts +0 -8
  69. package/dist/hooks/use-asgard-service-client.d.ts.map +0 -1
  70. package/dist/hooks/use-channel.d.ts +0 -20
  71. package/dist/hooks/use-channel.d.ts.map +0 -1
  72. package/dist/hooks/use-debounce.d.ts +0 -2
  73. package/dist/hooks/use-debounce.d.ts.map +0 -1
  74. package/dist/index.d.ts +0 -3
  75. package/dist/index.d.ts.map +0 -1
  76. package/dist/utils/format-time.d.ts +0 -2
  77. package/dist/utils/format-time.d.ts.map +0 -1
  78. package/dist/utils/index.d.ts +0 -2
  79. package/dist/utils/index.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,151 +1,195 @@
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;
1
+ import { jsx as o, jsxs as _ } from "react/jsx-runtime";
2
+ import * as x from "react";
3
+ import { useRef as z, useEffect as R, useState as N, useCallback as d, useMemo as B, createContext as ot, useContext as st, memo as ct } from "react";
4
+ import { AsgardServiceClient as rt, Channel as it, Conversation as at, MessageTemplateType as j } from "@asgard-js/core";
5
+ function G(e) {
6
+ var t, s, n = "";
7
+ if (typeof e == "string" || typeof e == "number") n += e;
8
+ else if (typeof e == "object") if (Array.isArray(e)) {
9
+ var c = e.length;
10
+ for (t = 0; t < c; t++) e[t] && (s = G(e[t])) && (n && (n += " "), n += s);
11
+ } else for (s in e) e[s] && (n && (n += " "), n += s);
12
+ return n;
12
13
  }
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;
14
+ function T() {
15
+ for (var e, t, s = 0, n = "", c = arguments.length; s < c; s++) (e = arguments[s]) && (t = G(e)) && (n && (n += " "), n += t);
16
+ return n;
16
17
  }
17
- function Y(o) {
18
- const { config: t } = o, e = R(null);
19
- return e.current || (e.current = new G(t)), T(() => () => {
20
- e.current && (e.current.close(), e.current = null);
21
- }, [t]), e.current;
18
+ function lt(e) {
19
+ const { config: t } = e, s = z(null);
20
+ return s.current || (s.current = new rt(t)), R(() => () => {
21
+ s.current && (s.current.close(), s.current = null);
22
+ }, [t]), s.current;
22
23
  }
23
- function tt(o) {
24
- const { client: t, customChannelId: e, initMessages: s, options: c } = o;
24
+ function _t(e) {
25
+ const {
26
+ client: t,
27
+ customChannelId: s,
28
+ customMessageId: n,
29
+ initMessages: c,
30
+ showDebugMessage: r
31
+ } = e;
25
32
  if (!t)
26
33
  throw new Error("Client instance is required");
27
- if (!e)
34
+ if (!s)
28
35
  throw new Error("Custom channel id is required");
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
- })
36
- );
37
- T(() => {
38
- t.setChannel({
39
- customChannelId: e,
40
- customMessageId: ""
41
- });
42
- }, [t, e]);
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
- });
36
+ const [i, a] = N(null), [u, p] = N(!0), [m, b] = N(!1), [l, h] = N(!1), [f, v] = N(null), C = z(null), L = d(() => {
37
+ b(!0), t == null || t.resetChannel(
38
+ { customChannelId: s, customMessageId: n },
39
+ {
40
+ onSseCompleted: () => {
41
+ b(!1), a(() => {
42
+ const g = new it({
43
+ client: t,
44
+ customChannelId: s,
45
+ conversation: new at({
46
+ showDebugMessage: r,
47
+ messages: new Map(
48
+ c == null ? void 0 : c.map((w) => [w.messageId, w])
49
+ )
50
+ })
51
+ });
52
+ return p(!0), h(g.isConnecting$.value), v(g.conversation$.value), g;
53
+ });
54
+ }
55
+ }
56
+ );
57
+ }, [
58
+ t,
59
+ s,
60
+ n,
61
+ c,
62
+ r
63
+ ]), M = d(() => {
64
+ var g;
65
+ a((w) => (w == null || w.close(), null)), p(!1), b(!1), h(!1), v(null), (g = C.current) == null || g.forEach(
66
+ (w) => w.unsubscribe()
67
+ );
68
+ }, []), $ = d(
69
+ (g) => {
70
+ i == null || i.sendMessage({ text: g });
75
71
  },
76
- [t, e, c]
72
+ [i]
77
73
  );
78
- return N(
74
+ return R(() => {
75
+ if (i)
76
+ return C.current = [
77
+ i == null ? void 0 : i.isConnecting$.subscribe(h),
78
+ i == null ? void 0 : i.conversation$.subscribe(v)
79
+ ], () => {
80
+ var g;
81
+ (g = C.current) == null || g.forEach(
82
+ (w) => w.unsubscribe()
83
+ );
84
+ };
85
+ }, [i]), R(() => {
86
+ !i && u && L();
87
+ }, [i, u, L]), R(() => () => M(), [M]), B(
79
88
  () => ({
80
- isConnecting: r,
81
- messages: i.messages,
82
- typingMessages: i.typingMessages,
83
- sendMessage: d
89
+ isOpen: u,
90
+ isResetting: m,
91
+ isConnecting: l,
92
+ conversation: f,
93
+ sendMessage: $,
94
+ resetChannel: L,
95
+ closeChannel: M
84
96
  }),
85
- [i, r, d]
97
+ [
98
+ u,
99
+ m,
100
+ l,
101
+ f,
102
+ $,
103
+ L,
104
+ M
105
+ ]
86
106
  );
87
107
  }
88
- function et(o, t) {
89
- const [e, s] = w(o);
90
- return T(() => {
108
+ function ut(e, t) {
109
+ const [s, n] = N(e);
110
+ return R(() => {
91
111
  const c = window.setTimeout(() => {
92
- s(o);
112
+ n(e);
93
113
  }, t ?? 300);
94
114
  return () => clearTimeout(c);
95
- }, [o, t]), e;
115
+ }, [e, t]), s;
96
116
  }
97
- const L = W({
117
+ const Y = ot({
98
118
  avatar: void 0,
99
119
  client: null,
120
+ isOpen: !1,
121
+ isResetting: !1,
100
122
  isConnecting: !1,
101
123
  messages: null,
102
- typingMessages: null,
103
124
  messageBoxBottomRef: { current: null },
104
- sendMessage: () => {
105
- }
125
+ botTypingPlaceholder: void 0
106
126
  });
107
- function ot(o) {
127
+ function dt(e) {
108
128
  const {
109
129
  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(
130
+ children: s,
131
+ config: n,
132
+ botTypingPlaceholder: c,
133
+ customChannelId: r,
134
+ customMessageId: i,
135
+ delayTime: a,
136
+ initMessages: u,
137
+ options: p,
138
+ ...m
139
+ } = e, b = z(null), l = lt({ config: n }), {
140
+ isOpen: h,
141
+ isResetting: f,
142
+ isConnecting: v,
143
+ conversation: C,
144
+ sendMessage: L,
145
+ resetChannel: M,
146
+ closeChannel: $
147
+ } = _t({
148
+ client: l,
149
+ customChannelId: r,
150
+ initMessages: u,
151
+ showDebugMessage: p == null ? void 0 : p.showDebugMessage
152
+ }), g = B(
124
153
  () => ({
125
154
  avatar: t,
126
- client: b,
127
- isConnecting: j,
128
- messages: C,
129
- typingMessages: x,
130
- sendMessage: z,
131
- messageBoxBottomRef: h
155
+ client: l,
156
+ isOpen: h,
157
+ isResetting: f,
158
+ isConnecting: v,
159
+ messages: (C == null ? void 0 : C.messages) ?? null,
160
+ sendMessage: L,
161
+ resetChannel: M,
162
+ closeChannel: $,
163
+ botTypingPlaceholder: c,
164
+ messageBoxBottomRef: b
132
165
  }),
133
- [t, b, j, C, z, x]
166
+ [
167
+ t,
168
+ l,
169
+ h,
170
+ f,
171
+ v,
172
+ C == null ? void 0 : C.messages,
173
+ L,
174
+ M,
175
+ $,
176
+ c
177
+ ]
134
178
  );
135
- return /* @__PURE__ */ n(L.Provider, { value: Q, children: /* @__PURE__ */ n("div", { ...d, children: e }) });
179
+ return /* @__PURE__ */ o(Y.Provider, { value: g, children: /* @__PURE__ */ o("div", { ...m, children: s }) });
136
180
  }
137
- function m() {
138
- return X(L);
181
+ function y() {
182
+ return st(Y);
139
183
  }
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
184
+ const ht = "_chatbot_header_f3p4c_1", mt = "_chatbot_header__content_f3p4c_1", bt = "_chatbot_header__title_f3p4c_9", gt = "_chatbot_header__extra_f3p4c_20", I = {
185
+ chatbot_header: ht,
186
+ chatbot_header__content: mt,
187
+ chatbot_header__title: bt,
188
+ chatbot_header__extra: gt
145
189
  };
146
- function at(o) {
147
- const { avatar: t } = o;
148
- return t ? /* @__PURE__ */ n(
190
+ function pt(e) {
191
+ const { avatar: t } = e;
192
+ return t ? /* @__PURE__ */ o(
149
193
  "img",
150
194
  {
151
195
  src: t,
@@ -156,7 +200,7 @@ function at(o) {
156
200
  borderRadius: "50%"
157
201
  }
158
202
  }
159
- ) : /* @__PURE__ */ a(
203
+ ) : /* @__PURE__ */ _(
160
204
  "svg",
161
205
  {
162
206
  width: "33",
@@ -165,15 +209,15 @@ function at(o) {
165
209
  fill: "none",
166
210
  xmlns: "http://www.w3.org/2000/svg",
167
211
  children: [
168
- /* @__PURE__ */ a("g", { "clip-path": "url(#clip0_3084_29383)", children: [
169
- /* @__PURE__ */ n(
212
+ /* @__PURE__ */ _("g", { "clip-path": "url(#clip0_3084_29383)", children: [
213
+ /* @__PURE__ */ o(
170
214
  "path",
171
215
  {
172
216
  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
217
  fill: "#333333"
174
218
  }
175
219
  ),
176
- /* @__PURE__ */ n(
220
+ /* @__PURE__ */ o(
177
221
  "path",
178
222
  {
179
223
  "fill-rule": "evenodd",
@@ -183,7 +227,7 @@ function at(o) {
183
227
  }
184
228
  )
185
229
  ] }),
186
- /* @__PURE__ */ n("defs", { children: /* @__PURE__ */ n("clipPath", { id: "clip0_3084_29383", children: /* @__PURE__ */ n(
230
+ /* @__PURE__ */ o("defs", { children: /* @__PURE__ */ o("clipPath", { id: "clip0_3084_29383", children: /* @__PURE__ */ o(
187
231
  "path",
188
232
  {
189
233
  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",
@@ -194,98 +238,116 @@ function at(o) {
194
238
  }
195
239
  );
196
240
  }
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 })
241
+ const ft = (e) => /* @__PURE__ */ x.createElement("svg", { width: 16, height: 16, viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M3.49453 2.3352C6.44049 -0.226723 10.9105 -0.106316 13.7142 2.69633C16.6428 5.62613 16.6428 10.3739 13.7144 13.3035C10.7846 16.2322 6.03581 16.2322 3.1073 13.3036C2.30873 12.505 1.71132 11.5536 1.34188 10.5109L1.78892 10.3525L1.34171 10.5106L1.22791 10.162C1.01752 9.46018 0.910643 8.73159 0.910643 7.9997H2.4542L2.46382 8.33865C2.49584 8.9024 2.60763 9.46037 2.79674 9.99539L2.7968 9.99536L2.90116 10.2683C3.19714 10.9887 3.63414 11.6475 4.19876 12.2121C6.52451 14.5379 10.2961 14.5379 12.6229 12.212C14.9486 9.88539 14.9486 6.11464 12.6227 3.78781C10.3306 1.49653 6.63579 1.46263 4.30292 3.68622L6.68087 3.68698V5.22954H3.49394H1.95141V3.68698V0.5H3.49394L3.49453 2.3352Z", fill: "#8C8C8C" })), Ct = (e) => /* @__PURE__ */ x.createElement("svg", { width: 15, height: 14, viewBox: "0 0 15 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M13.3496 0L7.41062 5.938L1.47162 0L0.411621 1.06L6.34962 6.999L0.411621 12.938L1.47162 13.999L7.41062 8.059L13.3496 13.999L14.4096 12.938L8.47162 6.999L14.4096 1.06L13.3496 0Z", fill: "#8C8C8C" }));
242
+ function vt(e) {
243
+ const { title: t } = e, { avatar: s, isOpen: n, isResetting: c, resetChannel: r, closeChannel: i } = y(), a = d(
244
+ (m) => {
245
+ !n && !c && (m.stopPropagation(), r == null || r());
246
+ },
247
+ [n, c, r]
248
+ ), u = d(
249
+ (m) => {
250
+ n && !c && (m.stopPropagation(), r == null || r());
251
+ },
252
+ [n, c, r]
253
+ ), p = d(
254
+ (m) => {
255
+ c || (m.stopPropagation(), i == null || i());
256
+ },
257
+ [c, i]
258
+ );
259
+ return /* @__PURE__ */ o("div", { className: I.chatbot_header, onClick: a, children: /* @__PURE__ */ _("div", { className: I.chatbot_header__content, children: [
260
+ /* @__PURE__ */ _("div", { className: I.chatbot_header__title, children: [
261
+ /* @__PURE__ */ o(pt, { avatar: s }),
262
+ /* @__PURE__ */ o("h4", { children: t })
203
263
  ] }),
204
- /* @__PURE__ */ n("div", { className: k.chatbot_header__extra })
264
+ /* @__PURE__ */ _("div", { className: I.chatbot_header__extra, children: [
265
+ /* @__PURE__ */ o("div", { onClick: u, children: /* @__PURE__ */ o(ft, {}) }),
266
+ /* @__PURE__ */ o("div", { onClick: p, children: /* @__PURE__ */ o(Ct, {}) })
267
+ ] })
205
268
  ] }) });
206
269
  }
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,
270
+ const xt = "_chatbot_body_1f0gq_1", yt = "_chatbot_body__content_1f0gq_7", P = {
271
+ chatbot_body: xt,
272
+ chatbot_body__content: yt
273
+ }, wt = "_template_box_1ozig_1", k = {
274
+ template_box: wt,
212
275
  "template_box--bot": "_template_box--bot_1ozig_7",
213
276
  "template_box--horizontal": "_template_box--horizontal_1ozig_7",
214
277
  "template_box--vertical": "_template_box--vertical_1ozig_10",
215
278
  "template_box--user": "_template_box--user_1ozig_14"
216
279
  };
217
- function M(o) {
218
- const { type: t, direction: e = "horizontal", children: s } = o, c = N(() => {
280
+ function E(e) {
281
+ const { type: t, direction: s = "horizontal", children: n } = e, c = B(() => {
219
282
  switch (t) {
220
283
  case "user":
221
- return u(g.template_box, g["template_box--user"]);
284
+ return T(k.template_box, k["template_box--user"]);
222
285
  case "bot":
223
286
  default:
224
- return u(
225
- g.template_box,
226
- g["template_box--bot"],
227
- e === "horizontal" ? g["template_box--horizontal"] : g["template_box--vertical"]
287
+ return T(
288
+ k.template_box,
289
+ k["template_box--bot"],
290
+ s === "horizontal" ? k["template_box--horizontal"] : k["template_box--vertical"]
228
291
  );
229
292
  }
230
- }, [e, t]);
231
- return /* @__PURE__ */ n("div", { className: c, children: s });
293
+ }, [s, t]);
294
+ return /* @__PURE__ */ o("div", { className: c, children: n });
232
295
  }
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
296
+ const Nt = "_template_box_content_12ojl_1", Tt = "_content_12ojl_7", F = {
297
+ template_box_content: Nt,
298
+ content: Tt
299
+ }, Rt = "_quick_replies_box_zoq7y_1", Lt = "_quick_reply_zoq7y_7", U = {
300
+ quick_replies_box: Rt,
301
+ quick_reply: Lt
239
302
  };
240
- function gt(o) {
241
- const { quickReplies: t } = o, { sendMessage: e, isConnecting: s } = m(), c = f(
303
+ function Mt(e) {
304
+ const { quickReplies: t } = e, { sendMessage: s, isConnecting: n } = y(), c = d(
242
305
  (r) => {
243
- e(r);
306
+ s == null || s(r);
244
307
  },
245
- [e]
308
+ [s]
246
309
  );
247
- return t != null && t.length ? /* @__PURE__ */ n("div", { className: Z.quick_replies_box, children: t.map((r) => /* @__PURE__ */ n(
310
+ return t != null && t.length ? /* @__PURE__ */ o("div", { className: U.quick_replies_box, children: t.map((r) => /* @__PURE__ */ o(
248
311
  "button",
249
312
  {
250
- className: Z.quick_reply,
251
- disabled: s,
313
+ className: U.quick_reply,
314
+ disabled: n,
252
315
  onClick: () => c(r.text),
253
316
  children: r.text
254
317
  },
255
318
  r.text
256
319
  )) }) : null;
257
320
  }
258
- function F(o) {
259
- return o.toLocaleTimeString("zh-TW", {
321
+ function tt(e) {
322
+ return e.toLocaleTimeString("zh-TW", {
260
323
  timeZone: "Asia/Taipei",
261
324
  hour: "2-digit",
262
325
  minute: "2-digit",
263
326
  hour12: !1
264
327
  });
265
328
  }
266
- const pt = "_time_rgg92_1", ft = {
267
- time: pt
329
+ const St = "_time_rgg92_1", Bt = {
330
+ time: St
268
331
  };
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;
332
+ function D(e) {
333
+ const { time: t, className: s } = e;
334
+ return t ? /* @__PURE__ */ o("div", { className: T(Bt.time, s), children: tt(t) }) : null;
272
335
  }
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: [
277
- s,
278
- /* @__PURE__ */ n(q, { time: e })
336
+ function O(e) {
337
+ const { quickReplies: t, time: s, children: n } = e;
338
+ return /* @__PURE__ */ _("div", { className: F.template_box_content, children: [
339
+ /* @__PURE__ */ _("div", { className: F.content, children: [
340
+ n,
341
+ /* @__PURE__ */ o(D, { time: s })
279
342
  ] }),
280
- !!(t != null && t.length) && /* @__PURE__ */ n(gt, { quickReplies: t })
343
+ !!(t != null && t.length) && /* @__PURE__ */ o(Mt, { quickReplies: t })
281
344
  ] });
282
345
  }
283
- const Ct = "_bot_avatar_xrs9x_1", U = {
284
- bot_avatar: Ct
285
- };
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(
346
+ const kt = "_bot_avatar_xrs9x_1", J = {
347
+ bot_avatar: kt
348
+ }, A = ct((e) => {
349
+ const { avatar: t } = e;
350
+ return t ? /* @__PURE__ */ o("img", { src: t, alt: "Bot Avatar", className: J.bot_avatar }) : /* @__PURE__ */ o("div", { className: J.bot_avatar, children: /* @__PURE__ */ _(
289
351
  "svg",
290
352
  {
291
353
  style: { width: "100%", height: "100%" },
@@ -293,14 +355,14 @@ function H() {
293
355
  fill: "none",
294
356
  xmlns: "http://www.w3.org/2000/svg",
295
357
  children: [
296
- /* @__PURE__ */ n(
358
+ /* @__PURE__ */ o(
297
359
  "path",
298
360
  {
299
361
  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",
300
362
  fill: "#585858"
301
363
  }
302
364
  ),
303
- /* @__PURE__ */ n(
365
+ /* @__PURE__ */ o(
304
366
  "path",
305
367
  {
306
368
  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",
@@ -310,55 +372,63 @@ function H() {
310
372
  ]
311
373
  }
312
374
  ) });
313
- }
314
- const xt = "_text_1djgp_1", vt = "_dot_1djgp_18", yt = "_blink_1djgp_1", p = {
315
- text: xt,
375
+ }), Ht = "_text_1djgp_1", zt = "_dot_1djgp_18", $t = "_blink_1djgp_1", H = {
376
+ text: Ht,
316
377
  "text--bot": "_text--bot_1djgp_7",
317
378
  "typing-indicator": "_typing-indicator_1djgp_13",
318
- dot: vt,
319
- blink: yt
379
+ dot: zt,
380
+ blink: $t
320
381
  };
321
- function wt(o) {
322
- const { children: t, onResize: e } = o, s = R(null);
323
- return T(() => {
382
+ function Vt(e) {
383
+ const { children: t, onResize: s } = e, n = z(null);
384
+ return R(() => {
324
385
  const c = new ResizeObserver((r) => {
325
- for (const _ of r) {
326
- const { width: i, height: l } = _.contentRect;
327
- e(i, l);
386
+ for (const i of r) {
387
+ const { width: a, height: u } = i.contentRect;
388
+ s(a, u);
328
389
  }
329
390
  });
330
- return s.current && c.observe(s.current), () => {
391
+ return n.current && c.observe(n.current), () => {
331
392
  c.disconnect();
332
393
  };
333
- }, [s, e]), /* @__PURE__ */ n("div", { ref: s, children: t });
394
+ }, [n, s]), /* @__PURE__ */ o("div", { ref: n, children: t });
334
395
  }
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 })
396
+ function et(e) {
397
+ const { isTyping: t, typingText: s } = e, { messageBoxBottomRef: n, avatar: c } = y(), r = d(() => {
398
+ var a;
399
+ (a = n.current) == null || a.scrollIntoView({ behavior: "smooth" });
400
+ }, [n]), i = ut(t, 500);
401
+ return i ? /* @__PURE__ */ _(E, { type: "bot", direction: "horizontal", children: [
402
+ /* @__PURE__ */ o(A, { avatar: c }),
403
+ /* @__PURE__ */ o(O, { time: /* @__PURE__ */ new Date(), children: /* @__PURE__ */ o("div", { className: T(H.text, H["text--bot"]), children: /* @__PURE__ */ _(Vt, { onResize: r, children: [
404
+ /* @__PURE__ */ o("span", { children: s ?? "" }),
405
+ i && /* @__PURE__ */ _("span", { className: H["typing-indicator"], children: [
406
+ /* @__PURE__ */ o("div", { className: H.dot }),
407
+ /* @__PURE__ */ o("div", { className: H.dot }),
408
+ /* @__PURE__ */ o("div", { className: H.dot })
348
409
  ] })
349
410
  ] }) }) })
350
411
  ] }) : null;
351
412
  }
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,
357
- card_actions: kt
413
+ function jt(e) {
414
+ const { placeholder: t } = e, { isConnecting: s, messages: n } = y(), c = B(
415
+ () => Array.from((n == null ? void 0 : n.values()) ?? []).some(
416
+ (r) => r.type === "bot" && r.isTyping
417
+ ),
418
+ [n]
419
+ );
420
+ return s && !c ? /* @__PURE__ */ o(et, { isTyping: !0, typingText: t }) : null;
421
+ }
422
+ const Et = "_card_root_1ygom_1", It = "_card_content_1ygom_10", Zt = "_card_title_1ygom_17", qt = "_card_description_1ygom_23", At = "_card_actions_1ygom_37", V = {
423
+ card_root: Et,
424
+ card_content: It,
425
+ card_title: Zt,
426
+ card_description: qt,
427
+ card_actions: At
358
428
  };
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(() => {
429
+ function nt(e) {
430
+ var i;
431
+ const { template: t } = e, { sendMessage: s } = y(), n = B(() => (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 = B(() => {
362
432
  switch (t == null ? void 0 : t.imageAspectRatio) {
363
433
  case "square":
364
434
  return "1 / 1";
@@ -366,25 +436,25 @@ function K(o) {
366
436
  default:
367
437
  return "1.51 / 1";
368
438
  }
369
- }, [t]), r = f(
370
- (i) => function() {
371
- switch (i.type) {
439
+ }, [t]), r = d(
440
+ (a) => function() {
441
+ switch (a.type) {
372
442
  case "message":
373
- e(i.text);
443
+ s(a.text);
374
444
  return;
375
445
  case "uri":
376
- window.open(i.uri, "_blank");
446
+ window.open(a.uri, "_blank");
377
447
  return;
378
448
  }
379
449
  },
380
- [e]
450
+ [s]
381
451
  );
382
- return /* @__PURE__ */ a("div", { className: v.card_root, children: [
383
- (t == null ? void 0 : t.thumbnailImageUrl) && /* @__PURE__ */ n(
452
+ return /* @__PURE__ */ _("div", { className: V.card_root, children: [
453
+ (t == null ? void 0 : t.thumbnailImageUrl) && /* @__PURE__ */ o(
384
454
  "img",
385
455
  {
386
456
  alt: t == null ? void 0 : t.title,
387
- src: s,
457
+ src: n,
388
458
  style: {
389
459
  display: "block",
390
460
  width: "100%",
@@ -393,188 +463,301 @@ function K(o) {
393
463
  }
394
464
  }
395
465
  ),
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)) })
466
+ /* @__PURE__ */ _("div", { className: V.card_content, children: [
467
+ /* @__PURE__ */ o("h5", { className: V.card_title, children: t == null ? void 0 : t.title }),
468
+ /* @__PURE__ */ o("div", { className: V.card_description, children: t == null ? void 0 : t.text }),
469
+ /* @__PURE__ */ o("div", { className: V.card_actions, children: (i = t == null ? void 0 : t.buttons) == null ? void 0 : i.map((a, u) => /* @__PURE__ */ o("button", { onClick: r(a.action), children: a.label }, u)) })
400
470
  ] })
401
471
  ] });
402
472
  }
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
- $,
473
+ function Dt(e) {
474
+ const { message: t } = e, { avatar: s } = y(), n = t.message.template;
475
+ return /* @__PURE__ */ _(E, { type: "bot", direction: "horizontal", children: [
476
+ /* @__PURE__ */ o(A, { avatar: s }),
477
+ /* @__PURE__ */ o(
478
+ O,
409
479
  {
410
480
  time: t.time,
411
- quickReplies: e == null ? void 0 : e.quickReplies,
412
- children: /* @__PURE__ */ n(K, { template: e })
481
+ quickReplies: n == null ? void 0 : n.quickReplies,
482
+ children: /* @__PURE__ */ o(nt, { template: n })
413
483
  }
414
484
  )
415
485
  ] });
416
486
  }
417
- const Ht = "_text_sbjtw_1", It = "_content_sbjtw_19", B = {
418
- text: Ht,
487
+ const Ot = "_text_sbjtw_1", Pt = "_content_sbjtw_19", Z = {
488
+ text: Ot,
419
489
  "text--user": "_text--user_sbjtw_7",
420
490
  "text--bot": "_text--bot_sbjtw_13",
421
- content: It
491
+ content: Pt
422
492
  };
423
- function D(o) {
424
- var e;
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
- $,
493
+ function W(e) {
494
+ var n;
495
+ const { message: t } = e, { avatar: s } = y();
496
+ return t.type === "user" ? /* @__PURE__ */ _(E, { type: "user", direction: "horizontal", children: [
497
+ /* @__PURE__ */ o("div", { className: T(Z.text, Z["text--user"]), children: t.text }),
498
+ /* @__PURE__ */ o(D, { time: t.time })
499
+ ] }) : /* @__PURE__ */ _(E, { type: "bot", direction: "horizontal", children: [
500
+ /* @__PURE__ */ o(A, { avatar: s }),
501
+ /* @__PURE__ */ o(
502
+ O,
433
503
  {
434
504
  time: t.time,
435
- quickReplies: (e = t.message.template) == null ? void 0 : e.quickReplies,
436
- children: /* @__PURE__ */ n("div", { className: u(B.text, B["text--bot"]), children: t.message.text })
505
+ quickReplies: (n = t.message.template) == null ? void 0 : n.quickReplies,
506
+ children: /* @__PURE__ */ o("div", { className: T(Z.text, Z["text--bot"]), children: t.message.text })
437
507
  }
438
508
  )
439
509
  ] });
440
510
  }
441
- const Rt = "_carousel_root_sv1hc_1", qt = "_carousel_time_sv1hc_12", V = {
442
- carousel_root: Rt,
443
- carousel_time: qt
511
+ const Ft = "_carousel_root_sv1hc_1", Ut = "_carousel_time_sv1hc_12", K = {
512
+ carousel_root: Ft,
513
+ carousel_time: Ut
444
514
  };
445
- function $t(o) {
446
- var s;
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 })
515
+ function Jt(e) {
516
+ var c;
517
+ const { message: t } = e, { avatar: s } = y(), n = t.message.template;
518
+ return /* @__PURE__ */ _(E, { type: "bot", direction: "vertical", children: [
519
+ /* @__PURE__ */ o(A, { avatar: s }),
520
+ /* @__PURE__ */ o("div", { className: K.carousel_root, children: (c = n.columns) == null ? void 0 : c.map((r, i) => /* @__PURE__ */ o(nt, { template: r }, i)) }),
521
+ /* @__PURE__ */ o(D, { className: K.carousel_time, time: t.time })
452
522
  ] });
453
523
  }
454
- const St = "_hint_root_g119q_1", At = "_time_g119q_14", E = {
455
- hint_root: St,
456
- time: At
524
+ const Wt = "_hint_root_g119q_1", Kt = "_time_g119q_14", Q = {
525
+ hint_root: Wt,
526
+ time: Kt
457
527
  };
458
- function Zt(o) {
459
- const { conversationMessage: t } = o;
528
+ function Qt(e) {
529
+ const { message: t } = e;
460
530
  if (t.type === "user") return null;
461
- const e = t.message.template;
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) }),
464
- e.text
531
+ const s = t.message.template;
532
+ return s.type !== j.HINT ? null : /* @__PURE__ */ _("div", { className: Q.hint_root, children: [
533
+ /* @__PURE__ */ o("div", { className: Q.time, children: tt(t.time) }),
534
+ s.text
465
535
  ] });
466
536
  }
467
- function Ut(o) {
468
- const { conversationMessage: t } = o;
537
+ function Xt(e) {
538
+ var s;
539
+ const { message: t } = e;
469
540
  if (t.type === "user")
470
- return /* @__PURE__ */ n(D, { conversationMessage: t });
471
- const e = t.message.template;
472
- switch (e == null ? void 0 : e.type) {
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 });
541
+ return /* @__PURE__ */ o(W, { message: t });
542
+ if (t.isTyping)
543
+ return /* @__PURE__ */ o(
544
+ et,
545
+ {
546
+ isTyping: t.isTyping,
547
+ typingText: t.typingText
548
+ }
549
+ );
550
+ switch ((s = t.message.template) == null ? void 0 : s.type) {
551
+ case j.TEXT:
552
+ return /* @__PURE__ */ o(W, { message: t });
553
+ case j.HINT:
554
+ return /* @__PURE__ */ o(Qt, { message: t });
555
+ case j.BUTTON:
556
+ return /* @__PURE__ */ o(Dt, { message: t });
557
+ case j.CAROUSEL:
558
+ return /* @__PURE__ */ o(Jt, { message: t });
481
559
  default:
482
- return /* @__PURE__ */ n("div", { children: "Unknown template" });
560
+ return /* @__PURE__ */ o("div", {});
483
561
  }
484
562
  }
485
- function Dt() {
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,
563
+ function Gt() {
564
+ const { messages: e, messageBoxBottomRef: t, botTypingPlaceholder: s } = y();
565
+ return R(() => {
566
+ var n;
567
+ (n = t.current) == null || n.scrollIntoView({ behavior: "smooth" });
568
+ }, [e, t]), /* @__PURE__ */ o("div", { className: P.chatbot_body, children: /* @__PURE__ */ _("div", { className: P.chatbot_body__content, children: [
569
+ Array.from((e == null ? void 0 : e.values()) ?? []).map((n) => /* @__PURE__ */ o(
570
+ Xt,
493
571
  {
494
- conversationMessage: s
572
+ message: n
495
573
  },
496
- crypto.randomUUID()
574
+ n.messageId
497
575
  )),
498
- Array.from((t == null ? void 0 : t.values()) ?? []).map((s) => /* @__PURE__ */ n(
499
- Nt,
576
+ /* @__PURE__ */ o(
577
+ jt,
500
578
  {
501
- typingMessage: s
502
- },
503
- crypto.randomUUID()
504
- )),
505
- /* @__PURE__ */ n("div", { ref: e })
579
+ placeholder: s ?? "正在輸入訊息"
580
+ }
581
+ ),
582
+ /* @__PURE__ */ o("div", { ref: t })
506
583
  ] }) });
507
584
  }
508
- const Vt = "_chatbot_footer_3box0_1", Et = "_chatbot_footer__content_3box0_1", Ot = "_chatbot_textarea_3box0_8", I = {
509
- chatbot_footer: Vt,
510
- chatbot_footer__content: Et,
511
- chatbot_textarea: Ot
512
- };
513
- function Pt() {
514
- const { sendMessage: o, isConnecting: t } = m(), [e, s] = w(""), [c, r] = w(!1), _ = f(
585
+ const Yt = "_chatbot_footer_aa5it_1", te = "_chatbot_footer__content_aa5it_1", ee = "_chatbot_textarea_aa5it_12", ne = "_chatbot_submit_button_aa5it_27", oe = "_chatbot_submit_button__disabled_aa5it_52", S = {
586
+ chatbot_footer: Yt,
587
+ chatbot_footer__content: te,
588
+ chatbot_textarea: ee,
589
+ chatbot_submit_button: ne,
590
+ chatbot_submit_button__disabled: oe
591
+ }, se = (e) => /* @__PURE__ */ x.createElement("svg", { width: 15, height: 12, viewBox: "0 0 15 12", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.createElement("path", { d: "M0.823242 11.6953V0.945312L14.3328 6.32031L0.823242 11.6953ZM1.90658 10.0911L11.3649 6.32031L1.90658 2.54948V4.98052L5.92574 6.32031L1.90658 7.6601V10.0911Z", fill: "white" })), ce = (e) => /* @__PURE__ */ x.createElement("svg", { width: 11, height: 16, viewBox: "0 0 11 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.createElement("path", { d: "M5.40658 9.90397C4.82435 9.90397 4.33158 9.7023 3.92824 9.29897C3.52491 8.89564 3.32324 8.40286 3.32324 7.82064V2.82064C3.32324 2.23842 3.52491 1.74564 3.92824 1.3423C4.33158 0.938971 4.82435 0.737305 5.40658 0.737305C5.9888 0.737305 6.48158 0.938971 6.88491 1.3423C7.28824 1.74564 7.48991 2.23842 7.48991 2.82064V7.82064C7.48991 8.40286 7.28824 8.89564 6.88491 9.29897C6.48158 9.7023 5.9888 9.90397 5.40658 9.90397ZM4.86491 15.1123V12.8654C3.56213 12.7208 2.47949 12.1724 1.61699 11.2202C0.754492 10.2679 0.323242 9.13467 0.323242 7.82064H1.40658C1.40658 8.92731 1.79706 9.87064 2.57803 10.6506C3.35887 11.4306 4.30331 11.8206 5.41137 11.8206C6.51928 11.8206 7.46213 11.4306 8.23991 10.6506C9.01769 9.87064 9.40658 8.92731 9.40658 7.82064H10.4899C10.4899 9.13467 10.0587 10.2679 9.19616 11.2202C8.33366 12.1724 7.25102 12.7208 5.94824 12.8654V15.1123H4.86491ZM5.40658 8.82064C5.68991 8.82064 5.92741 8.7248 6.11908 8.53314C6.31074 8.34147 6.40658 8.10397 6.40658 7.82064V2.82064C6.40658 2.5373 6.31074 2.2998 6.11908 2.10814C5.92741 1.91647 5.68991 1.82064 5.40658 1.82064C5.12324 1.82064 4.88574 1.91647 4.69408 2.10814C4.50241 2.2998 4.40658 2.5373 4.40658 2.82064V7.82064C4.40658 8.10397 4.50241 8.34147 4.69408 8.53314C4.88574 8.7248 5.12324 8.82064 5.40658 8.82064Z", fill: "white" })), re = (e) => /* @__PURE__ */ x.createElement("svg", { width: 40, height: 40, viewBox: "0 0 40 40", xmlns: "http://www.w3.org/2000/svg", ...e }, /* @__PURE__ */ x.createElement("circle", { cx: 20, cy: 20, r: 18, fill: "#D04444" }), /* @__PURE__ */ x.createElement("rect", { x: 12, y: 12, width: 16, height: 16, fill: "#FFFFFF", rx: 2, ry: 2 }));
592
+ function ie(e) {
593
+ const { setValue: t, className: s } = e, [n, c] = N(!1), r = z(null);
594
+ R(() => {
595
+ const l = window.SpeechRecognition || window.webkitSpeechRecognition;
596
+ if (!l) return;
597
+ const h = new l();
598
+ h.lang = "zh-TW", h.continuous = !0, h.interimResults = !0, h.onresult = (f) => {
599
+ for (let v = f.resultIndex; v < f.results.length; v++)
600
+ f.results[v].isFinal && t((C) => C + f.results[v][0].transcript);
601
+ }, h.onerror = (f) => {
602
+ alert(`語音識別錯誤: ${JSON.stringify(f.error)}`);
603
+ }, h.onend = () => {
604
+ c(!1);
605
+ }, r.current = h;
606
+ }, [t]);
607
+ const i = d(() => {
608
+ if (!r.current) {
609
+ alert("無法開始辨識: 語音識別器未初始化,請檢查是否有授權使用麥克風");
610
+ return;
611
+ }
612
+ try {
613
+ r.current.start(), c(!0);
614
+ } catch (l) {
615
+ alert(`無法開始辨識: ${JSON.stringify(l)}`);
616
+ }
617
+ }, []), a = d(() => {
618
+ r.current && (r.current.stop(), c(!1));
619
+ }, []), u = d(
515
620
  (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);
621
+ n || (l.preventDefault(), i());
518
622
  },
519
- []
520
- ), i = f(
623
+ [n, i]
624
+ ), p = d(
521
625
  (l) => {
522
- l.key === "Enter" && !c && !t && (o(e), s(""));
626
+ n && (l.preventDefault(), a());
523
627
  },
524
- [c, t, o, e]
628
+ [n, a]
629
+ ), m = d(
630
+ (l) => {
631
+ n || (l.preventDefault(), i());
632
+ },
633
+ [n, i]
634
+ ), b = d(
635
+ (l) => {
636
+ n && (l.preventDefault(), a());
637
+ },
638
+ [n, a]
525
639
  );
526
- return /* @__PURE__ */ n("div", { className: I.chatbot_footer, children: /* @__PURE__ */ n("div", { className: I.chatbot_footer__content, children: /* @__PURE__ */ n(
527
- "textarea",
640
+ return /* @__PURE__ */ o(
641
+ "div",
528
642
  {
529
- className: I.chatbot_textarea,
530
- disabled: t,
531
- cols: 40,
532
- value: e,
533
- placeholder: "Enter message",
534
- onChange: _,
535
- onKeyDown: i,
536
- onCompositionStart: () => r(!0),
537
- onCompositionEnd: () => r(!1)
643
+ className: s,
644
+ onMouseDown: u,
645
+ onMouseUp: p,
646
+ onTouchStart: m,
647
+ onTouchEnd: b,
648
+ children: n ? /* @__PURE__ */ o(re, {}) : /* @__PURE__ */ o(ce, {})
538
649
  }
539
- ) }) });
650
+ );
651
+ }
652
+ function ae() {
653
+ const { sendMessage: e, isConnecting: t } = y(), [s, n] = N(""), [c, r] = N(!1), i = z(null), a = B(() => t || !s, [t, s]), u = d(
654
+ (b) => {
655
+ const l = b.target, h = l.value;
656
+ l.style.height = "20px", h && (l.style.height = `${l.scrollHeight - 16}px`), n(b.target.value);
657
+ },
658
+ []
659
+ ), p = d(() => {
660
+ !c && !t && (e == null || e(s), n(""), i.current && (i.current.style.height = "20px"));
661
+ }, [c, t, e, s]), m = d(
662
+ (b) => {
663
+ if (b.key === "Enter" && !c && !t) {
664
+ e == null || e(s), n("");
665
+ const l = b.target;
666
+ l.style.height = "20px";
667
+ }
668
+ },
669
+ [c, t, e, s]
670
+ );
671
+ return /* @__PURE__ */ o("div", { className: S.chatbot_footer, children: /* @__PURE__ */ _("div", { className: S.chatbot_footer__content, children: [
672
+ /* @__PURE__ */ o(
673
+ "textarea",
674
+ {
675
+ ref: i,
676
+ className: S.chatbot_textarea,
677
+ disabled: t,
678
+ cols: 40,
679
+ value: s,
680
+ placeholder: "Enter message",
681
+ onChange: u,
682
+ onKeyDown: m,
683
+ onCompositionStart: () => r(!0),
684
+ onCompositionEnd: () => r(!1)
685
+ }
686
+ ),
687
+ s ? /* @__PURE__ */ o(
688
+ "button",
689
+ {
690
+ className: T(
691
+ S.chatbot_submit_button,
692
+ a && S.chatbot_submit_button__disabled
693
+ ),
694
+ disabled: a,
695
+ onClick: p,
696
+ children: /* @__PURE__ */ o(se, {})
697
+ }
698
+ ) : /* @__PURE__ */ o(
699
+ ie,
700
+ {
701
+ setValue: n,
702
+ className: T(
703
+ S.chatbot_submit_button,
704
+ t && S.chatbot_submit_button__disabled
705
+ )
706
+ }
707
+ )
708
+ ] }) });
540
709
  }
541
- const Lt = "_chatbot_root_1jllh_1", Ft = "_chatbot_root__fullScreen_1jllh_12", O = {
542
- chatbot_root: Lt,
543
- chatbot_root__fullScreen: Ft
710
+ const le = "_chatbot_root_18brc_1", _e = "_chatbot_root__fullScreen_18brc_13", X = {
711
+ chatbot_root: le,
712
+ chatbot_root__fullScreen: _e
713
+ }, ue = "_loading_16ajc_1", de = "_spinner_16ajc_14", he = "_spinner_svg_16ajc_19", me = "_rotate_16ajc_1", be = "_spinner_circle_16ajc_25", ge = "_dash_16ajc_1", q = {
714
+ loading: ue,
715
+ spinner: de,
716
+ spinner_svg: he,
717
+ rotate: me,
718
+ spinner_circle: be,
719
+ dash: ge
544
720
  };
545
- function Xt(o) {
721
+ function pe() {
722
+ const { isResetting: e } = y();
723
+ return e ? /* @__PURE__ */ o("div", { className: q.loading, children: /* @__PURE__ */ o("div", { className: q.spinner, children: /* @__PURE__ */ o("svg", { className: q.spinner_svg, viewBox: "0 0 50 50", children: /* @__PURE__ */ o("circle", { className: q.spinner_circle, cx: "25", cy: "25", r: "20" }) }) }) }) : null;
724
+ }
725
+ function xe(e) {
546
726
  const {
547
727
  title: t,
548
- config: e,
549
- customChannelId: s,
728
+ config: s,
729
+ customChannelId: n,
550
730
  initMessages: c,
551
731
  fullScreen: r = !1,
552
- avatar: _,
553
- options: i
554
- } = o;
555
- return /* @__PURE__ */ a(
556
- ot,
732
+ avatar: i,
733
+ options: a,
734
+ botTypingPlaceholder: u
735
+ } = e;
736
+ return /* @__PURE__ */ _(
737
+ dt,
557
738
  {
558
- className: u(
559
- O.chatbot_root,
560
- r && O.chatbot_root__fullScreen
739
+ className: T(
740
+ X.chatbot_root,
741
+ r && X.chatbot_root__fullScreen
561
742
  ),
562
- avatar: _,
563
- config: e,
564
- customChannelId: s,
743
+ avatar: i,
744
+ config: s,
745
+ customChannelId: n,
565
746
  initMessages: c,
566
- options: i,
747
+ botTypingPlaceholder: u,
748
+ options: a,
567
749
  children: [
568
- /* @__PURE__ */ n(it, { title: t }),
569
- /* @__PURE__ */ n(Dt, {}),
570
- /* @__PURE__ */ n(Pt, {})
750
+ /* @__PURE__ */ o(pe, {}),
751
+ /* @__PURE__ */ o(vt, { title: t }),
752
+ /* @__PURE__ */ o(Gt, {}),
753
+ /* @__PURE__ */ o(ae, {})
571
754
  ]
572
755
  }
573
756
  );
574
757
  }
575
758
  export {
576
- Xt as Chatbot,
577
- Y as useAsgardServiceClient,
578
- tt as useChannel,
579
- et as useDebounce
759
+ xe as Chatbot,
760
+ lt as useAsgardServiceClient,
761
+ _t as useChannel,
762
+ ut as useDebounce
580
763
  };