@hellotext/hellotext 2.4.53 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,7 @@ class Webchat {
30
30
  }
31
31
 
32
32
  this.containerToAppendTo.appendChild(this.data.html)
33
+ this.markCoexistingWidgets()
33
34
  this.mounted = true
34
35
 
35
36
  return true
@@ -69,6 +70,16 @@ class Webchat {
69
70
  get stylesheetLoaded() {
70
71
  return Business.waitForStylesheet(Business.latestStylesheet)
71
72
  }
73
+
74
+ markCoexistingWidgets() {
75
+ const webchat = this.data.html
76
+ const whatsapp = document.querySelector('.hellotext--whatsapp-widget')
77
+
78
+ if (!webchat || !whatsapp) return
79
+
80
+ webchat.classList.add('hellotext--with-whatsapp-widget')
81
+ whatsapp.classList.add('hellotext--with-webchat')
82
+ }
72
83
  }
73
84
 
74
85
  export { Webchat }
@@ -0,0 +1,68 @@
1
+ import { Configuration } from '../core'
2
+
3
+ import API from '../api'
4
+ import { Business } from './business'
5
+
6
+ class WhatsAppWidget {
7
+ static async load(id) {
8
+ const widget = new WhatsAppWidget({
9
+ id,
10
+ html: await API.whatsappWidgets.get(id)
11
+ })
12
+
13
+ widget.rendered = widget.render()
14
+
15
+ return widget
16
+ }
17
+
18
+ constructor(data) {
19
+ this.data = data
20
+ this.mounted = false
21
+ this.rendered = Promise.resolve(false)
22
+ }
23
+
24
+ async render() {
25
+ if (!this.data.html) return false
26
+
27
+ const container = this.containerToAppendTo
28
+ if (!container) {
29
+ console.warn(`Hellotext WhatsApp widget was not mounted because the container ${Configuration.whatsapp.container} was not found.`)
30
+ return false
31
+ }
32
+
33
+ if (!await this.stylesheetLoaded) {
34
+ console.warn('Hellotext WhatsApp widget was not mounted because its stylesheet failed to load.')
35
+ return false
36
+ }
37
+
38
+ container.appendChild(this.data.html)
39
+ this.markCoexistingWidgets()
40
+ this.mounted = true
41
+
42
+ return true
43
+ }
44
+
45
+ get containerToAppendTo() {
46
+ try {
47
+ return document.querySelector(Configuration.whatsapp.container)
48
+ } catch (_) {
49
+ return null
50
+ }
51
+ }
52
+
53
+ get stylesheetLoaded() {
54
+ return Business.waitForStylesheet(Business.latestStylesheet)
55
+ }
56
+
57
+ markCoexistingWidgets() {
58
+ const webchat = document.querySelector('.hellotext--webchat:not(.hellotext--whatsapp-widget)')
59
+ const whatsapp = this.data.html
60
+
61
+ if (!webchat || !whatsapp) return
62
+
63
+ webchat.classList.add('hellotext--with-whatsapp-widget')
64
+ whatsapp.classList.add('hellotext--with-webchat')
65
+ }
66
+ }
67
+
68
+ export { WhatsAppWidget }