@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
@@ -1,172 +1,124 @@
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; }
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; }
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; }
4
- 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); } }
5
- 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); }); }; }
6
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7
- 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); } }
8
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
- 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); }
11
- function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
12
- var id = 0;
13
- function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
14
1
  import Hellotext from '../hellotext';
15
2
  import { InputBuilder } from '../builders/input_builder';
16
3
  import { LogoBuilder } from '../builders/logo_builder';
17
4
  import { setSanitizedRichText } from '../core/sanitize_html';
18
- var _findOrCreateComponent = /*#__PURE__*/_classPrivateFieldLooseKey("findOrCreateComponent");
19
- var Form = /*#__PURE__*/function () {
20
- function Form(data) {
21
- var element = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
22
- _classCallCheck(this, Form);
23
- Object.defineProperty(this, _findOrCreateComponent, {
24
- value: _findOrCreateComponent2
25
- });
5
+ class Form {
6
+ constructor(data, element = null) {
26
7
  this.data = data;
27
- this.element = element || document.querySelector("[data-hello-form=\"".concat(this.id, "\"]")) || document.createElement('form');
8
+ this.element = element || document.querySelector(`[data-hello-form="${this.id}"]`) || document.createElement('form');
28
9
  }
29
- _createClass(Form, [{
30
- key: "mount",
31
- value: function () {
32
- var _mount = _asyncToGenerator(function* () {
33
- var {
34
- ifCompleted = true
35
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
36
- if (ifCompleted && this.hasBeenCompleted) {
37
- var _this$element;
38
- (_this$element = this.element) === null || _this$element === void 0 ? void 0 : _this$element.remove();
39
- return Hellotext.eventEmitter.dispatch('form:completed', _objectSpread({
40
- id: this.id
41
- }, JSON.parse(localStorage.getItem("hello-form-".concat(this.id)))));
42
- }
43
- var firstStep = this.data.steps[0];
44
- this.buildHeader(firstStep.header);
45
- this.buildInputs(firstStep.inputs);
46
- this.buildButton(firstStep.button);
47
- this.buildFooter(firstStep.footer);
48
- this.elementAttributes.forEach(attribute => {
49
- this.element.setAttribute(attribute.name, attribute.value);
50
- });
51
- if (!document.contains(this.element)) {
52
- document.body.appendChild(this.element);
53
- }
54
- if (!Hellotext.business.features.white_label) {
55
- this.element.prepend(LogoBuilder.build());
56
- }
10
+ async mount({
11
+ ifCompleted = true
12
+ } = {}) {
13
+ if (ifCompleted && this.hasBeenCompleted) {
14
+ this.element?.remove();
15
+ return Hellotext.eventEmitter.dispatch('form:completed', {
16
+ id: this.id,
17
+ ...JSON.parse(localStorage.getItem(`hello-form-${this.id}`))
57
18
  });
58
- function mount() {
59
- return _mount.apply(this, arguments);
60
- }
61
- return mount;
62
- }()
63
- }, {
64
- key: "buildHeader",
65
- value: function buildHeader(header) {
66
- var headerElement = _classPrivateFieldLooseBase(this, _findOrCreateComponent)[_findOrCreateComponent]('[data-form-header]', 'header');
67
- setSanitizedRichText(headerElement, header.content);
68
- if (this.element.querySelector('[data-form-header]')) {
69
- this.element.querySelector('[data-form-header]').replaceWith(headerElement);
70
- } else {
71
- this.element.prepend(headerElement);
72
- }
73
19
  }
74
- }, {
75
- key: "buildInputs",
76
- value: function buildInputs(inputs) {
77
- var inputsContainerElement = _classPrivateFieldLooseBase(this, _findOrCreateComponent)[_findOrCreateComponent]('[data-form-inputs]', 'main');
78
- var inputElements = inputs.map(input => InputBuilder.build(input));
79
- inputElements.forEach(inputElement => inputsContainerElement.appendChild(inputElement));
80
- if (this.element.querySelector('[data-form-inputs]')) {
81
- this.element.querySelector('[data-form-inputs]').replaceWith(inputsContainerElement);
82
- } else {
83
- this.element.querySelector('[data-form-header]').insertAdjacentHTML('afterend', inputsContainerElement.outerHTML);
84
- }
20
+ const firstStep = this.data.steps[0];
21
+ this.buildHeader(firstStep.header);
22
+ this.buildInputs(firstStep.inputs);
23
+ this.buildButton(firstStep.button);
24
+ this.buildFooter(firstStep.footer);
25
+ this.elementAttributes.forEach(attribute => {
26
+ this.element.setAttribute(attribute.name, attribute.value);
27
+ });
28
+ if (!document.contains(this.element)) {
29
+ document.body.appendChild(this.element);
85
30
  }
86
- }, {
87
- key: "buildButton",
88
- value: function buildButton(button) {
89
- var buttonElement = _classPrivateFieldLooseBase(this, _findOrCreateComponent)[_findOrCreateComponent]('[data-form-button]', 'button');
90
- buttonElement.innerText = button.text;
91
- buttonElement.setAttribute('data-action', 'click->hellotext--form#submit');
92
- buttonElement.setAttribute('data-hellotext--form-target', 'button');
93
- if (this.element.querySelector('[data-form-button]')) {
94
- this.element.querySelector('[data-form-button]').replaceWith(buttonElement);
95
- } else {
96
- this.element.querySelector('[data-form-inputs]').insertAdjacentHTML('afterend', buttonElement.outerHTML);
97
- }
31
+ if (!Hellotext.business.features.white_label) {
32
+ this.element.prepend(LogoBuilder.build());
98
33
  }
99
- }, {
100
- key: "buildFooter",
101
- value: function buildFooter(footer) {
102
- var element = _classPrivateFieldLooseBase(this, _findOrCreateComponent)[_findOrCreateComponent]('[data-form-footer]', 'footer');
103
- setSanitizedRichText(element, footer.content);
104
- if (this.element.querySelector('[data-form-footer]')) {
105
- this.element.querySelector('[data-form-footer]').replaceWith(element);
106
- } else {
107
- this.element.appendChild(element);
108
- }
34
+ }
35
+ buildHeader(header) {
36
+ const headerElement = this.#findOrCreateComponent('[data-form-header]', 'header');
37
+ setSanitizedRichText(headerElement, header.content);
38
+ if (this.element.querySelector('[data-form-header]')) {
39
+ this.element.querySelector('[data-form-header]').replaceWith(headerElement);
40
+ } else {
41
+ this.element.prepend(headerElement);
109
42
  }
110
- }, {
111
- key: "markAsCompleted",
112
- value: function markAsCompleted(data) {
113
- var payload = {
114
- state: 'completed',
115
- id: this.id,
116
- data,
117
- completedAt: new Date().getTime()
118
- };
119
- localStorage.setItem("hello-form-".concat(this.id), JSON.stringify(payload));
120
- Hellotext.eventEmitter.dispatch('form:completed', payload);
43
+ }
44
+ buildInputs(inputs) {
45
+ const inputsContainerElement = this.#findOrCreateComponent('[data-form-inputs]', 'main');
46
+ const inputElements = inputs.map(input => InputBuilder.build(input));
47
+ inputElements.forEach(inputElement => inputsContainerElement.appendChild(inputElement));
48
+ if (this.element.querySelector('[data-form-inputs]')) {
49
+ this.element.querySelector('[data-form-inputs]').replaceWith(inputsContainerElement);
50
+ } else {
51
+ this.element.querySelector('[data-form-header]').insertAdjacentHTML('afterend', inputsContainerElement.outerHTML);
121
52
  }
122
- }, {
123
- key: "hasBeenCompleted",
124
- get: function get() {
125
- return localStorage.getItem("hello-form-".concat(this.id)) !== null;
53
+ }
54
+ buildButton(button) {
55
+ const buttonElement = this.#findOrCreateComponent('[data-form-button]', 'button');
56
+ buttonElement.innerText = button.text;
57
+ buttonElement.setAttribute('data-action', 'click->hellotext--form#submit');
58
+ buttonElement.setAttribute('data-hellotext--form-target', 'button');
59
+ if (this.element.querySelector('[data-form-button]')) {
60
+ this.element.querySelector('[data-form-button]').replaceWith(buttonElement);
61
+ } else {
62
+ this.element.querySelector('[data-form-inputs]').insertAdjacentHTML('afterend', buttonElement.outerHTML);
126
63
  }
127
- }, {
128
- key: "id",
129
- get: function get() {
130
- return this.data.id;
64
+ }
65
+ buildFooter(footer) {
66
+ const element = this.#findOrCreateComponent('[data-form-footer]', 'footer');
67
+ setSanitizedRichText(element, footer.content);
68
+ if (this.element.querySelector('[data-form-footer]')) {
69
+ this.element.querySelector('[data-form-footer]').replaceWith(element);
70
+ } else {
71
+ this.element.appendChild(element);
131
72
  }
132
- }, {
133
- key: "localeAuthKey",
134
- get: function get() {
135
- var firstStep = this.data.steps[0];
136
- if (firstStep.inputs.some(input => input.kind === 'email') && firstStep.inputs.some(input => input.kind === 'phone')) {
137
- return 'phone_and_email';
138
- } else if (firstStep.inputs.some(input => input.kind === 'email')) {
139
- return 'email';
140
- } else if (firstStep.inputs.some(input => input.kind === 'phone')) {
141
- return 'phone';
142
- } else {
143
- return 'none';
144
- }
73
+ }
74
+ markAsCompleted(data) {
75
+ const payload = {
76
+ state: 'completed',
77
+ id: this.id,
78
+ data,
79
+ completedAt: new Date().getTime()
80
+ };
81
+ localStorage.setItem(`hello-form-${this.id}`, JSON.stringify(payload));
82
+ Hellotext.eventEmitter.dispatch('form:completed', payload);
83
+ }
84
+ get hasBeenCompleted() {
85
+ return localStorage.getItem(`hello-form-${this.id}`) !== null;
86
+ }
87
+ get id() {
88
+ return this.data.id;
89
+ }
90
+ get localeAuthKey() {
91
+ const firstStep = this.data.steps[0];
92
+ if (firstStep.inputs.some(input => input.kind === 'email') && firstStep.inputs.some(input => input.kind === 'phone')) {
93
+ return 'phone_and_email';
94
+ } else if (firstStep.inputs.some(input => input.kind === 'email')) {
95
+ return 'email';
96
+ } else if (firstStep.inputs.some(input => input.kind === 'phone')) {
97
+ return 'phone';
98
+ } else {
99
+ return 'none';
145
100
  }
146
- }, {
147
- key: "elementAttributes",
148
- get: function get() {
149
- return [{
150
- name: 'data-controller',
151
- value: 'hellotext--form'
152
- }, {
153
- name: 'data-hello-form',
154
- value: this.id
155
- }, {
156
- name: 'data-hellotext--form-data-value',
157
- value: JSON.stringify(this.data)
158
- }];
101
+ }
102
+ get elementAttributes() {
103
+ return [{
104
+ name: 'data-controller',
105
+ value: 'hellotext--form'
106
+ }, {
107
+ name: 'data-hello-form',
108
+ value: this.id
109
+ }, {
110
+ name: 'data-hellotext--form-data-value',
111
+ value: JSON.stringify(this.data)
112
+ }];
113
+ }
114
+ #findOrCreateComponent(selector, tag) {
115
+ const existingElement = this.element.querySelector(selector);
116
+ if (existingElement) {
117
+ return existingElement.cloneNode(true);
159
118
  }
160
- }]);
161
- return Form;
162
- }();
163
- function _findOrCreateComponent2(selector, tag) {
164
- var existingElement = this.element.querySelector(selector);
165
- if (existingElement) {
166
- return existingElement.cloneNode(true);
119
+ const createdElement = document.createElement(tag);
120
+ createdElement.setAttribute(selector.replace('[', '').replace(']', ''), '');
121
+ return createdElement;
167
122
  }
168
- var createdElement = document.createElement(tag);
169
- createdElement.setAttribute(selector.replace('[', '').replace(']', ''), '');
170
- return createdElement;
171
123
  }
172
124
  export { Form };
@@ -10,22 +10,8 @@ var _core = require("../core");
10
10
  var _form = require("./form");
11
11
  var _errors = require("../errors");
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 _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
19
- var id = 0;
20
- function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
21
- var _formIdsToFetch = /*#__PURE__*/_classPrivateFieldLooseKey("formIdsToFetch");
22
- let FormCollection = /*#__PURE__*/function () {
23
- function FormCollection() {
24
- _classCallCheck(this, FormCollection);
25
- Object.defineProperty(this, _formIdsToFetch, {
26
- get: _get_formIdsToFetch,
27
- set: void 0
28
- });
13
+ class FormCollection {
14
+ constructor() {
29
15
  this.forms = [];
30
16
  this.includes = this.includes.bind(this);
31
17
  this.excludes = this.excludes.bind(this);
@@ -38,95 +24,71 @@ let FormCollection = /*#__PURE__*/function () {
38
24
  });
39
25
  }
40
26
  }
41
- _createClass(FormCollection, [{
42
- key: "collectExistingFormsOnPage",
43
- value: function collectExistingFormsOnPage() {
44
- if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
45
- this.collect();
46
- }
47
- }
48
- }, {
49
- key: "formMutationObserver",
50
- value: function formMutationObserver(mutations) {
51
- const mutation = mutations.find(mutation => mutation.type === 'childList' && mutation.addedNodes.length > 0);
52
- if (!mutation) return;
53
- if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
54
- this.collect();
55
- }
56
- }
57
- }, {
58
- key: "collect",
59
- value: async function collect() {
60
- if (_hellotext.default.notInitialized) {
61
- throw new _errors.NotInitializedError();
62
- }
63
- if (this.fetching) return;
64
- if (typeof document === 'undefined' || !('querySelectorAll' in document)) {
65
- return console.warn('Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.');
66
- }
67
- const formsIdsToFetch = _classPrivateFieldLooseBase(this, _formIdsToFetch)[_formIdsToFetch];
68
- if (formsIdsToFetch.length === 0) return;
69
- const promises = formsIdsToFetch.map(id => {
70
- return _forms.default.get(id).then(response => response.json());
71
- });
72
- this.fetching = true;
73
- await Promise.all(promises).then(forms => forms.forEach(this.add)).then(() => _hellotext.default.eventEmitter.dispatch('forms:collected', this)).then(() => this.fetching = false);
74
- if (_core.Configuration.forms.autoMount) {
75
- this.forms.forEach(form => form.mount());
76
- }
77
- }
78
- }, {
79
- key: "forEach",
80
- value: function forEach(callback) {
81
- this.forms.forEach(callback);
27
+ collectExistingFormsOnPage() {
28
+ if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
29
+ this.collect();
82
30
  }
83
- }, {
84
- key: "map",
85
- value: function map(callback) {
86
- return this.forms.map(callback);
87
- }
88
- }, {
89
- key: "add",
90
- value: function add(data) {
91
- if (this.includes(data.id)) return;
92
- if (!_hellotext.default.business.data) {
93
- _hellotext.default.business.setData(data.business);
94
- _hellotext.default.business.setLocale(_core.Locale.toString());
95
- }
96
- if (!_hellotext.default.business.enabledWhitelist) {
97
- console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
98
- }
99
- this.forms.push(new _form.Form(data));
31
+ }
32
+ formMutationObserver(mutations) {
33
+ const mutation = mutations.find(mutation => mutation.type === 'childList' && mutation.addedNodes.length > 0);
34
+ if (!mutation) return;
35
+ if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
36
+ this.collect();
100
37
  }
101
- }, {
102
- key: "getById",
103
- value: function getById(id) {
104
- return this.forms.find(form => form.id === id);
38
+ }
39
+ async collect() {
40
+ if (_hellotext.default.notInitialized) {
41
+ throw new _errors.NotInitializedError();
105
42
  }
106
- }, {
107
- key: "getByIndex",
108
- value: function getByIndex(index) {
109
- return this.forms[index];
43
+ if (this.fetching) return;
44
+ if (typeof document === 'undefined' || !('querySelectorAll' in document)) {
45
+ return console.warn('Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.');
110
46
  }
111
- }, {
112
- key: "includes",
113
- value: function includes(formId) {
114
- return this.forms.some(form => form.id === formId);
47
+ const formsIdsToFetch = this.#formIdsToFetch;
48
+ if (formsIdsToFetch.length === 0) return;
49
+ const promises = formsIdsToFetch.map(id => {
50
+ return _forms.default.get(id).then(response => response.json());
51
+ });
52
+ this.fetching = true;
53
+ await Promise.all(promises).then(forms => forms.forEach(this.add)).then(() => _hellotext.default.eventEmitter.dispatch('forms:collected', this)).then(() => this.fetching = false);
54
+ if (_core.Configuration.forms.autoMount) {
55
+ this.forms.forEach(form => form.mount());
115
56
  }
116
- }, {
117
- key: "excludes",
118
- value: function excludes(id) {
119
- return !this.includes(id);
57
+ }
58
+ forEach(callback) {
59
+ this.forms.forEach(callback);
60
+ }
61
+ map(callback) {
62
+ return this.forms.map(callback);
63
+ }
64
+ add(data) {
65
+ if (this.includes(data.id)) return;
66
+ if (!_hellotext.default.business.data) {
67
+ _hellotext.default.business.setData(data.business);
68
+ _hellotext.default.business.setLocale(_core.Locale.toString());
120
69
  }
121
- }, {
122
- key: "length",
123
- get: function () {
124
- return this.forms.length;
70
+ if (!_hellotext.default.business.enabledWhitelist) {
71
+ console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
125
72
  }
126
- }]);
127
- return FormCollection;
128
- }();
129
- exports.FormCollection = FormCollection;
130
- function _get_formIdsToFetch() {
131
- return Array.from(document.querySelectorAll('[data-hello-form]')).map(form => form.dataset.helloForm).filter(this.excludes);
132
- }
73
+ this.forms.push(new _form.Form(data));
74
+ }
75
+ getById(id) {
76
+ return this.forms.find(form => form.id === id);
77
+ }
78
+ getByIndex(index) {
79
+ return this.forms[index];
80
+ }
81
+ includes(formId) {
82
+ return this.forms.some(form => form.id === formId);
83
+ }
84
+ excludes(id) {
85
+ return !this.includes(id);
86
+ }
87
+ get length() {
88
+ return this.forms.length;
89
+ }
90
+ get #formIdsToFetch() {
91
+ return Array.from(document.querySelectorAll('[data-hello-form]')).map(form => form.dataset.helloForm).filter(this.excludes);
92
+ }
93
+ }
94
+ exports.FormCollection = FormCollection;
@@ -1,26 +1,10 @@
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 _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
9
- var id = 0;
10
- function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
11
1
  import API from '../api/forms';
12
2
  import Hellotext from '../hellotext';
13
3
  import { Configuration, Locale } from '../core';
14
4
  import { Form } from './form';
15
5
  import { NotInitializedError } from '../errors';
16
- var _formIdsToFetch = /*#__PURE__*/_classPrivateFieldLooseKey("formIdsToFetch");
17
- var FormCollection = /*#__PURE__*/function () {
18
- function FormCollection() {
19
- _classCallCheck(this, FormCollection);
20
- Object.defineProperty(this, _formIdsToFetch, {
21
- get: _get_formIdsToFetch,
22
- set: void 0
23
- });
6
+ class FormCollection {
7
+ constructor() {
24
8
  this.forms = [];
25
9
  this.includes = this.includes.bind(this);
26
10
  this.excludes = this.excludes.bind(this);
@@ -33,101 +17,71 @@ var FormCollection = /*#__PURE__*/function () {
33
17
  });
34
18
  }
35
19
  }
36
- _createClass(FormCollection, [{
37
- key: "collectExistingFormsOnPage",
38
- value: function collectExistingFormsOnPage() {
39
- if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
40
- this.collect();
41
- }
42
- }
43
- }, {
44
- key: "formMutationObserver",
45
- value: function formMutationObserver(mutations) {
46
- var mutation = mutations.find(mutation => mutation.type === 'childList' && mutation.addedNodes.length > 0);
47
- if (!mutation) return;
48
- if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
49
- this.collect();
50
- }
51
- }
52
- }, {
53
- key: "collect",
54
- value: function () {
55
- var _collect = _asyncToGenerator(function* () {
56
- if (Hellotext.notInitialized) {
57
- throw new NotInitializedError();
58
- }
59
- if (this.fetching) return;
60
- if (typeof document === 'undefined' || !('querySelectorAll' in document)) {
61
- return console.warn('Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.');
62
- }
63
- var formsIdsToFetch = _classPrivateFieldLooseBase(this, _formIdsToFetch)[_formIdsToFetch];
64
- if (formsIdsToFetch.length === 0) return;
65
- var promises = formsIdsToFetch.map(id => {
66
- return API.get(id).then(response => response.json());
67
- });
68
- this.fetching = true;
69
- yield Promise.all(promises).then(forms => forms.forEach(this.add)).then(() => Hellotext.eventEmitter.dispatch('forms:collected', this)).then(() => this.fetching = false);
70
- if (Configuration.forms.autoMount) {
71
- this.forms.forEach(form => form.mount());
72
- }
73
- });
74
- function collect() {
75
- return _collect.apply(this, arguments);
76
- }
77
- return collect;
78
- }()
79
- }, {
80
- key: "forEach",
81
- value: function forEach(callback) {
82
- this.forms.forEach(callback);
83
- }
84
- }, {
85
- key: "map",
86
- value: function map(callback) {
87
- return this.forms.map(callback);
20
+ collectExistingFormsOnPage() {
21
+ if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
22
+ this.collect();
88
23
  }
89
- }, {
90
- key: "add",
91
- value: function add(data) {
92
- if (this.includes(data.id)) return;
93
- if (!Hellotext.business.data) {
94
- Hellotext.business.setData(data.business);
95
- Hellotext.business.setLocale(Locale.toString());
96
- }
97
- if (!Hellotext.business.enabledWhitelist) {
98
- console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
99
- }
100
- this.forms.push(new Form(data));
24
+ }
25
+ formMutationObserver(mutations) {
26
+ const mutation = mutations.find(mutation => mutation.type === 'childList' && mutation.addedNodes.length > 0);
27
+ if (!mutation) return;
28
+ if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
29
+ this.collect();
101
30
  }
102
- }, {
103
- key: "getById",
104
- value: function getById(id) {
105
- return this.forms.find(form => form.id === id);
31
+ }
32
+ async collect() {
33
+ if (Hellotext.notInitialized) {
34
+ throw new NotInitializedError();
106
35
  }
107
- }, {
108
- key: "getByIndex",
109
- value: function getByIndex(index) {
110
- return this.forms[index];
36
+ if (this.fetching) return;
37
+ if (typeof document === 'undefined' || !('querySelectorAll' in document)) {
38
+ return console.warn('Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.');
111
39
  }
112
- }, {
113
- key: "includes",
114
- value: function includes(formId) {
115
- return this.forms.some(form => form.id === formId);
40
+ const formsIdsToFetch = this.#formIdsToFetch;
41
+ if (formsIdsToFetch.length === 0) return;
42
+ const promises = formsIdsToFetch.map(id => {
43
+ return API.get(id).then(response => response.json());
44
+ });
45
+ this.fetching = true;
46
+ await Promise.all(promises).then(forms => forms.forEach(this.add)).then(() => Hellotext.eventEmitter.dispatch('forms:collected', this)).then(() => this.fetching = false);
47
+ if (Configuration.forms.autoMount) {
48
+ this.forms.forEach(form => form.mount());
116
49
  }
117
- }, {
118
- key: "excludes",
119
- value: function excludes(id) {
120
- return !this.includes(id);
50
+ }
51
+ forEach(callback) {
52
+ this.forms.forEach(callback);
53
+ }
54
+ map(callback) {
55
+ return this.forms.map(callback);
56
+ }
57
+ add(data) {
58
+ if (this.includes(data.id)) return;
59
+ if (!Hellotext.business.data) {
60
+ Hellotext.business.setData(data.business);
61
+ Hellotext.business.setLocale(Locale.toString());
121
62
  }
122
- }, {
123
- key: "length",
124
- get: function get() {
125
- return this.forms.length;
63
+ if (!Hellotext.business.enabledWhitelist) {
64
+ console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
126
65
  }
127
- }]);
128
- return FormCollection;
129
- }();
130
- function _get_formIdsToFetch() {
131
- return Array.from(document.querySelectorAll('[data-hello-form]')).map(form => form.dataset.helloForm).filter(this.excludes);
66
+ this.forms.push(new Form(data));
67
+ }
68
+ getById(id) {
69
+ return this.forms.find(form => form.id === id);
70
+ }
71
+ getByIndex(index) {
72
+ return this.forms[index];
73
+ }
74
+ includes(formId) {
75
+ return this.forms.some(form => form.id === formId);
76
+ }
77
+ excludes(id) {
78
+ return !this.includes(id);
79
+ }
80
+ get length() {
81
+ return this.forms.length;
82
+ }
83
+ get #formIdsToFetch() {
84
+ return Array.from(document.querySelectorAll('[data-hello-form]')).map(form => form.dataset.helloForm).filter(this.excludes);
85
+ }
132
86
  }
133
87
  export { FormCollection };