@hellotext/hellotext 2.5.7 → 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.
- package/README.md +0 -25
- package/dist/hellotext.js +1 -1
- package/index.d.ts +0 -6
- package/lib/api/acks.cjs +17 -31
- package/lib/api/acks.js +17 -42
- package/lib/api/businesses.cjs +14 -28
- package/lib/api/businesses.js +13 -36
- package/lib/api/events.cjs +26 -40
- package/lib/api/events.js +28 -52
- package/lib/api/forms.cjs +24 -40
- package/lib/api/forms.js +24 -57
- package/lib/api/identifications.cjs +15 -29
- package/lib/api/identifications.js +15 -40
- package/lib/api/index.cjs +25 -51
- package/lib/api/index.js +27 -54
- package/lib/api/push/identities.cjs +30 -46
- package/lib/api/push/identities.js +30 -63
- package/lib/api/response.cjs +30 -52
- package/lib/api/response.js +31 -60
- package/lib/api/submissions.cjs +18 -34
- package/lib/api/submissions.js +18 -48
- package/lib/api/webchat/messages.cjs +44 -64
- package/lib/api/webchat/messages.js +44 -80
- package/lib/api/webchats.cjs +37 -56
- package/lib/api/webchats.js +37 -65
- package/lib/api/whatsapp_widgets.cjs +49 -72
- package/lib/api/whatsapp_widgets.js +48 -91
- package/lib/builders/input_builder.cjs +36 -48
- package/lib/builders/input_builder.js +36 -48
- package/lib/builders/logo_builder.cjs +10 -29
- package/lib/builders/logo_builder.js +20 -28
- package/lib/channels/application_channel.cjs +136 -178
- package/lib/channels/application_channel.js +137 -180
- package/lib/channels/webchat_channel.cjs +125 -170
- package/lib/channels/webchat_channel.js +125 -170
- package/lib/controllers/form_controller.cjs +82 -121
- package/lib/controllers/form_controller.js +82 -130
- package/lib/controllers/message_controller.cjs +211 -282
- package/lib/controllers/message_controller.js +209 -284
- package/lib/controllers/mixins/usePopover.cjs +3 -6
- package/lib/controllers/mixins/usePopover.js +17 -22
- package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
- package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
- package/lib/controllers/webchat/useBehaviour.js +5 -5
- package/lib/controllers/webchat/useOpeningSequence.js +6 -6
- package/lib/controllers/webchat/useTeaser.js +9 -9
- package/lib/controllers/webchat_controller.cjs +916 -1088
- package/lib/controllers/webchat_controller.js +926 -1152
- package/lib/core/configuration/forms.cjs +21 -35
- package/lib/core/configuration/forms.js +20 -35
- package/lib/core/configuration/locale.cjs +36 -71
- package/lib/core/configuration/locale.js +36 -70
- package/lib/core/configuration/push.cjs +9 -21
- package/lib/core/configuration/push.js +8 -20
- package/lib/core/configuration/webchat.cjs +142 -182
- package/lib/core/configuration/webchat.js +145 -189
- package/lib/core/configuration/whatsapp.cjs +76 -102
- package/lib/core/configuration/whatsapp.js +76 -105
- package/lib/core/configuration.cjs +60 -78
- package/lib/core/configuration.js +59 -78
- package/lib/core/event.cjs +36 -59
- package/lib/core/event.js +35 -61
- package/lib/core/sanitize_html.js +4 -4
- package/lib/errors/invalid_event.cjs +5 -26
- package/lib/errors/invalid_event.js +5 -26
- package/lib/errors/not_initialized_error.cjs +5 -26
- package/lib/errors/not_initialized_error.js +5 -26
- package/lib/hellotext.cjs +185 -223
- package/lib/hellotext.js +188 -247
- package/lib/index.js +1 -1
- package/lib/models/business.cjs +114 -152
- package/lib/models/business.js +117 -162
- package/lib/models/cookies.cjs +34 -51
- package/lib/models/cookies.js +34 -51
- package/lib/models/fingerprint.cjs +8 -23
- package/lib/models/fingerprint.js +25 -58
- package/lib/models/form.cjs +106 -142
- package/lib/models/form.js +105 -153
- package/lib/models/form_collection.cjs +63 -101
- package/lib/models/form_collection.js +61 -107
- package/lib/models/page.cjs +106 -129
- package/lib/models/page.js +106 -131
- package/lib/models/push.cjs +278 -322
- package/lib/models/push.js +284 -357
- package/lib/models/query.cjs +21 -41
- package/lib/models/query.js +21 -41
- package/lib/models/session.cjs +33 -65
- package/lib/models/session.js +30 -63
- package/lib/models/user.cjs +29 -51
- package/lib/models/user.js +29 -51
- package/lib/models/utm.cjs +15 -27
- package/lib/models/utm.js +17 -32
- package/lib/models/webchat.cjs +52 -76
- package/lib/models/webchat.js +52 -90
- package/lib/models/whatsapp_widget.cjs +41 -59
- package/lib/models/whatsapp_widget.js +41 -73
- package/lib/vanilla.cjs +4 -7
- package/lib/vanilla.js +2 -1
- package/package.json +1 -9
- package/src/index.bundle.js +0 -1
- package/src/vanilla.js +2 -1
- package/styles/index.css +0 -30
package/lib/models/form.js
CHANGED
|
@@ -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
|
-
|
|
19
|
-
|
|
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(
|
|
8
|
+
this.element = element || document.querySelector(`[data-hello-form="${this.id}"]`) || document.createElement('form');
|
|
28
9
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
38
|
+
}
|
|
39
|
+
async collect() {
|
|
40
|
+
if (_hellotext.default.notInitialized) {
|
|
41
|
+
throw new _errors.NotInitializedError();
|
|
105
42
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
return
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
31
|
+
}
|
|
32
|
+
async collect() {
|
|
33
|
+
if (Hellotext.notInitialized) {
|
|
34
|
+
throw new NotInitializedError();
|
|
106
35
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
return
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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 };
|