@hellotext/hellotext 1.8.7 → 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.
Files changed (106) hide show
  1. package/dist/hellotext.js +1 -1
  2. package/lib/api/businesses.cjs +37 -0
  3. package/lib/api/businesses.js +3 -9
  4. package/lib/api/events.cjs +45 -0
  5. package/lib/api/events.js +8 -14
  6. package/lib/api/forms.cjs +51 -0
  7. package/lib/api/forms.js +10 -17
  8. package/lib/api/index.cjs +51 -0
  9. package/lib/api/index.js +10 -23
  10. package/lib/api/response.cjs +76 -0
  11. package/lib/api/response.js +1 -7
  12. package/lib/api/submissions.cjs +47 -0
  13. package/lib/api/submissions.js +9 -17
  14. package/lib/api/webchat/messages.cjs +70 -0
  15. package/lib/api/webchat/messages.js +10 -18
  16. package/lib/api/webchats.cjs +44 -0
  17. package/lib/api/webchats.js +8 -16
  18. package/lib/builders/input_builder.cjs +61 -0
  19. package/lib/builders/input_builder.js +4 -11
  20. package/lib/builders/logo_builder.cjs +50 -0
  21. package/lib/builders/logo_builder.js +5 -12
  22. package/lib/channels/application_channel.cjs +67 -0
  23. package/lib/channels/application_channel.js +1 -8
  24. package/lib/channels/{web_chat_channel.js → webchat_channel.cjs} +35 -20
  25. package/lib/channels/webchat_channel.js +3 -11
  26. package/lib/controllers/form_controller.cjs +141 -0
  27. package/lib/controllers/form_controller.js +15 -22
  28. package/lib/controllers/mixins/usePopover.cjs +59 -0
  29. package/lib/controllers/mixins/usePopover.js +6 -14
  30. package/lib/controllers/{web_chat/pagination_controller.js → webchat/emoji_picker_controller.cjs} +74 -29
  31. package/lib/controllers/webchat/emoji_picker_controller.js +11 -17
  32. package/lib/controllers/webchat_controller.cjs +433 -0
  33. package/lib/controllers/webchat_controller.js +49 -51
  34. package/lib/core/configuration/forms.cjs +49 -0
  35. package/lib/core/configuration/forms.js +2 -8
  36. package/lib/core/configuration/{web_chat.js → webchat.cjs} +53 -38
  37. package/lib/core/configuration/webchat.js +2 -9
  38. package/lib/core/configuration.cjs +65 -0
  39. package/lib/core/configuration.js +8 -13
  40. package/lib/core/event.cjs +71 -0
  41. package/lib/core/event.js +5 -11
  42. package/lib/core/index.cjs +20 -0
  43. package/lib/core/index.js +2 -20
  44. package/lib/errors/index.cjs +19 -0
  45. package/lib/errors/index.js +2 -19
  46. package/lib/errors/invalid_event.cjs +34 -0
  47. package/lib/errors/invalid_event.js +1 -7
  48. package/lib/errors/not_initialized_error.cjs +34 -0
  49. package/lib/errors/not_initialized_error.js +1 -7
  50. package/lib/hellotext.cjs +152 -0
  51. package/lib/hellotext.js +18 -27
  52. package/lib/index.cjs +20 -0
  53. package/lib/index.js +12 -20
  54. package/lib/locales/en.cjs +22 -0
  55. package/lib/locales/en.js +2 -9
  56. package/lib/locales/es.cjs +22 -0
  57. package/lib/locales/es.js +2 -9
  58. package/lib/locales/index.cjs +14 -0
  59. package/lib/locales/index.js +6 -14
  60. package/lib/models/business.cjs +65 -0
  61. package/lib/models/business.js +5 -12
  62. package/lib/models/cookies.cjs +40 -0
  63. package/lib/models/cookies.js +3 -10
  64. package/lib/models/form.cjs +166 -0
  65. package/lib/models/form.js +10 -17
  66. package/lib/models/form_collection.cjs +119 -0
  67. package/lib/models/form_collection.js +15 -22
  68. package/lib/models/index.cjs +54 -0
  69. package/lib/models/index.js +7 -54
  70. package/lib/models/query.cjs +51 -0
  71. package/lib/models/query.js +3 -9
  72. package/lib/models/session.cjs +58 -0
  73. package/lib/models/session.js +12 -17
  74. package/lib/models/{web_chat.js → webchat.cjs} +14 -22
  75. package/lib/models/webchat.js +6 -13
  76. package/lib/vanilla.cjs +13 -0
  77. package/lib/vanilla.js +1 -13
  78. package/package.json +34 -7
  79. package/src/controllers/webchat_controller.js +72 -47
  80. package/src/hellotext.js +3 -4
  81. package/src/models/session.js +4 -3
  82. package/.babelrc +0 -24
  83. package/.github/workflows/ci.yml +0 -24
  84. package/.prettierignore +0 -3
  85. package/.prettierrc.json +0 -18
  86. package/MIT-LICENSE +0 -20
  87. package/__tests__/builders/input_builder_test.js +0 -117
  88. package/__tests__/core/configuration/forms_test.js +0 -30
  89. package/__tests__/core/configuration/webchat_test.js +0 -163
  90. package/__tests__/core/configuration_test.js +0 -28
  91. package/__tests__/core/event_test.js +0 -56
  92. package/__tests__/hellotext_test.js +0 -197
  93. package/__tests__/models/business_test.js +0 -26
  94. package/__tests__/models/cookies_test.js +0 -25
  95. package/__tests__/models/form_collection_test.js +0 -103
  96. package/__tests__/models/form_test.js +0 -131
  97. package/__tests__/models/query_test.js +0 -97
  98. package/docs/forms.md +0 -176
  99. package/docs/tracking.md +0 -203
  100. package/docs/webchat.md +0 -101
  101. package/jest.config.js +0 -4
  102. package/jest.setup.js +0 -16
  103. package/lib/api/web_chat/messages.js +0 -74
  104. package/lib/api/web_chats.js +0 -53
  105. package/styles/index.css +0 -38
  106. package/webpack.config.js +0 -24
