@botonic/webchat-react 2.23.1
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/CHANGELOG.md +269 -0
- package/README.md +236 -0
- package/index.d.ts +81 -0
- package/index.js +46 -0
- package/lib/components/message/audio-message/audio-message.d.ts +20 -0
- package/lib/components/message/audio-message/index.d.ts +1 -0
- package/lib/components/message/button-message/button-message.d.ts +24 -0
- package/lib/components/message/button-message/index.d.ts +1 -0
- package/lib/components/message/carousel-message/carousel-message.d.ts +18 -0
- package/lib/components/message/carousel-message/index.d.ts +1 -0
- package/lib/components/message/document-message/document-message.d.ts +22 -0
- package/lib/components/message/document-message/index.d.ts +1 -0
- package/lib/components/message/image-message/image-message.d.ts +14 -0
- package/lib/components/message/image-message/index.d.ts +1 -0
- package/lib/components/message/index.d.ts +33 -0
- package/lib/components/message/location-message/index.d.ts +1 -0
- package/lib/components/message/location-message/location-message.d.ts +16 -0
- package/lib/components/message/message/index.d.ts +5 -0
- package/lib/components/message/message/message-avatar/index.d.ts +1 -0
- package/lib/components/message/message/message-avatar/message-avatar.d.ts +24 -0
- package/lib/components/message/message/message-bubble/index.d.ts +1 -0
- package/lib/components/message/message/message-bubble/message-bubble.d.ts +17 -0
- package/lib/components/message/message/message-info/index.d.ts +1 -0
- package/lib/components/message/message/message-info/message-info.d.ts +25 -0
- package/lib/components/message/message/message.d.ts +23 -0
- package/lib/components/message/message/use-message.d.ts +43 -0
- package/lib/components/message/text-message/index.d.ts +1 -0
- package/lib/components/message/text-message/text-message.d.ts +10 -0
- package/lib/components/message/video-message/index.d.ts +1 -0
- package/lib/components/message/video-message/video-message.d.ts +20 -0
- package/lib/components/message-machine-renderer/index.d.ts +3 -0
- package/lib/components/message-machine-renderer/message-machine-renderer.d.ts +28 -0
- package/lib/components/message-machine-renderer/use-avatar.d.ts +34 -0
- package/lib/components/message-machine-renderer/use-message-machine-renderer.d.ts +31 -0
- package/lib/components/shared/button-component/button-component.d.ts +24 -0
- package/lib/components/shared/button-component/index.d.ts +2 -0
- package/lib/components/shared/index.d.ts +2 -0
- package/lib/components/typing-indicator/index.d.ts +1 -0
- package/lib/components/typing-indicator/typing-indicator.d.ts +11 -0
- package/lib/components/webchat-app/index.d.ts +1 -0
- package/lib/components/webchat-app/webchat-app.d.ts +41 -0
- package/lib/components/webchat-container/use-webchat-container.d.ts +26 -0
- package/lib/components/webchat-container/webchat-container.d.ts +2 -0
- package/lib/components/webchat-header/use-webchat-header.d.ts +19 -0
- package/lib/components/webchat-header/webchat-header.d.ts +2 -0
- package/lib/components/webchat-input/use-webchat-input.d.ts +31 -0
- package/lib/components/webchat-input/webchat-input.d.ts +2 -0
- package/lib/components/webchat-messages/use-webchat-messages.d.ts +54 -0
- package/lib/components/webchat-messages/webchat-messages.d.ts +2 -0
- package/lib/components/webchat-overlay/base/confirm-modal/confirm-modal.d.ts +8 -0
- package/lib/components/webchat-overlay/base/confirm-modal/index.d.ts +2 -0
- package/lib/components/webchat-overlay/base/content/content.d.ts +9 -0
- package/lib/components/webchat-overlay/base/content/index.d.ts +2 -0
- package/lib/components/webchat-overlay/base/header/header.d.ts +4 -0
- package/lib/components/webchat-overlay/base/header/index.d.ts +3 -0
- package/lib/components/webchat-overlay/base/header/use-header.d.ts +13 -0
- package/lib/components/webchat-overlay/base/index.d.ts +5 -0
- package/lib/components/webchat-overlay/base/overlay/index.d.ts +3 -0
- package/lib/components/webchat-overlay/base/overlay/overlay.d.ts +18 -0
- package/lib/components/webchat-overlay/base/overlay/use-overlay.d.ts +23 -0
- package/lib/components/webchat-overlay/base/overlay-context.d.ts +25 -0
- package/lib/components/webchat-overlay/cover/frame/cover-frame.d.ts +8 -0
- package/lib/components/webchat-overlay/cover/frame/index.d.ts +2 -0
- package/lib/components/webchat-overlay/cover/index.d.ts +1 -0
- package/lib/components/webchat-overlay/index.d.ts +3 -0
- package/lib/components/webchat-overlay/webview/frame/index.d.ts +2 -0
- package/lib/components/webchat-overlay/webview/frame/webview-frame.d.ts +8 -0
- package/lib/components/webchat-overlay/webview/index.d.ts +1 -0
- package/lib/components/webchat-provider/webchat-provider.d.ts +22 -0
- package/lib/components/webchat-trigger/use-webchat-trigger.d.ts +38 -0
- package/lib/components/webchat-trigger/webchat-trigger-error-boundary.d.ts +19 -0
- package/lib/components/webchat-trigger/webchat-trigger.d.ts +2 -0
- package/lib/hooks/use-webchat-state.d.ts +21 -0
- package/lib/types/primitives.d.ts +15 -0
- package/lib/types/webchat-props.d.ts +103 -0
- package/package.json +37 -0
- package/styles.css +466 -0
- package/trigger.d.ts +40 -0
- package/trigger.js +215 -0
- package/webchat-app-CtAHJapU.js +2285 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { WebchatState } from '../../hooks/use-webchat-state';
|
|
3
|
+
import { WebchatMessagesProps } from '../../types/webchat-props';
|
|
4
|
+
export declare function useWebchatMessages(props: WebchatMessagesProps, state: WebchatState, ref: RefObject<HTMLDivElement>): {
|
|
5
|
+
messagesProps: {
|
|
6
|
+
ref: RefObject<HTMLDivElement>;
|
|
7
|
+
'aria-label': string;
|
|
8
|
+
'aria-live': "polite";
|
|
9
|
+
'data-webchat-messages': string;
|
|
10
|
+
enableScrollToBottom?: boolean;
|
|
11
|
+
};
|
|
12
|
+
messageListProps: {
|
|
13
|
+
messageActors: import('xstate').ActorRef<import('xstate').MachineSnapshot<{
|
|
14
|
+
message: import('@botonic/shared').WebchatMessage;
|
|
15
|
+
user: import('@botonic/shared').HubtypeUser;
|
|
16
|
+
status: import('@botonic/webchat-core').WebchatMessageStatus;
|
|
17
|
+
postMessageActor?: any;
|
|
18
|
+
}, {
|
|
19
|
+
type: "RETRY";
|
|
20
|
+
} | {
|
|
21
|
+
type: "BUTTON_CLICKED";
|
|
22
|
+
button: import('@botonic/shared').BotonicButtonContent;
|
|
23
|
+
}, {
|
|
24
|
+
[x: string]: import('xstate').ActorRefFromLogic<import('@botonic/webchat-core').PostMessageActor> | undefined;
|
|
25
|
+
}, "checkStatus" | "sending" | "idle" | "errorSendingMessage" | "performingPostback", string, import('xstate').NonReducibleUnknown, import('xstate').MetaObject, {
|
|
26
|
+
states: {
|
|
27
|
+
readonly checkStatus: {};
|
|
28
|
+
readonly sending: {};
|
|
29
|
+
readonly idle: {};
|
|
30
|
+
readonly performingPostback: {};
|
|
31
|
+
readonly errorSendingMessage: {};
|
|
32
|
+
};
|
|
33
|
+
}>, {
|
|
34
|
+
type: "RETRY";
|
|
35
|
+
} | {
|
|
36
|
+
type: "BUTTON_CLICKED";
|
|
37
|
+
button: import('@botonic/shared').BotonicButtonContent;
|
|
38
|
+
}, {
|
|
39
|
+
type: "PERSISTENCE.SAVE_MESSAGE";
|
|
40
|
+
} | {
|
|
41
|
+
type: "WEBVIEW.OPEN";
|
|
42
|
+
url: string;
|
|
43
|
+
title: string;
|
|
44
|
+
}>[];
|
|
45
|
+
isTyping: any;
|
|
46
|
+
customMessageRenderer: undefined;
|
|
47
|
+
botAvatarConfig: import('../message-machine-renderer').AvatarConfigResult | null;
|
|
48
|
+
agentAvatarConfig: import('../message-machine-renderer').AvatarConfigResult | null;
|
|
49
|
+
};
|
|
50
|
+
variants: {
|
|
51
|
+
variant: "default";
|
|
52
|
+
className: string | undefined;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ConfirmCloseOption } from '@botonic/webchat-core';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
export interface OverlayConfirmModalProps {
|
|
4
|
+
config: ConfirmCloseOption;
|
|
5
|
+
onConfirm: () => void;
|
|
6
|
+
onCancel: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const OverlayConfirmModal: FC<OverlayConfirmModalProps>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface OverlayContentProps {
|
|
2
|
+
className?: string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Renders the appropriate content based on the overlay type.
|
|
6
|
+
* - For 'webview': renders an iframe via OverlayWebviewFrame
|
|
7
|
+
* - For 'cover': renders a registered React component via OverlayCoverFrame
|
|
8
|
+
*/
|
|
9
|
+
export declare function OverlayContent({ className }: OverlayContentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OverlayState } from '@botonic/webchat-core';
|
|
2
|
+
export interface OverlayHeaderVariants {
|
|
3
|
+
variant: 'default' | 'minimal';
|
|
4
|
+
}
|
|
5
|
+
export interface UseOverlayHeaderResult {
|
|
6
|
+
title: string;
|
|
7
|
+
icon: string | undefined;
|
|
8
|
+
showClose: boolean;
|
|
9
|
+
variants: OverlayHeaderVariants;
|
|
10
|
+
}
|
|
11
|
+
export declare function useOverlayHeader(props: {
|
|
12
|
+
variant?: 'default' | 'minimal';
|
|
13
|
+
}, overlayState: OverlayState | null): UseOverlayHeaderResult;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { Overlay, type OverlayProps, useOverlay } from './overlay';
|
|
2
|
+
export { type CoverComponentRegistry, OverlayContext, type OverlayContextValue, useOverlayContext, } from './overlay-context';
|
|
3
|
+
export { OverlayHeader, type OverlayHeaderProps, useOverlayHeader, } from './header';
|
|
4
|
+
export { OverlayContent, type OverlayContentProps } from './content';
|
|
5
|
+
export { OverlayConfirmModal, type OverlayConfirmModalProps, } from './confirm-modal';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ConfirmCloseOption, OverlayState } from '@botonic/webchat-core';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { CoverComponentRegistry } from '../overlay-context';
|
|
4
|
+
export interface OverlayProps {
|
|
5
|
+
/** The current overlay state (webview or cover) */
|
|
6
|
+
overlayState: OverlayState | null;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
onSetTitle: (title: string) => void;
|
|
9
|
+
onSetIcon: (icon: string) => void;
|
|
10
|
+
onSetAllowClose: (allow: boolean) => void;
|
|
11
|
+
onSetConfirmClose: (config: ConfirmCloseOption) => void;
|
|
12
|
+
onSendPayload: (payload: unknown) => void;
|
|
13
|
+
onNavigate: (url: string) => void;
|
|
14
|
+
/** Registry of cover components that can be opened */
|
|
15
|
+
coverRegistry?: CoverComponentRegistry;
|
|
16
|
+
children?: ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export declare function Overlay({ overlayState, onClose, onSetTitle, onSetIcon, onSetAllowClose, onSetConfirmClose, onSendPayload, onNavigate, coverRegistry, children, }: OverlayProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ConfirmCloseOption, OverlayState } from '@botonic/webchat-core';
|
|
2
|
+
export interface OverlayHandlers {
|
|
3
|
+
onClose: () => void;
|
|
4
|
+
onSetTitle: (title: string) => void;
|
|
5
|
+
onSetIcon: (icon: string) => void;
|
|
6
|
+
onSetAllowClose: (allow: boolean) => void;
|
|
7
|
+
onSetConfirmClose: (config: ConfirmCloseOption) => void;
|
|
8
|
+
onSendPayload: (payload: unknown) => void;
|
|
9
|
+
onNavigate: (url: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface UseOverlayResult {
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
setIsLoading: (loading: boolean) => void;
|
|
14
|
+
showConfirmModal: boolean;
|
|
15
|
+
setShowConfirmModal: (show: boolean) => void;
|
|
16
|
+
attemptClose: () => void;
|
|
17
|
+
handleConfirmClose: () => void;
|
|
18
|
+
handleCancelClose: () => void;
|
|
19
|
+
variants: {
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export declare function useOverlay(overlayState: OverlayState | null, handlers: OverlayHandlers): UseOverlayResult;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ConfirmCloseOption, OverlayState } from '@botonic/webchat-core';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Registry of cover components that can be opened in the overlay
|
|
5
|
+
*/
|
|
6
|
+
export type CoverComponentRegistry = Record<string, ComponentType<any>>;
|
|
7
|
+
export interface OverlayContextValue {
|
|
8
|
+
overlayState: OverlayState | null;
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
onSetTitle: (title: string) => void;
|
|
11
|
+
onSetIcon: (icon: string) => void;
|
|
12
|
+
onSetAllowClose: (allow: boolean) => void;
|
|
13
|
+
onSetConfirmClose: (config: ConfirmCloseOption) => void;
|
|
14
|
+
onSendPayload: (payload: unknown) => void;
|
|
15
|
+
onNavigate: (url: string) => void;
|
|
16
|
+
sandboxPermissions: string;
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
setIsLoading: (loading: boolean) => void;
|
|
19
|
+
attemptClose: () => void;
|
|
20
|
+
showConfirmModal: boolean;
|
|
21
|
+
setShowConfirmModal: (show: boolean) => void;
|
|
22
|
+
coverRegistry?: CoverComponentRegistry;
|
|
23
|
+
}
|
|
24
|
+
export declare const OverlayContext: import('react').Context<OverlayContextValue | null>;
|
|
25
|
+
export declare function useOverlayContext(): OverlayContextValue;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface OverlayCoverFrameProps {
|
|
2
|
+
className?: string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Renders a registered React component for cover overlays.
|
|
6
|
+
* Only renders when the overlay is of type 'cover'.
|
|
7
|
+
*/
|
|
8
|
+
export declare function OverlayCoverFrame({ className }: OverlayCoverFrameProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OverlayCoverFrame, type OverlayCoverFrameProps } from './frame';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type CoverComponentRegistry, Overlay, OverlayConfirmModal, type OverlayConfirmModalProps, OverlayContent, type OverlayContentProps, OverlayContext, type OverlayContextValue, OverlayHeader, type OverlayHeaderProps, type OverlayProps, useOverlay, useOverlayContext, useOverlayHeader, } from './base';
|
|
2
|
+
export { OverlayCoverFrame, type OverlayCoverFrameProps } from './cover';
|
|
3
|
+
export { OverlayWebviewFrame, type OverlayWebviewFrameProps } from './webview';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface OverlayWebviewFrameProps {
|
|
2
|
+
className?: string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Renders an iframe for webview overlays.
|
|
6
|
+
* Only renders when the overlay is of type 'webview'.
|
|
7
|
+
*/
|
|
8
|
+
export declare function OverlayWebviewFrame({ className }: OverlayWebviewFrameProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OverlayWebviewFrame, type OverlayWebviewFrameProps } from './frame';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WebchatController } from '@botonic/webchat-core';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
import { WebchatState, WebchatStateProps } from '../../hooks/use-webchat-state';
|
|
4
|
+
interface WebchatContextValue {
|
|
5
|
+
state: WebchatState;
|
|
6
|
+
controller: WebchatController;
|
|
7
|
+
}
|
|
8
|
+
export interface WebchatProviderProps extends WebchatStateProps {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* XState-based WebchatProvider that uses the new separated architecture
|
|
13
|
+
*
|
|
14
|
+
* This provider uses WebchatController with initialization and operational machines.
|
|
15
|
+
* It provides better state management, persistence, and error handling.
|
|
16
|
+
*/
|
|
17
|
+
export declare const WebchatProvider: React.ForwardRefExoticComponent<WebchatProviderProps & React.RefAttributes<WebchatController>>;
|
|
18
|
+
/**
|
|
19
|
+
* Hook to access webchat context
|
|
20
|
+
*/
|
|
21
|
+
export declare function useWebchatContext(): WebchatContextValue;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AnimationEvent, ComponentType, LazyExoticComponent, RefObject } from 'react';
|
|
2
|
+
import { WebchatCompositionProps, WebchatTriggerProps } from '../../types/webchat-props';
|
|
3
|
+
export interface WebchatTriggerHookReturn {
|
|
4
|
+
triggerProps: {
|
|
5
|
+
ref: RefObject<HTMLButtonElement>;
|
|
6
|
+
type: 'button';
|
|
7
|
+
onClick: () => void;
|
|
8
|
+
onAnimationEnd?: (e: AnimationEvent<HTMLButtonElement>) => void;
|
|
9
|
+
'aria-label': string;
|
|
10
|
+
'aria-expanded': boolean;
|
|
11
|
+
};
|
|
12
|
+
icon: React.ReactNode;
|
|
13
|
+
isOpen: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
variants: {
|
|
16
|
+
position: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
17
|
+
isPulsing?: boolean;
|
|
18
|
+
isAppearing?: boolean;
|
|
19
|
+
isOpening?: boolean;
|
|
20
|
+
isClosing?: boolean;
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
isOpen: boolean;
|
|
23
|
+
};
|
|
24
|
+
webchatProps: WebchatCompositionProps;
|
|
25
|
+
/** When true, render the lazy webchat inside Suspense (loads on first open) */
|
|
26
|
+
shouldRenderWebchat: boolean;
|
|
27
|
+
/** Lazy component for default or custom composition (use inside Suspense) */
|
|
28
|
+
LazyWebchat: LazyExoticComponent<ComponentType<WebchatCompositionProps>> | null;
|
|
29
|
+
/** Load failed (e.g. chunk error); trigger can show retry */
|
|
30
|
+
loadError: boolean;
|
|
31
|
+
/** Call to retry loading after loadError */
|
|
32
|
+
retryLoad: () => void;
|
|
33
|
+
/** Call when lazy load fails (pass to Error Boundary onError) */
|
|
34
|
+
handleLoadError: (error: Error) => void;
|
|
35
|
+
/** Increments on retry; use as key for Error Boundary so it resets */
|
|
36
|
+
retryKey: number;
|
|
37
|
+
}
|
|
38
|
+
export declare function useWebchatTrigger(props: WebchatTriggerProps, ref: RefObject<HTMLButtonElement>): WebchatTriggerHookReturn;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Component, ReactNode } from 'react';
|
|
2
|
+
export interface WebchatTriggerErrorBoundaryProps {
|
|
3
|
+
onError: (error: Error) => void;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Catches errors from lazy-loaded webchat (e.g. chunk load failure).
|
|
8
|
+
* Calls onError so the trigger can show retry state.
|
|
9
|
+
*/
|
|
10
|
+
export declare class WebchatTriggerErrorBoundary extends Component<WebchatTriggerErrorBoundaryProps> {
|
|
11
|
+
state: {
|
|
12
|
+
hasError: boolean;
|
|
13
|
+
};
|
|
14
|
+
static getDerivedStateFromError(): {
|
|
15
|
+
hasError: true;
|
|
16
|
+
};
|
|
17
|
+
componentDidCatch(error: Error): void;
|
|
18
|
+
render(): ReactNode;
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OverlayState, WebchatConfig, WebchatController, WebchatMessageMachine } from '@botonic/webchat-core';
|
|
2
|
+
import { ActorRefFrom } from 'xstate';
|
|
3
|
+
import { AvatarConfig } from '../components/message-machine-renderer/use-avatar';
|
|
4
|
+
export type WebchatStateProps = WebchatConfig & {
|
|
5
|
+
avatarConfig?: AvatarConfig;
|
|
6
|
+
customMessages: any;
|
|
7
|
+
};
|
|
8
|
+
export interface WebchatState {
|
|
9
|
+
controller: WebchatController;
|
|
10
|
+
inputValue: string;
|
|
11
|
+
setInputValue: (value: string) => void;
|
|
12
|
+
isOpen: boolean;
|
|
13
|
+
isInitialized: boolean;
|
|
14
|
+
initializationError: boolean;
|
|
15
|
+
messageActors: ActorRefFrom<typeof WebchatMessageMachine>[];
|
|
16
|
+
connectionStatus: string;
|
|
17
|
+
overlayState: OverlayState | null;
|
|
18
|
+
avatarConfig?: AvatarConfig;
|
|
19
|
+
customMessages: any;
|
|
20
|
+
}
|
|
21
|
+
export declare function useWebchatState(stateProps: WebchatStateProps): WebchatState;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface MessageListProps {
|
|
2
|
+
messages: any[];
|
|
3
|
+
onMessageClick?: (messageId: string) => void;
|
|
4
|
+
customRenderer?: (message: any) => React.ReactNode;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface UserInputPanelProps {
|
|
8
|
+
value: string;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
onValueChange: (value: string) => void;
|
|
11
|
+
onFormSubmit: (event: Event) => void;
|
|
12
|
+
hasContent: boolean;
|
|
13
|
+
showAttachmentButton?: boolean;
|
|
14
|
+
isDisabled?: boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { WebchatController } from '@botonic/webchat-core';
|
|
2
|
+
import { ComponentType, ReactNode } from 'react';
|
|
3
|
+
import { CoverComponentRegistry } from '../components/webchat-overlay';
|
|
4
|
+
export interface BaseWebchatProps {
|
|
5
|
+
className?: string;
|
|
6
|
+
'aria-label'?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Props passed to custom webchat composition components.
|
|
10
|
+
* Implement this interface when creating a custom webchat layout.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* // my-webchat.tsx
|
|
15
|
+
* import { WebchatCompositionProps, WebchatProvider, WebchatContainer } from '@botonic/webchat-react'
|
|
16
|
+
*
|
|
17
|
+
* export default function MyWebchat(props: WebchatCompositionProps) {
|
|
18
|
+
* return (
|
|
19
|
+
* <WebchatProvider {...props}>
|
|
20
|
+
* <WebchatContainer>
|
|
21
|
+
* <MyCustomHeader />
|
|
22
|
+
* <WebchatMessages />
|
|
23
|
+
* <WebchatInput />
|
|
24
|
+
* </WebchatContainer>
|
|
25
|
+
* </WebchatProvider>
|
|
26
|
+
* )
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export interface WebchatCompositionProps {
|
|
31
|
+
/** Hubtype App ID */
|
|
32
|
+
appId: string;
|
|
33
|
+
/** Whether the webchat is open */
|
|
34
|
+
isOpen: boolean;
|
|
35
|
+
/** Callback when webchat should close */
|
|
36
|
+
onClose: () => void;
|
|
37
|
+
/** Callback when controller is ready - must be called for trigger to work */
|
|
38
|
+
onControllerReady: (controller: WebchatController) => void;
|
|
39
|
+
/** Additional config passed from WebchatTrigger */
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** Loader function type for lazy loading custom webchat compositions */
|
|
43
|
+
export type WebchatLoader = () => Promise<{
|
|
44
|
+
default: ComponentType<WebchatCompositionProps>;
|
|
45
|
+
}>;
|
|
46
|
+
export interface WebchatContainerProps extends BaseWebchatProps {
|
|
47
|
+
children: ReactNode;
|
|
48
|
+
layout?: 'default';
|
|
49
|
+
size?: 'compact' | 'normal' | 'large';
|
|
50
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
51
|
+
/**
|
|
52
|
+
* Registry of cover components that can be opened in the overlay.
|
|
53
|
+
* Use controller.overlay.openCover(componentId) to open a registered component.
|
|
54
|
+
*/
|
|
55
|
+
coverRegistry?: CoverComponentRegistry;
|
|
56
|
+
}
|
|
57
|
+
export interface WebchatMessagesProps extends BaseWebchatProps {
|
|
58
|
+
variant?: 'default';
|
|
59
|
+
enableScrollToBottom?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface WebchatInputProps extends BaseWebchatProps {
|
|
62
|
+
placeholder?: string;
|
|
63
|
+
variant?: 'default';
|
|
64
|
+
disabled?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface WebchatHeaderProps extends BaseWebchatProps {
|
|
67
|
+
title?: string;
|
|
68
|
+
showStatus?: boolean;
|
|
69
|
+
showClose?: boolean;
|
|
70
|
+
onClose?: () => void;
|
|
71
|
+
variant?: 'default';
|
|
72
|
+
}
|
|
73
|
+
export interface WebchatTriggerProps extends BaseWebchatProps {
|
|
74
|
+
/** Hubtype App ID - required for webchat connection */
|
|
75
|
+
appId: string;
|
|
76
|
+
/** Position on screen */
|
|
77
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
78
|
+
/** Custom icon for the trigger */
|
|
79
|
+
icon?: ReactNode;
|
|
80
|
+
/** Pulsing animation */
|
|
81
|
+
isPulsing?: boolean;
|
|
82
|
+
/** Additional webchat configuration passed to composition component */
|
|
83
|
+
webchatConfig?: Record<string, unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* Callback when webchat is fully loaded and ready.
|
|
86
|
+
* Receives the controller for full control (e.g., controller.open(), logging, analytics).
|
|
87
|
+
* The webchat loads automatically on mount; onReady decides whether to open or not.
|
|
88
|
+
*/
|
|
89
|
+
onReady?: (controller: WebchatController) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Custom webchat composition loader for full composition control.
|
|
92
|
+
* If not provided, uses default WebchatApp.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* <WebchatTrigger
|
|
97
|
+
* appId="xxx"
|
|
98
|
+
* loader={() => import('./my-webchat')}
|
|
99
|
+
* />
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
loader?: WebchatLoader;
|
|
103
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@botonic/webchat-react",
|
|
3
|
+
"version": "2.23.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"module": "./index.js",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"**/*.css"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"import": "./index.js"
|
|
14
|
+
},
|
|
15
|
+
"./trigger": {
|
|
16
|
+
"types": "./trigger.d.ts",
|
|
17
|
+
"import": "./trigger.js"
|
|
18
|
+
},
|
|
19
|
+
"./styles.css": "./styles.css"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@lilara/foundations": ">=0.3.1",
|
|
23
|
+
"@lilara/ui-web-react": ">=0.3.1",
|
|
24
|
+
"class-variance-authority": "^0.7.0",
|
|
25
|
+
"react-aria": "3.33.1",
|
|
26
|
+
"@xstate/react": "^5.0.4"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "^18.0.0",
|
|
30
|
+
"react-dom": "^18.0.0",
|
|
31
|
+
"@botonic/webchat-core": "2.23.1",
|
|
32
|
+
"@botonic/shared": "2.23.1"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|