@botpress/webchat 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +31 -0
  2. package/dist/components/Composer.d.ts +4 -5
  3. package/dist/components/Composer.js +13 -23
  4. package/dist/components/Container.d.ts +1 -1
  5. package/dist/components/Container.js +1 -6
  6. package/dist/components/ConversationList.d.ts +1 -1
  7. package/dist/components/ConversationList.js +5 -46
  8. package/dist/components/Header.d.ts +1 -3
  9. package/dist/components/Header.js +17 -64
  10. package/dist/components/VoiceRecorder.js +6 -2
  11. package/dist/components/common/{Avatar.d.ts → Avatar/index.d.ts} +0 -0
  12. package/dist/components/common/Avatar/index.js +13 -0
  13. package/dist/components/common/{BotInfo.d.ts → BotInfo/index.d.ts} +3 -3
  14. package/dist/components/common/BotInfo/index.js +102 -0
  15. package/dist/components/common/ConfirmDialog/index.d.ts +11 -0
  16. package/dist/components/common/ConfirmDialog/index.js +78 -0
  17. package/dist/components/common/Dialog/index.d.ts +17 -0
  18. package/dist/components/common/Dialog/index.js +57 -0
  19. package/dist/components/common/ToolTip/index.d.ts +10 -0
  20. package/dist/components/common/ToolTip/index.js +163 -0
  21. package/dist/components/common/ToolTip/utils.d.ts +15 -0
  22. package/dist/components/common/ToolTip/utils.js +78 -0
  23. package/dist/components/messages/InlineFeedback.d.ts +2 -1
  24. package/dist/components/messages/Message.js +2 -25
  25. package/dist/components/messages/MessageGroup.d.ts +1 -13
  26. package/dist/components/messages/MessageGroup.js +6 -40
  27. package/dist/components/messages/MessageList.d.ts +1 -1
  28. package/dist/components/messages/MessageList.js +8 -31
  29. package/dist/core/api.d.ts +4 -18
  30. package/dist/core/api.js +25 -150
  31. package/dist/core/constants.d.ts +4 -32
  32. package/dist/core/constants.js +18 -32
  33. package/dist/core/socket.d.ts +1 -12
  34. package/dist/core/socket.js +7 -73
  35. package/dist/{components/Stylesheet.d.ts → icons/Cancel.d.ts} +2 -2
  36. package/dist/icons/Cancel.js +10 -0
  37. package/dist/icons/Microphone.d.ts +5 -0
  38. package/dist/icons/Microphone.js +12 -0
  39. package/dist/index.d.ts +2 -8
  40. package/dist/index.js +9 -29
  41. package/dist/main.d.ts +2 -2
  42. package/dist/main.js +100 -168
  43. package/dist/store/composer.js +3 -6
  44. package/dist/store/index.d.ts +8 -18
  45. package/dist/store/index.js +98 -136
  46. package/dist/store/view.d.ts +3 -6
  47. package/dist/store/view.js +6 -23
  48. package/dist/translations/index.d.ts +3 -1
  49. package/dist/translations/index.js +44 -4
  50. package/dist/typings.d.ts +121 -71
  51. package/dist/utils/analytics.d.ts +5 -0
  52. package/dist/utils/analytics.js +37 -0
  53. package/dist/utils/index.d.ts +3 -0
  54. package/dist/utils/index.js +27 -0
  55. package/dist/utils/storage.d.ts +16 -0
  56. package/dist/utils/storage.js +129 -0
  57. package/package.json +4 -3
  58. package/dist/components/ContextMenu.d.ts +0 -2
  59. package/dist/components/ContextMenu.js +0 -33
  60. package/dist/components/OverridableComponent.d.ts +0 -24
  61. package/dist/components/OverridableComponent.js +0 -50
  62. package/dist/components/Stylesheet.js +0 -7
  63. package/dist/components/common/Avatar.js +0 -29
  64. package/dist/components/common/BotInfo.js +0 -110
  65. package/dist/icons/CloseChat.d.ts +0 -6
  66. package/dist/icons/CloseChat.js +0 -9
  67. package/dist/icons/Send.d.ts +0 -6
  68. package/dist/icons/Send.js +0 -8
  69. package/dist/utils.d.ts +0 -8
  70. package/dist/utils.js +0 -111
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const core_1 = require("@blueprintjs/core");
26
+ const react_1 = __importDefault(require("react"));
27
+ const react_dom_1 = __importDefault(require("react-dom"));
28
+ const Dialog_1 = require("../Dialog");
29
+ const styles = __importStar(require("./style.module.scss"));
30
+ const ConfirmDialogComponent = (props) => {
31
+ const onAccept = () => {
32
+ var _a;
33
+ removeDialog();
34
+ (_a = props.accept) === null || _a === void 0 ? void 0 : _a.call(props);
35
+ props.resolve(true);
36
+ };
37
+ const onDecline = () => {
38
+ var _a;
39
+ removeDialog();
40
+ (_a = props.decline) === null || _a === void 0 ? void 0 : _a.call(props);
41
+ props.resolve(false);
42
+ };
43
+ return (react_1.default.createElement(Dialog_1.Wrapper, { icon: "warning-sign", usePortal: false, isOpen: true, onClose: onDecline, size: "sm" },
44
+ react_1.default.createElement(Dialog_1.Body, null,
45
+ react_1.default.createElement(core_1.Icon, { icon: "warning-sign", iconSize: 32, className: styles.icon }),
46
+ react_1.default.createElement("div", null,
47
+ props.message,
48
+ props.body)),
49
+ react_1.default.createElement(Dialog_1.Footer, null,
50
+ react_1.default.createElement(core_1.Button, { id: "confirm-dialog-decline", className: core_1.Classes.BUTTON, type: "button", onClick: onDecline, text: props.declineLabel, tabIndex: 2, intent: core_1.Intent.NONE }),
51
+ react_1.default.createElement(core_1.Button, { id: "confirm-dialog-accept", className: core_1.Classes.BUTTON, type: "button", autoFocus: true, onClick: onAccept, text: props.acceptLabel, tabIndex: 3, intent: core_1.Intent.WARNING }))));
52
+ };
53
+ const defaultConfirmOptions = {
54
+ title: '',
55
+ accept: () => { },
56
+ acceptLabel: 'Confirm',
57
+ decline: () => { },
58
+ declineLabel: 'Decline'
59
+ };
60
+ const confirmDialog = (message, options) => {
61
+ return new Promise((resolve, _reject) => {
62
+ addDialog(Object.assign(Object.assign(Object.assign({ message }, defaultConfirmOptions), options), { isOpen: false, resolve }));
63
+ });
64
+ };
65
+ function addDialog(props) {
66
+ const body = document.getElementsByTagName('body')[0];
67
+ const div = document.createElement('div');
68
+ div.setAttribute('id', 'confirmDialog-container');
69
+ div.setAttribute('class', styles.ConfirmDialogContainer);
70
+ body.appendChild(div);
71
+ react_dom_1.default.render(react_1.default.createElement(ConfirmDialogComponent, Object.assign({}, props)), div);
72
+ }
73
+ function removeDialog() {
74
+ const div = document.getElementById('confirmDialog-container');
75
+ const body = document.getElementsByTagName('body')[0];
76
+ body.removeChild(div);
77
+ }
78
+ exports.default = confirmDialog;
@@ -0,0 +1,17 @@
1
+ import { IDialogProps } from '@blueprintjs/core';
2
+ import { FC } from 'react';
3
+ export interface DialogProps extends IDialogProps {
4
+ onSubmit?: () => void;
5
+ children: JSX.Element | JSX.Element[];
6
+ isOpen: boolean;
7
+ height?: number;
8
+ size?: 'sm' | 'md' | 'lg';
9
+ }
10
+ export declare const Wrapper: FC<DialogProps>;
11
+ export declare const Body: ({ children, className }: {
12
+ children: JSX.Element | JSX.Element[];
13
+ className?: string | undefined;
14
+ }) => JSX.Element;
15
+ export declare const Footer: ({ children }: {
16
+ children: JSX.Element | JSX.Element[];
17
+ }) => JSX.Element;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.Footer = exports.Body = exports.Wrapper = void 0;
26
+ const core_1 = require("@blueprintjs/core");
27
+ const classnames_1 = __importDefault(require("classnames"));
28
+ const react_1 = __importDefault(require("react"));
29
+ const style = __importStar(require("./style.module.scss"));
30
+ const Wrapper = (props) => {
31
+ let width = 500;
32
+ if (props.size === 'sm') {
33
+ width = 360;
34
+ }
35
+ else if (props.size === 'md') {
36
+ width = 700;
37
+ }
38
+ else if (props.size === 'lg') {
39
+ width = 900;
40
+ }
41
+ const onSubmit = (e) => {
42
+ var _a;
43
+ e.preventDefault();
44
+ (_a = props.onSubmit) === null || _a === void 0 ? void 0 : _a.call(props);
45
+ };
46
+ return (react_1.default.createElement(core_1.Dialog, Object.assign({ className: style.dialog, transitionDuration: 0, canOutsideClickClose: false, enforceFocus: false, style: { width, height: props.height } }, props), props.onSubmit ? (react_1.default.createElement("form", { className: style.form, onSubmit: onSubmit }, props.children)) : (props.children)));
47
+ };
48
+ exports.Wrapper = Wrapper;
49
+ const Body = ({ children, className }) => {
50
+ return react_1.default.createElement("div", { className: (0, classnames_1.default)(core_1.Classes.DIALOG_BODY, core_1.Classes.UI_TEXT, style.dialogBody, className) }, children);
51
+ };
52
+ exports.Body = Body;
53
+ const Footer = ({ children }) => {
54
+ return (react_1.default.createElement("div", { className: core_1.Classes.DIALOG_FOOTER },
55
+ react_1.default.createElement("div", { className: core_1.Classes.DIALOG_FOOTER_ACTIONS }, children)));
56
+ };
57
+ exports.Footer = Footer;
@@ -0,0 +1,10 @@
1
+ import { FC } from 'react';
2
+ interface ToolTipProps {
3
+ hoverOpenDelay?: number;
4
+ children: JSX.Element;
5
+ content?: string | JSX.Element;
6
+ position?: string;
7
+ childId?: string;
8
+ }
9
+ declare const ToolTip: FC<ToolTipProps>;
10
+ export default ToolTip;
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const classnames_1 = __importDefault(require("classnames"));
26
+ const uniqueId_1 = __importDefault(require("lodash/uniqueId"));
27
+ const react_1 = __importStar(require("react"));
28
+ const react_dom_1 = __importDefault(require("react-dom"));
29
+ const style = __importStar(require("./style.module.scss"));
30
+ const utils_1 = require("./utils");
31
+ const ToolTip = ({ childId, children, content, position = 'top', hoverOpenDelay }) => {
32
+ if (!content) {
33
+ return children;
34
+ }
35
+ const id = (0, react_1.useRef)(`botpress-tooltip-${(0, uniqueId_1.default)()}`);
36
+ const timeout = (0, react_1.useRef)(undefined);
37
+ const tooltipRef = (0, react_1.useRef)(null);
38
+ const tipRef = (0, react_1.useRef)(null);
39
+ const pastShow = (el) => {
40
+ var _a;
41
+ const elementRect = el.getBoundingClientRect();
42
+ const tooltipRect = (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
43
+ if (!tooltipRect) {
44
+ return;
45
+ }
46
+ const docWidth = document.documentElement.clientWidth, docHeight = document.documentElement.clientHeight;
47
+ const rx = elementRect.x + elementRect.width; // most right x
48
+ const lx = elementRect.x; // most left x
49
+ const ty = elementRect.y; // most top y
50
+ const by = elementRect.y + elementRect.height; // most bottom y
51
+ const overflowYMiddle = (tooltipRect.height - elementRect.height) / 2;
52
+ let overflowXMiddle = (tooltipRect.width - elementRect.width) / 2;
53
+ overflowXMiddle = overflowXMiddle < 0 ? 0 : overflowXMiddle;
54
+ const canBeXMiddle = rx + overflowXMiddle <= docWidth && lx - overflowXMiddle >= 0;
55
+ const canBeRight = rx + tooltipRect.width <= docWidth;
56
+ const canBeLeft = lx - tooltipRect.width >= 0;
57
+ const canBeYMiddle = ty - overflowYMiddle >= 0 && by + overflowYMiddle <= docHeight;
58
+ const canBeAbove = ty - tooltipRect.height >= 0;
59
+ const canBeBellow = by + tooltipRect.height <= docHeight;
60
+ let xClass = '';
61
+ let yClass = '';
62
+ switch (position) {
63
+ case 'top':
64
+ yClass = 'top';
65
+ if (!canBeAbove) {
66
+ yClass = 'bottom';
67
+ }
68
+ xClass = (0, utils_1.checkXPosition)(canBeXMiddle, canBeLeft);
69
+ break;
70
+ case 'bottom':
71
+ yClass = 'bottom';
72
+ if (!canBeBellow) {
73
+ yClass = 'top';
74
+ }
75
+ xClass = (0, utils_1.checkXPosition)(canBeXMiddle, canBeLeft);
76
+ break;
77
+ case 'left':
78
+ xClass = 'left';
79
+ if (!canBeLeft) {
80
+ xClass = 'right';
81
+ }
82
+ yClass = (0, utils_1.checkYPosition)(canBeYMiddle, canBeAbove);
83
+ break;
84
+ case 'right':
85
+ xClass = 'right';
86
+ if (!canBeRight) {
87
+ xClass = 'left';
88
+ }
89
+ yClass = (0, utils_1.checkYPosition)(canBeYMiddle, canBeAbove);
90
+ break;
91
+ }
92
+ const { left, top } = (0, utils_1.getPositions)({ xClass, yClass }, el, tooltipRef.current);
93
+ const tipPos = (0, utils_1.tipPosition)({ xClass, yClass }, el);
94
+ const inlineStyle = {
95
+ left: `${left}px`,
96
+ top: `${top}px`
97
+ };
98
+ setTimeout(() => {
99
+ var _a, _b, _c;
100
+ (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.classList.add(style.visible);
101
+ if (xClass) {
102
+ (_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.classList.add(xClass);
103
+ }
104
+ if (yClass) {
105
+ (_c = tooltipRef.current) === null || _c === void 0 ? void 0 : _c.classList.add(yClass);
106
+ }
107
+ if (tooltipRef.current) {
108
+ tooltipRef.current.style.left = inlineStyle.left;
109
+ tooltipRef.current.style.top = inlineStyle.top;
110
+ }
111
+ if (tipRef.current) {
112
+ tipRef.current.style.left = tipPos.left;
113
+ tipRef.current.style.right = tipPos.right;
114
+ }
115
+ }, hoverOpenDelay || 0);
116
+ };
117
+ const show = (event) => {
118
+ document.addEventListener('mousemove', mouseMove);
119
+ clearTimeout(timeout.current);
120
+ handleHtmlRendering();
121
+ pastShow(event.currentTarget);
122
+ };
123
+ const mouseMove = (event) => {
124
+ var _a;
125
+ if (!((_a = event.target) === null || _a === void 0 ? void 0 : _a.closest(`#${childId || `${id.current}-trigger`}`))) {
126
+ hide();
127
+ }
128
+ };
129
+ const handleHtmlRendering = (classNames = '', inlineStyle = {}, tipPos = {}) => {
130
+ const body = document.getElementsByTagName('body')[0];
131
+ const toolTip = document.getElementById(id.current);
132
+ const div = document.createElement('div');
133
+ div.setAttribute('id', id.current);
134
+ if (toolTip) {
135
+ body.replaceChild(div, toolTip);
136
+ }
137
+ else {
138
+ body.appendChild(div);
139
+ }
140
+ react_dom_1.default.render(react_1.default.createElement("div", { ref: tooltipRef, className: (0, classnames_1.default)(style.tooltip, classNames), style: inlineStyle },
141
+ react_1.default.createElement("div", { ref: tipRef, className: "tooltipArrow", style: tipPos }),
142
+ react_1.default.createElement("div", { className: "tooltipInner" }, content)), div);
143
+ };
144
+ const hide = (_event) => {
145
+ var _a;
146
+ document.removeEventListener('mousemove', mouseMove);
147
+ (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.classList.remove(style.visible);
148
+ const body = document.getElementsByTagName('body')[0];
149
+ clearTimeout(timeout.current);
150
+ timeout.current = window.setTimeout(() => {
151
+ const div = document.getElementById(id.current);
152
+ if (div) {
153
+ body.removeChild(div);
154
+ }
155
+ }, 300);
156
+ };
157
+ return react_1.default.cloneElement(react_1.default.Children.only(children), {
158
+ id: childId || `${id.current}-trigger`,
159
+ onMouseEnter: show,
160
+ onMouseLeave: hide
161
+ });
162
+ };
163
+ exports.default = ToolTip;
@@ -0,0 +1,15 @@
1
+ interface PositionClasses {
2
+ xClass: string;
3
+ yClass: string;
4
+ }
5
+ export declare const getPositions: (positionClasses: PositionClasses, el: EventTarget & Element, tooltip: HTMLDivElement | null) => {
6
+ left: number;
7
+ top: number;
8
+ };
9
+ export declare const tipPosition: (positionClasses: PositionClasses, el: Element & EventTarget) => {
10
+ left: string;
11
+ right: string;
12
+ };
13
+ export declare const checkXPosition: (canBeXMiddle: boolean, canBeLeft: boolean) => "left" | "right" | "";
14
+ export declare const checkYPosition: (canBeYMiddle: boolean, canBeAbove: boolean) => "bottom" | "top" | "";
15
+ export {};
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkYPosition = exports.checkXPosition = exports.tipPosition = exports.getPositions = void 0;
4
+ const getPositions = (positionClasses, el, tooltip) => {
5
+ const { xClass, yClass } = positionClasses;
6
+ const elementRect = el.getBoundingClientRect();
7
+ const tooltipRect = tooltip === null || tooltip === void 0 ? void 0 : tooltip.getBoundingClientRect();
8
+ const elLeft = elementRect.left;
9
+ const elWidth = elementRect.width;
10
+ const elTop = elementRect.top;
11
+ const elHeight = elementRect.height;
12
+ const tooltipWidth = (tooltipRect === null || tooltipRect === void 0 ? void 0 : tooltipRect.width) || 0;
13
+ const tooltipHeight = (tooltipRect === null || tooltipRect === void 0 ? void 0 : tooltipRect.height) || 0;
14
+ let left = elLeft + elWidth / 2 - tooltipWidth / 2;
15
+ if (xClass === 'left') {
16
+ left = elLeft - tooltipWidth;
17
+ if (yClass === 'top' || yClass === 'bottom') {
18
+ left = left + elWidth;
19
+ }
20
+ }
21
+ else if (xClass === 'right') {
22
+ left = elLeft;
23
+ if (yClass !== 'top' && yClass !== 'bottom') {
24
+ left = elLeft + elWidth;
25
+ }
26
+ }
27
+ let top = elTop + elHeight / 2 - tooltipHeight / 2;
28
+ if (yClass === 'top') {
29
+ top = elTop - tooltipHeight;
30
+ }
31
+ else if (yClass === 'bottom') {
32
+ top = elTop + elHeight;
33
+ }
34
+ return { left, top };
35
+ };
36
+ exports.getPositions = getPositions;
37
+ const tipPosition = (positionClasses, el) => {
38
+ const { xClass, yClass } = positionClasses;
39
+ const elementRect = el === null || el === void 0 ? void 0 : el.getBoundingClientRect();
40
+ const elWidth = (elementRect === null || elementRect === void 0 ? void 0 : elementRect.width) || 0;
41
+ let left = 'auto';
42
+ let right = 'auto';
43
+ if (xClass === 'left' && (yClass === 'top' || yClass === 'bottom')) {
44
+ right = `${elWidth / 2 - 5}px`;
45
+ }
46
+ else if (xClass === 'right' && (yClass === 'top' || yClass === 'bottom')) {
47
+ left = `${elWidth / 2 - 5}px`;
48
+ }
49
+ else if (!xClass) {
50
+ left = '50%';
51
+ }
52
+ return { left, right };
53
+ };
54
+ exports.tipPosition = tipPosition;
55
+ const checkXPosition = (canBeXMiddle, canBeLeft) => {
56
+ if (!canBeXMiddle) {
57
+ if (canBeLeft) {
58
+ return 'left';
59
+ }
60
+ else {
61
+ return 'right';
62
+ }
63
+ }
64
+ return '';
65
+ };
66
+ exports.checkXPosition = checkXPosition;
67
+ const checkYPosition = (canBeYMiddle, canBeAbove) => {
68
+ if (!canBeYMiddle) {
69
+ if (canBeAbove) {
70
+ return 'top';
71
+ }
72
+ else {
73
+ return 'bottom';
74
+ }
75
+ }
76
+ return '';
77
+ };
78
+ exports.checkYPosition = checkYPosition;
@@ -1,10 +1,11 @@
1
1
  import { FC } from 'react';
2
+ import { IntlShape } from 'react-intl';
2
3
  import { EventFeedback as MessageFeedback } from '../../typings';
3
4
  interface Props {
4
5
  onFeedback: (feedback: number, eventId: string) => void;
5
6
  messageId: string;
6
7
  messageFeedbacks: MessageFeedback[];
7
- intl: any;
8
+ intl: IntlShape;
8
9
  }
9
10
  export declare const InlineFeedback: FC<Props>;
10
11
  export {};
@@ -18,15 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
21
  var __importDefault = (this && this.__importDefault) || function (mod) {
31
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
23
  };
@@ -36,7 +27,6 @@ const classnames_1 = __importDefault(require("classnames"));
36
27
  const mobx_react_1 = require("mobx-react");
37
28
  const react_1 = __importStar(require("react"));
38
29
  const react_intl_1 = require("react-intl");
39
- const ContextMenu_1 = require("../ContextMenu");
40
30
  class Message extends react_1.Component {
41
31
  constructor() {
42
32
  super(...arguments);
@@ -44,9 +34,6 @@ class Message extends react_1.Component {
44
34
  hasError: false,
45
35
  showMore: false
46
36
  };
47
- this.handleContextMenu = (e) => {
48
- (0, ContextMenu_1.showContextMenu)(e, this.props);
49
- };
50
37
  }
51
38
  static getDerivedStateFromError(_error) {
52
39
  return { hasError: true };
@@ -54,11 +41,6 @@ class Message extends react_1.Component {
54
41
  renderTimestamp() {
55
42
  return (react_1.default.createElement("span", { className: "bpw-message-timestamp" }, this.props.store.intl.formatTime(new Date(this.props.sentOn), { hour: 'numeric', minute: 'numeric' })));
56
43
  }
57
- onMessageClicked() {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- yield this.props.store.loadEventInDebugger(this.props.messageId, true);
60
- });
61
- }
62
44
  render() {
63
45
  var _a, _b;
64
46
  if (this.state.hasError) {
@@ -67,7 +49,6 @@ class Message extends react_1.Component {
67
49
  const type = this.props.type || (this.props.payload && this.props.payload.type);
68
50
  const wrappedType = this.props.payload && this.props.payload.wrapped && this.props.payload.wrapped.type;
69
51
  const wrappedClass = `bpw-bubble-${wrappedType}`;
70
- const isEmulator = this.props.store.config.isEmulator;
71
52
  const rendered = (react_1.default.createElement(messaging_components_1.default, { key: this.props.messageId, content: this.props.payload, config: {
72
53
  messageId: this.props.messageId,
73
54
  noMessageBubble: this.props.noBubble,
@@ -82,7 +63,6 @@ class Message extends react_1.Component {
82
63
  shouldPlay: this.props.shouldPlay,
83
64
  intl: this.props.store.intl,
84
65
  escapeHTML: true,
85
- isInEmulator: this.props.store.config.isEmulator,
86
66
  showTimestamp: this.props.store.config.showTimestamp
87
67
  } }));
88
68
  if (rendered === null) {
@@ -92,11 +72,8 @@ class Message extends react_1.Component {
92
72
  if (this.props.noBubble || ((_b = (_a = this.props.payload) === null || _a === void 0 ? void 0 : _a.wrapped) === null || _b === void 0 ? void 0 : _b.noBubble)) {
93
73
  return (react_1.default.createElement("div", { className: (0, classnames_1.default)(this.props.className, wrappedClass), style: additionalStyle }, rendered));
94
74
  }
95
- return (react_1.default.createElement("div", { className: (0, classnames_1.default)(this.props.className, wrappedClass, 'bpw-chat-bubble', `bpw-bubble-${type}`, {
96
- 'bpw-bubble-highlight': this.props.isHighlighted,
97
- 'bpw-msg-hovering': isEmulator
98
- }), "data-from": this.props.fromLabel, onClick: () => this.onMessageClicked(), tabIndex: -1, style: additionalStyle },
99
- react_1.default.createElement("div", { tabIndex: -1, className: "bpw-chat-bubble-content", onContextMenu: type !== 'session_reset' ? this.handleContextMenu : () => { } },
75
+ return (react_1.default.createElement("div", { className: (0, classnames_1.default)(this.props.className, wrappedClass, 'bpw-chat-bubble', `bpw-bubble-${type}`), "data-from": this.props.fromLabel, tabIndex: -1, style: additionalStyle },
76
+ react_1.default.createElement("div", { tabIndex: -1, className: "bpw-chat-bubble-content" },
100
77
  react_1.default.createElement("span", { className: "sr-only" }, this.props.store.intl.formatMessage({
101
78
  id: this.props.isBotMessage ? 'message.botSaid' : 'message.iSaid',
102
79
  defaultMessage: this.props.isBotMessage ? 'Virtual assistant said : ' : 'I said : '
@@ -9,13 +9,6 @@ declare class MessageGroup extends React.Component<Props> {
9
9
  static getDerivedStateFromError(_error: Error): {
10
10
  hasError: boolean;
11
11
  };
12
- /**
13
- * @deprecated 12.0
14
- * Here, we convert old format to the new format Botpress uses internally.
15
- * - payload: all the data (raw, whatever) that is necessary to display the element
16
- * - type: extracted from payload for easy sorting
17
- */
18
- convertPayloadFromOldFormat: (data: any) => any;
19
12
  onAudioEnded: () => void;
20
13
  render(): JSX.Element | "* Cannot display message *";
21
14
  }
@@ -24,12 +17,7 @@ export default _default;
24
17
  declare type Props = {
25
18
  isBot: boolean;
26
19
  avatar: JSX.Element;
27
- userName: string;
28
20
  messages: MessageDetails[];
29
21
  isLastGroup: boolean;
30
- onFileUpload?: any;
31
- onSendData?: any;
32
- onFeedback?: any;
33
22
  store?: RootStore;
34
- highlightedMessages?: string[];
35
- } & Pick<StoreDef, 'showUserName' | 'messageWrapper'>;
23
+ } & Pick<StoreDef, 'sendFeedback' | 'sendData'>;
@@ -16,35 +16,6 @@ class MessageGroup extends react_1.default.Component {
16
16
  hasError: false,
17
17
  audioPlayingIndex: 0
18
18
  };
19
- /**
20
- * @deprecated 12.0
21
- * Here, we convert old format to the new format Botpress uses internally.
22
- * - payload: all the data (raw, whatever) that is necessary to display the element
23
- * - type: extracted from payload for easy sorting
24
- */
25
- this.convertPayloadFromOldFormat = (data) => {
26
- var _a, _b, _c;
27
- let payload = data.payload || data.message_data || data.message_raw || { text: data.message_text };
28
- if (!payload.type) {
29
- payload.type = data.message_type || ((_a = data.message_data) === null || _a === void 0 ? void 0 : _a.type) || 'text';
30
- }
31
- // Keeping compatibility with old schema for the quick reply
32
- if (data.message_type === 'quick_reply' && !payload.text) {
33
- payload.text = data.message_text;
34
- }
35
- if (data.message_type === 'file' && !payload.url) {
36
- payload.url = ((_b = data.message_data) === null || _b === void 0 ? void 0 : _b.url) || ((_c = data.message_raw) === null || _c === void 0 ? void 0 : _c.url);
37
- }
38
- if (this.props.messageWrapper && payload.type !== 'session_reset') {
39
- payload = {
40
- type: 'custom',
41
- module: this.props.messageWrapper.module,
42
- component: this.props.messageWrapper.component,
43
- wrapped: payload
44
- };
45
- }
46
- return payload;
47
- };
48
19
  this.onAudioEnded = () => {
49
20
  if (this.state.audioPlayingIndex >= this.props.messages.length - 1) {
50
21
  this.state.audioPlayingIndex = -1;
@@ -58,7 +29,7 @@ class MessageGroup extends react_1.default.Component {
58
29
  return { hasError: true };
59
30
  }
60
31
  render() {
61
- const { messages, avatar, isBot, showUserName, userName } = this.props;
32
+ const { messages, avatar, isBot } = this.props;
62
33
  const fromLabel = this.props.store.intl.formatMessage({
63
34
  id: this.props.isBot ? 'message.fromBotLabel' : 'message.fromMeLabel',
64
35
  defaultMessage: 'Me'
@@ -72,23 +43,18 @@ class MessageGroup extends react_1.default.Component {
72
43
  }) },
73
44
  avatar,
74
45
  react_1.default.createElement("div", { role: "region", className: 'bpw-message-container' },
75
- showUserName && react_1.default.createElement("div", { className: 'bpw-message-username' }, userName),
76
46
  react_1.default.createElement("div", { "aria-live": "assertive", role: "log", className: 'bpw-message-group' },
77
47
  react_1.default.createElement("span", { "data-from": fromLabel, className: "from hidden", "aria-hidden": "true" }, fromLabel),
78
48
  (0, sortBy_1.default)(messages, ['sent_on', 'eventId']).map((message, i, messages) => {
79
49
  const isLastMsg = i === messages.length - 1;
80
- const payload = this.convertPayloadFromOldFormat(message);
81
- const showInlineFeedback = isBot && isLastMsg && (payload.wrapped ? payload.wrapped.collectFeedback : payload.collectFeedback);
82
- return (react_1.default.createElement(Message_1.default, { key: `${message.id}-${message.payload.type}`, isHighlighted: this.props.highlightedMessages && this.props.highlightedMessages.includes(message.id), inlineFeedback: showInlineFeedback && (react_1.default.createElement(InlineFeedback_1.InlineFeedback, { intl: this.props.store.intl, messageId: message.id, onFeedback: this.props.onFeedback, messageFeedbacks: this.props.store.messageFeedbacks })), messageId: message.id, noBubble: !!payload.noBubble, fromLabel: fromLabel, isLastOfGroup: i >= this.props.messages.length - 1, isLastGroup: this.props.isLastGroup, isBotMessage: !message.authorId, payload: payload, sentOn: message.sentOn, onSendData: this.props.onSendData, onFileUpload: this.props.onFileUpload, store: this.props.store, onAudioEnded: this.onAudioEnded, shouldPlay: this.state.audioPlayingIndex === i }));
50
+ const payload = message.payload;
51
+ const showInlineFeedback = isBot && isLastMsg && payload.collectFeedback;
52
+ return (react_1.default.createElement(Message_1.default, { key: `${message.id}-${message.payload.type}`, inlineFeedback: showInlineFeedback && (react_1.default.createElement(InlineFeedback_1.InlineFeedback, { intl: this.props.store.intl, messageId: message.id, onFeedback: this.props.sendFeedback, messageFeedbacks: this.props.store.messageFeedbacks })), messageId: message.id, noBubble: !!payload.noBubble, fromLabel: fromLabel, isLastOfGroup: i >= this.props.messages.length - 1, isLastGroup: this.props.isLastGroup, isBotMessage: !message.authorId, payload: payload, sentOn: message.sentOn, onSendData: this.props.sendData, store: this.props.store, onAudioEnded: this.onAudioEnded, shouldPlay: this.state.audioPlayingIndex === i }));
83
53
  })))));
84
54
  }
85
55
  }
86
56
  exports.default = (0, mobx_react_1.inject)(({ store }) => ({
87
57
  store,
88
- onFeedback: store.sendFeedback,
89
- onSendData: store.sendData,
90
- onFileUpload: store.uploadFile,
91
- messageWrapper: store.messageWrapper,
92
- showUserName: store.config.showUserName,
93
- highlightedMessages: store.view.highlightedMessages
58
+ sendFeedback: store.sendFeedback,
59
+ sendData: store.sendData
94
60
  }))(MessageGroup);
@@ -7,4 +7,4 @@ declare const _default: React.ForwardRefExoticComponent<import("react-intl").Omi
7
7
  WrappedComponent: React.ComponentType<MessageListProps>;
8
8
  } & import("mobx-react").IWrappedComponent<unknown>;
9
9
  export default _default;
10
- declare type MessageListProps = WrappedComponentProps & Pick<StoreDef, 'intl' | 'isBotTyping' | 'focusedArea' | 'focusPrevious' | 'focusNext' | 'botAvatarUrl' | 'isEmulator' | 'botName' | 'enableArrowNavigation' | 'showUserAvatar' | 'currentMessages' | 'preferredLanguage'>;
10
+ declare type MessageListProps = WrappedComponentProps & Pick<StoreDef, 'intl' | 'isBotTyping' | 'focusedArea' | 'focusPrevious' | 'focusNext' | 'botAvatarUrl' | 'botName' | 'currentMessages' | 'preferredLanguage'>;