@cleartrip/talos-bot-interaction-widget 12.0.0 → 12.0.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/dist/BotInteractionWidget.d.ts +0 -1
- package/dist/BotInteractionWidget.d.ts.map +1 -1
- package/dist/DynamicBotInteractionWidget.d.ts +5 -0
- package/dist/DynamicBotInteractionWidget.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/style.d.ts +3 -10
- package/dist/style.d.ts.map +1 -1
- package/dist/talos-bot-interaction-widget.browser.cjs.js +1 -1
- package/dist/talos-bot-interaction-widget.browser.cjs.js.map +1 -1
- package/dist/talos-bot-interaction-widget.browser.esm.js +1 -1
- package/dist/talos-bot-interaction-widget.browser.esm.js.map +1 -1
- package/dist/talos-bot-interaction-widget.cjs.js +46 -21
- package/dist/talos-bot-interaction-widget.cjs.js.map +1 -1
- package/dist/talos-bot-interaction-widget.esm.js +48 -24
- package/dist/talos-bot-interaction-widget.esm.js.map +1 -1
- package/dist/talos-bot-interaction-widget.umd.js +223 -70
- package/dist/talos-bot-interaction-widget.umd.js.map +1 -1
- package/dist/type.d.ts +13 -2
- package/dist/type.d.ts.map +1 -1
- package/package.json +13 -10
- package/src/BotInteractionWidget.tsx +91 -0
- package/src/DynamicBotInteractionWidget.tsx +77 -0
- package/src/index.ts +3 -0
- package/src/style.ts +13 -0
- package/src/type.ts +74 -0
package/package.json
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cleartrip/talos-bot-interaction-widget",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.1",
|
|
4
4
|
"description": "Bot Interaction Widget Component",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/talos-bot-interaction-widget.cjs.js",
|
|
7
7
|
"jsnext:main": "dist/talos-bot-interaction-widget.esm.js",
|
|
8
8
|
"module": "dist/talos-bot-interaction-widget.esm.js",
|
|
9
|
+
"react-native": "src/index.ts",
|
|
9
10
|
"sideEffects": false,
|
|
10
11
|
"browser": {
|
|
11
12
|
"./dist/talos-bot-interaction-widget.esm.js": "./dist/talos-bot-interaction-widget.browser.esm.js",
|
|
12
13
|
"./dist/talos-bot-interaction-widget.cjs.js": "./dist/talos-bot-interaction-widget.browser.cjs.js"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
16
18
|
],
|
|
17
19
|
"dependencies": {
|
|
18
|
-
"@cleartrip/
|
|
19
|
-
"@cleartrip/
|
|
20
|
-
"@cleartrip/talos-
|
|
21
|
-
"@cleartrip/talos-
|
|
22
|
-
"@cleartrip/talos-
|
|
23
|
-
"@cleartrip/talos-
|
|
20
|
+
"@cleartrip/ct-design-style-manager": "5.32.0",
|
|
21
|
+
"@cleartrip/ct-design-types": "5.32.0",
|
|
22
|
+
"@cleartrip/talos-widget-types": "11.1.1",
|
|
23
|
+
"@cleartrip/talos-chat-timestamp": "11.1.1",
|
|
24
|
+
"@cleartrip/talos-use-chat-controller": "11.1.1",
|
|
25
|
+
"@cleartrip/talos-general-utils": "11.1.1",
|
|
26
|
+
"@cleartrip/talos-sequential-reveal": "11.1.1",
|
|
27
|
+
"@cleartrip/talos-animated-height": "11.1.1"
|
|
24
28
|
},
|
|
25
29
|
"peerDependencies": {
|
|
26
|
-
"@cleartrip/
|
|
27
|
-
"@cleartrip/talos-widget-manager": "1.11.0"
|
|
30
|
+
"@cleartrip/talos-widget-manager": "11.1.1"
|
|
28
31
|
},
|
|
29
32
|
"publishConfig": {
|
|
30
33
|
"access": "public"
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { Container } from "@cleartrip/ct-design-components";
|
|
3
|
+
import { SequentialReveal } from "@cleartrip/talos-sequential-reveal";
|
|
4
|
+
import { WidgetGenerator } from "@cleartrip/talos-widget-manager";
|
|
5
|
+
import { ChatTimestamp } from "@cleartrip/talos-chat-timestamp";
|
|
6
|
+
import { AnimatedHeight } from "@cleartrip/talos-animated-height";
|
|
7
|
+
import { useAppDispatch, usePresentation } from "@cleartrip/talos-use-chat-controller";
|
|
8
|
+
import { isEmpty } from "@cleartrip/talos-general-utils";
|
|
9
|
+
import { EntryAnimation } from "@cleartrip/talos-widget-types";
|
|
10
|
+
import type { IWidgetProps, IWidget } from "@cleartrip/talos-widget-types";
|
|
11
|
+
|
|
12
|
+
import { styles } from "./style";
|
|
13
|
+
|
|
14
|
+
import type { IBotInteractionWidgetProps, IBotInteractionWidgetMetadata, ISlotProps, ITimestampSlotProps } from "./type";
|
|
15
|
+
|
|
16
|
+
const Slot = ({ widget, animate, metaData, gap, onPresented }: ISlotProps) => {
|
|
17
|
+
/**
|
|
18
|
+
* Since BotInteractionWidget is a self-presenting widget, it needs to set the presentation for its children.
|
|
19
|
+
*/
|
|
20
|
+
const widgetWithDefaults: IWidget = {
|
|
21
|
+
...widget,
|
|
22
|
+
presentation: widget.presentation ?? {
|
|
23
|
+
entry: animate ? EntryAnimation.REVEAL : EntryAnimation.NONE,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const generator = (
|
|
27
|
+
<WidgetGenerator {...widgetWithDefaults} metaData={metaData} onPresented={onPresented} />
|
|
28
|
+
);
|
|
29
|
+
return gap ? <Container styleConfig={{ root: [gap] }}>{generator}</Container> : generator;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const TimestampSlot = ({ createdAt, animate, css, onPresented }: ITimestampSlotProps) => {
|
|
33
|
+
return (
|
|
34
|
+
<AnimatedHeight animate={animate} onAnimationEnd={onPresented}>
|
|
35
|
+
<Container styleConfig={{ root: css ? [css] : [] }}><ChatTimestamp createdAt={createdAt} /></Container>
|
|
36
|
+
</AnimatedHeight>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const BotInteractionWidget = (props: IWidgetProps<IBotInteractionWidgetProps, IBotInteractionWidgetMetadata>) => {
|
|
41
|
+
const { data, metaData, events, onPresented } = props ?? {};
|
|
42
|
+
const { heading, dynamicSlot, highlight, bodyContent, listSelection, workflowOptions, feedback } = data ?? {};
|
|
43
|
+
const { createdAt, messageId = "", chatId = "" } = metaData ?? {};
|
|
44
|
+
|
|
45
|
+
const { dispatchAll } = useAppDispatch();
|
|
46
|
+
const { onLoad } = events || {};
|
|
47
|
+
|
|
48
|
+
const { hasPresented, markPresented } = usePresentation();
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (hasPresented(chatId, messageId)) return;
|
|
52
|
+
dispatchAll(onLoad);
|
|
53
|
+
}, [onLoad]);
|
|
54
|
+
|
|
55
|
+
const animateRef = useRef(!!(messageId && chatId && !hasPresented(chatId, messageId)));
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (animateRef.current && messageId && chatId) {
|
|
59
|
+
markPresented(chatId, messageId);
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
const isContentShown = useMemo(() => {
|
|
64
|
+
return !isEmpty(heading) || !isEmpty(dynamicSlot) || !isEmpty(highlight) || !isEmpty(bodyContent) || !isEmpty(listSelection) || !isEmpty(workflowOptions);
|
|
65
|
+
}, [heading, dynamicSlot, highlight, bodyContent, listSelection, workflowOptions]);
|
|
66
|
+
|
|
67
|
+
const animate = animateRef.current;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* PresentationWrapper's AnimatedHeight reads `metaData.animate`, which the parent
|
|
71
|
+
* recomputes every render and can flip mid-sequence — stalling the reveal chain
|
|
72
|
+
* before later slots (e.g. feedback) ever mount. Stamping our frozen `animate`
|
|
73
|
+
* into it keeps every slot's entry animation and presentation signal in sync.
|
|
74
|
+
*/
|
|
75
|
+
const slotMetaData = metaData ? { ...metaData, animate } : metaData;
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<SequentialReveal animate={animate} onComplete={onPresented}>
|
|
79
|
+
{!isEmpty(heading) && <Slot animate={animate} widget={heading!} metaData={metaData} />}
|
|
80
|
+
{!isEmpty(dynamicSlot) && <Slot animate={animate} gap={styles.gap} widget={dynamicSlot!} metaData={metaData} />}
|
|
81
|
+
{!isEmpty(highlight) && <Slot animate={animate} gap={styles.gap} widget={highlight!} metaData={metaData} />}
|
|
82
|
+
{!isEmpty(bodyContent) && <Slot animate={animate} gap={styles.gap} widget={bodyContent!} metaData={metaData} />}
|
|
83
|
+
{!isEmpty(listSelection) && <Slot animate={animate} gap={styles.gap} widget={listSelection!} metaData={metaData} />}
|
|
84
|
+
{!isEmpty(workflowOptions) && <Slot animate={animate} gap={styles.gap} widget={workflowOptions!} metaData={metaData} />}
|
|
85
|
+
{isContentShown && createdAt && <TimestampSlot animate={animate} createdAt={createdAt} css={styles.timestampGap} />}
|
|
86
|
+
{!isEmpty(feedback) && <Slot animate={animate} gap={isContentShown ? styles.gap : {}} widget={feedback!} metaData={metaData} />}
|
|
87
|
+
</SequentialReveal>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default BotInteractionWidget;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { SequentialReveal } from "@cleartrip/talos-sequential-reveal";
|
|
3
|
+
import { WidgetGenerator } from "@cleartrip/talos-widget-manager";
|
|
4
|
+
import { useAppDispatch, usePresentation } from "@cleartrip/talos-use-chat-controller";
|
|
5
|
+
import { isEmpty } from "@cleartrip/talos-general-utils";
|
|
6
|
+
import { EntryAnimation } from "@cleartrip/talos-widget-types";
|
|
7
|
+
import type { IWidgetProps, IWidget } from "@cleartrip/talos-widget-types";
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
IDynamicBotInteractionWidgetProps,
|
|
11
|
+
IDynamicBotInteractionWidgetMetadata,
|
|
12
|
+
IDynamicSlotProps,
|
|
13
|
+
} from "./type";
|
|
14
|
+
|
|
15
|
+
const DynamicSlot = ({ widget, animate, metaData, onPresented }: IDynamicSlotProps) => {
|
|
16
|
+
/**
|
|
17
|
+
* Since DynamicBotInteractionWidget is a self-presenting widget, it needs to set the presentation for its children.
|
|
18
|
+
* Spacing is applied by WidgetGenerator → LayoutWrapper via widget.layout.
|
|
19
|
+
*/
|
|
20
|
+
const widgetWithDefaults: IWidget = {
|
|
21
|
+
...widget,
|
|
22
|
+
presentation: widget.presentation ?? {
|
|
23
|
+
entry: animate ? EntryAnimation.REVEAL : EntryAnimation.NONE,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
// @ts-ignore - To be fixed
|
|
29
|
+
<WidgetGenerator {...widgetWithDefaults} metaData={metaData} onPresented={onPresented} />
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const DynamicBotInteractionWidget = (
|
|
34
|
+
props: IWidgetProps<IDynamicBotInteractionWidgetProps, IDynamicBotInteractionWidgetMetadata>
|
|
35
|
+
) => {
|
|
36
|
+
const { data, metaData, events, onPresented } = props ?? {};
|
|
37
|
+
const { dynamicWidgets = [] } = data ?? {};
|
|
38
|
+
const { messageId = "", chatId = "" } = metaData ?? {};
|
|
39
|
+
|
|
40
|
+
const { dispatchAll } = useAppDispatch();
|
|
41
|
+
const { onLoad } = events || {};
|
|
42
|
+
|
|
43
|
+
const { hasPresented, markPresented } = usePresentation();
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (hasPresented(chatId, messageId)) return;
|
|
47
|
+
dispatchAll(onLoad);
|
|
48
|
+
}, [onLoad]);
|
|
49
|
+
|
|
50
|
+
const animateRef = useRef(!!(messageId && chatId && !hasPresented(chatId, messageId)));
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (animateRef.current && messageId && chatId) {
|
|
54
|
+
markPresented(chatId, messageId);
|
|
55
|
+
}
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
const animate = animateRef.current;
|
|
59
|
+
const slotMetaData = metaData ? { ...metaData, animate } : metaData;
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<SequentialReveal animate={animate} onComplete={onPresented}>
|
|
63
|
+
{dynamicWidgets
|
|
64
|
+
.filter((widget) => !isEmpty(widget))
|
|
65
|
+
.map((widget, index) => (
|
|
66
|
+
<DynamicSlot
|
|
67
|
+
key={`${widget.type}-${index}`}
|
|
68
|
+
animate={animate}
|
|
69
|
+
widget={widget}
|
|
70
|
+
metaData={slotMetaData}
|
|
71
|
+
/>
|
|
72
|
+
))}
|
|
73
|
+
</SequentialReveal>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default DynamicBotInteractionWidget;
|
package/src/index.ts
ADDED
package/src/style.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { makeStyles } from "@cleartrip/ct-design-style-manager";
|
|
2
|
+
|
|
3
|
+
export const styles = makeStyles((theme) => ({
|
|
4
|
+
gap: {
|
|
5
|
+
// Web used `&:empty { paddingTop: 0 }` to collapse empty slots. On both
|
|
6
|
+
// platforms the wrapper is now only rendered for non-empty slots (see the
|
|
7
|
+
// `!isEmpty(...)` guards in BotInteractionWidget), so no pseudo-selector.
|
|
8
|
+
paddingTop: theme.spacing[3],
|
|
9
|
+
},
|
|
10
|
+
timestampGap: {
|
|
11
|
+
paddingTop: theme.spacing[1],
|
|
12
|
+
},
|
|
13
|
+
}));
|
package/src/type.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { IWidget, IWidgetMetadata } from "@cleartrip/talos-widget-types";
|
|
2
|
+
import { ChatPageType } from "@cleartrip/talos-use-chat-controller";
|
|
3
|
+
import { ViewStyle } from "@cleartrip/ct-design-types";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export interface IBotInteractionWidgetProps {
|
|
7
|
+
/**
|
|
8
|
+
* Heading of the bot interaction widget
|
|
9
|
+
*/
|
|
10
|
+
heading?: IWidget;
|
|
11
|
+
/**
|
|
12
|
+
* Dynamic slot of the bot interaction widget
|
|
13
|
+
*/
|
|
14
|
+
dynamicSlot?: IWidget;
|
|
15
|
+
/**
|
|
16
|
+
* Highlight of the bot interaction widget
|
|
17
|
+
*/
|
|
18
|
+
highlight?: IWidget;
|
|
19
|
+
/**
|
|
20
|
+
* Body content of the bot interaction widget
|
|
21
|
+
*/
|
|
22
|
+
bodyContent?: IWidget;
|
|
23
|
+
/**
|
|
24
|
+
* List selection of the bot interaction widget (Vertical options)
|
|
25
|
+
*/
|
|
26
|
+
listSelection?: IWidget;
|
|
27
|
+
/**
|
|
28
|
+
* Workflow options of the bot interaction widget (Horizontal options)
|
|
29
|
+
*/
|
|
30
|
+
workflowOptions?: IWidget;
|
|
31
|
+
/**
|
|
32
|
+
* Feedback of the bot interaction widget
|
|
33
|
+
*/
|
|
34
|
+
feedback?: IWidget;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface IBotInteractionWidgetMetadata extends IWidgetMetadata {
|
|
38
|
+
createdAt: string;
|
|
39
|
+
messageId: string;
|
|
40
|
+
chatId: string;
|
|
41
|
+
isFeedbackSubmitted: boolean;
|
|
42
|
+
pageType: ChatPageType;
|
|
43
|
+
isLastMessage: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ISlotProps {
|
|
47
|
+
widget: IWidget;
|
|
48
|
+
animate: boolean;
|
|
49
|
+
metaData?: IBotInteractionWidgetMetadata;
|
|
50
|
+
gap?: ViewStyle;
|
|
51
|
+
onPresented?: () => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ITimestampSlotProps {
|
|
55
|
+
createdAt: string;
|
|
56
|
+
animate: boolean;
|
|
57
|
+
css?: ViewStyle;
|
|
58
|
+
onPresented?: () => void;
|
|
59
|
+
}
|
|
60
|
+
export interface IDynamicBotInteractionWidgetProps {
|
|
61
|
+
/**
|
|
62
|
+
* BE-ordered list of nested widgets rendered top-to-bottom.
|
|
63
|
+
* Spacing comes from each child's `layout` via LayoutWrapper.
|
|
64
|
+
*/
|
|
65
|
+
dynamicWidgets?: IWidget[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type IDynamicBotInteractionWidgetMetadata = IBotInteractionWidgetMetadata;
|
|
69
|
+
export interface IDynamicSlotProps {
|
|
70
|
+
widget: IWidget;
|
|
71
|
+
animate: boolean;
|
|
72
|
+
metaData?: IDynamicBotInteractionWidgetMetadata;
|
|
73
|
+
onPresented?: () => void;
|
|
74
|
+
}
|