@hellotext/hellotext 2.0.5 → 2.0.7

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/lib/hellotext.cjs CHANGED
@@ -33,14 +33,17 @@ let Hellotext = /*#__PURE__*/function () {
33
33
  * @param { Configuration } config
34
34
  */
35
35
  async function initialize(business, config) {
36
- this.forms = new _models.FormCollection();
37
- this.business = new _models.Business(business);
38
36
  _core.Configuration.assign(config);
39
37
  _models.Session.initialize();
38
+ this.business = new _models.Business(business);
39
+ this.forms = new _models.FormCollection();
40
40
  _classPrivateFieldLooseBase(this, _query)[_query] = new _models.Query();
41
41
  if (_core.Configuration.webchat.id) {
42
42
  this.webchat = await _models.Webchat.load(_core.Configuration.webchat.id);
43
43
  }
44
+ if (typeof MutationObserver !== 'undefined') {
45
+ this.forms.collectExistingFormsOnPage();
46
+ }
44
47
  }
45
48
 
46
49
  /**
package/lib/hellotext.js CHANGED
@@ -31,14 +31,17 @@ var Hellotext = /*#__PURE__*/function () {
31
31
  */
32
32
  function () {
33
33
  var _initialize = _asyncToGenerator(function* (business, config) {
34
- this.forms = new FormCollection();
35
- this.business = new Business(business);
36
34
  Configuration.assign(config);
37
35
  Session.initialize();
36
+ this.business = new Business(business);
37
+ this.forms = new FormCollection();
38
38
  _classPrivateFieldLooseBase(this, _query)[_query] = new Query();
39
39
  if (Configuration.webchat.id) {
40
40
  this.webchat = yield Webchat.load(Configuration.webchat.id);
41
41
  }
42
+ if (typeof MutationObserver !== 'undefined') {
43
+ this.forms.collectExistingFormsOnPage();
44
+ }
42
45
  });
43
46
  function initialize(_x, _x2) {
44
47
  return _initialize.apply(this, arguments);
@@ -39,12 +39,18 @@ let FormCollection = /*#__PURE__*/function () {
39
39
  }
40
40
  }
41
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
+ }, {
42
49
  key: "formMutationObserver",
43
50
  value: function formMutationObserver(mutations) {
44
51
  const mutation = mutations.find(mutation => mutation.type === 'childList' && mutation.addedNodes.length > 0);
45
52
  if (!mutation) return;
46
- const forms = Array.from(document.querySelectorAll('[data-hello-form]'));
47
- if (forms && _core.Configuration.forms.autoMount) {
53
+ if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
48
54
  this.collect();
49
55
  }
50
56
  }
@@ -83,13 +89,13 @@ let FormCollection = /*#__PURE__*/function () {
83
89
  key: "add",
84
90
  value: function add(data) {
85
91
  if (this.includes(data.id)) return;
86
- this.forms.push(new _form.Form(data));
87
92
  if (!_hellotext.default.business.data) {
88
93
  _hellotext.default.business.setData(data.business);
89
94
  }
90
95
  if (!_hellotext.default.business.enabledWhitelist) {
91
96
  console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
92
97
  }
98
+ this.forms.push(new _form.Form(data));
93
99
  }
94
100
  }, {
95
101
  key: "getById",
@@ -34,12 +34,18 @@ var FormCollection = /*#__PURE__*/function () {
34
34
  }
35
35
  }
36
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
+ }, {
37
44
  key: "formMutationObserver",
38
45
  value: function formMutationObserver(mutations) {
39
46
  var mutation = mutations.find(mutation => mutation.type === 'childList' && mutation.addedNodes.length > 0);
40
47
  if (!mutation) return;
41
- var forms = Array.from(document.querySelectorAll('[data-hello-form]'));
42
- if (forms && Configuration.forms.autoMount) {
48
+ if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
43
49
  this.collect();
44
50
  }
45
51
  }
@@ -84,13 +90,13 @@ var FormCollection = /*#__PURE__*/function () {
84
90
  key: "add",
85
91
  value: function add(data) {
86
92
  if (this.includes(data.id)) return;
87
- this.forms.push(new Form(data));
88
93
  if (!Hellotext.business.data) {
89
94
  Hellotext.business.setData(data.business);
90
95
  }
91
96
  if (!Hellotext.business.enabledWhitelist) {
92
97
  console.warn('No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.');
93
98
  }
99
+ this.forms.push(new Form(data));
94
100
  }
95
101
  }, {
96
102
  key: "getById",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellotext/hellotext",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "Hellotext JavaScript Client",
5
5
  "source": "src/index.js",
6
6
  "main": "lib/index.cjs",
package/src/hellotext.js CHANGED
@@ -20,17 +20,21 @@ class Hellotext {
20
20
  * @param { Configuration } config
21
21
  */
22
22
  static async initialize(business, config) {
23
- this.forms = new FormCollection()
24
- this.business = new Business(business)
25
-
26
23
  Configuration.assign(config)
27
24
  Session.initialize()
28
25
 
26
+ this.business = new Business(business)
27
+ this.forms = new FormCollection()
28
+
29
29
  this.#query = new Query()
30
30
 
31
31
  if (Configuration.webchat.id) {
32
32
  this.webchat = await Webchat.load(Configuration.webchat.id)
33
33
  }
34
+
35
+ if (typeof MutationObserver !== 'undefined') {
36
+ this.forms.collectExistingFormsOnPage()
37
+ }
34
38
  }
35
39
 
36
40
  /**
@@ -21,6 +21,12 @@ class FormCollection {
21
21
  }
22
22
  }
23
23
 
24
+ collectExistingFormsOnPage() {
25
+ if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
26
+ this.collect()
27
+ }
28
+ }
29
+
24
30
  formMutationObserver(mutations) {
25
31
  const mutation = mutations.find(
26
32
  mutation => mutation.type === 'childList' && mutation.addedNodes.length > 0,
@@ -28,9 +34,7 @@ class FormCollection {
28
34
 
29
35
  if (!mutation) return
30
36
 
31
- const forms = Array.from(document.querySelectorAll('[data-hello-form]'))
32
-
33
- if (forms && Configuration.forms.autoMount) {
37
+ if (Array.from(document.querySelectorAll('[data-hello-form]')).length > 0) {
34
38
  this.collect()
35
39
  }
36
40
  }
@@ -78,8 +82,6 @@ class FormCollection {
78
82
  add(data) {
79
83
  if (this.includes(data.id)) return
80
84
 
81
- this.forms.push(new Form(data))
82
-
83
85
  if (!Hellotext.business.data) {
84
86
  Hellotext.business.setData(data.business)
85
87
  }
@@ -89,6 +91,8 @@ class FormCollection {
89
91
  'No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms.',
90
92
  )
91
93
  }
94
+
95
+ this.forms.push(new Form(data))
92
96
  }
93
97
 
94
98
  getById(id) {