@@ -20,25 +20,27 @@ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "
20
20
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
21
21
  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; } }
22
22
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
23
- var WebChatChannel = /*#__PURE__*/function (_ApplicationChannel) {
24
- _inherits(WebChatChannel, _ApplicationChannel);
25
- var _super = _createSuper(WebChatChannel);
26
- function WebChatChannel(id, session) {
23
+ let WebchatChannel = /*#__PURE__*/function (_ApplicationChannel) {
24
+ _inherits(WebchatChannel, _ApplicationChannel);
25
+ var _super = _createSuper(WebchatChannel);
26
+ function WebchatChannel(id, session, conversation) {
27
27
  var _this;
28
- _classCallCheck(this, WebChatChannel);
28
+ _classCallCheck(this, WebchatChannel);
29
29
  _this = _super.call(this);
30
30
  _this.id = id;
31
31
  _this.session = session;
32
+ _this.conversation = conversation;
32
33
  _this.subscribe();
33
34
  return _this;
34
35
  }
35
- _createClass(WebChatChannel, [{
36
+ _createClass(WebchatChannel, [{
36
37
  key: "subscribe",
37
38
  value: function subscribe() {
38
- var params = {
39
- channel: "WebChatChannel",
39
+ const params = {
40
+ channel: "WebchatChannel",
40
41
  id: this.id,
41
- session: this.session
42
+ session: this.session,
43
+ conversation: this.conversation
42
44
  };
43
45
  this.send({
44
46
  command: 'subscribe',
@@ -48,10 +50,11 @@ var WebChatChannel = /*#__PURE__*/function (_ApplicationChannel) {
48
50
  }, {
49
51
  key: "unsubscribe",
50
52
  value: function unsubscribe() {
51
- var params = {
52
- channel: "WebChatChannel",
53
+ const params = {
54
+ channel: "WebchatChannel",
53
55
  id: this.id,
54
- session: this.session
56
+ session: this.session,
57
+ conversation: this.conversation
55
58
  };
56
59
  this.send({
57
60
  command: 'unsubscribe',
@@ -61,7 +64,7 @@ var WebChatChannel = /*#__PURE__*/function (_ApplicationChannel) {
61
64
  }, {
62
65
  key: "onMessage",
63
66
  value: function onMessage(callback) {
64
- _get(_getPrototypeOf(WebChatChannel.prototype), "onMessage", this).call(this, message => {
67
+ _get(_getPrototypeOf(WebchatChannel.prototype), "onMessage", this).call(this, message => {
65
68
  if (message.type !== 'message') return;
66
69
  callback(message);
67
70
  });
@@ -69,7 +72,7 @@ var WebChatChannel = /*#__PURE__*/function (_ApplicationChannel) {
69
72
  }, {
70
73
  key: "onConversationAssignment",
71
74
  value: function onConversationAssignment(callback) {
72
- _get(_getPrototypeOf(WebChatChannel.prototype), "onMessage", this).call(this, message => {
75
+ _get(_getPrototypeOf(WebchatChannel.prototype), "onMessage", this).call(this, message => {
73
76
  if (message.type === 'conversation.assigned') {
74
77
  callback(message);
75
78
  }
@@ -78,20 +81,32 @@ var WebChatChannel = /*#__PURE__*/function (_ApplicationChannel) {
78
81
  }, {
79
82
  key: "onAgentOnline",
80
83
  value: function onAgentOnline(callback) {
81
- _get(_getPrototypeOf(WebChatChannel.prototype), "onMessage", this).call(this, message => {
84
+ _get(_getPrototypeOf(WebchatChannel.prototype), "onMessage", this).call(this, message => {
82
85
  if (message.type === 'agent_is_online') {
83
86
  callback(message);
84
87
  }
85
88
  });
86
89
  }
87
90
  }, {
88
- key: "updateSubscription",
89
- value: function updateSubscription() {
91
+ key: "onReaction",
92
+ value: function onReaction(callback) {
93
+ _get(_getPrototypeOf(WebchatChannel.prototype), "onMessage", this).call(this, message => {
94
+ if (message.type === 'reaction.create' || message.type === 'reaction.destroy') {
95
+ callback(message);
96
+ }
97
+ });
98
+ }
99
+ }, {
100
+ key: "updateSubscriptionWith",
101
+ value: function updateSubscriptionWith(conversation) {
90
102
  this.unsubscribe();
91
- this.subscribe();
103
+ setTimeout(() => {
104
+ this.conversation = conversation;
105
+ this.subscribe();
106
+ }, 1000);
92
107
  }
93
108
  }]);
94
- return WebChatChannel;
109
+ return WebchatChannel;
95
110
  }(_application_channel.default);
96
- var _default = WebChatChannel;
111
+ var _default = WebchatChannel;
97
112
  exports.default = _default;
@@ -1,11 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _application_channel = _interopRequireDefault(require("./application_channel"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
1
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
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); } }
11
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; }
@@ -20,6 +12,7 @@ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "
20
12
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
21
13
  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; } }
22
14
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
15
+ import ApplicationChannel from './application_channel';
23
16
  var WebchatChannel = /*#__PURE__*/function (_ApplicationChannel) {
24
17
  _inherits(WebchatChannel, _ApplicationChannel);
25
18
  var _super = _createSuper(WebchatChannel);
@@ -107,6 +100,5 @@ var WebchatChannel = /*#__PURE__*/function (_ApplicationChannel) {
107
100
  }
108
101
  }]);
109
102
  return WebchatChannel;
110
- }(_application_channel.default);
111
- var _default = WebchatChannel;
112
- exports.default = _default;
103
+ }(ApplicationChannel);
104
+ export default WebchatChannel;
@@ -0,0 +1,141 @@
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 _hellotext = _interopRequireDefault(require("../hellotext"));
9
+ var _models = require("../models");
10
+ var _forms = _interopRequireDefault(require("../api/forms"));
11
+ var _core = require("../core");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ 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); } }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
17
+ 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); }
18
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
19
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
20
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
21
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
22
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
23
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
24
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
+ 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; } }
26
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
27
+ let _default = /*#__PURE__*/function (_Controller) {
28
+ _inherits(_default, _Controller);
29
+ var _super = _createSuper(_default);
30
+ function _default() {
31
+ _classCallCheck(this, _default);
32
+ return _super.apply(this, arguments);
33
+ }
34
+ _createClass(_default, [{
35
+ key: "initialize",
36
+ value: function initialize() {
37
+ this.form = new _models.Form(this.dataValue, this.element);
38
+ }
39
+ }, {
40
+ key: "connect",
41
+ value: function connect() {
42
+ _get(_getPrototypeOf(_default.prototype), "connect", this).call(this);
43
+ this.element.addEventListener('submit', this.submit.bind(this));
44
+ if (document.activeElement.tagName !== 'INPUT') {
45
+ this.inputTargets[0].focus();
46
+ }
47
+ }
48
+ }, {
49
+ key: "submit",
50
+ value: async function submit(e) {
51
+ e.preventDefault();
52
+ if (this.invalid) {
53
+ return this.showErrorMessages();
54
+ }
55
+ this.clearErrorMessages();
56
+ this.formData = Object.fromEntries(new FormData(this.element));
57
+ this.buttonTarget.disabled = true;
58
+ const response = await _forms.default.submit(this.form.id, this.formData);
59
+ this.buttonTarget.disabled = false;
60
+ const data = await response.json();
61
+ if (response.failed) {
62
+ data.errors.forEach(error => {
63
+ const {
64
+ type,
65
+ parameter
66
+ } = error;
67
+ const input = this.inputTargets.find(input => input.name === parameter);
68
+ input.setCustomValidity(_hellotext.default.business.locale.errors[type]);
69
+ input.reportValidity();
70
+ input.addEventListener('input', () => {
71
+ input.setCustomValidity('');
72
+ input.reportValidity();
73
+ });
74
+ });
75
+ return this.showErrorMessages();
76
+ }
77
+ this.buttonTarget.style.display = 'none';
78
+ this.element.querySelectorAll('input').forEach(input => input.disabled = true);
79
+ this.completed();
80
+ }
81
+ }, {
82
+ key: "completed",
83
+ value: function completed() {
84
+ this.form.markAsCompleted(this.formData);
85
+ if (!_core.Configuration.forms.shouldShowSuccessMessage) {
86
+ return this.element.remove();
87
+ }
88
+ if (typeof _core.Configuration.forms.successMessage === 'string') {
89
+ this.element.innerHTML = _core.Configuration.forms.successMessage;
90
+ } else {
91
+ this.element.innerHTML = _hellotext.default.business.locale.forms[this.form.localeAuthKey];
92
+ }
93
+ }
94
+
95
+ // private
96
+ }, {
97
+ key: "showErrorMessages",
98
+ value: function showErrorMessages() {
99
+ this.element.querySelectorAll('input:invalid').forEach(input => {
100
+ const parent = input.closest('article');
101
+ parent.querySelector('[data-error-container]').innerText = input.validationMessage;
102
+ });
103
+ }
104
+ }, {
105
+ key: "clearErrorMessages",
106
+ value: function clearErrorMessages() {
107
+ this.element.querySelectorAll('input').forEach(input => {
108
+ input.setCustomValidity('');
109
+ const parent = input.closest('article');
110
+ parent.querySelector('[data-error-container]').innerText = '';
111
+ });
112
+ }
113
+ }, {
114
+ key: "inputTargetConnected",
115
+ value: function inputTargetConnected(target) {
116
+ if (target.getAttribute('data-default-value')) {
117
+ target.value = target.getAttribute('data-default-value');
118
+ }
119
+ }
120
+ }, {
121
+ key: "requiredInputs",
122
+ get: function () {
123
+ return this.inputTargets.filter(input => input.required);
124
+ }
125
+ }, {
126
+ key: "invalid",
127
+ get: function () {
128
+ return !this.element.checkValidity();
129
+ }
130
+ }]);
131
+ return _default;
132
+ }(_stimulus.Controller);
133
+ exports.default = _default;
134
+ _default.values = {
135
+ data: Object,
136
+ step: {
137
+ type: Number,
138
+ default: 1
139
+ }
140
+ };
141
+ _default.targets = ['inputContainer', 'input', 'button', 'otpContainer'];
@@ -1,15 +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 _hellotext = _interopRequireDefault(require("../hellotext"));
9
- var _models = require("../models");
10
- var _forms = _interopRequireDefault(require("../api/forms"));
11
- var _core = require("../core");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
14
2
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
15
3
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -26,6 +14,11 @@ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "
26
14
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
27
15
  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; } }
28
16
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
17
+ import { Controller } from '@hotwired/stimulus';
18
+ import Hellotext from '../hellotext';
19
+ import { Form } from '../models';
20
+ import FormsAPI from '../api/forms';
21
+ import { Configuration } from '../core';
29
22
  var _default = /*#__PURE__*/function (_Controller) {
30
23
  _inherits(_default, _Controller);
31
24
  var _super = _createSuper(_default);
@@ -36,7 +29,7 @@ var _default = /*#__PURE__*/function (_Controller) {
36
29
  _createClass(_default, [{
37
30
  key: "initialize",
38
31
  value: function initialize() {
39
- this.form = new _models.Form(this.dataValue, this.element);
32
+ this.form = new Form(this.dataValue, this.element);
40
33
  }
41
34
  }, {
42
35
  key: "connect",
@@ -58,7 +51,7 @@ var _default = /*#__PURE__*/function (_Controller) {
58
51
  this.clearErrorMessages();
59
52
  this.formData = Object.fromEntries(new FormData(this.element));
60
53
  this.buttonTarget.disabled = true;
61
- var response = yield _forms.default.submit(this.form.id, this.formData);
54
+ var response = yield FormsAPI.submit(this.form.id, this.formData);
62
55
  this.buttonTarget.disabled = false;
63
56
  var data = yield response.json();
64
57
  if (response.failed) {
@@ -68,7 +61,7 @@ var _default = /*#__PURE__*/function (_Controller) {
68
61
  parameter
69
62
  } = error;
70
63
  var input = this.inputTargets.find(input => input.name === parameter);
71
- input.setCustomValidity(_hellotext.default.business.locale.errors[type]);
64
+ input.setCustomValidity(Hellotext.business.locale.errors[type]);
72
65
  input.reportValidity();
73
66
  input.addEventListener('input', () => {
74
67
  input.setCustomValidity('');
@@ -90,13 +83,13 @@ var _default = /*#__PURE__*/function (_Controller) {
90
83
  key: "completed",
91
84
  value: function completed() {
92
85
  this.form.markAsCompleted(this.formData);
93
- if (!_core.Configuration.forms.shouldShowSuccessMessage) {
86
+ if (!Configuration.forms.shouldShowSuccessMessage) {
94
87
  return this.element.remove();
95
88
  }
96
- if (typeof _core.Configuration.forms.successMessage === 'string') {
97
- this.element.innerHTML = _core.Configuration.forms.successMessage;
89
+ if (typeof Configuration.forms.successMessage === 'string') {
90
+ this.element.innerHTML = Configuration.forms.successMessage;
98
91
  } else {
99
- this.element.innerHTML = _hellotext.default.business.locale.forms[this.form.localeAuthKey];
92
+ this.element.innerHTML = Hellotext.business.locale.forms[this.form.localeAuthKey];
100
93
  }
101
94
  }
102
95
 
@@ -137,8 +130,7 @@ var _default = /*#__PURE__*/function (_Controller) {
137
130
  }
138
131
  }]);
139
132
  return _default;
140
- }(_stimulus.Controller);
141
- exports.default = _default;
133
+ }(Controller);
142
134
  _default.values = {
143
135
  data: Object,
144
136
  step: {
@@ -146,4 +138,5 @@ _default.values = {
146
138
  default: 1
147
139
  }
148
140
  };
149
- _default.targets = ['inputContainer', 'input', 'button', 'otpContainer'];
141
+ _default.targets = ['inputContainer', 'input', 'button', 'otpContainer'];
142
+ export { _default as default };
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.usePopover = void 0;
7
+ var _dom = require("@floating-ui/dom");
8
+ var _hellotext = _interopRequireDefault(require("../../hellotext"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const usePopover = controller => {
11
+ Object.assign(controller, {
12
+ show() {
13
+ this.openValue = true;
14
+ },
15
+ hide() {
16
+ this.openValue = false;
17
+ },
18
+ toggle() {
19
+ this.openValue = !this.openValue;
20
+ },
21
+ setupFloatingUI({
22
+ trigger,
23
+ popover
24
+ }) {
25
+ this.floatingUICleanup = (0, _dom.autoUpdate)(trigger, popover, () => {
26
+ (0, _dom.computePosition)(trigger, popover, {
27
+ placement: this.placementValue,
28
+ middleware: this.middlewares
29
+ }).then(({
30
+ x,
31
+ y
32
+ }) => {
33
+ const newStyle = {
34
+ left: `${x}px`,
35
+ top: `${y}px`
36
+ };
37
+ Object.assign(popover.style, newStyle);
38
+ });
39
+ });
40
+ },
41
+ openValueChanged() {
42
+ if (this.disabledValue) return;
43
+ if (this.openValue) {
44
+ this.popoverTarget.showPopover();
45
+ this.popoverTarget.setAttribute("aria-expanded", "true");
46
+ if (this['onPopoverOpened']) {
47
+ this.onPopoverOpened();
48
+ }
49
+ } else {
50
+ this.popoverTarget.hidePopover();
51
+ this.popoverTarget.removeAttribute("aria-expanded");
52
+ if (this['onPopoverClosed']) {
53
+ this.onPopoverClosed();
54
+ }
55
+ }
56
+ }
57
+ });
58
+ };
59
+ exports.usePopover = usePopover;
@@ -1,13 +1,6 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.usePopover = void 0;
7
- var _dom = require("@floating-ui/dom");
8
- var _hellotext = _interopRequireDefault(require("../../hellotext"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- var usePopover = controller => {
1
+ import { autoUpdate, computePosition } from '@floating-ui/dom';
2
+ import Hellotext from "../../hellotext";
3
+ export var usePopover = controller => {
11
4
  Object.assign(controller, {
12
5
  show() {
13
6
  this.openValue = true;
@@ -23,8 +16,8 @@ var usePopover = controller => {
23
16
  trigger,
24
17
  popover
25
18
  } = _ref;
26
- this.floatingUICleanup = (0, _dom.autoUpdate)(trigger, popover, () => {
27
- (0, _dom.computePosition)(trigger, popover, {
19
+ this.floatingUICleanup = autoUpdate(trigger, popover, () => {
20
+ computePosition(trigger, popover, {
28
21
  placement: this.placementValue,
29
22
  middleware: this.middlewares
30
23
  }).then(_ref2 => {
@@ -57,5 +50,4 @@ var usePopover = controller => {
57
50
  }
58
51
  }
59
52
  });
60
- };
61
- exports.usePopover = usePopover;
53
+ };
@@ -5,12 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _stimulus = require("@hotwired/stimulus");
8
- var _core = require("../../core");
9
- var _hellotext = _interopRequireDefault(require("../../hellotext"));
10
- var _messages = _interopRequireDefault(require("../../api/web_chat/messages"));
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
13
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
8
+ var _dom = require("@floating-ui/dom");
9
+ var _emojiMart = require("emoji-mart");
10
+ var _usePopover = require("../mixins/usePopover");
14
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
12
  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); } }
16
13
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -25,7 +22,7 @@ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "
25
22
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
23
  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; } }
27
24
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
- var _default = /*#__PURE__*/function (_Controller) {
25
+ let _default = /*#__PURE__*/function (_Controller) {
29
26
  _inherits(_default, _Controller);
30
27
  var _super = _createSuper(_default);
31
28
  function _default() {
@@ -35,47 +32,95 @@ var _default = /*#__PURE__*/function (_Controller) {
35
32
  _createClass(_default, [{
36
33
  key: "initialize",
37
34
  value: function initialize() {
38
- this.messagesAPI = new _messages.default(_core.Configuration.webChat.id);
39
- this.onScroll = this.onScroll.bind(this);
35
+ this.onEmojiSelect = this.onEmojiSelect.bind(this);
40
36
  _get(_getPrototypeOf(_default.prototype), "initialize", this).call(this);
41
37
  }
42
38
  }, {
43
39
  key: "connect",
44
40
  value: function connect() {
45
- this.scrollableTarget.addEventListener('scroll', this.onScroll);
41
+ (0, _usePopover.usePopover)(this);
42
+ this.setupFloatingUI({
43
+ trigger: this.buttonTarget,
44
+ popover: this.popoverTarget
45
+ });
46
+ this.popoverTarget.appendChild(this.pickerObject);
46
47
  _get(_getPrototypeOf(_default.prototype), "connect", this).call(this);
47
48
  }
48
49
  }, {
49
50
  key: "disconnect",
50
51
  value: function disconnect() {
51
- this.scrollableTarget.removeEventListener('scroll', this.onScroll);
52
+ this.floatingUICleanup();
52
53
  _get(_getPrototypeOf(_default.prototype), "disconnect", this).call(this);
53
54
  }
54
55
  }, {
55
- key: "onScroll",
56
- value: function () {
57
- var _onScroll = _asyncToGenerator(function* () {
58
- if (this.scrollableTarget.scrollTop > 300 || !this.nextPageValue) return;
59
- console.log('fetching....');
60
- var response = yield this.messagesAPI.index({
61
- page: this.nextPageValue,
62
- session: _hellotext.default.session
63
- });
64
- console.log(yield response.json());
56
+ key: "onEmojiSelect",
57
+ value: function onEmojiSelect(emoji) {
58
+ this.dispatch('selected', {
59
+ detail: emoji.native
65
60
  });
66
- function onScroll() {
67
- return _onScroll.apply(this, arguments);
61
+ this.hide();
62
+ }
63
+ }, {
64
+ key: "onClickOutside",
65
+ value: function onClickOutside(event) {
66
+ if (this.openValue && event.target.nodeType && this.element.contains(event.target) === false) {
67
+ this.openValue = false;
68
68
  }
69
- return onScroll;
70
- }()
69
+ }
70
+ }, {
71
+ key: "pickerObject",
72
+ get: function () {
73
+ return new _emojiMart.Picker({
74
+ onEmojiSelect: this.onEmojiSelect,
75
+ theme: 'light',
76
+ dynamicWidth: true,
77
+ previewPosition: 'none',
78
+ skinTonePosition: 'none',
79
+ emojiSize: this.sizeValue,
80
+ perLine: this.perLineValue,
81
+ data: async () => {
82
+ const response = await fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data');
83
+ return response.json();
84
+ }
85
+ });
86
+ }
87
+ }, {
88
+ key: "middlewares",
89
+ get: function () {
90
+ return [(0, _dom.offset)(5), (0, _dom.shift)({
91
+ padding: 24
92
+ }), (0, _dom.autoPlacement)({
93
+ allowedPlacements: ['top', 'bottom']
94
+ })];
95
+ }
71
96
  }]);
72
97
  return _default;
73
98
  }(_stimulus.Controller);
74
99
  exports.default = _default;
100
+ _default.targets = ['button', 'popover'];
75
101
  _default.values = {
76
- nextPage: {
102
+ placement: {
103
+ type: String,
104
+ default: "bottom-end"
105
+ },
106
+ open: {
107
+ type: Boolean,
108
+ default: false
109
+ },
110
+ autoPlacement: {
111
+ type: Boolean,
112
+ default: false
113
+ },
114
+ disabled: {
115
+ type: Boolean,
116
+ default: false
117
+ },
118
+ size: {
119
+ type: Number,
120
+ default: 24
121
+ },
122
+ perLine: {
77
123
  type: Number,
78
- default: undefined
124
+ default: 9
79
125
  }
80
- };
81
- _default.targets = ['scrollable'];
126
+ };