@hellotext/hellotext 2.5.6 → 2.5.8

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 (113) hide show
  1. package/README.md +5 -26
  2. package/dist/hellotext.js +1 -1
  3. package/dist/hellotext.js.LICENSE.txt +1 -1
  4. package/index.d.ts +15 -6
  5. package/lib/api/acks.cjs +17 -31
  6. package/lib/api/acks.js +17 -42
  7. package/lib/api/businesses.cjs +14 -28
  8. package/lib/api/businesses.js +13 -36
  9. package/lib/api/events.cjs +26 -40
  10. package/lib/api/events.js +28 -52
  11. package/lib/api/forms.cjs +24 -40
  12. package/lib/api/forms.js +24 -57
  13. package/lib/api/identifications.cjs +15 -29
  14. package/lib/api/identifications.js +15 -40
  15. package/lib/api/index.cjs +26 -46
  16. package/lib/api/index.js +28 -49
  17. package/lib/api/push/identities.cjs +43 -0
  18. package/lib/api/push/identities.js +35 -0
  19. package/lib/api/response.cjs +30 -52
  20. package/lib/api/response.js +31 -60
  21. package/lib/api/submissions.cjs +18 -34
  22. package/lib/api/submissions.js +18 -48
  23. package/lib/api/webchat/messages.cjs +44 -64
  24. package/lib/api/webchat/messages.js +44 -80
  25. package/lib/api/webchats.cjs +37 -56
  26. package/lib/api/webchats.js +37 -65
  27. package/lib/api/whatsapp_widgets.cjs +49 -72
  28. package/lib/api/whatsapp_widgets.js +48 -91
  29. package/lib/builders/input_builder.cjs +36 -48
  30. package/lib/builders/input_builder.js +36 -48
  31. package/lib/builders/logo_builder.cjs +10 -29
  32. package/lib/builders/logo_builder.js +20 -28
  33. package/lib/channels/application_channel.cjs +136 -178
  34. package/lib/channels/application_channel.js +137 -180
  35. package/lib/channels/webchat_channel.cjs +125 -170
  36. package/lib/channels/webchat_channel.js +125 -170
  37. package/lib/controllers/form_controller.cjs +82 -121
  38. package/lib/controllers/form_controller.js +82 -130
  39. package/lib/controllers/message_controller.cjs +211 -282
  40. package/lib/controllers/message_controller.js +209 -284
  41. package/lib/controllers/mixins/usePopover.cjs +3 -6
  42. package/lib/controllers/mixins/usePopover.js +17 -22
  43. package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
  44. package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
  45. package/lib/controllers/webchat/useBehaviour.js +5 -5
  46. package/lib/controllers/webchat/useOpeningSequence.js +6 -6
  47. package/lib/controllers/webchat/useTeaser.js +9 -9
  48. package/lib/controllers/webchat_controller.cjs +916 -1088
  49. package/lib/controllers/webchat_controller.js +926 -1152
  50. package/lib/core/configuration/forms.cjs +21 -35
  51. package/lib/core/configuration/forms.js +20 -35
  52. package/lib/core/configuration/locale.cjs +36 -71
  53. package/lib/core/configuration/locale.js +36 -70
  54. package/lib/core/configuration/push.cjs +16 -0
  55. package/lib/core/configuration/push.js +10 -0
  56. package/lib/core/configuration/webchat.cjs +142 -182
  57. package/lib/core/configuration/webchat.js +145 -189
  58. package/lib/core/configuration/whatsapp.cjs +76 -102
  59. package/lib/core/configuration/whatsapp.js +76 -105
  60. package/lib/core/configuration.cjs +62 -75
  61. package/lib/core/configuration.js +61 -75
  62. package/lib/core/event.cjs +36 -59
  63. package/lib/core/event.js +35 -61
  64. package/lib/core/sanitize_html.js +4 -4
  65. package/lib/errors/invalid_event.cjs +5 -26
  66. package/lib/errors/invalid_event.js +5 -26
  67. package/lib/errors/not_initialized_error.cjs +5 -26
  68. package/lib/errors/not_initialized_error.js +5 -26
  69. package/lib/hellotext.cjs +186 -211
  70. package/lib/hellotext.js +189 -236
  71. package/lib/index.js +1 -1
  72. package/lib/models/business.cjs +115 -152
  73. package/lib/models/business.js +118 -162
  74. package/lib/models/cookies.cjs +34 -51
  75. package/lib/models/cookies.js +34 -51
  76. package/lib/models/fingerprint.cjs +8 -23
  77. package/lib/models/fingerprint.js +25 -58
  78. package/lib/models/form.cjs +106 -142
  79. package/lib/models/form.js +105 -153
  80. package/lib/models/form_collection.cjs +63 -101
  81. package/lib/models/form_collection.js +61 -107
  82. package/lib/models/index.cjs +7 -0
  83. package/lib/models/index.js +1 -0
  84. package/lib/models/page.cjs +106 -129
  85. package/lib/models/page.js +106 -131
  86. package/lib/models/push.cjs +345 -0
  87. package/lib/models/push.js +339 -0
  88. package/lib/models/query.cjs +21 -41
  89. package/lib/models/query.js +21 -41
  90. package/lib/models/session.cjs +33 -65
  91. package/lib/models/session.js +30 -63
  92. package/lib/models/user.cjs +29 -51
  93. package/lib/models/user.js +29 -51
  94. package/lib/models/utm.cjs +15 -27
  95. package/lib/models/utm.js +17 -32
  96. package/lib/models/webchat.cjs +52 -76
  97. package/lib/models/webchat.js +52 -90
  98. package/lib/models/whatsapp_widget.cjs +41 -59
  99. package/lib/models/whatsapp_widget.js +41 -73
  100. package/lib/vanilla.cjs +4 -7
  101. package/lib/vanilla.js +2 -1
  102. package/package.json +2 -10
  103. package/src/api/index.js +5 -0
  104. package/src/api/push/identities.js +42 -0
  105. package/src/core/configuration/push.js +12 -0
  106. package/src/core/configuration.js +5 -0
  107. package/src/hellotext.js +15 -1
  108. package/src/index.bundle.js +0 -1
  109. package/src/models/business.js +1 -0
  110. package/src/models/index.js +1 -0
  111. package/src/models/push.js +397 -0
  112. package/src/vanilla.js +2 -1
  113. package/styles/index.css +0 -30
