@cleartrip/talos-bot-interaction-widget 11.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/type.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { IWidget, IWidgetMetadata } from "@cleartrip/talos-widget-types";
2
2
  import { ChatPageType } from "@cleartrip/talos-use-chat-controller";
3
+ import { ViewStyle } from "@cleartrip/ct-design-types";
3
4
  export interface IBotInteractionWidgetProps {
4
5
  heading?: IWidget;
5
6
  dynamicSlot?: IWidget;
@@ -21,13 +22,23 @@ export interface ISlotProps {
21
22
  widget: IWidget;
22
23
  animate: boolean;
23
24
  metaData?: IBotInteractionWidgetMetadata;
24
- gap?: object;
25
+ gap?: ViewStyle;
25
26
  onPresented?: () => void;
26
27
  }
27
28
  export interface ITimestampSlotProps {
28
29
  createdAt: string;
29
30
  animate: boolean;
30
- css?: object;
31
+ css?: ViewStyle;
32
+ onPresented?: () => void;
33
+ }
34
+ export interface IDynamicBotInteractionWidgetProps {
35
+ dynamicWidgets?: IWidget[];
36
+ }
37
+ export type IDynamicBotInteractionWidgetMetadata = IBotInteractionWidgetMetadata;
38
+ export interface IDynamicSlotProps {
39
+ widget: IWidget;
40
+ animate: boolean;
41
+ metaData?: IDynamicBotInteractionWidgetMetadata;
31
42
  onPresented?: () => void;
32
43
  }
33
44
  //# sourceMappingURL=type.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../packages/components/bot-interaction-widget/src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAEpE,MAAM,WAAW,0BAA0B;IAIvC,OAAO,CAAC,EAAE,OAAO,CAAC;IAIlB,WAAW,CAAC,EAAE,OAAO,CAAC;IAItB,SAAS,CAAC,EAAE,OAAO,CA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,eAAe,CAAC,EAAE,OAAO,CAAC;IAI1B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,6BAA8B,SAAQ,eAAe;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,OAAO,CAAC;IAC7B,QAAQ,EAAE,YAAY,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,6BAA6B,CAAC;IACzC,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B;AACD,MAAM,WAAW,iCAAiC;IAK9C,cAAc,CAAC,EAAE,OAAO,EAAE,CAAC;CAC9B;AAED,MAAM,MAAM,oCAAoC,GAAG,6BAA6B,CAAC;AACjF,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,oCAAoC,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B"}
package/package.json CHANGED
@@ -1,29 +1,33 @@
1
1
  {
2
2
  "name": "@cleartrip/talos-bot-interaction-widget",
3
- "version": "11.0.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/talos-widget-types": "1.10.0",
19
- "@cleartrip/talos-use-chat-controller": "1.10.0",
20
- "@cleartrip/talos-animated-height": "1.10.0",
21
- "@cleartrip/talos-general-utils": "1.10.0",
22
- "@cleartrip/talos-sequential-reveal": "1.10.0",
23
- "@cleartrip/talos-chat-timestamp": "1.10.0"
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/talos-widget-manager": "1.10.0"
30
+ "@cleartrip/talos-widget-manager": "11.1.1"
27
31
  },
28
32
  "publishConfig": {
29
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
@@ -0,0 +1,3 @@
1
+ export { default as BotInteractionWidget } from "./BotInteractionWidget";
2
+ export { default as DynamicBotInteractionWidget } from "./DynamicBotInteractionWidget";
3
+ export * from "./type";
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
+ }