@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.
- package/README.md +1 -0
- package/dist/hellotext.js +1 -1
- package/index.d.ts +18 -0
- package/lib/api/index.cjs +6 -0
- package/lib/api/index.js +6 -0
- package/lib/api/whatsapp_widgets.cjs +87 -0
- package/lib/api/whatsapp_widgets.js +99 -0
- package/lib/core/configuration/whatsapp.cjs +150 -0
- package/lib/core/configuration/whatsapp.js +147 -0
- package/lib/core/configuration.cjs +6 -1
- package/lib/core/configuration.js +5 -0
- package/lib/core/index.cjs +7 -0
- package/lib/core/index.js +1 -0
- package/lib/hellotext.cjs +11 -0
- package/lib/hellotext.js +12 -1
- package/lib/models/index.cjs +8 -1
- package/lib/models/index.js +2 -1
- package/lib/models/webchat.cjs +10 -0
- package/lib/models/webchat.js +10 -0
- package/lib/models/whatsapp_widget.cjs +77 -0
- package/lib/models/whatsapp_widget.js +84 -0
- package/package.json +1 -1
- package/src/api/index.js +5 -0
- package/src/api/whatsapp_widgets.js +71 -0
- package/src/core/configuration/whatsapp.js +143 -0
- package/src/core/configuration.js +5 -0
- package/src/core/index.js +1 -0
- package/src/hellotext.js +18 -0
- package/src/models/index.js +1 -0
- package/src/models/webchat.js +11 -0
- package/src/models/whatsapp_widget.js +68 -0
package/src/models/webchat.js
CHANGED
|
@@ -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 }
|