@pioneer-platform/pioneer 1.0.5

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 (81) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +204 -0
  3. package/es/assets/chat-icon.svg +1 -0
  4. package/es/assets/close-icon.png +0 -0
  5. package/es/assets/image.png +0 -0
  6. package/es/assets/logo-no-bg.svg +1 -0
  7. package/es/assets/paperclip-icon.png +0 -0
  8. package/es/assets/sounds/notification.mp3 +0 -0
  9. package/es/components/ChatWindow.js +59 -0
  10. package/es/components/Header.js +20 -0
  11. package/es/components/Launcher.js +96 -0
  12. package/es/components/LauncherNew.js +130 -0
  13. package/es/components/MessageList.js +22 -0
  14. package/es/components/Messages/EmojiMessage.js +7 -0
  15. package/es/components/Messages/FileMessage.js +10 -0
  16. package/es/components/Messages/TextMessage.js +12 -0
  17. package/es/components/Messages/index.js +40 -0
  18. package/es/components/PinMessage.js +42 -0
  19. package/es/components/UserInput.js +190 -0
  20. package/es/components/emoji-picker/EmojiPicker.js +34 -0
  21. package/es/components/emoji-picker/emojiData.json +1 -0
  22. package/es/components/icons/EmojiIcon.js +36 -0
  23. package/es/components/icons/FileIcon.js +36 -0
  24. package/es/components/icons/SendIcon.js +38 -0
  25. package/es/components/popups/PopupWindow.js +51 -0
  26. package/es/index.js +4 -0
  27. package/es/messageTypes.js +12 -0
  28. package/es/styles/chat-window.css +55 -0
  29. package/es/styles/emojiPicker.css +38 -0
  30. package/es/styles/header.css +53 -0
  31. package/es/styles/index.js +8 -0
  32. package/es/styles/launcher.css +87 -0
  33. package/es/styles/message.css +88 -0
  34. package/es/styles/pin-message.css +24 -0
  35. package/es/styles/popup-window.css +61 -0
  36. package/es/styles/user-input.css +140 -0
  37. package/lib/assets/chat-icon.svg +1 -0
  38. package/lib/assets/close-icon.png +0 -0
  39. package/lib/assets/image.png +0 -0
  40. package/lib/assets/logo-no-bg.svg +1 -0
  41. package/lib/assets/paperclip-icon.png +0 -0
  42. package/lib/assets/sounds/notification.mp3 +0 -0
  43. package/lib/components/ChatWindow.js +66 -0
  44. package/lib/components/Header.js +27 -0
  45. package/lib/components/Launcher.js +105 -0
  46. package/lib/components/LauncherNew.js +139 -0
  47. package/lib/components/MessageList.js +31 -0
  48. package/lib/components/Messages/EmojiMessage.js +14 -0
  49. package/lib/components/Messages/FileMessage.js +17 -0
  50. package/lib/components/Messages/TextMessage.js +19 -0
  51. package/lib/components/Messages/index.js +47 -0
  52. package/lib/components/PinMessage.js +49 -0
  53. package/lib/components/UserInput.js +199 -0
  54. package/lib/components/emoji-picker/EmojiPicker.js +41 -0
  55. package/lib/components/emoji-picker/emojiData.json +1 -0
  56. package/lib/components/icons/EmojiIcon.js +43 -0
  57. package/lib/components/icons/FileIcon.js +44 -0
  58. package/lib/components/icons/SendIcon.js +46 -0
  59. package/lib/components/popups/PopupWindow.js +59 -0
  60. package/lib/index.js +7 -0
  61. package/lib/messageTypes.js +14 -0
  62. package/lib/styles/chat-window.css +55 -0
  63. package/lib/styles/emojiPicker.css +38 -0
  64. package/lib/styles/header.css +53 -0
  65. package/lib/styles/index.js +10 -0
  66. package/lib/styles/launcher.css +87 -0
  67. package/lib/styles/message.css +88 -0
  68. package/lib/styles/pin-message.css +24 -0
  69. package/lib/styles/popup-window.css +61 -0
  70. package/lib/styles/user-input.css +140 -0
  71. package/package.json +53 -0
  72. package/umd/chat-icon.f032be1d.svg +1 -0
  73. package/umd/close-icon.3faa3158.png +0 -0
  74. package/umd/image.6779a2a6.png +0 -0
  75. package/umd/logo-no-bg.4d881dc9.svg +1 -0
  76. package/umd/main.8da8d3c4.css +5 -0
  77. package/umd/main.8da8d3c4.css.map +1 -0
  78. package/umd/notification.aa8f8c40.mp3 +0 -0
  79. package/umd/pioneer.js +6684 -0
  80. package/umd/pioneer.min.js +11 -0
  81. package/umd/pioneer.min.js.map +1 -0
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org>
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # popup-chat-react
2
+
3
+ `popup-chat-react` provides an intercom-like chat window that can be included easily in any project for free. It provides no messaging facilities, only the view component.
4
+
5
+ ![GitHub license](https://img.shields.io/github/package-json/v/asliddinusmonov/popup-chat-react.svg?style=flat-square) <a href="https://www.npmjs.com/package/popup-chat-react" target="\_parent">
6
+ <img alt="" src="https://img.shields.io/npm/dm/popup-chat-react.svg" />
7
+ </a>
8
+ <a href="https://github.com/asliddinusmonov/popup-chat-react" target="\_parent">
9
+ <img alt="" src="https://img.shields.io/github/stars/asliddinusmonov/popup-chat-react.svg?style=social&label=Star" />
10
+ </a>
11
+ <br/>
12
+
13
+ ![Demo gif of popup-chat-react being used](https://puu.sh/xei2F/fd4a121185.gif)
14
+
15
+ ## Features
16
+
17
+ - Customizeable
18
+ - Backend agnostic
19
+ - Free
20
+
21
+ ## [Demo](https://asliddinusmonov.github.io/popup-chat-react/)
22
+
23
+ ## Table of Contents
24
+ - [Installation](#installation)
25
+ - [Example](#example)
26
+ - [Components](#components)
27
+
28
+ ## Installation
29
+
30
+ ```
31
+ $ npm install popup-chat-react
32
+ ```
33
+
34
+ ## Example
35
+
36
+ ``` javascript
37
+ import React, { useState } from 'react';
38
+ import { Launcher } from '../../src';
39
+
40
+ function Demo() {
41
+ const [state, setState] = useState({
42
+ messageList: [],
43
+ newMessagesCount: 0,
44
+ isOpen: false,
45
+ fileUpload: true,
46
+ });
47
+
48
+ function onMessageWasSent(message) {
49
+ setState(state => ({
50
+ ...state,
51
+ messageList: [...state.messageList, message]
52
+ }));
53
+ }
54
+
55
+ function onFilesSelected(fileList) {
56
+ const objectURL = window.URL.createObjectURL(fileList[0]);
57
+
58
+ setState(state => ({
59
+ ...state,
60
+ messageList: [
61
+ ...state.messageList,
62
+ {
63
+ type: 'file', author: 'me',
64
+ data: {
65
+ url: objectURL,
66
+ fileName: fileList[0].name,
67
+ }
68
+ }
69
+ ]
70
+ }));
71
+ }
72
+
73
+ function sendMessage(text) {
74
+ if (text.length > 0) {
75
+ const newMessagesCount = state.isOpen ? state.newMessagesCount : state.newMessagesCount + 1;
76
+
77
+ setState(state => ({
78
+ ...state,
79
+ newMessagesCount: newMessagesCount,
80
+ messageList: [
81
+ ...state.messageList,
82
+ {
83
+ author: 'them',
84
+ type: 'text',
85
+ data: { text }
86
+ }
87
+ ]
88
+ }));
89
+ }
90
+ }
91
+
92
+ function onClick() {
93
+ setState(state => ({
94
+ ...state,
95
+ isOpen: !state.isOpen,
96
+ newMessagesCount: 0
97
+ }));
98
+ }
99
+
100
+ return (
101
+ <div>
102
+ <Header />
103
+
104
+ <TestArea
105
+ onMessage={sendMessage}
106
+ />
107
+
108
+ <Launcher
109
+ agentProfile={{
110
+ teamName: 'popup-chat-react',
111
+ imageUrl: 'https://a.slack-edge.com/66f9/img/avatars-teams/ava_0001-34.png'
112
+ }}
113
+ onMessageWasSent={onMessageWasSent}
114
+ onFilesSelected={onFilesSelected}
115
+ messageList={state.messageList}
116
+ newMessagesCount={state.newMessagesCount}
117
+ onClick={onClick}
118
+ isOpen={state.isOpen}
119
+ showEmoji
120
+ fileUpload={state.fileUpload}
121
+ pinMessage={{
122
+ imageUrl: 'https://a.slack-edge.com/66f9/img/avatars-teams/ava_0001-34.png',
123
+ title: 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.',
124
+ text: 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.'
125
+ }}
126
+ placeholder='placeholder'
127
+ />
128
+
129
+ <img className="demo-monster-img" src={monsterImgUrl} />
130
+ <Footer />
131
+ </div>
132
+ );
133
+ }
134
+ ```
135
+
136
+ For more detailed examples see the demo folder.
137
+
138
+ ## Components
139
+
140
+ # Launcher
141
+
142
+ `Launcher` is the only component needed to use popup-chat-react. It will react dynamically to changes in messages. All new messages must be added via a change in props as shown in the example.
143
+
144
+ Launcher props:
145
+
146
+ | prop | type | required | description |
147
+ |------------------|--------|----------|-------------|
148
+ | agentProfile | [object](#agent-profile-objects) | yes | Represents your product or service's customer service agent. Fields: imageUrl (string), teamName (string). |
149
+ | onClick | function | yes | Intercept the click event on the launcher. No argument sent when function is called. |
150
+ | isOpen | boolean | yes | Force the open/close state of the chat window. If this is not set, it will open and close when clicked. |
151
+ | messageList | [[message](#message-objects)] | yes | An array of message objects to be rendered as a conversation. |
152
+ | mute | boolean | no | Don't play sound for incoming messages. Defaults to `false`. |
153
+ | newMessagesCount | number | no | The number of new messages. If greater than 0, this number will be displayed in a badge on the launcher. Defaults to `0`. |
154
+ | onFilesSelected | function([fileList](https://developer.mozilla.org/en-US/docs/Web/API/FileList)) | no | Called after file has been selected from dialogue in chat window. |
155
+ | onMessageWasSent | function([message](#message-objects)) | yes | Called when a message is sent, with a message object as an argument. |
156
+ | showEmoji | boolean | no | Whether or not to show the emoji button in the input bar. Defaults to `true`.
157
+ | fileUpload | boolean | no |
158
+ | pinMessage | object | no |
159
+ | placeholder | string | no |
160
+
161
+
162
+ ### Message Objects
163
+
164
+ Message objects are rendered differently depending on their type. Currently, only text, file, and emoji types are supported. Each message object has an `author` field which can have the value 'me' or 'them'.
165
+
166
+ ``` javascript
167
+ {
168
+ author: 'them',
169
+ type: 'text',
170
+ data: {
171
+ text: 'some text'
172
+ }
173
+ }
174
+
175
+ {
176
+ author: 'me',
177
+ type: 'emoji',
178
+ data: {
179
+ code: 'someCode'
180
+ }
181
+ }
182
+
183
+
184
+ {
185
+ author: 'me',
186
+ type: 'file',
187
+ data: {
188
+ url: 'somefile.mp3',
189
+ fileName: 'Any old name'
190
+ }
191
+ }
192
+
193
+ ```
194
+
195
+ ### Agent Profile Objects
196
+
197
+ Look like this:
198
+
199
+ ```js
200
+ {
201
+ imageUrl: 'https://somewhere.on/the_web.png',
202
+ teamName: 'Da best'
203
+ }
204
+ ```
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-4749.48 -5020 35.036 35.036"><defs><style>.a{fill:none;}.b{fill:#4e8cff;}.c{clip-path:url(#a);}.d{fill:#fff;}.e{fill:#eff4f9;}</style><clipPath id="a"><path class="a" d="M0-399.479H17.555v17.555H0Z" transform="translate(0 399.479)"/></clipPath></defs><g transform="translate(-4886 -5075)"><circle class="b" cx="17.518" cy="17.518" r="17.518" transform="translate(136.52 55)"/><g transform="translate(145.13 64)"><g class="c"><g transform="translate(0 0)"><path class="d" d="M-381.924-190.962a8.778,8.778,0,0,0-8.778-8.778,8.778,8.778,0,0,0-8.778,8.778,8.745,8.745,0,0,0,2.26,5.879v1.442c0,.8.492,1.457,1.1,1.457h5.83a.843.843,0,0,0,.183-.02,8.778,8.778,0,0,0,8.184-8.757" transform="translate(399.479 199.74)"/></g><g transform="translate(0 0)"><path class="e" d="M-68.763-194.079a9.292,9.292,0,0,1,6.38-8.888c-.252-.022-.506-.033-.763-.033a8.774,8.774,0,0,0-8.778,8.778A9.508,9.508,0,0,0-69.7-188.3c.005,0,0,.009,0,.01-.311.352-1.924,2.849.021,2.849h2.25c-1.23-.022,1.263-2.107.269-3.494a8.225,8.225,0,0,1-1.6-5.141" transform="translate(71.924 203)"/></g></g></g></g></svg>
Binary file
Binary file
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-4749.48 -5020 35.036 35.036"><defs><style>.a{fill:none;}.b{fill:#4e8cff;}.c{clip-path:url(#a);}.d{fill:#fff;}.e{fill:#eff4f9;}</style><clipPath id="a"><path class="a" d="M0-399.479H17.555v17.555H0Z" transform="translate(0 399.479)"/></clipPath></defs><g transform="translate(-4886 -5075)"><g transform="translate(145.13 64)"><g class="c"><g transform="translate(0 0)"><path class="d" d="M-381.924-190.962a8.778,8.778,0,0,0-8.778-8.778,8.778,8.778,0,0,0-8.778,8.778,8.745,8.745,0,0,0,2.26,5.879v1.442c0,.8.492,1.457,1.1,1.457h5.83a.843.843,0,0,0,.183-.02,8.778,8.778,0,0,0,8.184-8.757" transform="translate(399.479 199.74)"/></g><g transform="translate(0 0)"><path class="e" d="M-68.763-194.079a9.292,9.292,0,0,1,6.38-8.888c-.252-.022-.506-.033-.763-.033a8.774,8.774,0,0,0-8.778,8.778A9.508,9.508,0,0,0-69.7-188.3c.005,0,0,.009,0,.01-.311.352-1.924,2.849.021,2.849h2.25c-1.23-.022,1.263-2.107.269-3.494a8.225,8.225,0,0,1-1.6-5.141" transform="translate(71.924 203)"/></g></g></g></g></svg>
Binary file
@@ -0,0 +1,59 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import classNames from 'classnames';
4
+ import MessageList from './MessageList';
5
+ import UserInput from './UserInput';
6
+ import Header from './Header';
7
+ import PinMessage from './PinMessage';
8
+ function ChatWindow(props) {
9
+ var isOpen = props.isOpen,
10
+ onClose = props.onClose,
11
+ agentProfile = props.agentProfile,
12
+ showEmoji = props.showEmoji,
13
+ fileUpload = props.fileUpload,
14
+ messageList = props.messageList,
15
+ onUserInputSubmit = props.onUserInputSubmit,
16
+ onFilesSelected = props.onFilesSelected,
17
+ pinMessage = props.pinMessage,
18
+ onPinMessage = props.onPinMessage,
19
+ placeholder = props.placeholder;
20
+ var teamName = agentProfile.teamName,
21
+ imageUrl = agentProfile.imageUrl;
22
+ return /*#__PURE__*/React.createElement("div", {
23
+ className: classNames('sc-chat-window', {
24
+ 'opened': isOpen
25
+ }, {
26
+ 'closed': !isOpen
27
+ })
28
+ }, /*#__PURE__*/React.createElement(Header, {
29
+ teamName: teamName,
30
+ imageUrl: imageUrl,
31
+ onClose: onClose
32
+ }), pinMessage && /*#__PURE__*/React.createElement(PinMessage, {
33
+ pinMessage: pinMessage,
34
+ onPinMessage: onPinMessage
35
+ }), /*#__PURE__*/React.createElement(MessageList, {
36
+ messages: messageList,
37
+ imageUrl: imageUrl
38
+ }), /*#__PURE__*/React.createElement(UserInput, {
39
+ onSubmit: onUserInputSubmit,
40
+ onFilesSelected: onFilesSelected,
41
+ showEmoji: showEmoji,
42
+ fileUpload: fileUpload,
43
+ placeholder: placeholder
44
+ }));
45
+ }
46
+ ChatWindow.propTypes = process.env.NODE_ENV !== "production" ? {
47
+ isOpen: PropTypes.bool.isRequired,
48
+ onClose: PropTypes.func.isRequired,
49
+ agentProfile: PropTypes.object.isRequired,
50
+ showEmoji: PropTypes.bool,
51
+ fileUpload: PropTypes.bool,
52
+ messageList: PropTypes.array,
53
+ onUserInputSubmit: PropTypes.func.isRequired,
54
+ onFilesSelected: PropTypes.func,
55
+ pinMessage: PropTypes.object,
56
+ onPinMessage: PropTypes.func,
57
+ placeholder: PropTypes.string
58
+ } : {};
59
+ export default ChatWindow;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import closeIcon from './../assets/close-icon.png';
3
+ function Header(props) {
4
+ return /*#__PURE__*/React.createElement("div", {
5
+ className: "sc-header"
6
+ }, /*#__PURE__*/React.createElement("img", {
7
+ className: "sc-header--img",
8
+ src: props.imageUrl,
9
+ alt: ""
10
+ }), /*#__PURE__*/React.createElement("div", {
11
+ className: "sc-header--team-name"
12
+ }, " ", props.teamName, " "), /*#__PURE__*/React.createElement("div", {
13
+ className: "sc-header--close-button",
14
+ onClick: props.onClose
15
+ }, /*#__PURE__*/React.createElement("img", {
16
+ src: closeIcon,
17
+ alt: ""
18
+ })));
19
+ }
20
+ export default Header;
@@ -0,0 +1,96 @@
1
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
2
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
3
+ import PropTypes from 'prop-types';
4
+ import React, { Component } from 'react';
5
+ import ChatWindow from './ChatWindow';
6
+ import launcherIcon from './../assets/logo-no-bg.svg';
7
+ import incomingMessageSound from './../assets/sounds/notification.mp3';
8
+ import launcherIconActive from './../assets/close-icon.png';
9
+ var Launcher = /*#__PURE__*/function (_Component) {
10
+ _inheritsLoose(Launcher, _Component);
11
+ function Launcher() {
12
+ var _this;
13
+ _this = _Component.call(this) || this;
14
+ _this.state = {
15
+ launcherIcon: launcherIcon,
16
+ isOpen: false
17
+ };
18
+ return _this;
19
+ }
20
+ var _proto = Launcher.prototype;
21
+ _proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
22
+ if (this.props.mute) {
23
+ return;
24
+ }
25
+ var nextMessage = nextProps.messageList[nextProps.messageList.length - 1];
26
+ var isIncoming = (nextMessage || {}).author === 'them';
27
+ var isNew = nextProps.messageList.length > this.props.messageList.length;
28
+ if (isIncoming && isNew) {
29
+ this.playIncomingMessageSound();
30
+ }
31
+ };
32
+ _proto.playIncomingMessageSound = function playIncomingMessageSound() {
33
+ var audio = new Audio(incomingMessageSound);
34
+ audio.play();
35
+ };
36
+ _proto.handleClick = function handleClick() {
37
+ if (this.props.handleClick !== undefined) {
38
+ this.props.handleClick();
39
+ } else {
40
+ this.setState({
41
+ isOpen: !this.state.isOpen
42
+ });
43
+ }
44
+ };
45
+ _proto.render = function render() {
46
+ var isOpen = this.props.hasOwnProperty('isOpen') ? this.props.isOpen : this.state.isOpen;
47
+ var classList = ['sc-launcher', isOpen ? 'opened' : ''];
48
+ return /*#__PURE__*/React.createElement("div", {
49
+ id: "sc-launcher"
50
+ }, /*#__PURE__*/React.createElement("div", {
51
+ className: classList.join(' '),
52
+ onClick: this.handleClick.bind(this)
53
+ }, /*#__PURE__*/React.createElement(MessageCount, {
54
+ count: this.props.newMessagesCount,
55
+ isOpen: isOpen
56
+ }), /*#__PURE__*/React.createElement("img", {
57
+ className: 'sc-open-icon',
58
+ src: launcherIconActive
59
+ }), /*#__PURE__*/React.createElement("img", {
60
+ className: 'sc-closed-icon',
61
+ src: launcherIcon
62
+ })), /*#__PURE__*/React.createElement(ChatWindow, {
63
+ messageList: this.props.messageList,
64
+ onUserInputSubmit: this.props.onMessageWasSent,
65
+ onFilesSelected: this.props.onFilesSelected,
66
+ agentProfile: this.props.agentProfile,
67
+ isOpen: isOpen,
68
+ onClose: this.handleClick.bind(this),
69
+ showEmoji: this.props.showEmoji
70
+ }));
71
+ };
72
+ return Launcher;
73
+ }(Component);
74
+ var MessageCount = function MessageCount(props) {
75
+ if (props.count === 0 || props.isOpen === true) {
76
+ return null;
77
+ }
78
+ return /*#__PURE__*/React.createElement("div", {
79
+ className: 'sc-new-messages-count'
80
+ }, props.count);
81
+ };
82
+ Launcher.propTypes = process.env.NODE_ENV !== "production" ? {
83
+ onMessageWasReceived: PropTypes.func,
84
+ onMessageWasSent: PropTypes.func,
85
+ newMessagesCount: PropTypes.number,
86
+ isOpen: PropTypes.bool,
87
+ handleClick: PropTypes.func,
88
+ messageList: PropTypes.arrayOf(PropTypes.object),
89
+ mute: PropTypes.bool,
90
+ showEmoji: PropTypes.bool
91
+ } : {};
92
+ Launcher.defaultProps = {
93
+ newMessagesCount: 0,
94
+ showEmoji: true
95
+ };
96
+ export default Launcher;
@@ -0,0 +1,130 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import { pipe, prop, length, last, equals } from 'ramda';
3
+ import React, { useState, useEffect } from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import classNames from 'classnames';
6
+ import ChatWindow from './ChatWindow';
7
+ import launcherIcon from '../assets/logo-no-bg.svg';
8
+ import launcherIconActive from '../assets/close-icon.png';
9
+ import incomingMessageSound from '../assets/sounds/notification.mp3';
10
+ function LauncherNew(props) {
11
+ var isOpen = props.isOpen,
12
+ onClick = props.onClick,
13
+ mute = props.mute,
14
+ showEmoji = props.showEmoji,
15
+ agentProfile = props.agentProfile,
16
+ messageList = props.messageList,
17
+ newMessagesCount = props.newMessagesCount,
18
+ onMessageWasSent = props.onMessageWasSent,
19
+ onFilesSelected = props.onFilesSelected,
20
+ fileUpload = props.fileUpload,
21
+ pinMessage = props.pinMessage,
22
+ onPinMessage = props.onPinMessage,
23
+ placeholder = props.placeholder;
24
+ var defaultState = {
25
+ isOpen: false,
26
+ messageList: messageList
27
+ };
28
+ var _useState = useState(defaultState),
29
+ state = _useState[0],
30
+ setState = _useState[1];
31
+ useEffect(function () {
32
+ setState(function (state) {
33
+ return _extends({}, state, {
34
+ isOpen: isOpen
35
+ });
36
+ });
37
+ }, [isOpen]);
38
+ useEffect(function () {
39
+ var prevMessageListLength = pipe(prop('messageList'), length)(state);
40
+ var massageListLength = length(messageList);
41
+ var isIncoming = pipe(last, prop('author'), equals('them'))(messageList);
42
+ var isNew = massageListLength > prevMessageListLength;
43
+ if (isIncoming && isNew) {
44
+ if (!mute) {
45
+ playIncomingMessageSound();
46
+ }
47
+ setState(function (state) {
48
+ return _extends({}, state, {
49
+ messageList: messageList
50
+ });
51
+ });
52
+ }
53
+ }, [messageList]);
54
+ function playIncomingMessageSound() {
55
+ var audio = new Audio(incomingMessageSound);
56
+ audio.play();
57
+ }
58
+ function handleClick() {
59
+ if (onClick) {
60
+ onClick();
61
+ } else {
62
+ setState(function (state) {
63
+ return _extends({}, state, {
64
+ isOpen: !state.isOpen
65
+ });
66
+ });
67
+ }
68
+ }
69
+ return /*#__PURE__*/React.createElement("div", {
70
+ id: "sc-launcher"
71
+ }, /*#__PURE__*/React.createElement("div", {
72
+ className: classNames('sc-launcher', {
73
+ 'opened': state.isOpen
74
+ }),
75
+ onClick: handleClick
76
+ }, /*#__PURE__*/React.createElement(MessageCount, {
77
+ count: newMessagesCount,
78
+ isOpen: state.isOpen
79
+ }), /*#__PURE__*/React.createElement("img", {
80
+ className: 'sc-open-icon',
81
+ src: launcherIconActive
82
+ }), /*#__PURE__*/React.createElement("img", {
83
+ className: 'sc-closed-icon',
84
+ src: launcherIcon
85
+ })), /*#__PURE__*/React.createElement(ChatWindow, {
86
+ messageList: messageList,
87
+ onUserInputSubmit: onMessageWasSent,
88
+ onFilesSelected: onFilesSelected,
89
+ agentProfile: agentProfile,
90
+ isOpen: state.isOpen,
91
+ onClose: onClick,
92
+ showEmoji: showEmoji,
93
+ fileUpload: fileUpload,
94
+ pinMessage: pinMessage,
95
+ onPinMessage: onPinMessage,
96
+ placeholder: placeholder
97
+ }));
98
+ }
99
+ var MessageCount = function MessageCount(_ref) {
100
+ var count = _ref.count,
101
+ isOpen = _ref.isOpen;
102
+ if (count === 0 || isOpen === true) return null;
103
+ return /*#__PURE__*/React.createElement("div", {
104
+ className: "sc-new-messages-count"
105
+ }, count);
106
+ };
107
+ LauncherNew.propTypes = process.env.NODE_ENV !== "production" ? {
108
+ isOpen: PropTypes.bool,
109
+ onClick: PropTypes.func,
110
+ mute: PropTypes.bool,
111
+ showEmoji: PropTypes.bool,
112
+ messageList: PropTypes.arrayOf(PropTypes.object),
113
+ newMessagesCount: PropTypes.number,
114
+ onMessageWasSent: PropTypes.func,
115
+ onMessageWasReceived: PropTypes.func,
116
+ fileUpload: PropTypes.bool,
117
+ pinMessage: PropTypes.object,
118
+ onPinMessage: PropTypes.func,
119
+ placeholder: PropTypes.string
120
+ } : {};
121
+ LauncherNew.defaultProps = {
122
+ isOpen: false,
123
+ mute: false,
124
+ showEmoji: true,
125
+ messageList: [],
126
+ newMessagesCount: 0,
127
+ fileUpload: true,
128
+ placeholder: 'Write a reply...'
129
+ };
130
+ export default LauncherNew;
@@ -0,0 +1,22 @@
1
+ import { prop } from 'ramda';
2
+ import React, { useRef, useEffect } from 'react';
3
+ import Message from './Messages';
4
+ function MessageList(props) {
5
+ var element = useRef(null);
6
+ var elementCurrent = prop('current', element);
7
+ useEffect(function () {
8
+ if (elementCurrent) {
9
+ elementCurrent.scrollTop = elementCurrent.scrollHeight;
10
+ }
11
+ }, [props]);
12
+ return /*#__PURE__*/React.createElement("div", {
13
+ className: "sc-message-list",
14
+ ref: element
15
+ }, props.messages.map(function (message, i) {
16
+ return /*#__PURE__*/React.createElement(Message, {
17
+ message: message,
18
+ key: i
19
+ });
20
+ }));
21
+ }
22
+ export default MessageList;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ var EmojiMessage = function EmojiMessage(props) {
3
+ return /*#__PURE__*/React.createElement("div", {
4
+ className: "sc-message--emoji"
5
+ }, props.data.emoji);
6
+ };
7
+ export default EmojiMessage;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import FileIcon from './../icons/FileIcon';
3
+ var FileMessage = function FileMessage(props) {
4
+ return /*#__PURE__*/React.createElement("a", {
5
+ className: "sc-message--file",
6
+ href: props.data.url,
7
+ download: props.data.fileName
8
+ }, /*#__PURE__*/React.createElement(FileIcon, null), /*#__PURE__*/React.createElement("p", null, props.data.fileName));
9
+ };
10
+ export default FileMessage;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import Linkify from 'react-linkify';
3
+ var TextMessage = function TextMessage(props) {
4
+ return /*#__PURE__*/React.createElement("div", {
5
+ className: "sc-message--text"
6
+ }, /*#__PURE__*/React.createElement(Linkify, {
7
+ properties: {
8
+ target: '_blank'
9
+ }
10
+ }, props.data.text));
11
+ };
12
+ export default TextMessage;
@@ -0,0 +1,40 @@
1
+ import { prop, equals } from 'ramda';
2
+ import React from 'react';
3
+ import classNames from 'classnames';
4
+ import TextMessage from './TextMessage';
5
+ import EmojiMessage from './EmojiMessage';
6
+ import FileMessage from './FileMessage';
7
+ import chatIconUrl from './../../assets/chat-icon.svg';
8
+ function Message(_ref) {
9
+ var message = _ref.message;
10
+ var type = prop('type', message);
11
+ var author = prop('author', message);
12
+ var me = equals(author, 'me');
13
+ function renderMessageOfType(type) {
14
+ switch (type) {
15
+ case 'text':
16
+ return /*#__PURE__*/React.createElement(TextMessage, message);
17
+ case 'emoji':
18
+ return /*#__PURE__*/React.createElement(EmojiMessage, message);
19
+ case 'file':
20
+ return /*#__PURE__*/React.createElement(FileMessage, message);
21
+ default:
22
+ console.error("Attempting to load message with unsupported file type '" + type + "'");
23
+ }
24
+ }
25
+ return /*#__PURE__*/React.createElement("div", {
26
+ className: "sc-message"
27
+ }, /*#__PURE__*/React.createElement("div", {
28
+ className: classNames('sc-message--content', {
29
+ 'sent': me
30
+ }, {
31
+ 'received': !me
32
+ })
33
+ }, /*#__PURE__*/React.createElement("div", {
34
+ className: "sc-message--avatar",
35
+ style: {
36
+ backgroundImage: "url(" + chatIconUrl + ")"
37
+ }
38
+ }), renderMessageOfType(type)));
39
+ }
40
+ export default Message;