@opencx/widget 2.6.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/basic.cjs +89 -89
  2. package/dist/basic.cjs.map +1 -1
  3. package/dist/basic.d.ts +1 -1
  4. package/dist/basic.js +34083 -34125
  5. package/dist/basic.js.map +1 -1
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +3 -22
  9. package/dist/react.cjs +1 -1
  10. package/dist/react.cjs.map +1 -1
  11. package/dist/react.d.ts +1 -1
  12. package/dist/react.js +20 -10
  13. package/dist/react.js.map +1 -1
  14. package/dist/src/designs/react/basic/index.d.ts +10 -0
  15. package/dist/src/designs/{basic → react/basic}/utils/group-messages-by-type.d.ts +1 -1
  16. package/dist/src/{@components → designs/react/components}/BotOrAgentMessage.d.ts +1 -1
  17. package/dist/src/{@components → designs/react/components}/BotOrAgentMessageGroup.d.ts +2 -2
  18. package/dist/src/designs/react/components/BotOrAgentMessageWrapper.d.ts +7 -0
  19. package/dist/src/{@components → designs/react/components}/Fallback.component.d.ts +2 -2
  20. package/dist/src/{components → designs/react/components}/RenderFile.d.ts +2 -2
  21. package/dist/src/{@components → designs/react/components}/Text.component.d.ts +1 -1
  22. package/dist/src/{components → designs/react/components}/UserMessageGroup.d.ts +1 -1
  23. package/dist/src/{components → designs/react/components}/VoteButtons.d.ts +1 -1
  24. package/dist/src/designs/{constants.d.ts → react/constants.d.ts} +2 -4
  25. package/dist/src/designs/react/hooks/useLocale.d.ts +6 -0
  26. package/dist/src/{index.d.ts → designs/react/index.d.ts} +2 -2
  27. package/dist/src/designs/translation/ar.locale.d.ts +2 -0
  28. package/dist/src/designs/translation/de.locale.d.ts +2 -0
  29. package/dist/src/designs/translation/en.locale.d.ts +2 -0
  30. package/dist/src/designs/translation/fr.locale.d.ts +2 -0
  31. package/dist/src/designs/translation/index.d.ts +14 -0
  32. package/dist/src/designs/translation/nl.locale.d.ts +2 -0
  33. package/dist/src/designs/translation/pt.locale.d.ts +2 -0
  34. package/dist/src/designs/translation/translation.types.d.ts +4 -0
  35. package/dist/{core/client → src/headless/core}/api.d.ts +56 -143
  36. package/dist/src/headless/core/context/contact.d.ts +25 -0
  37. package/dist/src/headless/core/context/message.d.ts +40 -0
  38. package/dist/src/headless/core/context/session.d.ts +74 -0
  39. package/dist/src/headless/core/context/widget.d.ts +16 -0
  40. package/dist/src/headless/core/index.d.ts +7 -0
  41. package/dist/{core → src/headless/core}/sdk/index.d.ts +5 -4
  42. package/dist/src/headless/core/types/WidgetConfig.d.ts +34 -0
  43. package/dist/src/headless/core/types/agent-or-bot.d.ts +6 -0
  44. package/dist/src/headless/core/types/helpers.d.ts +4 -0
  45. package/dist/{core → src/headless/core}/types/messages.d.ts +11 -31
  46. package/dist/src/headless/core/types/schemas.d.ts +9 -0
  47. package/dist/src/headless/core/utils/Poller.d.ts +12 -0
  48. package/dist/{core/types/pub-sub.d.ts → src/headless/core/utils/PubSub.d.ts} +6 -9
  49. package/dist/{react-web/core-integration/components.d.ts → src/headless/react/ComponentRegistry.d.ts} +1 -1
  50. package/dist/src/headless/react/WidgetProvider.d.ts +17 -0
  51. package/dist/src/headless/react/hooks/useConfig.d.ts +1 -0
  52. package/dist/src/headless/react/hooks/useContact.d.ts +10 -0
  53. package/dist/src/headless/react/hooks/useIsAwaitingBotReply.d.ts +3 -0
  54. package/dist/src/headless/react/hooks/useMessages.d.ts +8 -0
  55. package/dist/{react-web/core-integration → src/headless/react}/hooks/usePreludeData.d.ts +2 -2
  56. package/dist/{react-web/core-integration → src/headless/react}/hooks/usePubsub.d.ts +1 -1
  57. package/dist/src/headless/react/hooks/useSession.d.ts +6 -0
  58. package/dist/{react-web/core-integration → src/headless/react}/hooks/useUploadFiles.d.ts +1 -1
  59. package/dist/{react-web/core-integration → src/headless/react}/hooks/useVote.d.ts +2 -2
  60. package/dist/src/headless/react/index.d.ts +11 -0
  61. package/dist/src/headless/react/types/components.d.ts +15 -0
  62. package/dist/style.css +1 -1
  63. package/dist/useUploadFiles-BZa0DENN.cjs +18 -0
  64. package/dist/useUploadFiles-BZa0DENN.cjs.map +1 -0
  65. package/dist/useUploadFiles-BaCcqTwX.js +1336 -0
  66. package/dist/useUploadFiles-BaCcqTwX.js.map +1 -0
  67. package/dist/widget-BlvH6dre.cjs +2 -0
  68. package/dist/widget-BlvH6dre.cjs.map +1 -0
  69. package/dist/widget-DbgWez1r.js +514 -0
  70. package/dist/widget-DbgWez1r.js.map +1 -0
  71. package/dist-embed/script.js +127 -142
  72. package/dist-embed/script.js.map +1 -1
  73. package/package.json +12 -8
  74. package/dist/api-BEtFfKMB.cjs +0 -2
  75. package/dist/api-BEtFfKMB.cjs.map +0 -1
  76. package/dist/api-Cez5T-se.js +0 -1393
  77. package/dist/api-Cez5T-se.js.map +0 -1
  78. package/dist/core/client/chat.d.ts +0 -101
  79. package/dist/core/client/config.d.ts +0 -43
  80. package/dist/core/client/contact.d.ts +0 -29
  81. package/dist/core/client/index.d.ts +0 -4
  82. package/dist/core/errors/index.d.ts +0 -27
  83. package/dist/core/index.d.ts +0 -9
  84. package/dist/core/platform/audio.d.ts +0 -38
  85. package/dist/core/platform/index.d.ts +0 -15
  86. package/dist/core/platform/logger.d.ts +0 -14
  87. package/dist/core/platform/storage.d.ts +0 -52
  88. package/dist/core/tests/platform/logger.test.d.ts +0 -1
  89. package/dist/core/tests/platform/storage.test.d.ts +0 -1
  90. package/dist/core/tests/test-utils.d.ts +0 -2
  91. package/dist/core/tests/types/pub-sub.test.d.ts +0 -1
  92. package/dist/core/types/contact.d.ts +0 -2
  93. package/dist/core/types/helpers.d.ts +0 -20
  94. package/dist/core/types/index.d.ts +0 -52
  95. package/dist/core/types/prelude.d.ts +0 -14
  96. package/dist/core/types/schemas-v2.d.ts +0 -10
  97. package/dist/index-BzidnDPX.cjs +0 -18
  98. package/dist/index-BzidnDPX.cjs.map +0 -1
  99. package/dist/index-DUlnC30_.js +0 -1219
  100. package/dist/index-DUlnC30_.js.map +0 -1
  101. package/dist/react-web/core-integration/ChatProvider.d.ts +0 -107
  102. package/dist/react-web/core-integration/hooks/useChatMessages.d.ts +0 -70
  103. package/dist/react-web/core-integration/hooks/useChatSession.d.ts +0 -83
  104. package/dist/react-web/core-integration/hooks/useConfig.d.ts +0 -1
  105. package/dist/react-web/core-integration/hooks/useContact.d.ts +0 -17
  106. package/dist/react-web/core-integration/hooks/useLocale.d.ts +0 -4
  107. package/dist/react-web/core-integration/hooks.d.ts +0 -9
  108. package/dist/react-web/core-integration/index.d.ts +0 -2
  109. package/dist/react-web/core-integration/locales/ar.locale.d.ts +0 -2
  110. package/dist/react-web/core-integration/locales/de.locale.d.ts +0 -2
  111. package/dist/react-web/core-integration/locales/en.locale.d.ts +0 -55
  112. package/dist/react-web/core-integration/locales/fr.locale.d.ts +0 -2
  113. package/dist/react-web/core-integration/locales/helper.d.ts +0 -65
  114. package/dist/react-web/core-integration/locales/index.d.ts +0 -3
  115. package/dist/react-web/core-integration/locales/nl.locale.d.ts +0 -2
  116. package/dist/react-web/core-integration/locales/pt.locale.d.ts +0 -2
  117. package/dist/react-web/hooks/useScrollTo.d.ts +0 -2
  118. package/dist/react-web/index.d.ts +0 -4
  119. package/dist/react-web/types/components.d.ts +0 -13
  120. package/dist/react-web/types/index.d.ts +0 -8
  121. package/dist/react-web/types/options.d.ts +0 -17
  122. package/dist/src/@components/BotOrAgentMessageWrapper.d.ts +0 -9
  123. package/dist/src/@components/ChatEvent.component.d.ts +0 -9
  124. package/dist/src/@components/index.d.ts +0 -6
  125. package/dist/src/designs/basic/index.d.ts +0 -8
  126. /package/dist/src/designs/{basic → react/basic}/WidgetPopoverTrigger.d.ts +0 -0
  127. /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatFooter.d.ts +0 -0
  128. /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatHeader.d.ts +0 -0
  129. /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatMain.d.ts +0 -0
  130. /package/dist/src/designs/{basic → react/basic}/screens/chat-screen/ChatScreen.d.ts +0 -0
  131. /package/dist/src/designs/{basic → react/basic}/screens/root-screen.d.ts +0 -0
  132. /package/dist/src/designs/{basic → react/basic}/screens/welcome-screen/WelcomeScreen.d.ts +0 -0
  133. /package/dist/{core/tests/client/integration-perisitance.test.d.ts → src/designs/react/basic/widget-interaction-tests/widget.test.d.ts} +0 -0
  134. /package/dist/src/{@components → designs/react/components}/Loading.component.d.ts +0 -0
  135. /package/dist/src/{@components → designs/react/components}/OpenLogoSvg.d.ts +0 -0
  136. /package/dist/src/{components → designs/react/components}/keyboard.d.ts +0 -0
  137. /package/dist/src/{components → designs/react/components/lib}/MotionDiv.d.ts +0 -0
  138. /package/dist/src/{components → designs/react/components/lib}/avatar.d.ts +0 -0
  139. /package/dist/src/{components → designs/react/components/lib}/button.d.ts +0 -0
  140. /package/dist/src/{components → designs/react/components/lib}/dialog.d.ts +0 -0
  141. /package/dist/src/{components → designs/react/components/lib}/dropdown-menu.d.ts +0 -0
  142. /package/dist/src/{components → designs/react/components/lib}/input.d.ts +0 -0
  143. /package/dist/src/{components → designs/react/components/lib}/popover.d.ts +0 -0
  144. /package/dist/src/{components → designs/react/components/lib}/skeleton.d.ts +0 -0
  145. /package/dist/src/{components → designs/react/components/lib}/switch.d.ts +0 -0
  146. /package/dist/src/{components → designs/react/components/lib}/tooltip.d.ts +0 -0
  147. /package/dist/src/{utils.d.ts → designs/react/components/lib/utils/cn.d.ts} +0 -0
  148. /package/dist/src/{components → designs/react/components/lib}/wobble.d.ts +0 -0
  149. /package/dist/src/{@components → designs/react/components}/markdown.d.ts +0 -0
  150. /package/dist/{react-web → src/designs/react}/hooks/useWidgetContentHeight.d.ts +0 -0
  151. /package/dist/src/{render.d.ts → designs/react/render.d.ts} +0 -0
  152. /package/dist/{core/tests/client/integration.test.d.ts → src/headless/core/utils/PubSub.test.d.ts} +0 -0
  153. /package/dist/{core/utils/genUuid.d.ts → src/headless/core/utils/uuid.d.ts} +0 -0
  154. /package/dist/{react-web → src/headless/react}/utils/create-safe-context.d.ts +0 -0
  155. /package/dist/{core/tests/platform/audio.test.d.ts → vitest/setup.d.ts} +0 -0
