@hellotext/hellotext 1.8.6 → 2.0.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.
- package/README.md +3 -0
- package/dist/hellotext.js +1 -1
- package/lib/api/businesses.cjs +37 -0
- package/lib/api/businesses.js +3 -9
- package/lib/api/events.cjs +45 -0
- package/lib/api/events.js +8 -14
- package/lib/api/forms.cjs +51 -0
- package/lib/api/forms.js +10 -17
- package/lib/api/index.cjs +51 -0
- package/lib/api/index.js +10 -23
- package/lib/api/response.cjs +76 -0
- package/lib/api/response.js +1 -7
- package/lib/api/submissions.cjs +47 -0
- package/lib/api/submissions.js +9 -17
- package/lib/api/webchat/messages.cjs +70 -0
- package/lib/api/webchat/messages.js +10 -18
- package/lib/api/webchats.cjs +44 -0
- package/lib/api/webchats.js +8 -16
- package/lib/builders/input_builder.cjs +61 -0
- package/lib/builders/input_builder.js +4 -11
- package/lib/builders/logo_builder.cjs +50 -0
- package/lib/builders/logo_builder.js +5 -12
- package/lib/channels/application_channel.cjs +67 -0
- package/lib/channels/application_channel.js +1 -8
- package/lib/channels/{web_chat_channel.js → webchat_channel.cjs} +35 -20
- package/lib/channels/webchat_channel.js +3 -11
- package/lib/controllers/form_controller.cjs +141 -0
- package/lib/controllers/form_controller.js +15 -22
- package/lib/controllers/mixins/usePopover.cjs +59 -0
- package/lib/controllers/mixins/usePopover.js +6 -14
- package/lib/controllers/{web_chat/pagination_controller.js → webchat/emoji_picker_controller.cjs} +74 -29
- package/lib/controllers/webchat/emoji_picker_controller.js +11 -17
- package/lib/controllers/webchat_controller.cjs +433 -0
- package/lib/controllers/webchat_controller.js +49 -51
- package/lib/core/configuration/forms.cjs +49 -0
- package/lib/core/configuration/forms.js +2 -8
- package/lib/core/configuration/{web_chat.js → webchat.cjs} +53 -38
- package/lib/core/configuration/webchat.js +2 -9
- package/lib/core/configuration.cjs +65 -0
- package/lib/core/configuration.js +8 -13
- package/lib/core/event.cjs +71 -0
- package/lib/core/event.js +5 -11
- package/lib/core/index.cjs +20 -0
- package/lib/core/index.js +2 -20
- package/lib/errors/index.cjs +19 -0
- package/lib/errors/index.js +2 -19
- package/lib/errors/invalid_event.cjs +34 -0
- package/lib/errors/invalid_event.js +1 -7
- package/lib/errors/not_initialized_error.cjs +34 -0
- package/lib/errors/not_initialized_error.js +1 -7
- package/lib/hellotext.cjs +152 -0
- package/lib/hellotext.js +18 -27
- package/lib/index.cjs +20 -0
- package/lib/index.js +12 -20
- package/lib/locales/en.cjs +22 -0
- package/lib/locales/en.js +2 -9
- package/lib/locales/es.cjs +22 -0
- package/lib/locales/es.js +2 -9
- package/lib/locales/index.cjs +14 -0
- package/lib/locales/index.js +6 -14
- package/lib/models/business.cjs +65 -0
- package/lib/models/business.js +5 -12
- package/lib/models/cookies.cjs +40 -0
- package/lib/models/cookies.js +3 -10
- package/lib/models/form.cjs +166 -0
- package/lib/models/form.js +10 -17
- package/lib/models/form_collection.cjs +119 -0
- package/lib/models/form_collection.js +15 -22
- package/lib/models/index.cjs +54 -0
- package/lib/models/index.js +7 -54
- package/lib/models/query.cjs +51 -0
- package/lib/models/query.js +3 -9
- package/lib/models/session.cjs +58 -0
- package/lib/models/session.js +12 -17
- package/lib/models/{web_chat.js → webchat.cjs} +14 -22
- package/lib/models/webchat.js +6 -13
- package/lib/vanilla.cjs +13 -0
- package/lib/vanilla.js +1 -13
- package/package.json +34 -7
- package/src/controllers/webchat_controller.js +72 -47
- package/src/hellotext.js +5 -6
- package/src/models/session.js +4 -3
- package/.babelrc +0 -24
- package/.github/workflows/ci.yml +0 -24
- package/.prettierignore +0 -3
- package/.prettierrc.json +0 -18
- package/MIT-LICENSE +0 -20
- package/__tests__/builders/input_builder_test.js +0 -117
- package/__tests__/core/configuration/forms_test.js +0 -30
- package/__tests__/core/configuration/webchat_test.js +0 -163
- package/__tests__/core/configuration_test.js +0 -28
- package/__tests__/core/event_test.js +0 -56
- package/__tests__/hellotext_test.js +0 -197
- package/__tests__/models/business_test.js +0 -26
- package/__tests__/models/cookies_test.js +0 -25
- package/__tests__/models/form_collection_test.js +0 -103
- package/__tests__/models/form_test.js +0 -131
- package/__tests__/models/query_test.js +0 -97
- package/docs/forms.md +0 -176
- package/docs/tracking.md +0 -168
- package/docs/webchat.md +0 -101
- package/jest.config.js +0 -4
- package/jest.setup.js +0 -16
- package/lib/api/web_chat/messages.js +0 -74
- package/lib/api/web_chats.js +0 -53
- package/styles/index.css +0 -38
- package/webpack.config.js +0 -24
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _stimulus = require("@hotwired/stimulus");
|
|
8
|
-
var _dom = require("@floating-ui/dom");
|
|
9
|
-
var _messages = _interopRequireDefault(require("../api/webchat/messages"));
|
|
10
|
-
var _webchat_channel = _interopRequireDefault(require("../channels/webchat_channel"));
|
|
11
|
-
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
12
|
-
var _webchat = require("../core/configuration/webchat");
|
|
13
|
-
var _usePopover = require("./mixins/usePopover");
|
|
14
|
-
var _logo_builder = require("../builders/logo_builder");
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
18
3
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -32,6 +17,14 @@ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "
|
|
|
32
17
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
33
18
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
34
19
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
20
|
+
import { flip, offset, shift } from '@floating-ui/dom';
|
|
21
|
+
import { Controller } from '@hotwired/stimulus';
|
|
22
|
+
import WebchatMessagesAPI from '../api/webchat/messages';
|
|
23
|
+
import WebchatChannel from '../channels/webchat_channel';
|
|
24
|
+
import Hellotext from '../hellotext';
|
|
25
|
+
import { Webchat as WebchatConfiguration, behaviors } from '../core/configuration/webchat';
|
|
26
|
+
import { LogoBuilder } from '../builders/logo_builder';
|
|
27
|
+
import { usePopover } from './mixins/usePopover';
|
|
35
28
|
var _default = /*#__PURE__*/function (_Controller) {
|
|
36
29
|
_inherits(_default, _Controller);
|
|
37
30
|
var _super = _createSuper(_default);
|
|
@@ -42,8 +35,8 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
42
35
|
_createClass(_default, [{
|
|
43
36
|
key: "initialize",
|
|
44
37
|
value: function initialize() {
|
|
45
|
-
this.messagesAPI = new
|
|
46
|
-
this.webChatChannel = new
|
|
38
|
+
this.messagesAPI = new WebchatMessagesAPI(this.idValue);
|
|
39
|
+
this.webChatChannel = new WebchatChannel(this.idValue, Hellotext.session, this.conversationIdValue);
|
|
47
40
|
this.files = [];
|
|
48
41
|
this.onMessageReceived = this.onMessageReceived.bind(this);
|
|
49
42
|
this.onConversationAssignment = this.onConversationAssignment.bind(this);
|
|
@@ -55,9 +48,9 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
55
48
|
}, {
|
|
56
49
|
key: "connect",
|
|
57
50
|
value: function connect() {
|
|
58
|
-
|
|
59
|
-
this.popoverTarget.classList.add(...
|
|
60
|
-
this.triggerTarget.classList.add(...
|
|
51
|
+
usePopover(this);
|
|
52
|
+
this.popoverTarget.classList.add(...WebchatConfiguration.classes);
|
|
53
|
+
this.triggerTarget.classList.add(...WebchatConfiguration.triggerClasses);
|
|
61
54
|
this.setupFloatingUI({
|
|
62
55
|
trigger: this.triggerTarget,
|
|
63
56
|
popover: this.popoverTarget
|
|
@@ -67,13 +60,13 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
67
60
|
this.webChatChannel.onAgentOnline(this.onAgentOnline);
|
|
68
61
|
this.webChatChannel.onReaction(this.onMessageReaction);
|
|
69
62
|
this.messagesContainerTarget.addEventListener('scroll', this.onScroll);
|
|
70
|
-
if (!
|
|
71
|
-
this.toolbarTarget.appendChild(
|
|
63
|
+
if (!Hellotext.business.features.white_label) {
|
|
64
|
+
this.toolbarTarget.appendChild(LogoBuilder.build());
|
|
72
65
|
}
|
|
73
66
|
if (localStorage.getItem("hellotext--webchat--".concat(this.idValue)) === 'opened') {
|
|
74
67
|
this.openValue = true;
|
|
75
68
|
}
|
|
76
|
-
|
|
69
|
+
Hellotext.eventEmitter.dispatch('webchat:mounted');
|
|
77
70
|
_get(_getPrototypeOf(_default.prototype), "connect", this).call(this);
|
|
78
71
|
}
|
|
79
72
|
}, {
|
|
@@ -91,7 +84,7 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
91
84
|
this.fetchingNextPage = true;
|
|
92
85
|
var response = yield this.messagesAPI.index({
|
|
93
86
|
page: this.nextPageValue,
|
|
94
|
-
session:
|
|
87
|
+
session: Hellotext.session
|
|
95
88
|
});
|
|
96
89
|
var {
|
|
97
90
|
next: nextPage,
|
|
@@ -141,7 +134,7 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
141
134
|
}, {
|
|
142
135
|
key: "onClickOutside",
|
|
143
136
|
value: function onClickOutside(event) {
|
|
144
|
-
if (
|
|
137
|
+
if (WebchatConfiguration.behaviour === behaviors.POPOVER && this.openValue && event.target.nodeType && this.element.contains(event.target) === false) {
|
|
145
138
|
this.openValue = false;
|
|
146
139
|
}
|
|
147
140
|
}
|
|
@@ -156,7 +149,7 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
156
149
|
});
|
|
157
150
|
this.scrolled = true;
|
|
158
151
|
}
|
|
159
|
-
|
|
152
|
+
Hellotext.eventEmitter.dispatch('webchat:opened');
|
|
160
153
|
localStorage.setItem("hellotext--webchat--".concat(this.idValue), 'opened');
|
|
161
154
|
if (this.unreadCounterTarget.style.display === 'none') return;
|
|
162
155
|
this.unreadCounterTarget.style.display = 'none';
|
|
@@ -166,9 +159,9 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
166
159
|
}, {
|
|
167
160
|
key: "onPopoverClosed",
|
|
168
161
|
value: function onPopoverClosed() {
|
|
169
|
-
|
|
162
|
+
Hellotext.eventEmitter.dispatch('webchat:closed');
|
|
170
163
|
setTimeout(() => {
|
|
171
|
-
this.inputTarget.value =
|
|
164
|
+
this.inputTarget.value = '';
|
|
172
165
|
});
|
|
173
166
|
localStorage.setItem("hellotext--webchat--".concat(this.idValue), 'closed');
|
|
174
167
|
}
|
|
@@ -218,7 +211,7 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
218
211
|
});
|
|
219
212
|
}
|
|
220
213
|
this.messagesContainerTarget.appendChild(element);
|
|
221
|
-
|
|
214
|
+
Hellotext.eventEmitter.dispatch('webchat:message:received', _objectSpread(_objectSpread({}, message), {}, {
|
|
222
215
|
body: element.querySelector('[data-body]').innerText
|
|
223
216
|
}));
|
|
224
217
|
element.scrollIntoView({
|
|
@@ -262,7 +255,7 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
262
255
|
this.files.forEach(file => {
|
|
263
256
|
formData.append('message[attachments][]', file);
|
|
264
257
|
});
|
|
265
|
-
formData.append('session',
|
|
258
|
+
formData.append('session', Hellotext.session);
|
|
266
259
|
var element = this.messageTemplateTarget.cloneNode(true);
|
|
267
260
|
element.classList.add('received');
|
|
268
261
|
element.style.removeProperty('display');
|
|
@@ -278,10 +271,10 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
278
271
|
element.scrollIntoView({
|
|
279
272
|
behavior: 'smooth'
|
|
280
273
|
});
|
|
281
|
-
this.inputTarget.value =
|
|
274
|
+
this.inputTarget.value = '';
|
|
282
275
|
this.files = [];
|
|
283
|
-
this.attachmentContainerTarget.
|
|
284
|
-
this.
|
|
276
|
+
this.attachmentContainerTarget.style.display = 'none';
|
|
277
|
+
this.errorMessageContainerTarget.style.display = 'none';
|
|
285
278
|
this.inputTarget.focus();
|
|
286
279
|
var response = yield this.messagesAPI.create(formData);
|
|
287
280
|
if (response.failed) {
|
|
@@ -290,11 +283,12 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
290
283
|
var data = yield response.json();
|
|
291
284
|
element.setAttribute('data-id', data.id);
|
|
292
285
|
message.id = data.id;
|
|
293
|
-
|
|
286
|
+
Hellotext.eventEmitter.dispatch('webchat:message:sent', message);
|
|
294
287
|
if (data.conversation !== this.conversationIdValue) {
|
|
295
288
|
this.conversationIdValue = data.conversation;
|
|
296
289
|
this.webChatChannel.updateSubscriptionWith(this.conversationIdValue);
|
|
297
290
|
}
|
|
291
|
+
this.attachmentContainerTarget.style.display = '';
|
|
298
292
|
});
|
|
299
293
|
function sendMessage() {
|
|
300
294
|
return _sendMessage.apply(this, arguments);
|
|
@@ -309,10 +303,10 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
309
303
|
}, {
|
|
310
304
|
key: "onFileInputChange",
|
|
311
305
|
value: function onFileInputChange() {
|
|
312
|
-
this.errorMessageContainerTarget.
|
|
306
|
+
this.errorMessageContainerTarget.style.display = 'none';
|
|
313
307
|
this.files = Array.from(this.attachmentInputTarget.files);
|
|
314
308
|
var fileMaxSizeTooMuch = this.files.find(file => {
|
|
315
|
-
var type = file.type.split(
|
|
309
|
+
var type = file.type.split('/')[0];
|
|
316
310
|
if (['image', 'video', 'audio'].includes(type)) {
|
|
317
311
|
return this.mediaValue[type].max_size < file.size;
|
|
318
312
|
} else {
|
|
@@ -320,12 +314,12 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
320
314
|
}
|
|
321
315
|
});
|
|
322
316
|
if (fileMaxSizeTooMuch) {
|
|
323
|
-
var type = fileMaxSizeTooMuch.type.split(
|
|
317
|
+
var type = fileMaxSizeTooMuch.type.split('/')[0];
|
|
324
318
|
var mediaType = ['image', 'audio', 'video'].includes(type) ? type : 'document';
|
|
325
319
|
this.errorMessageContainerTarget.innerText = this.fileSizeErrorMessageValue.replace('%{limit}', this.byteToMegabyte(this.mediaValue[mediaType].max_size));
|
|
326
320
|
return;
|
|
327
321
|
}
|
|
328
|
-
this.errorMessageContainerTarget.innerText =
|
|
322
|
+
this.errorMessageContainerTarget.innerText = '';
|
|
329
323
|
this.files.forEach(file => this.createAttachmentElement(file));
|
|
330
324
|
this.inputTarget.focus();
|
|
331
325
|
}
|
|
@@ -333,9 +327,9 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
333
327
|
key: "createAttachmentElement",
|
|
334
328
|
value: function createAttachmentElement(file) {
|
|
335
329
|
var element = this.attachmentElement();
|
|
336
|
-
this.attachmentContainerTarget.
|
|
330
|
+
this.attachmentContainerTarget.style.display = '';
|
|
337
331
|
element.setAttribute('data-name', file.name);
|
|
338
|
-
if (file.type.startsWith(
|
|
332
|
+
if (file.type.startsWith('image/')) {
|
|
339
333
|
var thumbnail = this.attachmentImageTarget.cloneNode(true);
|
|
340
334
|
thumbnail.src = URL.createObjectURL(file);
|
|
341
335
|
thumbnail.style.display = 'block';
|
|
@@ -343,8 +337,12 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
343
337
|
this.attachmentContainerTarget.appendChild(element);
|
|
344
338
|
this.attachmentContainerTarget.style.display = 'flex';
|
|
345
339
|
} else {
|
|
346
|
-
element.querySelector(
|
|
347
|
-
|
|
340
|
+
var main = element.querySelector('main');
|
|
341
|
+
main.style.height = '5rem';
|
|
342
|
+
main.style.borderRadius = '0.375rem';
|
|
343
|
+
main.style.backgroundColor = '#e5e7eb';
|
|
344
|
+
main.style.padding = '0.25rem';
|
|
345
|
+
element.querySelector('p[data-attachment-name]').innerText = file.name;
|
|
348
346
|
}
|
|
349
347
|
}
|
|
350
348
|
}, {
|
|
@@ -362,7 +360,7 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
362
360
|
key: "attachmentTargetDisconnected",
|
|
363
361
|
value: function attachmentTargetDisconnected() {
|
|
364
362
|
if (this.attachmentTargets.length === 0) {
|
|
365
|
-
this.attachmentContainerTarget.innerHTML =
|
|
363
|
+
this.attachmentContainerTarget.innerHTML = '';
|
|
366
364
|
this.attachmentContainerTarget.style.display = 'none';
|
|
367
365
|
}
|
|
368
366
|
}
|
|
@@ -370,9 +368,9 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
370
368
|
key: "attachmentElement",
|
|
371
369
|
value: function attachmentElement() {
|
|
372
370
|
var element = this.attachmentTemplateTarget.cloneNode(true);
|
|
373
|
-
element.removeAttribute(
|
|
371
|
+
element.removeAttribute('hidden');
|
|
374
372
|
element.style.display = 'flex';
|
|
375
|
-
element.setAttribute(
|
|
373
|
+
element.setAttribute('data-hellotext--webchat-target', 'attachment');
|
|
376
374
|
return element;
|
|
377
375
|
}
|
|
378
376
|
}, {
|
|
@@ -409,14 +407,13 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
409
407
|
}, {
|
|
410
408
|
key: "middlewares",
|
|
411
409
|
get: function get() {
|
|
412
|
-
return [
|
|
410
|
+
return [offset(5), shift({
|
|
413
411
|
padding: 24
|
|
414
|
-
}),
|
|
412
|
+
}), flip()];
|
|
415
413
|
}
|
|
416
414
|
}]);
|
|
417
415
|
return _default;
|
|
418
|
-
}(
|
|
419
|
-
exports.default = _default;
|
|
416
|
+
}(Controller);
|
|
420
417
|
_default.values = {
|
|
421
418
|
id: String,
|
|
422
419
|
conversationId: String,
|
|
@@ -424,7 +421,7 @@ _default.values = {
|
|
|
424
421
|
fileSizeErrorMessage: String,
|
|
425
422
|
placement: {
|
|
426
423
|
type: String,
|
|
427
|
-
default:
|
|
424
|
+
default: 'bottom-end'
|
|
428
425
|
},
|
|
429
426
|
open: {
|
|
430
427
|
type: Boolean,
|
|
@@ -443,4 +440,5 @@ _default.values = {
|
|
|
443
440
|
default: undefined
|
|
444
441
|
}
|
|
445
442
|
};
|
|
446
|
-
_default.targets = ['trigger', 'popover', 'input', 'attachmentInput', 'attachmentButton', 'errorMessageContainer', 'attachmentTemplate', 'attachmentContainer', 'attachment', 'messageTemplate', 'messagesContainer', 'title', 'onlineStatus', 'attachmentImage', 'footer', 'toolbar', 'message', 'unreadCounter'];
|
|
443
|
+
_default.targets = ['trigger', 'popover', 'input', 'attachmentInput', 'attachmentButton', 'errorMessageContainer', 'attachmentTemplate', 'attachmentContainer', 'attachment', 'messageTemplate', 'messagesContainer', 'title', 'onlineStatus', 'attachmentImage', 'footer', 'toolbar', 'message', 'unreadCounter'];
|
|
444
|
+
export { _default as default };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Forms = void 0;
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
/**
|
|
13
|
+
* @class Forms
|
|
14
|
+
* @classdesc
|
|
15
|
+
* Configuration for forms
|
|
16
|
+
* @property {Boolean} autoMount - whether to auto mount forms
|
|
17
|
+
* @property {Boolean|String} successMessage - whether to show success message after form completion or not
|
|
18
|
+
*/
|
|
19
|
+
let Forms = /*#__PURE__*/function () {
|
|
20
|
+
function Forms() {
|
|
21
|
+
_classCallCheck(this, Forms);
|
|
22
|
+
}
|
|
23
|
+
_createClass(Forms, null, [{
|
|
24
|
+
key: "assign",
|
|
25
|
+
value:
|
|
26
|
+
/**
|
|
27
|
+
* @param {Object} props
|
|
28
|
+
* @param {Boolean} [props.autoMount=true] - whether to auto mount forms
|
|
29
|
+
* @param {Boolean|String} [props.successMessage=true] - whether to show success message after form completion or not
|
|
30
|
+
*/
|
|
31
|
+
function assign(props) {
|
|
32
|
+
if (props) {
|
|
33
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
34
|
+
this[key] = value;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
40
|
+
key: "shouldShowSuccessMessage",
|
|
41
|
+
get: function () {
|
|
42
|
+
return this.successMessage;
|
|
43
|
+
}
|
|
44
|
+
}]);
|
|
45
|
+
return Forms;
|
|
46
|
+
}();
|
|
47
|
+
exports.Forms = Forms;
|
|
48
|
+
Forms.autoMount = true;
|
|
49
|
+
Forms.successMessage = true;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Forms = void 0;
|
|
7
1
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
2
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
3
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -45,6 +39,6 @@ var Forms = /*#__PURE__*/function () {
|
|
|
45
39
|
}]);
|
|
46
40
|
return Forms;
|
|
47
41
|
}();
|
|
48
|
-
exports.Forms = Forms;
|
|
49
42
|
Forms.autoMount = true;
|
|
50
|
-
Forms.successMessage = true;
|
|
43
|
+
Forms.successMessage = true;
|
|
44
|
+
export { Forms };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.behaviors = exports.
|
|
6
|
+
exports.behaviors = exports.Webchat = void 0;
|
|
7
7
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
8
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
9
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -17,7 +17,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
17
17
|
/**
|
|
18
18
|
* @enum {Placement}
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
const placements = {
|
|
21
21
|
TOP_LEFT: 'top-left',
|
|
22
22
|
TOP_RIGHT: 'top-right',
|
|
23
23
|
BOTTOM_LEFT: 'bottom-left',
|
|
@@ -31,20 +31,20 @@ var placements = {
|
|
|
31
31
|
/**
|
|
32
32
|
* @enum {Behaviour}
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
const behaviors = {
|
|
35
35
|
MODAL: 'modal',
|
|
36
36
|
POPOVER: 'popover'
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* @typedef {Object} Style
|
|
41
|
-
* @property {string}
|
|
42
|
-
* @property {string}
|
|
41
|
+
* @property {string} primaryColor - The primary webchat color (e.g., a hex code or color name).
|
|
42
|
+
* @property {string} secondaryColor - The secondary webchat color or style (e.g., a hex code or color name).
|
|
43
43
|
* @property {string} typography - The typography style (e.g., font family).
|
|
44
44
|
*/
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* @class
|
|
47
|
+
* @class Webchat
|
|
48
48
|
* @classdesc
|
|
49
49
|
* Configuration for webchat
|
|
50
50
|
* @property {String} id - the id of the webchat.
|
|
@@ -56,39 +56,39 @@ var behaviors = {
|
|
|
56
56
|
* @property {Style} style - the style of the webchat.
|
|
57
57
|
*/
|
|
58
58
|
exports.behaviors = behaviors;
|
|
59
|
-
|
|
60
|
-
function
|
|
61
|
-
_classCallCheck(this,
|
|
59
|
+
let Webchat = /*#__PURE__*/function () {
|
|
60
|
+
function Webchat() {
|
|
61
|
+
_classCallCheck(this, Webchat);
|
|
62
62
|
}
|
|
63
|
-
_createClass(
|
|
63
|
+
_createClass(Webchat, null, [{
|
|
64
64
|
key: "container",
|
|
65
|
-
get: function
|
|
65
|
+
get: function () {
|
|
66
66
|
return this._container;
|
|
67
67
|
},
|
|
68
|
-
set: function
|
|
68
|
+
set: function (value) {
|
|
69
69
|
this._container = value;
|
|
70
70
|
}
|
|
71
71
|
}, {
|
|
72
72
|
key: "placement",
|
|
73
|
-
get: function
|
|
73
|
+
get: function () {
|
|
74
74
|
return this._placement;
|
|
75
75
|
},
|
|
76
|
-
set: function
|
|
76
|
+
set: function (value) {
|
|
77
77
|
if (!Object.values(placements).includes(value)) {
|
|
78
|
-
throw new Error(
|
|
78
|
+
throw new Error(`Invalid placement value: ${value}`);
|
|
79
79
|
}
|
|
80
80
|
this._placement = value;
|
|
81
81
|
}
|
|
82
82
|
}, {
|
|
83
83
|
key: "classes",
|
|
84
|
-
get: function
|
|
84
|
+
get: function () {
|
|
85
85
|
if (typeof this._classes === 'string') {
|
|
86
86
|
return this._classes.split(',').map(c => c.trim());
|
|
87
87
|
} else {
|
|
88
88
|
return this._classes;
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
|
-
set: function
|
|
91
|
+
set: function (value) {
|
|
92
92
|
if (!Array.isArray(value) && typeof value !== 'string') {
|
|
93
93
|
throw new Error('classes must be an array or a string');
|
|
94
94
|
}
|
|
@@ -96,14 +96,14 @@ var WebChat = /*#__PURE__*/function () {
|
|
|
96
96
|
}
|
|
97
97
|
}, {
|
|
98
98
|
key: "triggerClasses",
|
|
99
|
-
get: function
|
|
99
|
+
get: function () {
|
|
100
100
|
if (typeof this._triggerClasses === 'string') {
|
|
101
101
|
return this._triggerClasses.split(',').map(c => c.trim());
|
|
102
102
|
} else {
|
|
103
103
|
return this._triggerClasses;
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
|
-
set: function
|
|
106
|
+
set: function (value) {
|
|
107
107
|
if (!Array.isArray(value) && typeof value !== 'string') {
|
|
108
108
|
throw new Error('triggerClasses must be an array or a string');
|
|
109
109
|
}
|
|
@@ -111,36 +111,47 @@ var WebChat = /*#__PURE__*/function () {
|
|
|
111
111
|
}
|
|
112
112
|
}, {
|
|
113
113
|
key: "id",
|
|
114
|
-
get: function
|
|
114
|
+
get: function () {
|
|
115
115
|
return this._id;
|
|
116
116
|
},
|
|
117
|
-
set: function
|
|
117
|
+
set: function (value) {
|
|
118
118
|
this._id = value;
|
|
119
119
|
}
|
|
120
120
|
}, {
|
|
121
121
|
key: "isSet",
|
|
122
|
-
get: function
|
|
122
|
+
get: function () {
|
|
123
123
|
return !!this._id;
|
|
124
124
|
}
|
|
125
125
|
}, {
|
|
126
126
|
key: "style",
|
|
127
|
-
get: function
|
|
127
|
+
get: function () {
|
|
128
128
|
return this._style;
|
|
129
129
|
},
|
|
130
|
-
set: function
|
|
130
|
+
set: function (value) {
|
|
131
131
|
if (typeof value !== 'object') {
|
|
132
132
|
throw new Error('Style must be an object');
|
|
133
133
|
}
|
|
134
|
+
Object.entries(value).forEach(([key, value]) => {
|
|
135
|
+
if (!['primaryColor', 'secondaryColor', 'typography'].includes(key)) {
|
|
136
|
+
throw new Error(`Invalid style property: ${key}`);
|
|
137
|
+
}
|
|
138
|
+
if (key === 'typography') {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (!this.isHexOrRgba(value)) {
|
|
142
|
+
throw new Error(`Invalid color value: ${value} for ${key}. Colors must be hex or rgb/a.`);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
134
145
|
this._style = value;
|
|
135
146
|
}
|
|
136
147
|
}, {
|
|
137
148
|
key: "behaviour",
|
|
138
|
-
get: function
|
|
149
|
+
get: function () {
|
|
139
150
|
return this._behaviour;
|
|
140
151
|
},
|
|
141
|
-
set: function
|
|
152
|
+
set: function (value) {
|
|
142
153
|
if (!Object.values(behaviors).includes(value)) {
|
|
143
|
-
throw new Error(
|
|
154
|
+
throw new Error(`Invalid behaviour value: ${value}`);
|
|
144
155
|
}
|
|
145
156
|
this._behaviour = value;
|
|
146
157
|
}
|
|
@@ -148,21 +159,25 @@ var WebChat = /*#__PURE__*/function () {
|
|
|
148
159
|
key: "assign",
|
|
149
160
|
value: function assign(props) {
|
|
150
161
|
if (props) {
|
|
151
|
-
Object.entries(props).forEach(
|
|
152
|
-
var [key, value] = _ref;
|
|
162
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
153
163
|
this[key] = value;
|
|
154
164
|
});
|
|
155
165
|
}
|
|
156
166
|
return this;
|
|
157
167
|
}
|
|
168
|
+
}, {
|
|
169
|
+
key: "isHexOrRgba",
|
|
170
|
+
value: function isHexOrRgba(value) {
|
|
171
|
+
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value) || /^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(value);
|
|
172
|
+
}
|
|
158
173
|
}]);
|
|
159
|
-
return
|
|
174
|
+
return Webchat;
|
|
160
175
|
}();
|
|
161
|
-
exports.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
176
|
+
exports.Webchat = Webchat;
|
|
177
|
+
Webchat._id = void 0;
|
|
178
|
+
Webchat._container = 'body';
|
|
179
|
+
Webchat._placement = 'bottom-right';
|
|
180
|
+
Webchat._classes = [];
|
|
181
|
+
Webchat._triggerClasses = [];
|
|
182
|
+
Webchat._style = {};
|
|
183
|
+
Webchat._behaviour = behaviors.POPOVER;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.behaviors = exports.Webchat = void 0;
|
|
7
1
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
2
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
3
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -55,7 +49,6 @@ var behaviors = {
|
|
|
55
49
|
* @property {Behaviour} behaviour - the behaviour of the webchat, defaults to 'popover'.
|
|
56
50
|
* @property {Style} style - the style of the webchat.
|
|
57
51
|
*/
|
|
58
|
-
exports.behaviors = behaviors;
|
|
59
52
|
var Webchat = /*#__PURE__*/function () {
|
|
60
53
|
function Webchat() {
|
|
61
54
|
_classCallCheck(this, Webchat);
|
|
@@ -175,11 +168,11 @@ var Webchat = /*#__PURE__*/function () {
|
|
|
175
168
|
}]);
|
|
176
169
|
return Webchat;
|
|
177
170
|
}();
|
|
178
|
-
exports.Webchat = Webchat;
|
|
179
171
|
Webchat._id = void 0;
|
|
180
172
|
Webchat._container = 'body';
|
|
181
173
|
Webchat._placement = 'bottom-right';
|
|
182
174
|
Webchat._classes = [];
|
|
183
175
|
Webchat._triggerClasses = [];
|
|
184
176
|
Webchat._style = {};
|
|
185
|
-
Webchat._behaviour = behaviors.POPOVER;
|
|
177
|
+
Webchat._behaviour = behaviors.POPOVER;
|
|
178
|
+
export { Webchat, behaviors };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Configuration = void 0;
|
|
7
|
+
var _forms = require("./configuration/forms");
|
|
8
|
+
var _webchat = require("./configuration/webchat");
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
/**
|
|
15
|
+
* @class Configuration
|
|
16
|
+
* @classdesc
|
|
17
|
+
* Configuration for Hellotext
|
|
18
|
+
* @property {Boolean} [autoGenerateSession=true] - whether to auto generate session or not
|
|
19
|
+
* @property {String} [session] - session id
|
|
20
|
+
* @property {Forms} [forms] - form configuration
|
|
21
|
+
* @property {Webchat} [webchat] - webchat configuration
|
|
22
|
+
*/
|
|
23
|
+
let Configuration = /*#__PURE__*/function () {
|
|
24
|
+
function Configuration() {
|
|
25
|
+
_classCallCheck(this, Configuration);
|
|
26
|
+
}
|
|
27
|
+
_createClass(Configuration, null, [{
|
|
28
|
+
key: "assign",
|
|
29
|
+
value:
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param props
|
|
33
|
+
* @param {Boolean} [props.autoGenerateSession=true] - whether to auto generate session or not
|
|
34
|
+
* @param {String} [props.session] - session id
|
|
35
|
+
* @param {Object} [props.forms] - form configuration
|
|
36
|
+
* @returns {Configuration}
|
|
37
|
+
*/
|
|
38
|
+
function assign(props) {
|
|
39
|
+
if (props) {
|
|
40
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
41
|
+
if (key === 'forms') {
|
|
42
|
+
this.forms = _forms.Forms.assign(value);
|
|
43
|
+
} else if (key === 'webChat') {
|
|
44
|
+
this.webchat = _webchat.Webchat.assign(value);
|
|
45
|
+
} else {
|
|
46
|
+
this[key] = value;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "endpoint",
|
|
54
|
+
value: function endpoint(path) {
|
|
55
|
+
return `${this.apiRoot}/${path}`;
|
|
56
|
+
}
|
|
57
|
+
}]);
|
|
58
|
+
return Configuration;
|
|
59
|
+
}();
|
|
60
|
+
exports.Configuration = Configuration;
|
|
61
|
+
Configuration.apiRoot = 'https://api.hellotext.com/v1';
|
|
62
|
+
Configuration.autoGenerateSession = true;
|
|
63
|
+
Configuration.session = null;
|
|
64
|
+
Configuration.forms = _forms.Forms;
|
|
65
|
+
Configuration.webchat = _webchat.Webchat;
|