@@ -10,135 +10,96 @@ var _models = require("../models");
10
10
  var _forms = _interopRequireDefault(require("../api/forms"));
11
11
  var _core = require("../core");
12
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);
13
+ class _default extends _stimulus.Controller {
14
+ static values = {
15
+ data: Object,
16
+ step: {
17
+ type: Number,
18
+ default: 1
19
+ }
20
+ };
21
+ static targets = ['inputContainer', 'input', 'button', 'otpContainer'];
22
+ initialize() {
23
+ this.form = new _models.Form(this.dataValue, this.element);
33
24
  }
34
- _createClass(_default, [{
35
- key: "initialize",
36
- value: function initialize() {
37
- this.form = new _models.Form(this.dataValue, this.element);
25
+ connect() {
26
+ super.connect();
27
+ this.element.addEventListener('submit', this.submit.bind(this));
28
+ if (document.activeElement.tagName !== 'INPUT') {
29
+ this.inputTargets[0].focus();
38
30
  }
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
- }
31
+ }
32
+ async submit(e) {
33
+ e.preventDefault();
34
+ if (this.invalid) {
35
+ return this.showErrorMessages();
47
36
  }
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]);
37
+ this.clearErrorMessages();
38
+ this.formData = Object.fromEntries(new FormData(this.element));
39
+ this.buttonTarget.disabled = true;
40
+ const response = await _forms.default.submit(this.form.id, this.formData);
41
+ this.buttonTarget.disabled = false;
42
+ const data = await response.json();
43
+ if (response.failed) {
44
+ data.errors.forEach(error => {
45
+ const {
46
+ type,
47
+ parameter
48
+ } = error;
49
+ const input = this.inputTargets.find(input => input.name === parameter);
50
+ input.setCustomValidity(_hellotext.default.business.locale.errors[type]);
51
+ input.reportValidity();
52
+ input.addEventListener('input', () => {
53
+ input.setCustomValidity('');
69
54
  input.reportValidity();
70
- input.addEventListener('input', () => {
71
- input.setCustomValidity('');
72
- input.reportValidity();
73
- });
74
55
  });
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.inputTargets.forEach(input => {
100
- const errorsContainer = input.closest('article').querySelector('[data-error-container]');
101
- if (input.validity.valid) {
102
- errorsContainer.innerText = '';
103
- } else {
104
- errorsContainer.innerText = input.validationMessage;
105
- }
106
- });
107
- }
108
- }, {
109
- key: "clearErrorMessages",
110
- value: function clearErrorMessages() {
111
- this.inputTargets.forEach(input => {
112
- input.setCustomValidity('');
113
- input.closest('article').querySelector('[data-error-container]').innerText = '';
114
56
  });
57
+ return this.showErrorMessages();
115
58
  }
116
- }, {
117
- key: "inputTargetConnected",
118
- value: function inputTargetConnected(target) {
119
- if (target.getAttribute('data-default-value')) {
120
- target.value = target.getAttribute('data-default-value');
121
- }
59
+ this.buttonTarget.style.display = 'none';
60
+ this.element.querySelectorAll('input').forEach(input => input.disabled = true);
61
+ this.completed();
62
+ }
63
+ completed() {
64
+ this.form.markAsCompleted(this.formData);
65
+ if (!_core.Configuration.forms.shouldShowSuccessMessage) {
66
+ return this.element.remove();
122
67
  }
123
- }, {
124
- key: "requiredInputs",
125
- get: function () {
126
- return this.inputTargets.filter(input => input.required);
68
+ if (typeof _core.Configuration.forms.successMessage === 'string') {
69
+ this.element.innerHTML = _core.Configuration.forms.successMessage;
70
+ } else {
71
+ this.element.innerHTML = _hellotext.default.business.locale.forms[this.form.localeAuthKey];
127
72
  }
128
- }, {
129
- key: "invalid",
130
- get: function () {
131
- return !this.element.checkValidity();
73
+ }
74
+
75
+ // private
76
+
77
+ showErrorMessages() {
78
+ this.inputTargets.forEach(input => {
79
+ const errorsContainer = input.closest('article').querySelector('[data-error-container]');
80
+ if (input.validity.valid) {
81
+ errorsContainer.innerText = '';
82
+ } else {
83
+ errorsContainer.innerText = input.validationMessage;
84
+ }
85
+ });
86
+ }
87
+ clearErrorMessages() {
88
+ this.inputTargets.forEach(input => {
89
+ input.setCustomValidity('');
90
+ input.closest('article').querySelector('[data-error-container]').innerText = '';
91
+ });
92
+ }
93
+ inputTargetConnected(target) {
94
+ if (target.getAttribute('data-default-value')) {
95
+ target.value = target.getAttribute('data-default-value');
132
96
  }
133
- }]);
134
- return _default;
135
- }(_stimulus.Controller);
136
- exports.default = _default;
137
- _default.values = {
138
- data: Object,
139
- step: {
140
- type: Number,
141
- default: 1
142
97
  }
143
- };
144
- _default.targets = ['inputContainer', 'input', 'button', 'otpContainer'];
98
+ get requiredInputs() {
99
+ return this.inputTargets.filter(input => input.required);
100
+ }
101
+ get invalid() {
102
+ return !this.element.checkValidity();
103
+ }
104
+ }
105
+ exports.default = _default;
@@ -1,145 +1,97 @@
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); } }
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); }); }; }
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
- 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); } }
5
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
- 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); }
8
- 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); }
9
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
10
- 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); }
11
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
- 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); }; }
13
- 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); }
14
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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; } }
16
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
17
1
  import { Controller } from '@hotwired/stimulus';
