@hellotext/hellotext 2.0.9 → 2.1.1
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/dist/hellotext.js +1 -1
- package/index.d.ts +1 -0
- package/lib/controllers/mixins/usePopover.cjs +9 -7
- package/lib/controllers/mixins/usePopover.js +9 -6
- package/lib/controllers/webchat_controller.cjs +39 -0
- package/lib/controllers/webchat_controller.js +39 -0
- package/lib/core/configuration/webchat.cjs +31 -1
- package/lib/core/configuration/webchat.js +31 -1
- package/package.json +1 -1
- package/src/controllers/mixins/usePopover.js +14 -12
- package/src/controllers/webchat_controller.js +43 -0
- package/src/core/configuration/webchat.js +53 -20
|
@@ -10,9 +10,22 @@ const placements = {
|
|
|
10
10
|
TOP_LEFT: 'top-left',
|
|
11
11
|
TOP_RIGHT: 'top-right',
|
|
12
12
|
BOTTOM_LEFT: 'bottom-left',
|
|
13
|
-
BOTTOM_RIGHT: 'bottom-right'
|
|
13
|
+
BOTTOM_RIGHT: 'bottom-right',
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {'absolute' | 'fixed'} Strategy
|
|
18
|
+
* @description Valid strategies for the webchat.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @enum {Strategy}
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const strategies = {
|
|
26
|
+
ABSOLUTE: 'absolute',
|
|
27
|
+
FIXED: 'fixed',
|
|
28
|
+
}
|
|
16
29
|
|
|
17
30
|
/**
|
|
18
31
|
* @typedef {'modal' | 'popover'} Behaviour
|
|
@@ -23,7 +36,7 @@ const placements = {
|
|
|
23
36
|
*/
|
|
24
37
|
const behaviors = {
|
|
25
38
|
MODAL: 'modal',
|
|
26
|
-
POPOVER: 'popover'
|
|
39
|
+
POPOVER: 'popover',
|
|
27
40
|
}
|
|
28
41
|
|
|
29
42
|
/**
|
|
@@ -33,7 +46,6 @@ const behaviors = {
|
|
|
33
46
|
* @property {string} typography - The typography style (e.g., font family).
|
|
34
47
|
*/
|
|
35
48
|
|
|
36
|
-
|
|
37
49
|
/**
|
|
38
50
|
* @class Webchat
|
|
39
51
|
* @classdesc
|
|
@@ -45,6 +57,7 @@ const behaviors = {
|
|
|
45
57
|
* @property {String} triggerClasses - additional classes to apply to the webchat popup trigger.
|
|
46
58
|
* @property {Behaviour} behaviour - the behaviour of the webchat, defaults to 'popover'.
|
|
47
59
|
* @property {Style} style - the style of the webchat.
|
|
60
|
+
* @property {Strategy} strategy - the strategy used to position the webchat. Defaults to 'absolute'
|
|
48
61
|
*/
|
|
49
62
|
|
|
50
63
|
class Webchat {
|
|
@@ -55,6 +68,7 @@ class Webchat {
|
|
|
55
68
|
static _triggerClasses = []
|
|
56
69
|
static _style = {}
|
|
57
70
|
static _behaviour = behaviors.POPOVER
|
|
71
|
+
static _strategy = null
|
|
58
72
|
|
|
59
73
|
static set container(value) {
|
|
60
74
|
this._container = value
|
|
@@ -65,7 +79,7 @@ class Webchat {
|
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
static set placement(value) {
|
|
68
|
-
if(!Object.values(placements).includes(value)) {
|
|
82
|
+
if (!Object.values(placements).includes(value)) {
|
|
69
83
|
throw new Error(`Invalid placement value: ${value}`)
|
|
70
84
|
}
|
|
71
85
|
|
|
@@ -77,34 +91,34 @@ class Webchat {
|
|
|
77
91
|
}
|
|
78
92
|
|
|
79
93
|
static set classes(value) {
|
|
80
|
-
if(!Array.isArray(value) && typeof value !== 'string') {
|
|
94
|
+
if (!Array.isArray(value) && typeof value !== 'string') {
|
|
81
95
|
throw new Error('classes must be an array or a string')
|
|
82
96
|
}
|
|
83
97
|
|
|
84
|
-
this._classes = value
|
|
98
|
+
this._classes = value
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
static get classes() {
|
|
88
|
-
if(typeof this._classes === 'string') {
|
|
102
|
+
if (typeof this._classes === 'string') {
|
|
89
103
|
return this._classes.split(',').map(c => c.trim())
|
|
90
104
|
} else {
|
|
91
|
-
return this._classes
|
|
105
|
+
return this._classes
|
|
92
106
|
}
|
|
93
107
|
}
|
|
94
108
|
|
|
95
109
|
static set triggerClasses(value) {
|
|
96
|
-
if(!Array.isArray(value) && typeof value !== 'string') {
|
|
110
|
+
if (!Array.isArray(value) && typeof value !== 'string') {
|
|
97
111
|
throw new Error('triggerClasses must be an array or a string')
|
|
98
112
|
}
|
|
99
113
|
|
|
100
|
-
this._triggerClasses = value
|
|
114
|
+
this._triggerClasses = value
|
|
101
115
|
}
|
|
102
116
|
|
|
103
117
|
static get triggerClasses() {
|
|
104
|
-
if(typeof this._triggerClasses === 'string') {
|
|
118
|
+
if (typeof this._triggerClasses === 'string') {
|
|
105
119
|
return this._triggerClasses.split(',').map(c => c.trim())
|
|
106
120
|
} else {
|
|
107
|
-
return this._triggerClasses
|
|
121
|
+
return this._triggerClasses
|
|
108
122
|
}
|
|
109
123
|
}
|
|
110
124
|
|
|
@@ -125,20 +139,20 @@ class Webchat {
|
|
|
125
139
|
}
|
|
126
140
|
|
|
127
141
|
static set style(value) {
|
|
128
|
-
if(typeof value !== 'object') {
|
|
142
|
+
if (typeof value !== 'object') {
|
|
129
143
|
throw new Error('Style must be an object')
|
|
130
144
|
}
|
|
131
145
|
|
|
132
146
|
Object.entries(value).forEach(([key, value]) => {
|
|
133
|
-
if(!['primaryColor', 'secondaryColor', 'typography'].includes(key)) {
|
|
147
|
+
if (!['primaryColor', 'secondaryColor', 'typography'].includes(key)) {
|
|
134
148
|
throw new Error(`Invalid style property: ${key}`)
|
|
135
149
|
}
|
|
136
150
|
|
|
137
|
-
if(key === 'typography') {
|
|
151
|
+
if (key === 'typography') {
|
|
138
152
|
return
|
|
139
153
|
}
|
|
140
154
|
|
|
141
|
-
if(!this.isHexOrRgba(value)) {
|
|
155
|
+
if (!this.isHexOrRgba(value)) {
|
|
142
156
|
throw new Error(`Invalid color value: ${value} for ${key}. Colors must be hex or rgb/a.`)
|
|
143
157
|
}
|
|
144
158
|
})
|
|
@@ -151,15 +165,31 @@ class Webchat {
|
|
|
151
165
|
}
|
|
152
166
|
|
|
153
167
|
static set behaviour(value) {
|
|
154
|
-
if(!Object.values(behaviors).includes(value)) {
|
|
168
|
+
if (!Object.values(behaviors).includes(value)) {
|
|
155
169
|
throw new Error(`Invalid behaviour value: ${value}`)
|
|
156
170
|
}
|
|
157
171
|
|
|
158
172
|
this._behaviour = value
|
|
159
173
|
}
|
|
160
174
|
|
|
175
|
+
static get strategy() {
|
|
176
|
+
if (this._strategy) {
|
|
177
|
+
return this._strategy
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return this.container == 'body' ? strategies.FIXED : strategies.ABSOLUTE
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static set strategy(value) {
|
|
184
|
+
if (value && !Object.values(strategies).includes(value)) {
|
|
185
|
+
throw new Error(`Invalid strategy value: ${value}`)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this._strategy = value
|
|
189
|
+
}
|
|
190
|
+
|
|
161
191
|
static assign(props) {
|
|
162
|
-
if(props) {
|
|
192
|
+
if (props) {
|
|
163
193
|
Object.entries(props).forEach(([key, value]) => {
|
|
164
194
|
this[key] = value
|
|
165
195
|
})
|
|
@@ -169,8 +199,11 @@ class Webchat {
|
|
|
169
199
|
}
|
|
170
200
|
|
|
171
201
|
static isHexOrRgba(value) {
|
|
172
|
-
return
|
|
202
|
+
return (
|
|
203
|
+
/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value) ||
|
|
204
|
+
/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(value)
|
|
205
|
+
)
|
|
173
206
|
}
|
|
174
207
|
}
|
|
175
208
|
|
|
176
|
-
export {
|
|
209
|
+
export { behaviors, Webchat }
|