@hellotext/hellotext 2.0.8 → 2.1.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/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export interface HellotextConfig {
17
17
  secondaryColor?: string
18
18
  typography?: string
19
19
  }
20
+ strategy?: 'absolute' | 'fixed'
20
21
  }
21
22
  session?: string
22
23
  autoGenerateSession?: boolean
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.usePopover = void 0;
7
7
  var _dom = require("@floating-ui/dom");
8
- var _hellotext = _interopRequireDefault(require("../../hellotext"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ var _core = require("../../core");
10
9
  const usePopover = controller => {
11
10
  Object.assign(controller, {
12
11
  show() {
@@ -25,14 +24,17 @@ const usePopover = controller => {
25
24
  this.floatingUICleanup = (0, _dom.autoUpdate)(trigger, popover, () => {
26
25
  (0, _dom.computePosition)(trigger, popover, {
27
26
  placement: this.placementValue,
28
- middleware: this.middlewares
27
+ middleware: this.middlewares,
28
+ strategy: _core.Configuration.webchat.strategy
29
29
  }).then(({
30
30
  x,
31
- y
31
+ y,
32
+ strategy
32
33
  }) => {
33
34
  const newStyle = {
34
35
  left: `${x}px`,
35
- top: `${y}px`
36
+ top: `${y}px`,
37
+ position: strategy
36
38
  };
37
39
  Object.assign(popover.style, newStyle);
38
40
  });
@@ -42,13 +44,13 @@ const usePopover = controller => {
42
44
  if (this.disabledValue) return;
43
45
  if (this.openValue) {
44
46
  this.popoverTarget.showPopover();
45
- this.popoverTarget.setAttribute("aria-expanded", "true");
47
+ this.popoverTarget.setAttribute('aria-expanded', 'true');
46
48
  if (this['onPopoverOpened']) {
47
49
  this.onPopoverOpened();
48
50
  }
49
51
  } else {
50
52
  this.popoverTarget.hidePopover();
51
- this.popoverTarget.removeAttribute("aria-expanded");
53
+ this.popoverTarget.removeAttribute('aria-expanded');
52
54
  if (this['onPopoverClosed']) {
53
55
  this.onPopoverClosed();
54
56
  }
@@ -1,5 +1,5 @@
1
1
  import { autoUpdate, computePosition } from '@floating-ui/dom';
2
- import Hellotext from "../../hellotext";
2
+ import { Configuration } from '../../core';
3
3
  export var usePopover = controller => {
4
4
  Object.assign(controller, {
5
5
  show() {
@@ -19,15 +19,18 @@ export var usePopover = controller => {
19
19
  this.floatingUICleanup = autoUpdate(trigger, popover, () => {
20
20
  computePosition(trigger, popover, {
21
21
  placement: this.placementValue,
22
- middleware: this.middlewares
22
+ middleware: this.middlewares,
23
+ strategy: Configuration.webchat.strategy
23
24
  }).then(_ref2 => {
24
25
  var {
25
26
  x,
26
- y
27
+ y,
28
+ strategy
27
29
  } = _ref2;
28
30
  var newStyle = {
29
31
  left: "".concat(x, "px"),
30
- top: "".concat(y, "px")
32
+ top: "".concat(y, "px"),
33
+ position: strategy
31
34
  };
32
35
  Object.assign(popover.style, newStyle);
33
36
  });
@@ -37,13 +40,13 @@ export var usePopover = controller => {
37
40
  if (this.disabledValue) return;
38
41
  if (this.openValue) {
39
42
  this.popoverTarget.showPopover();
40
- this.popoverTarget.setAttribute("aria-expanded", "true");
43
+ this.popoverTarget.setAttribute('aria-expanded', 'true');
41
44
  if (this['onPopoverOpened']) {
42
45
  this.onPopoverOpened();
43
46
  }
44
47
  } else {
45
48
  this.popoverTarget.hidePopover();
46
- this.popoverTarget.removeAttribute("aria-expanded");
49
+ this.popoverTarget.removeAttribute('aria-expanded');
47
50
  if (this['onPopoverClosed']) {
48
51
  this.onPopoverClosed();
49
52
  }
@@ -24,6 +24,20 @@ const placements = {
24
24
  BOTTOM_RIGHT: 'bottom-right'
25
25
  };
26
26
 
27
+ /**
28
+ * @typedef {'absolute' | 'fixed'} Strategy
29
+ * @description Valid strategies for the webchat.
30
+ */
31
+
32
+ /**
33
+ * @enum {Strategy}
34
+ */
35
+
36
+ const strategies = {
37
+ ABSOLUTE: 'absolute',
38
+ FIXED: 'fixed'
39
+ };
40
+
27
41
  /**
28
42
  * @typedef {'modal' | 'popover'} Behaviour
29
43
  */
@@ -54,6 +68,7 @@ const behaviors = {
54
68
  * @property {String} triggerClasses - additional classes to apply to the webchat popup trigger.
55
69
  * @property {Behaviour} behaviour - the behaviour of the webchat, defaults to 'popover'.
56
70
  * @property {Style} style - the style of the webchat.
71
+ * @property {Strategy} strategy - the strategy used to position the webchat. Defaults to 'absolute'
57
72
  */
58
73
  exports.behaviors = behaviors;
59
74
  let Webchat = /*#__PURE__*/function () {
@@ -155,6 +170,20 @@ let Webchat = /*#__PURE__*/function () {
155
170
  }
156
171
  this._behaviour = value;
157
172
  }
173
+ }, {
174
+ key: "strategy",
175
+ get: function () {
176
+ if (this._strategy) {
177
+ return this._strategy;
178
+ }
179
+ return this.container == 'body' ? strategies.FIXED : strategies.ABSOLUTE;
180
+ },
181
+ set: function (value) {
182
+ if (value && !Object.values(strategies).includes(value)) {
183
+ throw new Error(`Invalid strategy value: ${value}`);
184
+ }
185
+ this._strategy = value;
186
+ }
158
187
  }, {
159
188
  key: "assign",
160
189
  value: function assign(props) {
@@ -180,4 +209,5 @@ Webchat._placement = 'bottom-right';
180
209
  Webchat._classes = [];
181
210
  Webchat._triggerClasses = [];
182
211
  Webchat._style = {};
183
- Webchat._behaviour = behaviors.POPOVER;
212
+ Webchat._behaviour = behaviors.POPOVER;
213
+ Webchat._strategy = null;
@@ -18,6 +18,20 @@ var placements = {
18
18
  BOTTOM_RIGHT: 'bottom-right'
19
19
  };
20
20
 
21
+ /**
22
+ * @typedef {'absolute' | 'fixed'} Strategy
23
+ * @description Valid strategies for the webchat.
24
+ */
25
+
26
+ /**
27
+ * @enum {Strategy}
28
+ */
29
+
30
+ var strategies = {
31
+ ABSOLUTE: 'absolute',
32
+ FIXED: 'fixed'
33
+ };
34
+
21
35
  /**
22
36
  * @typedef {'modal' | 'popover'} Behaviour
23
37
  */
@@ -48,6 +62,7 @@ var behaviors = {
48
62
  * @property {String} triggerClasses - additional classes to apply to the webchat popup trigger.
49
63
  * @property {Behaviour} behaviour - the behaviour of the webchat, defaults to 'popover'.
50
64
  * @property {Style} style - the style of the webchat.
65
+ * @property {Strategy} strategy - the strategy used to position the webchat. Defaults to 'absolute'
51
66
  */
52
67
  var Webchat = /*#__PURE__*/function () {
53
68
  function Webchat() {
@@ -149,6 +164,20 @@ var Webchat = /*#__PURE__*/function () {
149
164
  }
150
165
  this._behaviour = value;
151
166
  }
167
+ }, {
168
+ key: "strategy",
169
+ get: function get() {
170
+ if (this._strategy) {
171
+ return this._strategy;
172
+ }
173
+ return this.container == 'body' ? strategies.FIXED : strategies.ABSOLUTE;
174
+ },
175
+ set: function set(value) {
176
+ if (value && !Object.values(strategies).includes(value)) {
177
+ throw new Error("Invalid strategy value: ".concat(value));
178
+ }
179
+ this._strategy = value;
180
+ }
152
181
  }, {
153
182
  key: "assign",
154
183
  value: function assign(props) {
@@ -175,4 +204,5 @@ Webchat._classes = [];
175
204
  Webchat._triggerClasses = [];
176
205
  Webchat._style = {};
177
206
  Webchat._behaviour = behaviors.POPOVER;
178
- export { Webchat, behaviors };
207
+ Webchat._strategy = null;
208
+ export { behaviors, Webchat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellotext/hellotext",
3
- "version": "2.0.8",
3
+ "version": "2.1.0",
4
4
  "description": "Hellotext JavaScript Client",
5
5
  "source": "src/index.js",
6
6
  "main": "lib/index.cjs",
@@ -91,7 +91,7 @@
91
91
  "url": "https://github.com/hellotext/hellotext.js/issues"
92
92
  },
93
93
  "dependencies": {
94
- "@floating-ui/dom": "^1.6.12",
94
+ "@floating-ui/dom": "^1.7.3",
95
95
  "@hotwired/stimulus": "^3.0.0",
96
96
  "emoji-mart": "^5.6.0"
97
97
  },
@@ -1,7 +1,7 @@
1
1
  import { autoUpdate, computePosition } from '@floating-ui/dom'
2
- import Hellotext from "../../hellotext";
2
+ import { Configuration } from '../../core'
3
3
 
4
- export const usePopover = (controller) => {
4
+ export const usePopover = controller => {
5
5
  Object.assign(controller, {
6
6
  show() {
7
7
  this.openValue = true
@@ -17,34 +17,36 @@ export const usePopover = (controller) => {
17
17
  computePosition(trigger, popover, {
18
18
  placement: this.placementValue,
19
19
  middleware: this.middlewares,
20
- }).then(({x, y}) => {
20
+ strategy: Configuration.webchat.strategy,
21
+ }).then(({ x, y, strategy }) => {
21
22
  const newStyle = {
22
23
  left: `${x}px`,
23
- top: `${y}px`
24
+ top: `${y}px`,
25
+ position: strategy,
24
26
  }
25
27
 
26
28
  Object.assign(popover.style, newStyle)
27
- });
29
+ })
28
30
  })
29
31
  },
30
32
  openValueChanged() {
31
- if(this.disabledValue) return
33
+ if (this.disabledValue) return
32
34
 
33
- if(this.openValue) {
35
+ if (this.openValue) {
34
36
  this.popoverTarget.showPopover()
35
- this.popoverTarget.setAttribute("aria-expanded", "true")
37
+ this.popoverTarget.setAttribute('aria-expanded', 'true')
36
38
 
37
- if(this['onPopoverOpened']) {
39
+ if (this['onPopoverOpened']) {
38
40
  this.onPopoverOpened()
39
41
  }
40
42
  } else {
41
43
  this.popoverTarget.hidePopover()
42
- this.popoverTarget.removeAttribute("aria-expanded")
44
+ this.popoverTarget.removeAttribute('aria-expanded')
43
45
 
44
- if(this['onPopoverClosed']) {
46
+ if (this['onPopoverClosed']) {
45
47
  this.onPopoverClosed()
46
48
  }
47
49
  }
48
- }
50
+ },
49
51
  })
50
52
  }
@@ -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 /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value) || /^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(value);
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 { Webchat, behaviors }
209
+ export { behaviors, Webchat }