18
2
  import Hellotext from '../hellotext';
19
3
  import { Form } from '../models';
20
4
  import FormsAPI from '../api/forms';
21
5
  import { Configuration } from '../core';
22
- var _default = /*#__PURE__*/function (_Controller) {
23
- _inherits(_default, _Controller);
24
- var _super = _createSuper(_default);
25
- function _default() {
26
- _classCallCheck(this, _default);
27
- return _super.apply(this, arguments);
6
+ export default class extends Controller {
7
+ static values = {
8
+ data: Object,
9
+ step: {
10
+ type: Number,
11
+ default: 1
12
+ }
13
+ };
14
+ static targets = ['inputContainer', 'input', 'button', 'otpContainer'];
15
+ initialize() {
16
+ this.form = new Form(this.dataValue, this.element);
28
17
  }
29
- _createClass(_default, [{
30
- key: "initialize",
31
- value: function initialize() {
32
- this.form = new Form(this.dataValue, this.element);
18
+ connect() {
19
+ super.connect();
20
+ this.element.addEventListener('submit', this.submit.bind(this));
21
+ if (document.activeElement.tagName !== 'INPUT') {
22
+ this.inputTargets[0].focus();
33
23
  }
34
- }, {
35
- key: "connect",
36
- value: function connect() {
37
- _get(_getPrototypeOf(_default.prototype), "connect", this).call(this);
38
- this.element.addEventListener('submit', this.submit.bind(this));
39
- if (document.activeElement.tagName !== 'INPUT') {
40
- this.inputTargets[0].focus();
41
- }
24
+ }
25
+ async submit(e) {
26
+ e.preventDefault();
27
+ if (this.invalid) {
28
+ return this.showErrorMessages();
42
29
  }
43
- }, {
44
- key: "submit",
45
- value: function () {
46
- var _submit = _asyncToGenerator(function* (e) {
47
- e.preventDefault();
48
- if (this.invalid) {
49
- return this.showErrorMessages();
50
- }
51
- this.clearErrorMessages();
52
- this.formData = Object.fromEntries(new FormData(this.element));
53
- this.buttonTarget.disabled = true;
54
- var response = yield FormsAPI.submit(this.form.id, this.formData);
55
- this.buttonTarget.disabled = false;
56
- var data = yield response.json();
57
- if (response.failed) {
58
- data.errors.forEach(error => {
59
- var {
60
- type,
61
- parameter
62
- } = error;
63
- var input = this.inputTargets.find(input => input.name === parameter);
64
- input.setCustomValidity(Hellotext.business.locale.errors[type]);
65
- input.reportValidity();
66
- input.addEventListener('input', () => {
67
- input.setCustomValidity('');
68
- input.reportValidity();
69
- });
70
- });
71
- return this.showErrorMessages();
72
- }
73
- this.buttonTarget.style.display = 'none';
74
- this.element.querySelectorAll('input').forEach(input => input.disabled = true);
75
- this.completed();
30
+ this.clearErrorMessages();
31
+ this.formData = Object.fromEntries(new FormData(this.element));
32
+ this.buttonTarget.disabled = true;
33
+ const response = await FormsAPI.submit(this.form.id, this.formData);
34
+ this.buttonTarget.disabled = false;
35
+ const data = await response.json();
36
+ if (response.failed) {
37
+ data.errors.forEach(error => {
38
+ const {
39
+ type,
40
+ parameter
41
+ } = error;
42
+ const input = this.inputTargets.find(input => input.name === parameter);
43
+ input.setCustomValidity(Hellotext.business.locale.errors[type]);
44
+ input.reportValidity();
45
+ input.addEventListener('input', () => {
46
+ input.setCustomValidity('');
47
+ input.reportValidity();
48
+ });
76
49
  });
77
- function submit(_x) {
78
- return _submit.apply(this, arguments);
79
- }
80
- return submit;
81
- }()
82
- }, {
83
- key: "completed",
84
- value: function completed() {
85
- this.form.markAsCompleted(this.formData);
86
- if (!Configuration.forms.shouldShowSuccessMessage) {
87
- return this.element.remove();
88
- }
89
- if (typeof Configuration.forms.successMessage === 'string') {
90
- this.element.innerHTML = Configuration.forms.successMessage;
91
- } else {
92
- this.element.innerHTML = Hellotext.business.locale.forms[this.form.localeAuthKey];
93
- }
50
+ return this.showErrorMessages();
94
51
  }
95
-
96
- // private
97
- }, {
98
- key: "showErrorMessages",
99
- value: function showErrorMessages() {
100
- this.inputTargets.forEach(input => {
101
- var errorsContainer = input.closest('article').querySelector('[data-error-container]');
102
- if (input.validity.valid) {
103
- errorsContainer.innerText = '';
104
- } else {
105
- errorsContainer.innerText = input.validationMessage;
106
- }
107
- });
52
+ this.buttonTarget.style.display = 'none';
53
+ this.element.querySelectorAll('input').forEach(input => input.disabled = true);
54
+ this.completed();
55
+ }
56
+ completed() {
57
+ this.form.markAsCompleted(this.formData);
58
+ if (!Configuration.forms.shouldShowSuccessMessage) {
59
+ return this.element.remove();
108
60
  }
109
- }, {
110
- key: "clearErrorMessages",
111
- value: function clearErrorMessages() {
112
- this.inputTargets.forEach(input => {
113
- input.setCustomValidity('');
114
- input.closest('article').querySelector('[data-error-container]').innerText = '';
115
- });
61
+ if (typeof Configuration.forms.successMessage === 'string') {
62
+ this.element.innerHTML = Configuration.forms.successMessage;
63
+ } else {
64
+ this.element.innerHTML = Hellotext.business.locale.forms[this.form.localeAuthKey];
116
65
  }
117
- }, {
118
- key: "inputTargetConnected",
119
- value: function inputTargetConnected(target) {
120
- if (target.getAttribute('data-default-value')) {
121
- target.value = target.getAttribute('data-default-value');
66
+ }
67
+
68
+ // private
69
+
70
+ showErrorMessages() {
71
+ this.inputTargets.forEach(input => {
72
+ const errorsContainer = input.closest('article').querySelector('[data-error-container]');
73
+ if (input.validity.valid) {
74
+ errorsContainer.innerText = '';
75
+ } else {
76
+ errorsContainer.innerText = input.validationMessage;
122
77
  }
78
+ });
79
+ }
80
+ clearErrorMessages() {
81
+ this.inputTargets.forEach(input => {
82
+ input.setCustomValidity('');
83
+ input.closest('article').querySelector('[data-error-container]').innerText = '';
84
+ });
85
+ }
86
+ inputTargetConnected(target) {
87
+ if (target.getAttribute('data-default-value')) {
88
+ target.value = target.getAttribute('data-default-value');
123
89
  }
124
- }, {
125
- key: "requiredInputs",
126
- get: function get() {
127
- return this.inputTargets.filter(input => input.required);
128
- }
129
- }, {
130
- key: "invalid",
131
- get: function get() {
132
- return !this.element.checkValidity();
133
- }
134
- }]);
135
- return _default;
136
- }(Controller);
137
- _default.values = {
138
- data: Object,
139
- step: {
140
- type: Number,
141
- default: 1
142
90
  }
143
- };
144
- _default.targets = ['inputContainer', 'input', 'button', 'otpContainer'];
145
- export { _default as default };
91
+ get requiredInputs() {
92
+ return this.inputTargets.filter(input => input.required);
93
+ }
94
+ get invalid() {
95
+ return !this.element.checkValidity();
96
+ }
97
+ }