@opencx/widget 3.0.11 → 3.0.13
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.
- package/dist/designs.cjs +59 -59
- package/dist/designs.cjs.map +1 -1
- package/dist/designs.js +8642 -8522
- package/dist/designs.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/react.cjs +1 -1
- package/dist/react.js +12 -12
- package/dist/src/designs/react/components/lib/button.d.ts +1 -1
- package/dist/src/designs/react/components/lib/loading.d.ts +4 -0
- package/dist/src/designs/react/screens/sessions/index.d.ts +2 -0
- package/dist/src/headless/core/context/{contact.d.ts → contact.ctx.d.ts} +3 -3
- package/dist/src/headless/core/context/message.ctx.d.ts +33 -0
- package/dist/src/headless/core/context/router.ctx.d.ts +29 -0
- package/dist/src/headless/core/context/{session.d.ts → session.ctx.d.ts} +23 -17
- package/dist/src/headless/core/context/{widget.d.ts → widget.ctx.d.ts} +5 -3
- package/dist/src/headless/core/index.d.ts +6 -5
- package/dist/src/headless/core/sdk/schema.d.ts +2 -0
- package/dist/src/headless/core/utils/Poller.d.ts +2 -2
- package/dist/src/headless/core/utils/{PubSub.d.ts → PrimitiveState.d.ts} +1 -1
- package/dist/src/headless/react/hooks/useContact.d.ts +1 -1
- package/dist/src/headless/react/hooks/useMessages.d.ts +1 -1
- package/dist/src/headless/react/hooks/usePreludeData.d.ts +3 -1
- package/dist/src/headless/react/hooks/usePrimitiveState.d.ts +2 -0
- package/dist/src/headless/react/hooks/useSession.d.ts +8 -7
- package/dist/src/headless/react/hooks/useWidgetRouter.d.ts +7 -0
- package/dist/src/headless/react/index.d.ts +1 -1
- package/dist/useUploadFiles-CiUgziil.cjs +18 -0
- package/dist/useUploadFiles-CiUgziil.cjs.map +1 -0
- package/dist/{useUploadFiles-B-HZXbPR.js → useUploadFiles-ClUXwfKK.js} +243 -237
- package/dist/useUploadFiles-ClUXwfKK.js.map +1 -0
- package/dist/widget.ctx-C7UzbSii.cjs +2 -0
- package/dist/widget.ctx-C7UzbSii.cjs.map +1 -0
- package/dist/{widget-BOaF1U-p.js → widget.ctx-DkDwIMJZ.js} +108 -73
- package/dist/widget.ctx-DkDwIMJZ.js.map +1 -0
- package/dist-embed/script.js +112 -102
- package/dist-embed/script.js.map +1 -1
- package/package.json +1 -1
- package/dist/src/designs/react/components/lib/dialog.d.ts +0 -276
- package/dist/src/headless/core/context/message.d.ts +0 -42
- package/dist/src/headless/react/hooks/usePubsub.d.ts +0 -2
- package/dist/useUploadFiles-B-HZXbPR.js.map +0 -1
- package/dist/useUploadFiles-WylOvupS.cjs +0 -18
- package/dist/useUploadFiles-WylOvupS.cjs.map +0 -1
- package/dist/widget-6i5ISSQC.cjs +0 -2
- package/dist/widget-6i5ISSQC.cjs.map +0 -1
- package/dist/widget-BOaF1U-p.js.map +0 -1
- /package/dist/src/designs/react/screens/{chat-screen → chat}/ChatFooter.d.ts +0 -0
- /package/dist/src/designs/react/screens/{chat-screen → chat}/ChatHeader.d.ts +0 -0
- /package/dist/src/designs/react/screens/{chat-screen → chat}/ChatMain.d.ts +0 -0
- /package/dist/src/designs/react/screens/{chat-screen/ChatScreen.d.ts → chat/index.d.ts} +0 -0
- /package/dist/src/designs/react/screens/{root-screen.d.ts → index.d.ts} +0 -0
- /package/dist/src/designs/react/screens/{welcome-screen/WelcomeScreen.d.ts → welcome/index.d.ts} +0 -0
- /package/dist/src/headless/core/utils/{PubSub.test.d.ts → PrimitiveState.test.d.ts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./widget.ctx-C7UzbSii.cjs");exports.PrimitiveState=t.PrimitiveState;exports.WidgetCtx=t.WidgetCtx;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
package/dist/react.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useUploadFiles-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useUploadFiles-CiUgziil.cjs");function a(t,s,u){const{widgetCtx:{api:i}}=e.useWidget();return e._default(async o=>o==="up"?i.vote({action:"upvote",messagePublicId:t,sessionId:s}).then(u):i.vote({action:"downvote",messagePublicId:t,sessionId:s}).then(u),[i,t,s,u])}exports.WidgetProvider=e.WidgetProvider;exports.useConfig=e.useConfig;exports.useContact=e.useContact;exports.useIsAwaitingBotReply=e.useIsAwaitingBotReply;exports.useMessages=e.useMessages;exports.usePreludeData=e.usePreludeData;exports.usePrimitiveState=e.usePrimitiveState;exports.useSession=e.useSession;exports.useUploadFiles=e.useUploadFiles;exports.useWidget=e.useWidget;exports.useVote=a;
|
|
2
2
|
//# sourceMappingURL=react.cjs.map
|
package/dist/react.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { u as o, _ as
|
|
2
|
-
import { W as p, a as d, b as f, c as
|
|
3
|
-
function n(e, t,
|
|
4
|
-
const { widgetCtx: { api:
|
|
5
|
-
return
|
|
6
|
-
async (u) => u === "up" ?
|
|
7
|
-
[
|
|
1
|
+
import { u as o, _ as i } from "./useUploadFiles-ClUXwfKK.js";
|
|
2
|
+
import { W as p, a as d, b as f, c as m, d as v, e as c, f as P, g as b, h } from "./useUploadFiles-ClUXwfKK.js";
|
|
3
|
+
function n(e, t, a) {
|
|
4
|
+
const { widgetCtx: { api: s } } = o();
|
|
5
|
+
return i(
|
|
6
|
+
async (u) => u === "up" ? s.vote({ action: "upvote", messagePublicId: e, sessionId: t }).then(a) : s.vote({ action: "downvote", messagePublicId: e, sessionId: t }).then(a),
|
|
7
|
+
[s, e, t, a]
|
|
8
8
|
);
|
|
9
9
|
}
|
|
10
10
|
export {
|
|
11
11
|
p as WidgetProvider,
|
|
12
12
|
d as useConfig,
|
|
13
13
|
f as useContact,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
m as useIsAwaitingBotReply,
|
|
15
|
+
v as useMessages,
|
|
16
|
+
c as usePreludeData,
|
|
17
|
+
P as usePrimitiveState,
|
|
18
|
+
b as useSession,
|
|
19
19
|
h as useUploadFiles,
|
|
20
20
|
n as useVote,
|
|
21
21
|
o as useWidget
|
|
@@ -2,7 +2,7 @@ import { VariantProps } from 'class-variance-authority';
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
declare const buttonVariants: (props?: ({
|
|
4
4
|
variant?: "default" | "link" | "outline" | "destructive" | "secondary" | "ghost" | null | undefined;
|
|
5
|
-
size?: "default" | "icon" | "sm" | "lg" | "fit" | null | undefined;
|
|
5
|
+
size?: "default" | "icon" | "sm" | "lg" | "fit" | "free" | null | undefined;
|
|
6
6
|
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
7
7
|
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
|
8
8
|
asChild?: boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PrimitiveState } from '../utils/PrimitiveState';
|
|
2
2
|
import { ApiCaller } from '../api';
|
|
3
3
|
import { WidgetConfig } from '../types/WidgetConfig';
|
|
4
4
|
import { Dto } from '../sdk';
|
|
@@ -12,13 +12,13 @@ type ContactState = {
|
|
|
12
12
|
export declare class ContactCtx {
|
|
13
13
|
private config;
|
|
14
14
|
private api;
|
|
15
|
-
state:
|
|
15
|
+
state: PrimitiveState<ContactState>;
|
|
16
16
|
constructor({ config, api, }: {
|
|
17
17
|
api: ApiCaller;
|
|
18
18
|
config: WidgetConfig;
|
|
19
19
|
});
|
|
20
20
|
shouldCollectData: () => boolean;
|
|
21
|
-
autoCreateUnverifiedUser
|
|
21
|
+
private autoCreateUnverifiedUser;
|
|
22
22
|
createUnverifiedContact: (payload: Dto["CreateUnverifiedContactDto"]) => Promise<void>;
|
|
23
23
|
}
|
|
24
24
|
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ApiCaller } from '../api';
|
|
2
|
+
import { WidgetConfig } from '../types/WidgetConfig';
|
|
3
|
+
import { SafeOmit, SomeOptional } from '../types/helpers';
|
|
4
|
+
import { MessageType } from '../types/messages';
|
|
5
|
+
import { SendMessageDto } from '../types/schemas';
|
|
6
|
+
import { PrimitiveState } from '../utils/PrimitiveState';
|
|
7
|
+
import { SessionCtx } from './session.ctx';
|
|
8
|
+
export declare class MessageCtx {
|
|
9
|
+
private config;
|
|
10
|
+
private api;
|
|
11
|
+
private sessionCtx;
|
|
12
|
+
private poller;
|
|
13
|
+
state: PrimitiveState<{
|
|
14
|
+
messages: MessageType[];
|
|
15
|
+
isSendingMessage: boolean;
|
|
16
|
+
suggestedReplies: string[] | null;
|
|
17
|
+
}>;
|
|
18
|
+
private sendMessageAbortController;
|
|
19
|
+
constructor({ config, api, sessionCtx, }: {
|
|
20
|
+
config: WidgetConfig;
|
|
21
|
+
api: ApiCaller;
|
|
22
|
+
sessionCtx: SessionCtx;
|
|
23
|
+
});
|
|
24
|
+
reset: () => void;
|
|
25
|
+
private registerPolling;
|
|
26
|
+
sendMessage: (input: SomeOptional<SafeOmit<SendMessageDto, "bot_token" | "uuid">, "session_id" | "user">) => Promise<void>;
|
|
27
|
+
private fetchAndSetHistory;
|
|
28
|
+
/** Not the best name but whatever */
|
|
29
|
+
private static mapHistoryToMessage;
|
|
30
|
+
private static toUserMessage;
|
|
31
|
+
private static toBotMessage;
|
|
32
|
+
private static toErrorMessage;
|
|
33
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PrimitiveState } from '../utils/PrimitiveState';
|
|
2
|
+
import { ContactCtx } from './contact.ctx';
|
|
3
|
+
import { SessionCtx } from './session.ctx';
|
|
4
|
+
import { WidgetCtx } from './widget.ctx';
|
|
5
|
+
type RouterState = {
|
|
6
|
+
screen: /** A welcome screen to collect user data. Useful in public non-logged-in environments */ "welcome"
|
|
7
|
+
/** Show a list of the user's previous sessions */
|
|
8
|
+
| "sessions"
|
|
9
|
+
/** Self-explanatory */
|
|
10
|
+
| "chat";
|
|
11
|
+
};
|
|
12
|
+
export declare class RouterCtx {
|
|
13
|
+
state: PrimitiveState<RouterState>;
|
|
14
|
+
private contactCtx;
|
|
15
|
+
private sessionCtx;
|
|
16
|
+
private resetChat;
|
|
17
|
+
constructor({ contactCtx, sessionCtx, resetChat, }: {
|
|
18
|
+
contactCtx: ContactCtx;
|
|
19
|
+
sessionCtx: SessionCtx;
|
|
20
|
+
resetChat: WidgetCtx["resetChat"];
|
|
21
|
+
});
|
|
22
|
+
private registerRoutingListener;
|
|
23
|
+
toSessionsScreen: () => void;
|
|
24
|
+
/**
|
|
25
|
+
* @param sessionId The ID of the session to open, or `undefined` if it is a new chat session
|
|
26
|
+
*/
|
|
27
|
+
toChatScreen: (sessionId?: string) => void;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
import { ApiCaller } from '../api';
|
|
2
2
|
import { SessionDto } from '../types/schemas';
|
|
3
3
|
import { WidgetConfig } from '../types/WidgetConfig';
|
|
4
|
-
import {
|
|
5
|
-
import { ContactCtx } from './contact';
|
|
6
|
-
type
|
|
7
|
-
/**
|
|
4
|
+
import { PrimitiveState } from '../utils/PrimitiveState';
|
|
5
|
+
import { ContactCtx } from './contact.ctx';
|
|
6
|
+
type SessionState = {
|
|
7
|
+
/**
|
|
8
|
+
* The currently selected session.
|
|
9
|
+
* Can be null if no session is selected, or if in chat screen and the session is not created yet.
|
|
10
|
+
*/
|
|
8
11
|
session: SessionDto | null;
|
|
9
|
-
sessions: {
|
|
10
|
-
/** List of all user sessions */
|
|
11
|
-
data: SessionDto[];
|
|
12
|
-
/** A cursor to get the next page of sessions */
|
|
13
|
-
cursor: string | undefined;
|
|
14
|
-
/** Indicates if no more pages are left */
|
|
15
|
-
isLastPage: boolean;
|
|
16
|
-
/** Did fetch for the first time */
|
|
17
|
-
didInitialFetch: boolean;
|
|
18
|
-
};
|
|
19
12
|
isCreatingSession: boolean;
|
|
20
13
|
};
|
|
14
|
+
type SessionsState = {
|
|
15
|
+
/** List of all user sessions */
|
|
16
|
+
data: SessionDto[];
|
|
17
|
+
/** A cursor to get the next page of sessions */
|
|
18
|
+
cursor: string | undefined;
|
|
19
|
+
/** Indicates if no more pages are left */
|
|
20
|
+
isLastPage: boolean;
|
|
21
|
+
/** Did fetch for the first time */
|
|
22
|
+
didStartInitialFetch: boolean;
|
|
23
|
+
isInitialFetchLoading: boolean;
|
|
24
|
+
};
|
|
21
25
|
export declare class SessionCtx {
|
|
22
26
|
private config;
|
|
23
27
|
private api;
|
|
24
28
|
private contactCtx;
|
|
25
29
|
private poller;
|
|
26
|
-
|
|
30
|
+
sessionState: PrimitiveState<SessionState>;
|
|
31
|
+
sessionsState: PrimitiveState<SessionsState>;
|
|
27
32
|
constructor({ config, api, contactCtx, }: {
|
|
28
33
|
config: WidgetConfig;
|
|
29
34
|
api: ApiCaller;
|
|
@@ -31,8 +36,8 @@ export declare class SessionCtx {
|
|
|
31
36
|
});
|
|
32
37
|
/** Clears the session and stops polling */
|
|
33
38
|
reset: () => Promise<void>;
|
|
34
|
-
registerPolling
|
|
35
|
-
registerInitialSessionsFetch
|
|
39
|
+
private registerPolling;
|
|
40
|
+
private registerInitialSessionsFetch;
|
|
36
41
|
createSession: () => Promise<{
|
|
37
42
|
id: string;
|
|
38
43
|
createdAt: string;
|
|
@@ -46,6 +51,7 @@ export declare class SessionCtx {
|
|
|
46
51
|
};
|
|
47
52
|
channel: string;
|
|
48
53
|
isVerified: boolean;
|
|
54
|
+
lastMessage: string | null;
|
|
49
55
|
} | null>;
|
|
50
56
|
loadMoreSessions: () => Promise<void>;
|
|
51
57
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ApiCaller } from '../api';
|
|
2
2
|
import { WidgetConfig } from '../types/WidgetConfig';
|
|
3
|
-
import { ContactCtx } from './contact';
|
|
4
|
-
import { MessageCtx } from './message';
|
|
5
|
-
import {
|
|
3
|
+
import { ContactCtx } from './contact.ctx';
|
|
4
|
+
import { MessageCtx } from './message.ctx';
|
|
5
|
+
import { RouterCtx } from './router.ctx';
|
|
6
|
+
import { SessionCtx } from './session.ctx';
|
|
6
7
|
export declare class WidgetCtx {
|
|
7
8
|
config: WidgetConfig;
|
|
8
9
|
api: ApiCaller;
|
|
9
10
|
contactCtx: ContactCtx;
|
|
10
11
|
sessionCtx: SessionCtx;
|
|
11
12
|
messageCtx: MessageCtx;
|
|
13
|
+
routerCtx: RouterCtx;
|
|
12
14
|
constructor({ config }: {
|
|
13
15
|
config: WidgetConfig;
|
|
14
16
|
});
|
|
@@ -3,8 +3,9 @@ export type { SafeExtract, SafeOmit, SomeOptional, StringOrLiteral, } from './ty
|
|
|
3
3
|
export type { WidgetComponentKey, DefaultWidgetTextComponentData, UserMessageType, AgentMessageType, BotMessageType, MessageType, } from './types/messages';
|
|
4
4
|
export type { MessageAttachmentType, MessageDto, PreludeDto, SendMessageDto, SendMessageOutputDto, SessionDto, VoteInputDto, VoteOutputDto, } from './types/schemas';
|
|
5
5
|
export type { WidgetConfig } from './types/WidgetConfig';
|
|
6
|
-
export { WidgetCtx } from './context/widget';
|
|
7
|
-
export type { ContactCtx } from './context/contact';
|
|
8
|
-
export type { SessionCtx } from './context/session';
|
|
9
|
-
export type { MessageCtx } from './context/message';
|
|
10
|
-
export {
|
|
6
|
+
export { WidgetCtx } from './context/widget.ctx';
|
|
7
|
+
export type { ContactCtx } from './context/contact.ctx';
|
|
8
|
+
export type { SessionCtx } from './context/session.ctx';
|
|
9
|
+
export type { MessageCtx } from './context/message.ctx';
|
|
10
|
+
export type { RouterCtx } from './context/router.ctx';
|
|
11
|
+
export { PrimitiveState } from './utils/PrimitiveState';
|
|
@@ -249,6 +249,7 @@ export interface components {
|
|
|
249
249
|
};
|
|
250
250
|
channel: string;
|
|
251
251
|
isVerified: boolean;
|
|
252
|
+
lastMessage: string | null;
|
|
252
253
|
}[];
|
|
253
254
|
/** @description The `cursor` for the request to get the next set of items. Null if there is no more data. */
|
|
254
255
|
next: string | null;
|
|
@@ -352,6 +353,7 @@ export interface components {
|
|
|
352
353
|
};
|
|
353
354
|
channel: string;
|
|
354
355
|
isVerified: boolean;
|
|
356
|
+
lastMessage: string | null;
|
|
355
357
|
};
|
|
356
358
|
WidgetVoteDto: {
|
|
357
359
|
/** @enum {string} */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PrimitiveState } from './PrimitiveState';
|
|
2
2
|
export type PollingState = {
|
|
3
3
|
isPolling: boolean;
|
|
4
4
|
isError: boolean;
|
|
5
5
|
};
|
|
6
6
|
export declare class Poller {
|
|
7
|
-
state:
|
|
7
|
+
state: PrimitiveState<PollingState>;
|
|
8
8
|
private abortController;
|
|
9
9
|
reset: () => void;
|
|
10
10
|
stopPolling: (() => void) | null;
|
|
@@ -6,5 +6,5 @@ export declare function useContact(): {
|
|
|
6
6
|
isCreatingUnverifiedContact: boolean;
|
|
7
7
|
isErrorCreatingUnverifiedContact: boolean;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
createUnverifiedContact: (payload: import('../../core/sdk').Dto["CreateUnverifiedContactDto"]) => Promise<void>;
|
|
10
10
|
};
|
|
@@ -4,5 +4,5 @@ export declare function useMessages(): {
|
|
|
4
4
|
isSendingMessage: boolean;
|
|
5
5
|
suggestedReplies: string[] | null;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
sendMessage: (input: import('../../core').SomeOptional<import('../../core').SafeOmit<import('../../core').SendMessageDto, "bot_token" | "uuid">, "session_id" | "user">) => Promise<void>;
|
|
8
8
|
};
|
|
@@ -32,5 +32,7 @@ declare function usePreludeData(): import('swr').SWRResponse<import('openapi-fet
|
|
|
32
32
|
"X-Bot-Token": string;
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
|
-
}, `${string}/${string}`>, any,
|
|
35
|
+
}, `${string}/${string}`>, any, {
|
|
36
|
+
revalidateOnFocus: false;
|
|
37
|
+
}>;
|
|
36
38
|
export { usePreludeData };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export declare function useSession(): {
|
|
2
2
|
sessionState: {
|
|
3
3
|
session: import('../../core').SessionDto | null;
|
|
4
|
-
sessions: {
|
|
5
|
-
data: import('../../core').SessionDto[];
|
|
6
|
-
cursor: string | undefined;
|
|
7
|
-
isLastPage: boolean;
|
|
8
|
-
didInitialFetch: boolean;
|
|
9
|
-
};
|
|
10
4
|
isCreatingSession: boolean;
|
|
11
5
|
};
|
|
12
|
-
|
|
6
|
+
sessionsState: {
|
|
7
|
+
data: import('../../core').SessionDto[];
|
|
8
|
+
cursor: string | undefined;
|
|
9
|
+
isLastPage: boolean;
|
|
10
|
+
didStartInitialFetch: boolean;
|
|
11
|
+
isInitialFetchLoading: boolean;
|
|
12
|
+
};
|
|
13
|
+
loadMoreSessions: () => Promise<void>;
|
|
13
14
|
};
|
|
@@ -5,7 +5,7 @@ export { useContact } from './hooks/useContact';
|
|
|
5
5
|
export { useIsAwaitingBotReply } from './hooks/useIsAwaitingBotReply';
|
|
6
6
|
export { useMessages } from './hooks/useMessages';
|
|
7
7
|
export { usePreludeData } from './hooks/usePreludeData';
|
|
8
|
-
export {
|
|
8
|
+
export { usePrimitiveState } from './hooks/usePrimitiveState';
|
|
9
9
|
export { useSession } from './hooks/useSession';
|
|
10
10
|
export { useVote } from './hooks/useVote';
|
|
11
11
|
export { type FileWithProgress, useUploadFiles } from './hooks/useUploadFiles';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";var qt=Object.defineProperty;var Bt=(e,t,n)=>t in e?qt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ke=(e,t,n)=>Bt(e,typeof t!="symbol"?t+"":t,n);const E=require("react"),Ht=require("react/jsx-runtime"),Gt=require("./widget.ctx-C7UzbSii.cjs"),$t=require("uuid");class kt{constructor(t){Ke(this,"components",[{key:"fallback",component:t=>"fallback"},{key:"loading",component:t=>"loading"}]);const{components:n}=t;if(n&&n.forEach(r=>this.register(r)),this.components.length===0)throw new Error("No components registered");if(!this.get("fallback"))throw new Error("No fallback component registered")}register(t){const n=this.components.findIndex(r=>r.key===t.key);return n!==-1?this.components[n]=t:this.components.push(t),this}get(t){const n=this.components.find(r=>r.key.toUpperCase()===t.toUpperCase());return n||null}getOrFallback(t){return t?this.get(t)||this.get("fallback"):this.get("fallback")}getComponent(t,n){var r;return n?this.getOrFallback(t).component:(r=this.get(t))==null?void 0:r.component}}function Kt(e){const t=E.createContext({});return[()=>{const r=E.useContext(t);if(r===void 0)throw new Error("useSafeContext must be used within a Provider");return r},t.Provider]}const zt="3.0.13",[K,Yt]=Kt();function Jt({options:e,children:t,components:n}){const r=E.useMemo(()=>new Gt.WidgetCtx({config:e}),[e]),o=E.useMemo(()=>new kt({components:n}),[n]);return Ht.jsx(Yt,{value:{widgetCtx:r,components:n,componentStore:o,version:zt},children:t})}function Xt(){const{widgetCtx:e}=K();return e.config}function re(e){return E.useSyncExternalStore(e.subscribe,e.get,e.get)}function Qt(){const{widgetCtx:e}=K();return{contactState:re(e.contactCtx.state),createUnverifiedContact:e.contactCtx.createUnverifiedContact}}function tt(){const{widgetCtx:e}=K();return{messagesState:re(e.messageCtx.state),sendMessage:e.messageCtx.sendMessage}}function nt(){const{widgetCtx:e}=K(),t=re(e.sessionCtx.sessionState),n=re(e.sessionCtx.sessionsState);return{sessionState:t,sessionsState:n,loadMoreSessions:e.sessionCtx.loadMoreSessions}}function Zt(){var r;const{sessionState:e}=nt(),{messagesState:t}=tt();return{isAwaitingBotReply:(!((r=e.session)!=null&&r.isHandedOff)||e.session.assignee.kind==="ai"||e.isCreatingSession)&&t.isSendingMessage}}var en=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function tn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function nn(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var n=function r(){return this instanceof r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}),n}var Oe={exports:{}},ye={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* use-sync-external-store-shim.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var ze;function rn(){if(ze)return ye;ze=1;var e=E;function t(u,l){return u===l&&(u!==0||1/u===1/l)||u!==u&&l!==l}var n=typeof Object.is=="function"?Object.is:t,r=e.useState,o=e.useEffect,s=e.useLayoutEffect,i=e.useDebugValue;function d(u,l){var c=l(),y=r({inst:{value:c,getSnapshot:l}}),h=y[0].inst,T=y[1];return s(function(){h.value=c,h.getSnapshot=l,_(h)&&T({inst:h})},[u,c,l]),o(function(){return _(h)&&T({inst:h}),u(function(){_(h)&&T({inst:h})})},[u]),i(c),c}function _(u){var l=u.getSnapshot;u=u.value;try{var c=l();return!n(u,c)}catch{return!0}}function f(u,l){return l()}var a=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?f:d;return ye.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:a,ye}var ge={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* use-sync-external-store-shim.development.js
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*/var Ye;function on(){return Ye||(Ye=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=E,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function n(R){{for(var v=arguments.length,S=new Array(v>1?v-1:0),w=1;w<v;w++)S[w-1]=arguments[w];r("error",R,S)}}function r(R,v,S){{var w=t.ReactDebugCurrentFrame,I=w.getStackAddendum();I!==""&&(v+="%s",S=S.concat([I]));var m=S.map(function(D){return String(D)});m.unshift("Warning: "+v),Function.prototype.apply.call(console[R],console,m)}}function o(R,v){return R===v&&(R!==0||1/R===1/v)||R!==R&&v!==v}var s=typeof Object.is=="function"?Object.is:o,i=e.useState,d=e.useEffect,_=e.useLayoutEffect,f=e.useDebugValue,a=!1,u=!1;function l(R,v,S){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."));var w=v();if(!u){var I=v();s(w,I)||(n("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var m=i({inst:{value:w,getSnapshot:v}}),D=m[0].inst,P=m[1];return _(function(){D.value=w,D.getSnapshot=v,c(D)&&P({inst:D})},[R,w,v]),d(function(){c(D)&&P({inst:D});var B=function(){c(D)&&P({inst:D})};return R(B)},[R]),f(w),w}function c(R){var v=R.getSnapshot,S=R.value;try{var w=v();return!s(S,w)}catch{return!0}}function y(R,v,S){return v()}var h=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",T=!h,p=T?y:l,z=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:p;ge.useSyncExternalStore=z,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),ge}process.env.NODE_ENV==="production"?Oe.exports=rn():Oe.exports=on();var sn=Oe.exports;const G=()=>{},L=G(),Ee=Object,g=e=>e===L,N=e=>typeof e=="function",$=(e,t)=>({...e,...t}),an=e=>N(e.then),ue=new WeakMap;let un=0;const oe=e=>{const t=typeof e,n=e&&e.constructor,r=n==Date;let o,s;if(Ee(e)===e&&!r&&n!=RegExp){if(o=ue.get(e),o)return o;if(o=++un+"~",ue.set(e,o),n==Array){for(o="@",s=0;s<e.length;s++)o+=oe(e[s])+",";ue.set(e,o)}if(n==Ee){o="#";const i=Ee.keys(e).sort();for(;!g(s=i.pop());)g(e[s])||(o+=s+":"+oe(e[s])+",");ue.set(e,o)}}else o=r?e.toJSON():t=="symbol"?e.toString():t=="string"?JSON.stringify(e):""+e;return o},q=new WeakMap,ve={},ce={},Pe="undefined",de=typeof window!=Pe,Re=typeof document!=Pe,cn=()=>de&&typeof window.requestAnimationFrame!=Pe,rt=(e,t)=>{const n=q.get(e);return[()=>!g(t)&&e.get(t)||ve,r=>{if(!g(t)){const o=e.get(t);t in ce||(ce[t]=o),n[5](t,$(o,r),o||ve)}},n[6],()=>!g(t)&&t in ce?ce[t]:!g(t)&&e.get(t)||ve]};let Ce=!0;const fn=()=>Ce,[Te,De]=de&&window.addEventListener?[window.addEventListener.bind(window),window.removeEventListener.bind(window)]:[G,G],ln=()=>{const e=Re&&document.visibilityState;return g(e)||e!=="hidden"},dn=e=>(Re&&document.addEventListener("visibilitychange",e),Te("focus",e),()=>{Re&&document.removeEventListener("visibilitychange",e),De("focus",e)}),pn=e=>{const t=()=>{Ce=!0,e()},n=()=>{Ce=!1};return Te("online",t),Te("offline",n),()=>{De("online",t),De("offline",n)}},_n={isOnline:fn,isVisible:ln},hn={initFocus:dn,initReconnect:pn},Je=!E.useId,se=!de||"Deno"in window,yn=e=>cn()?window.requestAnimationFrame(e):setTimeout(e,1),we=se?E.useEffect:E.useLayoutEffect,Se=typeof navigator<"u"&&navigator.connection,Xe=!se&&Se&&(["slow-2g","2g"].includes(Se.effectiveType)||Se.saveData),Le=e=>{if(N(e))try{e=e()}catch{e=""}const t=e;return e=typeof e=="string"?e:(Array.isArray(e)?e.length:e)?oe(e):"",[e,t]};let gn=0;const Ae=()=>++gn,ot=0,st=1,it=2,En=3;var ne={__proto__:null,ERROR_REVALIDATE_EVENT:En,FOCUS_EVENT:ot,MUTATE_EVENT:it,RECONNECT_EVENT:st};async function at(...e){const[t,n,r,o]=e,s=$({populateCache:!0,throwOnError:!0},typeof o=="boolean"?{revalidate:o}:o||{});let i=s.populateCache;const d=s.rollbackOnError;let _=s.optimisticData;const f=l=>typeof d=="function"?d(l):d!==!1,a=s.throwOnError;if(N(n)){const l=n,c=[],y=t.keys();for(const h of y)!/^\$(inf|sub)\$/.test(h)&&l(t.get(h)._k)&&c.push(h);return Promise.all(c.map(u))}return u(n);async function u(l){const[c]=Le(l);if(!c)return;const[y,h]=rt(t,c),[T,p,z,R]=q.get(t),v=()=>{const F=T[c];return(N(s.revalidate)?s.revalidate(y().data,l):s.revalidate!==!1)&&(delete z[c],delete R[c],F&&F[0])?F[0](it).then(()=>y().data):y().data};if(e.length<3)return v();let S=r,w;const I=Ae();p[c]=[I,0];const m=!g(_),D=y(),P=D.data,B=D._c,k=g(B)?P:B;if(m&&(_=N(_)?_(k,P):_,h({data:_,_c:k})),N(S))try{S=S(k)}catch(F){w=F}if(S&&an(S))if(S=await S.catch(F=>{w=F}),I!==p[c][0]){if(w)throw w;return S}else w&&m&&f(w)&&(i=!0,h({data:k,_c:L}));if(i&&!w)if(N(i)){const F=i(S,k);h({data:F,error:L,_c:L})}else h({data:S,error:L,_c:L});if(p[c][1]=Ae(),Promise.resolve(v()).then(()=>{h({_c:L})}),w){if(a)throw w;return}return S}}const Qe=(e,t)=>{for(const n in e)e[n][0]&&e[n][0](t)},vn=(e,t)=>{if(!q.has(e)){const n=$(hn,t),r={},o=at.bind(L,e);let s=G;const i={},d=(a,u)=>{const l=i[a]||[];return i[a]=l,l.push(u),()=>l.splice(l.indexOf(u),1)},_=(a,u,l)=>{e.set(a,u);const c=i[a];if(c)for(const y of c)y(u,l)},f=()=>{if(!q.has(e)&&(q.set(e,[r,{},{},{},o,_,d]),!se)){const a=n.initFocus(setTimeout.bind(L,Qe.bind(L,r,ot))),u=n.initReconnect(setTimeout.bind(L,Qe.bind(L,r,st)));s=()=>{a&&a(),u&&u(),q.delete(e)}}};return f(),[e,o,f,s]}return[e,q.get(e)[4]]},wn=(e,t,n,r,o)=>{const s=n.errorRetryCount,i=o.retryCount,d=~~((Math.random()+.5)*(1<<(i<8?i:8)))*n.errorRetryInterval;!g(s)&&i>s||setTimeout(r,d,o)},Sn=(e,t)=>oe(e)==oe(t),[ut,mn]=vn(new Map),bn=$({onLoadingSlow:G,onSuccess:G,onError:G,onErrorRetry:wn,onDiscarded:G,revalidateOnFocus:!0,revalidateOnReconnect:!0,revalidateIfStale:!0,shouldRetryOnError:!0,errorRetryInterval:Xe?1e4:5e3,focusThrottleInterval:5*1e3,dedupingInterval:2*1e3,loadingTimeout:Xe?5e3:3e3,compare:Sn,isPaused:()=>!1,cache:ut,mutate:mn,fallback:{}},_n),On=(e,t)=>{const n=$(e,t);if(t){const{use:r,fallback:o}=e,{use:s,fallback:i}=t;r&&s&&(n.use=r.concat(s)),o&&i&&(n.fallback=$(o,i))}return n},Rn=E.createContext({}),Cn="$inf$",ct=de&&window.__SWR_DEVTOOLS_USE__,Tn=ct?window.__SWR_DEVTOOLS_USE__:[],Dn=()=>{ct&&(window.__SWR_DEVTOOLS_REACT__=E)},An=e=>N(e[1])?[e[0],e[1],e[2]||{}]:[e[0],null,(e[1]===null?e[2]:e[1])||{}],xn=()=>$(bn,E.useContext(Rn)),jn=e=>(t,n,r)=>e(t,n&&((...s)=>{const[i]=Le(t),[,,,d]=q.get(ut);if(i.startsWith(Cn))return n(...s);const _=d[i];return g(_)?n(...s):(delete d[i],_)}),r),Pn=Tn.concat(jn),Ln=e=>function(...n){const r=xn(),[o,s,i]=An(n),d=On(r,i);let _=e;const{use:f}=d,a=(f||[]).concat(Pn);for(let u=a.length;u--;)_=a[u](_);return _(o,s||d.fetcher||null,d)},In=(e,t,n)=>{const r=t[e]||(t[e]=[]);return r.push(n),()=>{const o=r.indexOf(n);o>=0&&(r[o]=r[r.length-1],r.pop())}};Dn();const Ze=E.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)}),me={dedupe:!0},Vn=(e,t,n)=>{const{cache:r,compare:o,suspense:s,fallbackData:i,revalidateOnMount:d,revalidateIfStale:_,refreshInterval:f,refreshWhenHidden:a,refreshWhenOffline:u,keepPreviousData:l}=n,[c,y,h,T]=q.get(r),[p,z]=Le(e),R=E.useRef(!1),v=E.useRef(!1),S=E.useRef(p),w=E.useRef(t),I=E.useRef(n),m=()=>I.current,D=()=>m().isVisible()&&m().isOnline(),[P,B,k,F]=rt(r,p),Y=E.useRef({}).current,Ft=g(i)?n.fallback[p]:i,Me=(b,O)=>{for(const x in Y){const C=x;if(C==="data"){if(!o(b[C],O[C])&&(!g(b[C])||!o(ae,O[C])))return!1}else if(O[C]!==b[C])return!1}return!0},Ne=E.useMemo(()=>{const b=!p||!t?!1:g(d)?m().isPaused()||s?!1:g(_)?!0:_:d,O=j=>{const U=$(j);return delete U._k,b?{isValidating:!0,isLoading:!0,...U}:U},x=P(),C=F(),M=O(x),Z=x===C?M:O(C);let A=M;return[()=>{const j=O(P());return Me(j,A)?(A.data=j.data,A.isLoading=j.isLoading,A.isValidating=j.isValidating,A.error=j.error,A):(A=j,j)},()=>Z]},[r,p]),J=sn.useSyncExternalStore(E.useCallback(b=>k(p,(O,x)=>{Me(x,O)||b()}),[r,p]),Ne[0],Ne[1]),Ue=!R.current,Mt=c[p]&&c[p].length>0,X=J.data,Q=g(X)?Ft:X,ie=J.error,We=E.useRef(Q),ae=l?g(X)?We.current:X:Q,qe=Mt&&!g(ie)?!1:Ue&&!g(d)?d:m().isPaused()?!1:s?g(Q)?!1:_:g(Q)||_,Be=!!(p&&t&&Ue&&qe),Nt=g(J.isValidating)?Be:J.isValidating,Ut=g(J.isLoading)?Be:J.isLoading,te=E.useCallback(async b=>{const O=w.current;if(!p||!O||v.current||m().isPaused())return!1;let x,C,M=!0;const Z=b||{},A=!h[p]||!Z.dedupe,j=()=>Je?!v.current&&p===S.current&&R.current:p===S.current,U={isValidating:!1,isLoading:!1},Ge=()=>{B(U)},$e=()=>{const V=h[p];V&&V[1]===C&&delete h[p]},ke={isValidating:!0};g(P().data)&&(ke.isLoading=!0);try{if(A&&(B(ke),n.loadingTimeout&&g(P().data)&&setTimeout(()=>{M&&j()&&m().onLoadingSlow(p,n)},n.loadingTimeout),h[p]=[O(z),Ae()]),[x,C]=h[p],x=await x,A&&setTimeout($e,n.dedupingInterval),!h[p]||h[p][1]!==C)return A&&j()&&m().onDiscarded(p),!1;U.error=L;const V=y[p];if(!g(V)&&(C<=V[0]||C<=V[1]||V[1]===0))return Ge(),A&&j()&&m().onDiscarded(p),!1;const W=P().data;U.data=o(W,x)?W:x,A&&j()&&m().onSuccess(x,p,n)}catch(V){$e();const W=m(),{shouldRetryOnError:_e}=W;W.isPaused()||(U.error=V,A&&j()&&(W.onError(V,p,W),(_e===!0||N(_e)&&_e(V))&&(!m().revalidateOnFocus||!m().revalidateOnReconnect||D())&&W.onErrorRetry(V,p,W,Wt=>{const he=c[p];he&&he[0]&&he[0](ne.ERROR_REVALIDATE_EVENT,Wt)},{retryCount:(Z.retryCount||0)+1,dedupe:!0})))}return M=!1,Ge(),!0},[p,r]),He=E.useCallback((...b)=>at(r,S.current,...b),[]);if(we(()=>{w.current=t,I.current=n,g(X)||(We.current=X)}),we(()=>{if(!p)return;const b=te.bind(L,me);let O=0;const C=In(p,c,(M,Z={})=>{if(M==ne.FOCUS_EVENT){const A=Date.now();m().revalidateOnFocus&&A>O&&D()&&(O=A+m().focusThrottleInterval,b())}else if(M==ne.RECONNECT_EVENT)m().revalidateOnReconnect&&D()&&b();else{if(M==ne.MUTATE_EVENT)return te();if(M==ne.ERROR_REVALIDATE_EVENT)return te(Z)}});return v.current=!1,S.current=p,R.current=!0,B({_k:z}),qe&&(g(Q)||se?b():yn(b)),()=>{v.current=!0,C()}},[p]),we(()=>{let b;function O(){const C=N(f)?f(P().data):f;C&&b!==-1&&(b=setTimeout(x,C))}function x(){!P().error&&(a||m().isVisible())&&(u||m().isOnline())?te(me).then(O):O()}return O(),()=>{b&&(clearTimeout(b),b=-1)}},[f,a,u,p]),E.useDebugValue(ae),s&&g(Q)&&p){if(!Je&&se)throw new Error("Fallback data is required when using suspense in SSR.");w.current=t,I.current=n,v.current=!1;const b=T[p];if(!g(b)){const O=He(b);Ze(O)}if(g(ie)){const O=te(me);g(ae)||(O.status="fulfilled",O.value=!0),Ze(O)}else throw ie}return{mutate:He,get data(){return Y.data=!0,ae},get error(){return Y.error=!0,ie},get isValidating(){return Y.isValidating=!0,Nt},get isLoading(){return Y.isLoading=!0,Ut}}},Fn=Ln(Vn);function Mn(){const{widgetCtx:e}=K();return Fn([e.config.token],e.api.widgetPrelude,{revalidateOnFocus:!1})}var ft={},xe=function(e,t){return xe=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=r[o])},xe(e,t)};function lt(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");xe(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}exports.__assign=function(){return exports.__assign=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},exports.__assign.apply(this,arguments)};function Ie(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function dt(e,t,n,r){var o=arguments.length,s=o<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,i;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(e,t,n,r);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);return o>3&&s&&Object.defineProperty(t,n,s),s}function pt(e,t){return function(n,r){t(n,r,e)}}function _t(e,t,n,r,o,s){function i(p){if(p!==void 0&&typeof p!="function")throw new TypeError("Function expected");return p}for(var d=r.kind,_=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--){var y={};for(var h in r)y[h]=h==="access"?{}:r[h];for(var h in r.access)y.access[h]=r.access[h];y.addInitializer=function(p){if(l)throw new TypeError("Cannot add initializers after decoration has completed");s.push(i(p||null))};var T=(0,n[c])(d==="accessor"?{get:a.get,set:a.set}:a[_],y);if(d==="accessor"){if(T===void 0)continue;if(T===null||typeof T!="object")throw new TypeError("Object expected");(u=i(T.get))&&(a.get=u),(u=i(T.set))&&(a.set=u),(u=i(T.init))&&o.unshift(u)}else(u=i(T))&&(d==="field"?o.unshift(u):a[_]=u)}f&&Object.defineProperty(f,r.name,a),l=!0}function ht(e,t,n){for(var r=arguments.length>2,o=0;o<t.length;o++)n=r?t[o].call(e,n):t[o].call(e);return r?n:void 0}function yt(e){return typeof e=="symbol"?e:"".concat(e)}function gt(e,t,n){return typeof t=="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:n?"".concat(n," ",t):t})}function Et(e,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(e,t)}function vt(e,t,n,r){function o(s){return s instanceof n?s:new n(function(i){i(s)})}return new(n||(n=Promise))(function(s,i){function d(a){try{f(r.next(a))}catch(u){i(u)}}function _(a){try{f(r.throw(a))}catch(u){i(u)}}function f(a){a.done?s(a.value):o(a.value).then(d,_)}f((r=r.apply(e,t||[])).next())})}function wt(e,t){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,o,s,i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=d(0),i.throw=d(1),i.return=d(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function d(f){return function(a){return _([f,a])}}function _(f){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,f[0]&&(n=0)),n;)try{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;switch(o=0,s&&(f=[f[0]&2,s.value]),f[0]){case 0:case 1:s=f;break;case 4:return n.label++,{value:f[1],done:!1};case 5:n.label++,o=f[1],f=[0];continue;case 7:f=n.ops.pop(),n.trys.pop();continue;default:if(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(f[0]===6||f[0]===2)){n=0;continue}if(f[0]===3&&(!s||f[1]>s[0]&&f[1]<s[3])){n.label=f[1];break}if(f[0]===6&&n.label<s[1]){n.label=s[1],s=f;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(f);break}s[2]&&n.ops.pop(),n.trys.pop();continue}f=t.call(e,n)}catch(a){f=[6,a],o=0}finally{r=s=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}var pe=Object.create?function(e,t,n,r){r===void 0&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]};function St(e,t){for(var n in e)n!=="default"&&!Object.prototype.hasOwnProperty.call(t,n)&&pe(t,e,n)}function le(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ve(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),o,s=[],i;try{for(;(t===void 0||t-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(d){i={error:d}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s}function mt(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(Ve(arguments[t]));return e}function bt(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),o=0,t=0;t<n;t++)for(var s=arguments[t],i=0,d=s.length;i<d;i++,o++)r[o]=s[i];return r}function Fe(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}function ee(e){return this instanceof ee?(this.v=e,this):new ee(e)}function Ot(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),d("next"),d("throw"),d("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(c){return function(y){return Promise.resolve(y).then(c,u)}}function d(c,y){r[c]&&(o[c]=function(h){return new Promise(function(T,p){s.push([c,h,T,p])>1||_(c,h)})},y&&(o[c]=y(o[c])))}function _(c,y){try{f(r[c](y))}catch(h){l(s[0][3],h)}}function f(c){c.value instanceof ee?Promise.resolve(c.value.v).then(a,u):l(s[0][2],c)}function a(c){_("next",c)}function u(c){_("throw",c)}function l(c,y){c(y),s.shift(),s.length&&_(s[0][0],s[0][1])}}function Rt(e){var t,n;return t={},r("next"),r("throw",function(o){throw o}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(o,s){t[o]=e[o]?function(i){return(n=!n)?{value:ee(e[o](i)),done:!1}:s?s(i):i}:s}}function Ct(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof le=="function"?le(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[s]=e[s]&&function(i){return new Promise(function(d,_){i=e[s](i),o(d,_,i.done,i.value)})}}function o(s,i,d,_){Promise.resolve(_).then(function(f){s({value:f,done:d})},i)}}function Tt(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var Nn=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};function Dt(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n in e)n!=="default"&&Object.prototype.hasOwnProperty.call(e,n)&&pe(t,e,n);return Nn(t,e),t}function At(e){return e&&e.__esModule?e:{default:e}}function xt(e,t,n,r){if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");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");return n==="m"?r:n==="a"?r.call(e):r?r.value:t.get(e)}function jt(e,t,n,r,o){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!o)throw new TypeError("Private accessor was defined without a setter");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");return r==="a"?o.call(e,n):o?o.value=n:t.set(e,n),n}function Pt(e,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof e=="function"?t===e:e.has(t)}function Lt(e,t,n){if(t!=null){if(typeof t!="object"&&typeof t!="function")throw new TypeError("Object expected.");var r,o;if(n){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");r=t[Symbol.asyncDispose]}if(r===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");r=t[Symbol.dispose],n&&(o=r)}if(typeof r!="function")throw new TypeError("Object not disposable.");o&&(r=function(){try{o.call(this)}catch(s){return Promise.reject(s)}}),e.stack.push({value:t,dispose:r,async:n})}else n&&e.stack.push({async:!0});return t}var Un=typeof SuppressedError=="function"?SuppressedError:function(e,t,n){var r=new Error(n);return r.name="SuppressedError",r.error=e,r.suppressed=t,r};function It(e){function t(s){e.error=e.hasError?new Un(s,e.error,"An error was suppressed during disposal."):s,e.hasError=!0}var n,r=0;function o(){for(;n=e.stack.pop();)try{if(!n.async&&r===1)return r=0,e.stack.push(n),Promise.resolve().then(o);if(n.dispose){var s=n.dispose.call(n.value);if(n.async)return r|=2,Promise.resolve(s).then(o,function(i){return t(i),o()})}else r|=1}catch(i){t(i)}if(r===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return o()}function Vt(e,t){return typeof e=="string"&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(n,r,o,s,i){return r?t?".jsx":".js":o&&(!s||!i)?n:o+s+"."+i.toLowerCase()+"js"}):e}const Wn={__extends:lt,__assign:exports.__assign,__rest:Ie,__decorate:dt,__param:pt,__esDecorate:_t,__runInitializers:ht,__propKey:yt,__setFunctionName:gt,__metadata:Et,__awaiter:vt,__generator:wt,__createBinding:pe,__exportStar:St,__values:le,__read:Ve,__spread:mt,__spreadArrays:bt,__spreadArray:Fe,__await:ee,__asyncGenerator:Ot,__asyncDelegator:Rt,__asyncValues:Ct,__makeTemplateObject:Tt,__importStar:Dt,__importDefault:At,__classPrivateFieldGet:xt,__classPrivateFieldSet:jt,__classPrivateFieldIn:Pt,__addDisposableResource:Lt,__disposeResources:It,__rewriteRelativeImportExtension:Vt},qn=Object.freeze(Object.defineProperty({__proto__:null,__addDisposableResource:Lt,get __assign(){return exports.__assign},__asyncDelegator:Rt,__asyncGenerator:Ot,__asyncValues:Ct,__await:ee,__awaiter:vt,__classPrivateFieldGet:xt,__classPrivateFieldIn:Pt,__classPrivateFieldSet:jt,__createBinding:pe,__decorate:dt,__disposeResources:It,__esDecorate:_t,__exportStar:St,__extends:lt,__generator:wt,__importDefault:At,__importStar:Dt,__makeTemplateObject:Tt,__metadata:Et,__param:pt,__propKey:yt,__read:Ve,__rest:Ie,__rewriteRelativeImportExtension:Vt,__runInitializers:ht,__setFunctionName:gt,__spread:mt,__spreadArray:Fe,__spreadArrays:bt,__values:le,default:Wn},Symbol.toStringTag,{value:"Module"})),Bn=nn(qn);var fe={},et;function Hn(){if(et)return fe;et=1,Object.defineProperty(fe,"__esModule",{value:!0});var e=E;function t(){var n=e.useRef(!1),r=e.useCallback(function(){return n.current},[]);return e.useEffect(function(){return n.current=!0,function(){n.current=!1}},[]),r}return fe.default=t,fe}Object.defineProperty(ft,"__esModule",{value:!0});var je=Bn,be=E,Gn=je.__importDefault(Hn());function $n(e,t,n){t===void 0&&(t=[]),n===void 0&&(n={loading:!1});var r=be.useRef(0),o=Gn.default(),s=be.useState(n),i=s[0],d=s[1],_=be.useCallback(function(){for(var f=[],a=0;a<arguments.length;a++)f[a]=arguments[a];var u=++r.current;return i.loading||d(function(l){return je.__assign(je.__assign({},l),{loading:!0})}),e.apply(void 0,f).then(function(l){return o()&&u===r.current&&d({value:l,loading:!1}),l},function(l){return o()&&u===r.current&&d({error:l,loading:!1}),l})},t);return[i,_]}var kn=ft.default=$n;const H=new Map;function Kn(){const[e,t]=E.useState([]),{widgetCtx:{api:n}}=K();function r(a){const u=a.map(l=>({file:l,id:$t.v4(),status:"pending",progress:0}));t(l=>[...l,...u]),u.forEach(i)}function o(a,u){t(l=>l.map(c=>c.id===a?{...c,...u}:c))}function s(a){t(u=>u.filter(l=>l.id!==a))}const i=async a=>{const u=new AbortController;H.set(a.id,u);try{t(c=>c.map(y=>y.id===a.id?{...y,status:"uploading",progress:0}:y));const l=await n.uploadFile(a,{signal:u.signal,onUploadProgress:c=>{if(!c.total)return;const y=Math.round(c.loaded*100/c.total);o(a.id,{progress:y})}});o(a.id,{status:"success",fileUrl:l.fileUrl,progress:100})}catch(l){u.signal.aborted||o(a.id,{status:"error",error:l instanceof Error?l.message:"Upload failed",progress:0})}finally{H.delete(a.id)}},d=a=>{const u=H.get(a);u&&(u.abort(),H.delete(a)),s(a)},_=E.useMemo(()=>e.filter(a=>a.status==="success"&&a.fileUrl),[e]);function f(){H.forEach(a=>a.abort()),H.clear(),t([])}return E.useEffect(()=>()=>{H.forEach(a=>a.abort()),H.clear()},[]),{allFiles:e,appendFiles:r,handleCancelUpload:d,successFiles:_,emptyTheFiles:f,getFileById:a=>e.find(u=>u.id===a),getUploadProgress:a=>{var u;return((u=e.find(l=>l.id===a))==null?void 0:u.progress)??0},getUploadStatus:a=>{var u;return(u=e.find(l=>l.id===a))==null?void 0:u.status},hasErrors:e.some(a=>a.status==="error"),isUploading:e.some(a=>a.status==="uploading")}}exports.WidgetProvider=Jt;exports.__rest=Ie;exports.__spreadArray=Fe;exports._default=kn;exports.commonjsGlobal=en;exports.getDefaultExportFromCjs=tn;exports.useConfig=Xt;exports.useContact=Qt;exports.useIsAwaitingBotReply=Zt;exports.useMessages=tt;exports.usePreludeData=Mn;exports.usePrimitiveState=re;exports.useSession=nt;exports.useUploadFiles=Kn;exports.useWidget=K;
|
|
18
|
+
//# sourceMappingURL=useUploadFiles-CiUgziil.cjs.map
|