@@ -0,0 +1,1336 @@
1
+ var Kt = Object.defineProperty;
2
+ var kt = (e, t, n) => t in e ? Kt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var Ye = (e, t, n) => kt(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import k, { createContext as rt, useContext as ot, useMemo as le, useSyncExternalStore as zt, useEffect as st, useLayoutEffect as Yt, useRef as K, useCallback as Ee, useDebugValue as Jt, useState as Xt } from "react";
5
+ import { jsx as Qt } from "react/jsx-runtime";
6
+ import { W as Zt } from "./widget-DbgWez1r.js";
7
+ import { v4 as en } from "uuid";
8
+ class tn {
9
+ constructor(t) {
10
+ Ye(this, "components", [
11
+ {
12
+ key: "fallback",
13
+ component: (t) => "fallback"
14
+ },
15
+ {
16
+ key: "loading",
17
+ component: (t) => "loading"
18
+ }
19
+ ]);
20
+ const { components: n } = t;
21
+ if (n && n.forEach((r) => this.register(r)), this.components.length === 0)
22
+ throw new Error("No components registered");
23
+ if (!this.get("fallback"))
24
+ throw new Error("No fallback component registered");
25
+ }
26
+ register(t) {
27
+ const n = this.components.findIndex((r) => r.key === t.key);
28
+ return n !== -1 ? this.components[n] = t : this.components.push(t), this;
29
+ }
30
+ get(t) {
31
+ const n = this.components.find(
32
+ (r) => r.key.toUpperCase() === t.toUpperCase()
33
+ );
34
+ return n || null;
35
+ }
36
+ getOrFallback(t) {
37
+ return t ? this.get(t) || this.get("fallback") : this.get("fallback");
38
+ }
39
+ getComponent(t, n) {
40
+ var r;
41
+ return n ? this.getOrFallback(t).component : (r = this.get(t)) == null ? void 0 : r.component;
42
+ }
43
+ }
44
+ function nn(e) {
45
+ const t = rt({});
46
+ return [() => {
47
+ const r = ot(t);
48
+ if (r === void 0)
49
+ throw new Error("useSafeContext must be used within a Provider");
50
+ return r;
51
+ }, t.Provider];
52
+ }
53
+ const [te, rn] = nn();
54
+ function er({
55
+ options: e,
56
+ children: t,
57
+ components: n
58
+ }) {
59
+ const r = le(
60
+ () => new Zt({ config: e }),
61
+ [e]
62
+ ), o = le(
63
+ () => new tn({
64
+ components: n
65
+ }),
66
+ [n]
67
+ );
68
+ return /* @__PURE__ */ Qt(
69
+ rn,
70
+ {
71
+ value: {
72
+ widgetCtx: r,
73
+ components: n,
74
+ componentStore: o,
75
+ version: void 0
76
+ },
77
+ children: t
78
+ }
79
+ );
80
+ }
81
+ function tr() {
82
+ const { widgetCtx: e } = te();
83
+ return e.config;
84
+ }
85
+ function Ve(e) {
86
+ return zt(e.subscribe, e.get, e.get);
87
+ }
88
+ function nr() {
89
+ const { widgetCtx: e } = te();
90
+ return {
91
+ state: Ve(e.contactCtx.state),
92
+ contactCtx: e.contactCtx
93
+ };
94
+ }
95
+ function on() {
96
+ const { widgetCtx: e } = te();
97
+ return { messages: Ve(e.messageCtx.state), messageCtx: e.messageCtx };
98
+ }
99
+ function sn() {
100
+ const { widgetCtx: e } = te();
101
+ return { session: Ve(e.sessionCtx.state) };
102
+ }
103
+ function rr() {
104
+ var r;
105
+ const { session: e } = sn(), { messages: t } = on();
106
+ return { isAwaitingBotReply: (!((r = e.session) != null && r.isHandedOff) || e.session.assignee.kind === "ai" || e.isCreatingSession) && t.isSendingMessage };
107
+ }
108
+ var or = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
109
+ function sr(e) {
110
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
111
+ }
112
+ function an(e) {
113
+ if (e.__esModule) return e;
114
+ var t = e.default;
115
+ if (typeof t == "function") {
116
+ var n = function r() {
117
+ return this instanceof r ? Reflect.construct(t, arguments, this.constructor) : t.apply(this, arguments);
118
+ };
119
+ n.prototype = t.prototype;
120
+ } else n = {};
121
+ return Object.defineProperty(n, "__esModule", { value: !0 }), Object.keys(e).forEach(function(r) {
122
+ var o = Object.getOwnPropertyDescriptor(e, r);
123
+ Object.defineProperty(n, r, o.get ? o : {
124
+ enumerable: !0,
125
+ get: function() {
126
+ return e[r];
127
+ }
128
+ });
129
+ }), n;
130
+ }
131
+ var Ce = { exports: {} }, ve = {};
132
+ /**
133
+ * @license React
134
+ * use-sync-external-store-shim.production.min.js
135
+ *
136
+ * Copyright (c) Facebook, Inc. and its affiliates.
137
+ *
138
+ * This source code is licensed under the MIT license found in the
139
+ * LICENSE file in the root directory of this source tree.
140
+ */
141
+ var Je;
142
+ function un() {
143
+ if (Je) return ve;
144
+ Je = 1;
145
+ var e = k;
146
+ function t(u, l) {
147
+ return u === l && (u !== 0 || 1 / u === 1 / l) || u !== u && l !== l;
148
+ }
149
+ var n = typeof Object.is == "function" ? Object.is : t, r = e.useState, o = e.useEffect, s = e.useLayoutEffect, i = e.useDebugValue;
150
+ function d(u, l) {
151
+ var c = l(), y = r({ inst: { value: c, getSnapshot: l } }), _ = y[0].inst, T = y[1];
152
+ return s(function() {
153
+ _.value = c, _.getSnapshot = l, h(_) && T({ inst: _ });
154
+ }, [u, c, l]), o(function() {
155
+ return h(_) && T({ inst: _ }), u(function() {
156
+ h(_) && T({ inst: _ });
157
+ });
158
+ }, [u]), i(c), c;
159
+ }
160
+ function h(u) {
161
+ var l = u.getSnapshot;
162
+ u = u.value;
163
+ try {
164
+ var c = l();
165
+ return !n(u, c);
166
+ } catch {
167
+ return !0;
168
+ }
169
+ }
170
+ function f(u, l) {
171
+ return l();
172
+ }
173
+ var a = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? f : d;
174
+ return ve.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : a, ve;
175
+ }
176
+ var we = {};
177
+ /**
178
+ * @license React
179
+ * use-sync-external-store-shim.development.js
180
+ *
181
+ * Copyright (c) Facebook, Inc. and its affiliates.
182
+ *
183
+ * This source code is licensed under the MIT license found in the
184
+ * LICENSE file in the root directory of this source tree.
185
+ */
186
+ var Xe;
187
+ function cn() {
188
+ return Xe || (Xe = 1, process.env.NODE_ENV !== "production" && function() {
189
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
190
+ var e = k, t = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
191
+ function n(O) {
192
+ {
193
+ for (var E = arguments.length, w = new Array(E > 1 ? E - 1 : 0), v = 1; v < E; v++)
194
+ w[v - 1] = arguments[v];
195
+ r("error", O, w);
196
+ }
197
+ }
198
+ function r(O, E, w) {
199
+ {
200
+ var v = t.ReactDebugCurrentFrame, L = v.getStackAddendum();
201
+ L !== "" && (E += "%s", w = w.concat([L]));
202
+ var m = w.map(function(C) {
203
+ return String(C);
204
+ });
205
+ m.unshift("Warning: " + E), Function.prototype.apply.call(console[O], console, m);
206
+ }
207
+ }
208
+ function o(O, E) {
209
+ return O === E && (O !== 0 || 1 / O === 1 / E) || O !== O && E !== E;
210
+ }
211
+ var s = typeof Object.is == "function" ? Object.is : o, i = e.useState, d = e.useEffect, h = e.useLayoutEffect, f = e.useDebugValue, a = !1, u = !1;
212
+ function l(O, E, w) {
213
+ a || e.startTransition !== void 0 && (a = !0, n("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));
214
+ var v = E();
215
+ if (!u) {
216
+ var L = E();
217
+ s(v, L) || (n("The result of getSnapshot should be cached to avoid an infinite loop"), u = !0);
218
+ }
219
+ var m = i({
220
+ inst: {
221
+ value: v,
222
+ getSnapshot: E
223
+ }
224
+ }), C = m[0].inst, x = m[1];
225
+ return h(function() {
226
+ C.value = v, C.getSnapshot = E, c(C) && x({
227
+ inst: C
228
+ });
229
+ }, [O, v, E]), d(function() {
230
+ c(C) && x({
231
+ inst: C
232
+ });
233
+ var q = function() {
234
+ c(C) && x({
235
+ inst: C
236
+ });
237
+ };
238
+ return O(q);
239
+ }, [O]), f(v), v;
240
+ }
241
+ function c(O) {
242
+ var E = O.getSnapshot, w = O.value;
243
+ try {
244
+ var v = E();
245
+ return !s(w, v);
246
+ } catch {
247
+ return !0;
248
+ }
249
+ }
250
+ function y(O, E, w) {
251
+ return E();
252
+ }
253
+ var _ = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", T = !_, p = T ? y : l, z = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : p;
254
+ we.useSyncExternalStore = z, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
255
+ }()), we;
256
+ }
257
+ process.env.NODE_ENV === "production" ? Ce.exports = un() : Ce.exports = cn();
258
+ var fn = Ce.exports;
259
+ const H = () => {
260
+ }, P = (
261
+ /*#__NOINLINE__*/
262
+ H()
263
+ ), me = Object, g = (e) => e === P, N = (e) => typeof e == "function", G = (e, t) => ({
264
+ ...e,
265
+ ...t
266
+ }), ln = (e) => N(e.then), ue = /* @__PURE__ */ new WeakMap();
267
+ let dn = 0;
268
+ const oe = (e) => {
269
+ const t = typeof e, n = e && e.constructor, r = n == Date;
270
+ let o, s;
271
+ if (me(e) === e && !r && n != RegExp) {
272
+ if (o = ue.get(e), o) return o;
273
+ if (o = ++dn + "~", ue.set(e, o), n == Array) {
274
+ for (o = "@", s = 0; s < e.length; s++)
275
+ o += oe(e[s]) + ",";
276
+ ue.set(e, o);
277
+ }
278
+ if (n == me) {
279
+ o = "#";
280
+ const i = me.keys(e).sort();
281
+ for (; !g(s = i.pop()); )
282
+ g(e[s]) || (o += s + ":" + oe(e[s]) + ",");
283
+ ue.set(e, o);
284
+ }
285
+ } else
286
+ o = r ? e.toJSON() : t == "symbol" ? e.toString() : t == "string" ? JSON.stringify(e) : "" + e;
287
+ return o;
288
+ }, W = /* @__PURE__ */ new WeakMap(), be = {}, ce = {}, Fe = "undefined", he = typeof window != Fe, De = typeof document != Fe, pn = () => he && typeof window.requestAnimationFrame != Fe, it = (e, t) => {
289
+ const n = W.get(e);
290
+ return [
291
+ // Getter
292
+ () => !g(t) && e.get(t) || be,
293
+ // Setter
294
+ (r) => {
295
+ if (!g(t)) {
296
+ const o = e.get(t);
297
+ t in ce || (ce[t] = o), n[5](t, G(o, r), o || be);
298
+ }
299
+ },
300
+ // Subscriber
301
+ n[6],
302
+ // Get server cache snapshot
303
+ () => !g(t) && t in ce ? ce[t] : !g(t) && e.get(t) || be
304
+ ];
305
+ };
306
+ let Ae = !0;
307
+ const hn = () => Ae, [je, xe] = he && window.addEventListener ? [
308
+ window.addEventListener.bind(window),
309
+ window.removeEventListener.bind(window)
310
+ ] : [
311
+ H,
312
+ H
313
+ ], _n = () => {
314
+ const e = De && document.visibilityState;
315
+ return g(e) || e !== "hidden";
316
+ }, yn = (e) => (De && document.addEventListener("visibilitychange", e), je("focus", e), () => {
317
+ De && document.removeEventListener("visibilitychange", e), xe("focus", e);
318
+ }), gn = (e) => {
319
+ const t = () => {
320
+ Ae = !0, e();
321
+ }, n = () => {
322
+ Ae = !1;
323
+ };
324
+ return je("online", t), je("offline", n), () => {
325
+ xe("online", t), xe("offline", n);
326
+ };
327
+ }, En = {
328
+ isOnline: hn,
329
+ isVisible: _n
330
+ }, vn = {
331
+ initFocus: yn,
332
+ initReconnect: gn
333
+ }, Qe = !k.useId, se = !he || "Deno" in window, wn = (e) => pn() ? window.requestAnimationFrame(e) : setTimeout(e, 1), Se = se ? st : Yt, Oe = typeof navigator < "u" && navigator.connection, Ze = !se && Oe && ([
334
+ "slow-2g",
335
+ "2g"
336
+ ].includes(Oe.effectiveType) || Oe.saveData), Ne = (e) => {
337
+ if (N(e))
338
+ try {
339
+ e = e();
340
+ } catch {
341
+ e = "";
342
+ }
343
+ const t = e;
344
+ return e = typeof e == "string" ? e : (Array.isArray(e) ? e.length : e) ? oe(e) : "", [
345
+ e,
346
+ t
347
+ ];
348
+ };
349
+ let mn = 0;
350
+ const Pe = () => ++mn, at = 0, ut = 1, ct = 2, bn = 3;
351
+ var re = {
352
+ __proto__: null,
353
+ ERROR_REVALIDATE_EVENT: bn,
354
+ FOCUS_EVENT: at,
355
+ MUTATE_EVENT: ct,
356
+ RECONNECT_EVENT: ut
357
+ };
358
+ async function ft(...e) {
359
+ const [t, n, r, o] = e, s = G({
360
+ populateCache: !0,
361
+ throwOnError: !0
362
+ }, typeof o == "boolean" ? {
363
+ revalidate: o
364
+ } : o || {});
365
+ let i = s.populateCache;
366
+ const d = s.rollbackOnError;
367
+ let h = s.optimisticData;
368
+ const f = (l) => typeof d == "function" ? d(l) : d !== !1, a = s.throwOnError;
369
+ if (N(n)) {
370
+ const l = n, c = [], y = t.keys();
371
+ for (const _ of y)
372
+ // Skip the special useSWRInfinite and useSWRSubscription keys.
373
+ !/^\$(inf|sub)\$/.test(_) && l(t.get(_)._k) && c.push(_);
374
+ return Promise.all(c.map(u));
375
+ }
376
+ return u(n);
377
+ async function u(l) {
378
+ const [c] = Ne(l);
379
+ if (!c) return;
380
+ const [y, _] = it(t, c), [T, p, z, O] = W.get(t), E = () => {
381
+ const V = T[c];
382
+ return (N(s.revalidate) ? s.revalidate(y().data, l) : s.revalidate !== !1) && (delete z[c], delete O[c], V && V[0]) ? V[0](ct).then(() => y().data) : y().data;
383
+ };
384
+ if (e.length < 3)
385
+ return E();
386
+ let w = r, v;
387
+ const L = Pe();
388
+ p[c] = [
389
+ L,
390
+ 0
391
+ ];
392
+ const m = !g(h), C = y(), x = C.data, q = C._c, $ = g(q) ? x : q;
393
+ if (m && (h = N(h) ? h($, x) : h, _({
394
+ data: h,
395
+ _c: $
396
+ })), N(w))
397
+ try {
398
+ w = w($);
399
+ } catch (V) {
400
+ v = V;
401
+ }
402
+ if (w && ln(w))
403
+ if (w = await w.catch((V) => {
404
+ v = V;
405
+ }), L !== p[c][0]) {
406
+ if (v) throw v;
407
+ return w;
408
+ } else v && m && f(v) && (i = !0, _({
409
+ data: $,
410
+ _c: P
411
+ }));
412
+ if (i && !v)
413
+ if (N(i)) {
414
+ const V = i(w, $);
415
+ _({
416
+ data: V,
417
+ error: P,
418
+ _c: P
419
+ });
420
+ } else
421
+ _({
422
+ data: w,
423
+ error: P,
424
+ _c: P
425
+ });
426
+ if (p[c][1] = Pe(), Promise.resolve(E()).then(() => {
427
+ _({
428
+ _c: P
429
+ });
430
+ }), v) {
431
+ if (a) throw v;
432
+ return;
433
+ }
434
+ return w;
435
+ }
436
+ }
437
+ const et = (e, t) => {
438
+ for (const n in e)
439
+ e[n][0] && e[n][0](t);
440
+ }, Sn = (e, t) => {
441
+ if (!W.has(e)) {
442
+ const n = G(vn, t), r = {}, o = ft.bind(P, e);
443
+ let s = H;
444
+ const i = {}, d = (a, u) => {
445
+ const l = i[a] || [];
446
+ return i[a] = l, l.push(u), () => l.splice(l.indexOf(u), 1);
447
+ }, h = (a, u, l) => {
448
+ e.set(a, u);
449
+ const c = i[a];
450
+ if (c)
451
+ for (const y of c)
452
+ y(u, l);
453
+ }, f = () => {
454
+ if (!W.has(e) && (W.set(e, [
455
+ r,
456
+ {},
457
+ {},
458
+ {},
459
+ o,
460
+ h,
461
+ d
462
+ ]), !se)) {
463
+ const a = n.initFocus(setTimeout.bind(P, et.bind(P, r, at))), u = n.initReconnect(setTimeout.bind(P, et.bind(P, r, ut)));
464
+ s = () => {
465
+ a && a(), u && u(), W.delete(e);
466
+ };
467
+ }
468
+ };
469
+ return f(), [
470
+ e,
471
+ o,
472
+ f,
473
+ s
474
+ ];
475
+ }
476
+ return [
477
+ e,
478
+ W.get(e)[4]
479
+ ];
480
+ }, On = (e, t, n, r, o) => {
481
+ const s = n.errorRetryCount, i = o.retryCount, d = ~~((Math.random() + 0.5) * (1 << (i < 8 ? i : 8))) * n.errorRetryInterval;
482
+ !g(s) && i > s || setTimeout(r, d, o);
483
+ }, Rn = (e, t) => oe(e) == oe(t), [lt, Tn] = Sn(/* @__PURE__ */ new Map()), Cn = G(
484
+ {
485
+ // events
486
+ onLoadingSlow: H,
487
+ onSuccess: H,
488
+ onError: H,
489
+ onErrorRetry: On,
490
+ onDiscarded: H,
491
+ // switches
492
+ revalidateOnFocus: !0,
493
+ revalidateOnReconnect: !0,
494
+ revalidateIfStale: !0,
495
+ shouldRetryOnError: !0,
496
+ // timeouts
497
+ errorRetryInterval: Ze ? 1e4 : 5e3,
498
+ focusThrottleInterval: 5 * 1e3,
499
+ dedupingInterval: 2 * 1e3,
500
+ loadingTimeout: Ze ? 5e3 : 3e3,
501
+ // providers
502
+ compare: Rn,
503
+ isPaused: () => !1,
504
+ cache: lt,
505
+ mutate: Tn,
506
+ fallback: {}
507
+ },
508
+ // use web preset by default
509
+ En
510
+ ), Dn = (e, t) => {
511
+ const n = G(e, t);
512
+ if (t) {
513
+ const { use: r, fallback: o } = e, { use: s, fallback: i } = t;
514
+ r && s && (n.use = r.concat(s)), o && i && (n.fallback = G(o, i));
515
+ }
516
+ return n;
517
+ }, An = rt({}), jn = "$inf$", dt = he && window.__SWR_DEVTOOLS_USE__, xn = dt ? window.__SWR_DEVTOOLS_USE__ : [], Pn = () => {
518
+ dt && (window.__SWR_DEVTOOLS_REACT__ = k);
519
+ }, Ln = (e) => N(e[1]) ? [
520
+ e[0],
521
+ e[1],
522
+ e[2] || {}
523
+ ] : [
524
+ e[0],
525
+ null,
526
+ (e[1] === null ? e[2] : e[1]) || {}
527
+ ], In = () => G(Cn, ot(An)), Vn = (e) => (t, n, r) => e(t, n && ((...s) => {
528
+ const [i] = Ne(t), [, , , d] = W.get(lt);
529
+ if (i.startsWith(jn))
530
+ return n(...s);
531
+ const h = d[i];
532
+ return g(h) ? n(...s) : (delete d[i], h);
533
+ }), r), Fn = xn.concat(Vn), Nn = (e) => function(...n) {
534
+ const r = In(), [o, s, i] = Ln(n), d = Dn(r, i);
535
+ let h = e;
536
+ const { use: f } = d, a = (f || []).concat(Fn);
537
+ for (let u = a.length; u--; )
538
+ h = a[u](h);
539
+ return h(o, s || d.fetcher || null, d);
540
+ }, Mn = (e, t, n) => {
541
+ const r = t[e] || (t[e] = []);
542
+ return r.push(n), () => {
543
+ const o = r.indexOf(n);
544
+ o >= 0 && (r[o] = r[r.length - 1], r.pop());
545
+ };
546
+ };
547
+ Pn();
548
+ const tt = k.use || ((e) => {
549
+ if (e.status === "pending")
550
+ throw e;
551
+ if (e.status === "fulfilled")
552
+ return e.value;
553
+ throw e.status === "rejected" ? e.reason : (e.status = "pending", e.then((t) => {
554
+ e.status = "fulfilled", e.value = t;
555
+ }, (t) => {
556
+ e.status = "rejected", e.reason = t;
557
+ }), e);
558
+ }), Re = {
559
+ dedupe: !0
560
+ }, Un = (e, t, n) => {
561
+ const { cache: r, compare: o, suspense: s, fallbackData: i, revalidateOnMount: d, revalidateIfStale: h, refreshInterval: f, refreshWhenHidden: a, refreshWhenOffline: u, keepPreviousData: l } = n, [c, y, _, T] = W.get(r), [p, z] = Ne(e), O = K(!1), E = K(!1), w = K(p), v = K(t), L = K(n), m = () => L.current, C = () => m().isVisible() && m().isOnline(), [x, q, $, V] = it(r, p), Y = K({}).current, qt = g(i) ? n.fallback[p] : i, Ue = (b, S) => {
562
+ for (const A in Y) {
563
+ const R = A;
564
+ if (R === "data") {
565
+ if (!o(b[R], S[R]) && (!g(b[R]) || !o(ae, S[R])))
566
+ return !1;
567
+ } else if (S[R] !== b[R])
568
+ return !1;
569
+ }
570
+ return !0;
571
+ }, We = le(() => {
572
+ const b = !p || !t ? !1 : g(d) ? m().isPaused() || s ? !1 : g(h) ? !0 : h : d, S = (j) => {
573
+ const M = G(j);
574
+ return delete M._k, b ? {
575
+ isValidating: !0,
576
+ isLoading: !0,
577
+ ...M
578
+ } : M;
579
+ }, A = x(), R = V(), F = S(A), Z = A === R ? F : S(R);
580
+ let D = F;
581
+ return [
582
+ () => {
583
+ const j = S(x());
584
+ return Ue(j, D) ? (D.data = j.data, D.isLoading = j.isLoading, D.isValidating = j.isValidating, D.error = j.error, D) : (D = j, j);
585
+ },
586
+ () => Z
587
+ ];
588
+ }, [
589
+ r,
590
+ p
591
+ ]), J = fn.useSyncExternalStore(Ee(
592
+ (b) => $(p, (S, A) => {
593
+ Ue(A, S) || b();
594
+ }),
595
+ // eslint-disable-next-line react-hooks/exhaustive-deps
596
+ [
597
+ r,
598
+ p
599
+ ]
600
+ ), We[0], We[1]), qe = !O.current, Bt = c[p] && c[p].length > 0, X = J.data, Q = g(X) ? qt : X, ie = J.error, Be = K(Q), ae = l ? g(X) ? Be.current : X : Q, He = Bt && !g(ie) ? !1 : qe && !g(d) ? d : m().isPaused() ? !1 : s ? g(Q) ? !1 : h : g(Q) || h, Ge = !!(p && t && qe && He), Ht = g(J.isValidating) ? Ge : J.isValidating, Gt = g(J.isLoading) ? Ge : J.isLoading, ne = Ee(
601
+ async (b) => {
602
+ const S = v.current;
603
+ if (!p || !S || E.current || m().isPaused())
604
+ return !1;
605
+ let A, R, F = !0;
606
+ const Z = b || {}, D = !_[p] || !Z.dedupe, j = () => Qe ? !E.current && p === w.current && O.current : p === w.current, M = {
607
+ isValidating: !1,
608
+ isLoading: !1
609
+ }, Ke = () => {
610
+ q(M);
611
+ }, ke = () => {
612
+ const I = _[p];
613
+ I && I[1] === R && delete _[p];
614
+ }, ze = {
615
+ isValidating: !0
616
+ };
617
+ g(x().data) && (ze.isLoading = !0);
618
+ try {
619
+ if (D && (q(ze), n.loadingTimeout && g(x().data) && setTimeout(() => {
620
+ F && j() && m().onLoadingSlow(p, n);
621
+ }, n.loadingTimeout), _[p] = [
622
+ S(z),
623
+ Pe()
624
+ ]), [A, R] = _[p], A = await A, D && setTimeout(ke, n.dedupingInterval), !_[p] || _[p][1] !== R)
625
+ return D && j() && m().onDiscarded(p), !1;
626
+ M.error = P;
627
+ const I = y[p];
628
+ if (!g(I) && // case 1
629
+ (R <= I[0] || // case 2
630
+ R <= I[1] || // case 3
631
+ I[1] === 0))
632
+ return Ke(), D && j() && m().onDiscarded(p), !1;
633
+ const U = x().data;
634
+ M.data = o(U, A) ? U : A, D && j() && m().onSuccess(A, p, n);
635
+ } catch (I) {
636
+ ke();
637
+ const U = m(), { shouldRetryOnError: ye } = U;
638
+ U.isPaused() || (M.error = I, D && j() && (U.onError(I, p, U), (ye === !0 || N(ye) && ye(I)) && (!m().revalidateOnFocus || !m().revalidateOnReconnect || C()) && U.onErrorRetry(I, p, U, ($t) => {
639
+ const ge = c[p];
640
+ ge && ge[0] && ge[0](re.ERROR_REVALIDATE_EVENT, $t);
641
+ }, {
642
+ retryCount: (Z.retryCount || 0) + 1,
643
+ dedupe: !0
644
+ })));
645
+ }
646
+ return F = !1, Ke(), !0;
647
+ },
648
+ // `setState` is immutable, and `eventsCallback`, `fnArg`, and
649
+ // `keyValidating` are depending on `key`, so we can exclude them from
650
+ // the deps array.
651
+ //
652
+ // FIXME:
653
+ // `fn` and `config` might be changed during the lifecycle,
654
+ // but they might be changed every render like this.
655
+ // `useSWR('key', () => fetch('/api/'), { suspense: true })`
656
+ // So we omit the values from the deps array
657
+ // even though it might cause unexpected behaviors.
658
+ // eslint-disable-next-line react-hooks/exhaustive-deps
659
+ [
660
+ p,
661
+ r
662
+ ]
663
+ ), $e = Ee(
664
+ // Use callback to make sure `keyRef.current` returns latest result every time
665
+ (...b) => ft(r, w.current, ...b),
666
+ // eslint-disable-next-line react-hooks/exhaustive-deps
667
+ []
668
+ );
669
+ if (Se(() => {
670
+ v.current = t, L.current = n, g(X) || (Be.current = X);
671
+ }), Se(() => {
672
+ if (!p) return;
673
+ const b = ne.bind(P, Re);
674
+ let S = 0;
675
+ const R = Mn(p, c, (F, Z = {}) => {
676
+ if (F == re.FOCUS_EVENT) {
677
+ const D = Date.now();
678
+ m().revalidateOnFocus && D > S && C() && (S = D + m().focusThrottleInterval, b());
679
+ } else if (F == re.RECONNECT_EVENT)
680
+ m().revalidateOnReconnect && C() && b();
681
+ else {
682
+ if (F == re.MUTATE_EVENT)
683
+ return ne();
684
+ if (F == re.ERROR_REVALIDATE_EVENT)
685
+ return ne(Z);
686
+ }
687
+ });
688
+ return E.current = !1, w.current = p, O.current = !0, q({
689
+ _k: z
690
+ }), He && (g(Q) || se ? b() : wn(b)), () => {
691
+ E.current = !0, R();
692
+ };
693
+ }, [
694
+ p
695
+ ]), Se(() => {
696
+ let b;
697
+ function S() {
698
+ const R = N(f) ? f(x().data) : f;
699
+ R && b !== -1 && (b = setTimeout(A, R));
700
+ }
701
+ function A() {
702
+ !x().error && (a || m().isVisible()) && (u || m().isOnline()) ? ne(Re).then(S) : S();
703
+ }
704
+ return S(), () => {
705
+ b && (clearTimeout(b), b = -1);
706
+ };
707
+ }, [
708
+ f,
709
+ a,
710
+ u,
711
+ p
712
+ ]), Jt(ae), s && g(Q) && p) {
713
+ if (!Qe && se)
714
+ throw new Error("Fallback data is required when using suspense in SSR.");
715
+ v.current = t, L.current = n, E.current = !1;
716
+ const b = T[p];
717
+ if (!g(b)) {
718
+ const S = $e(b);
719
+ tt(S);
720
+ }
721
+ if (g(ie)) {
722
+ const S = ne(Re);
723
+ g(ae) || (S.status = "fulfilled", S.value = !0), tt(S);
724
+ } else
725
+ throw ie;
726
+ }
727
+ return {
728
+ mutate: $e,
729
+ get data() {
730
+ return Y.data = !0, ae;
731
+ },
732
+ get error() {
733
+ return Y.error = !0, ie;
734
+ },
735
+ get isValidating() {
736
+ return Y.isValidating = !0, Ht;
737
+ },
738
+ get isLoading() {
739
+ return Y.isLoading = !0, Gt;
740
+ }
741
+ };
742
+ }, Wn = Nn(Un);
743
+ function ir() {
744
+ const { widgetCtx: e } = te();
745
+ return Wn([e.config.token], e.api.widgetPrelude);
746
+ }
747
+ var pt = {}, Le = function(e, t) {
748
+ return Le = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, r) {
749
+ n.__proto__ = r;
750
+ } || function(n, r) {
751
+ for (var o in r) Object.prototype.hasOwnProperty.call(r, o) && (n[o] = r[o]);
752
+ }, Le(e, t);
753
+ };
754
+ function ht(e, t) {
755
+ if (typeof t != "function" && t !== null)
756
+ throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
757
+ Le(e, t);
758
+ function n() {
759
+ this.constructor = e;
760
+ }
761
+ e.prototype = t === null ? Object.create(t) : (n.prototype = t.prototype, new n());
762
+ }
763
+ var de = function() {
764
+ return de = Object.assign || function(t) {
765
+ for (var n, r = 1, o = arguments.length; r < o; r++) {
766
+ n = arguments[r];
767
+ for (var s in n) Object.prototype.hasOwnProperty.call(n, s) && (t[s] = n[s]);
768
+ }
769
+ return t;
770
+ }, de.apply(this, arguments);
771
+ };
772
+ function _t(e, t) {
773
+ var n = {};
774
+ for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && t.indexOf(r) < 0 && (n[r] = e[r]);
775
+ if (e != null && typeof Object.getOwnPropertySymbols == "function")
776
+ for (var o = 0, r = Object.getOwnPropertySymbols(e); o < r.length; o++)
777
+ t.indexOf(r[o]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[o]) && (n[r[o]] = e[r[o]]);
778
+ return n;
779
+ }
780
+ function yt(e, t, n, r) {
781
+ var o = arguments.length, s = o < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, i;
782
+ if (typeof Reflect == "object" && typeof Reflect.decorate == "function") s = Reflect.decorate(e, t, n, r);
783
+ else for (var d = e.length - 1; d >= 0; d--) (i = e[d]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, n, s) : i(t, n)) || s);
784
+ return o > 3 && s && Object.defineProperty(t, n, s), s;
785
+ }
786
+ function gt(e, t) {
787
+ return function(n, r) {
788
+ t(n, r, e);
789
+ };
790
+ }
791
+ function Et(e, t, n, r, o, s) {
792
+ function i(p) {
793
+ if (p !== void 0 && typeof p != "function") throw new TypeError("Function expected");
794
+ return p;
795
+ }
796
+ for (var d = r.kind, h = d === "getter" ? "get" : d === "setter" ? "set" : "value", f = !t && e ? r.static ? e : e.prototype : null, a = t || (f ? Object.getOwnPropertyDescriptor(f, r.name) : {}), u, l = !1, c = n.length - 1; c >= 0; c--) {
797
+ var y = {};
798
+ for (var _ in r) y[_] = _ === "access" ? {} : r[_];
799
+ for (var _ in r.access) y.access[_] = r.access[_];
800
+ y.addInitializer = function(p) {
801
+ if (l) throw new TypeError("Cannot add initializers after decoration has completed");
802
+ s.push(i(p || null));
803
+ };
804
+ var T = (0, n[c])(d === "accessor" ? { get: a.get, set: a.set } : a[h], y);
805
+ if (d === "accessor") {
806
+ if (T === void 0) continue;
807
+ if (T === null || typeof T != "object") throw new TypeError("Object expected");
808
+ (u = i(T.get)) && (a.get = u), (u = i(T.set)) && (a.set = u), (u = i(T.init)) && o.unshift(u);
809
+ } else (u = i(T)) && (d === "field" ? o.unshift(u) : a[h] = u);
810
+ }
811
+ f && Object.defineProperty(f, r.name, a), l = !0;
812
+ }
813
+ function vt(e, t, n) {
814
+ for (var r = arguments.length > 2, o = 0; o < t.length; o++)
815
+ n = r ? t[o].call(e, n) : t[o].call(e);
816
+ return r ? n : void 0;
817
+ }
818
+ function wt(e) {
819
+ return typeof e == "symbol" ? e : "".concat(e);
820
+ }
821
+ function mt(e, t, n) {
822
+ return typeof t == "symbol" && (t = t.description ? "[".concat(t.description, "]") : ""), Object.defineProperty(e, "name", { configurable: !0, value: n ? "".concat(n, " ", t) : t });
823
+ }
824
+ function bt(e, t) {
825
+ if (typeof Reflect == "object" && typeof Reflect.metadata == "function") return Reflect.metadata(e, t);
826
+ }
827
+ function St(e, t, n, r) {
828
+ function o(s) {
829
+ return s instanceof n ? s : new n(function(i) {
830
+ i(s);
831
+ });
832
+ }
833
+ return new (n || (n = Promise))(function(s, i) {
834
+ function d(a) {
835
+ try {
836
+ f(r.next(a));
837
+ } catch (u) {
838
+ i(u);
839
+ }
840
+ }
841
+ function h(a) {
842
+ try {
843
+ f(r.throw(a));
844
+ } catch (u) {
845
+ i(u);
846
+ }
847
+ }
848
+ function f(a) {
849
+ a.done ? s(a.value) : o(a.value).then(d, h);
850
+ }
851
+ f((r = r.apply(e, t || [])).next());
852
+ });
853
+ }
854
+ function Ot(e, t) {
855
+ var n = { label: 0, sent: function() {
856
+ if (s[0] & 1) throw s[1];
857
+ return s[1];
858
+ }, trys: [], ops: [] }, r, o, s, i = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype);
859
+ return i.next = d(0), i.throw = d(1), i.return = d(2), typeof Symbol == "function" && (i[Symbol.iterator] = function() {
860
+ return this;
861
+ }), i;
862
+ function d(f) {
863
+ return function(a) {
864
+ return h([f, a]);
865
+ };
866
+ }
867
+ function h(f) {
868
+ if (r) throw new TypeError("Generator is already executing.");
869
+ for (; i && (i = 0, f[0] && (n = 0)), n; ) try {
870
+ if (r = 1, o && (s = f[0] & 2 ? o.return : f[0] ? o.throw || ((s = o.return) && s.call(o), 0) : o.next) && !(s = s.call(o, f[1])).done) return s;
871
+ switch (o = 0, s && (f = [f[0] & 2, s.value]), f[0]) {
872
+ case 0:
873
+ case 1:
874
+ s = f;
875
+ break;
876
+ case 4:
877
+ return n.label++, { value: f[1], done: !1 };
878
+ case 5:
879
+ n.label++, o = f[1], f = [0];
880
+ continue;
881
+ case 7:
882
+ f = n.ops.pop(), n.trys.pop();
883
+ continue;
884
+ default:
885
+ if (s = n.trys, !(s = s.length > 0 && s[s.length - 1]) && (f[0] === 6 || f[0] === 2)) {
886
+ n = 0;
887
+ continue;
888
+ }
889
+ if (f[0] === 3 && (!s || f[1] > s[0] && f[1] < s[3])) {
890
+ n.label = f[1];
891
+ break;
892
+ }
893
+ if (f[0] === 6 && n.label < s[1]) {
894
+ n.label = s[1], s = f;
895
+ break;
896
+ }
897
+ if (s && n.label < s[2]) {
898
+ n.label = s[2], n.ops.push(f);
899
+ break;
900
+ }
901
+ s[2] && n.ops.pop(), n.trys.pop();
902
+ continue;
903
+ }
904
+ f = t.call(e, n);
905
+ } catch (a) {
906
+ f = [6, a], o = 0;
907
+ } finally {
908
+ r = s = 0;
909
+ }
910
+ if (f[0] & 5) throw f[1];
911
+ return { value: f[0] ? f[1] : void 0, done: !0 };
912
+ }
913
+ }
914
+ var _e = Object.create ? function(e, t, n, r) {
915
+ r === void 0 && (r = n);
916
+ var o = Object.getOwnPropertyDescriptor(t, n);
917
+ (!o || ("get" in o ? !t.__esModule : o.writable || o.configurable)) && (o = { enumerable: !0, get: function() {
918
+ return t[n];
919
+ } }), Object.defineProperty(e, r, o);
920
+ } : function(e, t, n, r) {
921
+ r === void 0 && (r = n), e[r] = t[n];
922
+ };
923
+ function Rt(e, t) {
924
+ for (var n in e) n !== "default" && !Object.prototype.hasOwnProperty.call(t, n) && _e(t, e, n);
925
+ }
926
+ function pe(e) {
927
+ var t = typeof Symbol == "function" && Symbol.iterator, n = t && e[t], r = 0;
928
+ if (n) return n.call(e);
929
+ if (e && typeof e.length == "number") return {
930
+ next: function() {
931
+ return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e };
932
+ }
933
+ };
934
+ throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
935
+ }
936
+ function Me(e, t) {
937
+ var n = typeof Symbol == "function" && e[Symbol.iterator];
938
+ if (!n) return e;
939
+ var r = n.call(e), o, s = [], i;
940
+ try {
941
+ for (; (t === void 0 || t-- > 0) && !(o = r.next()).done; ) s.push(o.value);
942
+ } catch (d) {
943
+ i = { error: d };
944
+ } finally {
945
+ try {
946
+ o && !o.done && (n = r.return) && n.call(r);
947
+ } finally {
948
+ if (i) throw i.error;
949
+ }
950
+ }
951
+ return s;
952
+ }
953
+ function Tt() {
954
+ for (var e = [], t = 0; t < arguments.length; t++)
955
+ e = e.concat(Me(arguments[t]));
956
+ return e;
957
+ }
958
+ function Ct() {
959
+ for (var e = 0, t = 0, n = arguments.length; t < n; t++) e += arguments[t].length;
960
+ for (var r = Array(e), o = 0, t = 0; t < n; t++)
961
+ for (var s = arguments[t], i = 0, d = s.length; i < d; i++, o++)
962
+ r[o] = s[i];
963
+ return r;
964
+ }
965
+ function Dt(e, t, n) {
966
+ if (n || arguments.length === 2) for (var r = 0, o = t.length, s; r < o; r++)
967
+ (s || !(r in t)) && (s || (s = Array.prototype.slice.call(t, 0, r)), s[r] = t[r]);
968
+ return e.concat(s || Array.prototype.slice.call(t));
969
+ }
970
+ function ee(e) {
971
+ return this instanceof ee ? (this.v = e, this) : new ee(e);
972
+ }
973
+ function At(e, t, n) {
974
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
975
+ var r = n.apply(e, t || []), o, s = [];
976
+ return o = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), d("next"), d("throw"), d("return", i), o[Symbol.asyncIterator] = function() {
977
+ return this;
978
+ }, o;
979
+ function i(c) {
980
+ return function(y) {
981
+ return Promise.resolve(y).then(c, u);
982
+ };
983
+ }
984
+ function d(c, y) {
985
+ r[c] && (o[c] = function(_) {
986
+ return new Promise(function(T, p) {
987
+ s.push([c, _, T, p]) > 1 || h(c, _);
988
+ });
989
+ }, y && (o[c] = y(o[c])));
990
+ }
991
+ function h(c, y) {
992
+ try {
993
+ f(r[c](y));
994
+ } catch (_) {
995
+ l(s[0][3], _);
996
+ }
997
+ }
998
+ function f(c) {
999
+ c.value instanceof ee ? Promise.resolve(c.value.v).then(a, u) : l(s[0][2], c);
1000
+ }
1001
+ function a(c) {
1002
+ h("next", c);
1003
+ }
1004
+ function u(c) {
1005
+ h("throw", c);
1006
+ }
1007
+ function l(c, y) {
1008
+ c(y), s.shift(), s.length && h(s[0][0], s[0][1]);
1009
+ }
1010
+ }
1011
+ function jt(e) {
1012
+ var t, n;
1013
+ return t = {}, r("next"), r("throw", function(o) {
1014
+ throw o;
1015
+ }), r("return"), t[Symbol.iterator] = function() {
1016
+ return this;
1017
+ }, t;
1018
+ function r(o, s) {
1019
+ t[o] = e[o] ? function(i) {
1020
+ return (n = !n) ? { value: ee(e[o](i)), done: !1 } : s ? s(i) : i;
1021
+ } : s;
1022
+ }
1023
+ }
1024
+ function xt(e) {
1025
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1026
+ var t = e[Symbol.asyncIterator], n;
1027
+ return t ? t.call(e) : (e = typeof pe == "function" ? pe(e) : e[Symbol.iterator](), n = {}, r("next"), r("throw"), r("return"), n[Symbol.asyncIterator] = function() {
1028
+ return this;
1029
+ }, n);
1030
+ function r(s) {
1031
+ n[s] = e[s] && function(i) {
1032
+ return new Promise(function(d, h) {
1033
+ i = e[s](i), o(d, h, i.done, i.value);
1034
+ });
1035
+ };
1036
+ }
1037
+ function o(s, i, d, h) {
1038
+ Promise.resolve(h).then(function(f) {
1039
+ s({ value: f, done: d });
1040
+ }, i);
1041
+ }
1042
+ }
1043
+ function Pt(e, t) {
1044
+ return Object.defineProperty ? Object.defineProperty(e, "raw", { value: t }) : e.raw = t, e;
1045
+ }
1046
+ var qn = Object.create ? function(e, t) {
1047
+ Object.defineProperty(e, "default", { enumerable: !0, value: t });
1048
+ } : function(e, t) {
1049
+ e.default = t;
1050
+ };
1051
+ function Lt(e) {
1052
+ if (e && e.__esModule) return e;
1053
+ var t = {};
1054
+ if (e != null) for (var n in e) n !== "default" && Object.prototype.hasOwnProperty.call(e, n) && _e(t, e, n);
1055
+ return qn(t, e), t;
1056
+ }
1057
+ function It(e) {
1058
+ return e && e.__esModule ? e : { default: e };
1059
+ }
1060
+ function Vt(e, t, n, r) {
1061
+ if (n === "a" && !r) throw new TypeError("Private accessor was defined without a getter");
1062
+ if (typeof t == "function" ? e !== t || !r : !t.has(e)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1063
+ return n === "m" ? r : n === "a" ? r.call(e) : r ? r.value : t.get(e);
1064
+ }
1065
+ function Ft(e, t, n, r, o) {
1066
+ if (r === "m") throw new TypeError("Private method is not writable");
1067
+ if (r === "a" && !o) throw new TypeError("Private accessor was defined without a setter");
1068
+ if (typeof t == "function" ? e !== t || !o : !t.has(e)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1069
+ return r === "a" ? o.call(e, n) : o ? o.value = n : t.set(e, n), n;
1070
+ }
1071
+ function Nt(e, t) {
1072
+ if (t === null || typeof t != "object" && typeof t != "function") throw new TypeError("Cannot use 'in' operator on non-object");
1073
+ return typeof e == "function" ? t === e : e.has(t);
1074
+ }
1075
+ function Mt(e, t, n) {
1076
+ if (t != null) {
1077
+ if (typeof t != "object" && typeof t != "function") throw new TypeError("Object expected.");
1078
+ var r, o;
1079
+ if (n) {
1080
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
1081
+ r = t[Symbol.asyncDispose];
1082
+ }
1083
+ if (r === void 0) {
1084
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
1085
+ r = t[Symbol.dispose], n && (o = r);
1086
+ }
1087
+ if (typeof r != "function") throw new TypeError("Object not disposable.");
1088
+ o && (r = function() {
1089
+ try {
1090
+ o.call(this);
1091
+ } catch (s) {
1092
+ return Promise.reject(s);
1093
+ }
1094
+ }), e.stack.push({ value: t, dispose: r, async: n });
1095
+ } else n && e.stack.push({ async: !0 });
1096
+ return t;
1097
+ }
1098
+ var Bn = typeof SuppressedError == "function" ? SuppressedError : function(e, t, n) {
1099
+ var r = new Error(n);
1100
+ return r.name = "SuppressedError", r.error = e, r.suppressed = t, r;
1101
+ };
1102
+ function Ut(e) {
1103
+ function t(s) {
1104
+ e.error = e.hasError ? new Bn(s, e.error, "An error was suppressed during disposal.") : s, e.hasError = !0;
1105
+ }
1106
+ var n, r = 0;
1107
+ function o() {
1108
+ for (; n = e.stack.pop(); )
1109
+ try {
1110
+ if (!n.async && r === 1) return r = 0, e.stack.push(n), Promise.resolve().then(o);
1111
+ if (n.dispose) {
1112
+ var s = n.dispose.call(n.value);
1113
+ if (n.async) return r |= 2, Promise.resolve(s).then(o, function(i) {
1114
+ return t(i), o();
1115
+ });
1116
+ } else r |= 1;
1117
+ } catch (i) {
1118
+ t(i);
1119
+ }
1120
+ if (r === 1) return e.hasError ? Promise.reject(e.error) : Promise.resolve();
1121
+ if (e.hasError) throw e.error;
1122
+ }
1123
+ return o();
1124
+ }
1125
+ function Wt(e, t) {
1126
+ return typeof e == "string" && /^\.\.?\//.test(e) ? e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function(n, r, o, s, i) {
1127
+ return r ? t ? ".jsx" : ".js" : o && (!s || !i) ? n : o + s + "." + i.toLowerCase() + "js";
1128
+ }) : e;
1129
+ }
1130
+ const Hn = {
1131
+ __extends: ht,
1132
+ __assign: de,
1133
+ __rest: _t,
1134
+ __decorate: yt,
1135
+ __param: gt,
1136
+ __esDecorate: Et,
1137
+ __runInitializers: vt,
1138
+ __propKey: wt,
1139
+ __setFunctionName: mt,
1140
+ __metadata: bt,
1141
+ __awaiter: St,
1142
+ __generator: Ot,
1143
+ __createBinding: _e,
1144
+ __exportStar: Rt,
1145
+ __values: pe,
1146
+ __read: Me,
1147
+ __spread: Tt,
1148
+ __spreadArrays: Ct,
1149
+ __spreadArray: Dt,
1150
+ __await: ee,
1151
+ __asyncGenerator: At,
1152
+ __asyncDelegator: jt,
1153
+ __asyncValues: xt,
1154
+ __makeTemplateObject: Pt,
1155
+ __importStar: Lt,
1156
+ __importDefault: It,
1157
+ __classPrivateFieldGet: Vt,
1158
+ __classPrivateFieldSet: Ft,
1159
+ __classPrivateFieldIn: Nt,
1160
+ __addDisposableResource: Mt,
1161
+ __disposeResources: Ut,
1162
+ __rewriteRelativeImportExtension: Wt
1163
+ }, Gn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1164
+ __proto__: null,
1165
+ __addDisposableResource: Mt,
1166
+ get __assign() {
1167
+ return de;
1168
+ },
1169
+ __asyncDelegator: jt,
1170
+ __asyncGenerator: At,
1171
+ __asyncValues: xt,
1172
+ __await: ee,
1173
+ __awaiter: St,
1174
+ __classPrivateFieldGet: Vt,
1175
+ __classPrivateFieldIn: Nt,
1176
+ __classPrivateFieldSet: Ft,
1177
+ __createBinding: _e,
1178
+ __decorate: yt,
1179
+ __disposeResources: Ut,
1180
+ __esDecorate: Et,
1181
+ __exportStar: Rt,
1182
+ __extends: ht,
1183
+ __generator: Ot,
1184
+ __importDefault: It,
1185
+ __importStar: Lt,
1186
+ __makeTemplateObject: Pt,
1187
+ __metadata: bt,
1188
+ __param: gt,
1189
+ __propKey: wt,
1190
+ __read: Me,
1191
+ __rest: _t,
1192
+ __rewriteRelativeImportExtension: Wt,
1193
+ __runInitializers: vt,
1194
+ __setFunctionName: mt,
1195
+ __spread: Tt,
1196
+ __spreadArray: Dt,
1197
+ __spreadArrays: Ct,
1198
+ __values: pe,
1199
+ default: Hn
1200
+ }, Symbol.toStringTag, { value: "Module" })), $n = /* @__PURE__ */ an(Gn);
1201
+ var fe = {}, nt;
1202
+ function Kn() {
1203
+ if (nt) return fe;
1204
+ nt = 1, Object.defineProperty(fe, "__esModule", { value: !0 });
1205
+ var e = k;
1206
+ function t() {
1207
+ var n = e.useRef(!1), r = e.useCallback(function() {
1208
+ return n.current;
1209
+ }, []);
1210
+ return e.useEffect(function() {
1211
+ return n.current = !0, function() {
1212
+ n.current = !1;
1213
+ };
1214
+ }, []), r;
1215
+ }
1216
+ return fe.default = t, fe;
1217
+ }
1218
+ Object.defineProperty(pt, "__esModule", { value: !0 });
1219
+ var Ie = $n, Te = k, kn = Ie.__importDefault(Kn());
1220
+ function zn(e, t, n) {
1221
+ t === void 0 && (t = []), n === void 0 && (n = { loading: !1 });
1222
+ var r = Te.useRef(0), o = kn.default(), s = Te.useState(n), i = s[0], d = s[1], h = Te.useCallback(function() {
1223
+ for (var f = [], a = 0; a < arguments.length; a++)
1224
+ f[a] = arguments[a];
1225
+ var u = ++r.current;
1226
+ return i.loading || d(function(l) {
1227
+ return Ie.__assign(Ie.__assign({}, l), { loading: !0 });
1228
+ }), e.apply(void 0, f).then(function(l) {
1229
+ return o() && u === r.current && d({ value: l, loading: !1 }), l;
1230
+ }, function(l) {
1231
+ return o() && u === r.current && d({ error: l, loading: !1 }), l;
1232
+ });
1233
+ }, t);
1234
+ return [i, h];
1235
+ }
1236
+ var ar = pt.default = zn;
1237
+ const B = /* @__PURE__ */ new Map();
1238
+ function ur() {
1239
+ const [e, t] = Xt([]), { widgetCtx: { api: n } } = te();
1240
+ function r(a) {
1241
+ const u = a.map((l) => ({
1242
+ file: l,
1243
+ id: en(),
1244
+ status: "pending",
1245
+ progress: 0
1246
+ }));
1247
+ t((l) => [...l, ...u]), u.forEach(i);
1248
+ }
1249
+ function o(a, u) {
1250
+ t(
1251
+ (l) => l.map((c) => c.id === a ? { ...c, ...u } : c)
1252
+ );
1253
+ }
1254
+ function s(a) {
1255
+ t((u) => u.filter((l) => l.id !== a));
1256
+ }
1257
+ const i = async (a) => {
1258
+ const u = new AbortController();
1259
+ B.set(a.id, u);
1260
+ try {
1261
+ t(
1262
+ (c) => c.map(
1263
+ (y) => y.id === a.id ? { ...y, status: "uploading", progress: 0 } : y
1264
+ )
1265
+ );
1266
+ const l = await n.uploadFile(a, {
1267
+ signal: u.signal,
1268
+ onUploadProgress: (c) => {
1269
+ if (!c.total) return;
1270
+ const y = Math.round(
1271
+ c.loaded * 100 / c.total
1272
+ );
1273
+ o(a.id, { progress: y });
1274
+ }
1275
+ });
1276
+ o(a.id, {
1277
+ status: "success",
1278
+ fileUrl: l.fileUrl,
1279
+ progress: 100
1280
+ });
1281
+ } catch (l) {
1282
+ u.signal.aborted || o(a.id, {
1283
+ status: "error",
1284
+ error: l instanceof Error ? l.message : "Upload failed",
1285
+ progress: 0
1286
+ });
1287
+ } finally {
1288
+ B.delete(a.id);
1289
+ }
1290
+ }, d = (a) => {
1291
+ const u = B.get(a);
1292
+ u && (u.abort(), B.delete(a)), s(a);
1293
+ }, h = le(() => e.filter((a) => a.status === "success" && a.fileUrl), [e]);
1294
+ function f() {
1295
+ B.forEach((a) => a.abort()), B.clear(), t([]);
1296
+ }
1297
+ return st(() => () => {
1298
+ B.forEach((a) => a.abort()), B.clear();
1299
+ }, []), {
1300
+ allFiles: e,
1301
+ appendFiles: r,
1302
+ handleCancelUpload: d,
1303
+ successFiles: h,
1304
+ emptyTheFiles: f,
1305
+ getFileById: (a) => e.find((u) => u.id === a),
1306
+ getUploadProgress: (a) => {
1307
+ var u;
1308
+ return ((u = e.find((l) => l.id === a)) == null ? void 0 : u.progress) ?? 0;
1309
+ },
1310
+ getUploadStatus: (a) => {
1311
+ var u;
1312
+ return (u = e.find((l) => l.id === a)) == null ? void 0 : u.status;
1313
+ },
1314
+ hasErrors: e.some((a) => a.status === "error"),
1315
+ isUploading: e.some((a) => a.status === "uploading")
1316
+ };
1317
+ }
1318
+ export {
1319
+ er as W,
1320
+ ar as _,
1321
+ tr as a,
1322
+ nr as b,
1323
+ rr as c,
1324
+ on as d,
1325
+ ir as e,
1326
+ Ve as f,
1327
+ sn as g,
1328
+ ur as h,
1329
+ de as i,
1330
+ _t as j,
1331
+ Dt as k,
1332
+ or as l,
1333
+ sr as m,
1334
+ te as u
1335
+ };
1336
+ //# sourceMappingURL=useUploadFiles-BaCcqTwX.js.map