@hellotext/hellotext 2.5.6 → 2.5.8
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 +5 -26
- package/dist/hellotext.js +1 -1
- package/dist/hellotext.js.LICENSE.txt +1 -1
- package/index.d.ts +15 -6
- package/lib/api/acks.cjs +17 -31
- package/lib/api/acks.js +17 -42
- package/lib/api/businesses.cjs +14 -28
- package/lib/api/businesses.js +13 -36
- package/lib/api/events.cjs +26 -40
- package/lib/api/events.js +28 -52
- package/lib/api/forms.cjs +24 -40
- package/lib/api/forms.js +24 -57
- package/lib/api/identifications.cjs +15 -29
- package/lib/api/identifications.js +15 -40
- package/lib/api/index.cjs +26 -46
- package/lib/api/index.js +28 -49
- package/lib/api/push/identities.cjs +43 -0
- package/lib/api/push/identities.js +35 -0
- package/lib/api/response.cjs +30 -52
- package/lib/api/response.js +31 -60
- package/lib/api/submissions.cjs +18 -34
- package/lib/api/submissions.js +18 -48
- package/lib/api/webchat/messages.cjs +44 -64
- package/lib/api/webchat/messages.js +44 -80
- package/lib/api/webchats.cjs +37 -56
- package/lib/api/webchats.js +37 -65
- package/lib/api/whatsapp_widgets.cjs +49 -72
- package/lib/api/whatsapp_widgets.js +48 -91
- package/lib/builders/input_builder.cjs +36 -48
- package/lib/builders/input_builder.js +36 -48
- package/lib/builders/logo_builder.cjs +10 -29
- package/lib/builders/logo_builder.js +20 -28
- package/lib/channels/application_channel.cjs +136 -178
- package/lib/channels/application_channel.js +137 -180
- package/lib/channels/webchat_channel.cjs +125 -170
- package/lib/channels/webchat_channel.js +125 -170
- package/lib/controllers/form_controller.cjs +82 -121
- package/lib/controllers/form_controller.js +82 -130
- package/lib/controllers/message_controller.cjs +211 -282
- package/lib/controllers/message_controller.js +209 -284
- package/lib/controllers/mixins/usePopover.cjs +3 -6
- package/lib/controllers/mixins/usePopover.js +17 -22
- package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
- package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
- package/lib/controllers/webchat/useBehaviour.js +5 -5
- package/lib/controllers/webchat/useOpeningSequence.js +6 -6
- package/lib/controllers/webchat/useTeaser.js +9 -9
- package/lib/controllers/webchat_controller.cjs +916 -1088
- package/lib/controllers/webchat_controller.js +926 -1152
- package/lib/core/configuration/forms.cjs +21 -35
- package/lib/core/configuration/forms.js +20 -35
- package/lib/core/configuration/locale.cjs +36 -71
- package/lib/core/configuration/locale.js +36 -70
- package/lib/core/configuration/push.cjs +16 -0
- package/lib/core/configuration/push.js +10 -0
- package/lib/core/configuration/webchat.cjs +142 -182
- package/lib/core/configuration/webchat.js +145 -189
- package/lib/core/configuration/whatsapp.cjs +76 -102
- package/lib/core/configuration/whatsapp.js +76 -105
- package/lib/core/configuration.cjs +62 -75
- package/lib/core/configuration.js +61 -75
- package/lib/core/event.cjs +36 -59
- package/lib/core/event.js +35 -61
- package/lib/core/sanitize_html.js +4 -4
- package/lib/errors/invalid_event.cjs +5 -26
- package/lib/errors/invalid_event.js +5 -26
- package/lib/errors/not_initialized_error.cjs +5 -26
- package/lib/errors/not_initialized_error.js +5 -26
- package/lib/hellotext.cjs +186 -211
- package/lib/hellotext.js +189 -236
- package/lib/index.js +1 -1
- package/lib/models/business.cjs +115 -152
- package/lib/models/business.js +118 -162
- package/lib/models/cookies.cjs +34 -51
- package/lib/models/cookies.js +34 -51
- package/lib/models/fingerprint.cjs +8 -23
- package/lib/models/fingerprint.js +25 -58
- package/lib/models/form.cjs +106 -142
- package/lib/models/form.js +105 -153
- package/lib/models/form_collection.cjs +63 -101
- package/lib/models/form_collection.js +61 -107
- package/lib/models/index.cjs +7 -0
- package/lib/models/index.js +1 -0
- package/lib/models/page.cjs +106 -129
- package/lib/models/page.js +106 -131
- package/lib/models/push.cjs +345 -0
- package/lib/models/push.js +339 -0
- package/lib/models/query.cjs +21 -41
- package/lib/models/query.js +21 -41
- package/lib/models/session.cjs +33 -65
- package/lib/models/session.js +30 -63
- package/lib/models/user.cjs +29 -51
- package/lib/models/user.js +29 -51
- package/lib/models/utm.cjs +15 -27
- package/lib/models/utm.js +17 -32
- package/lib/models/webchat.cjs +52 -76
- package/lib/models/webchat.js +52 -90
- package/lib/models/whatsapp_widget.cjs +41 -59
- package/lib/models/whatsapp_widget.js +41 -73
- package/lib/vanilla.cjs +4 -7
- package/lib/vanilla.js +2 -1
- package/package.json +2 -10
- package/src/api/index.js +5 -0
- package/src/api/push/identities.js +42 -0
- package/src/core/configuration/push.js +12 -0
- package/src/core/configuration.js +5 -0
- package/src/hellotext.js +15 -1
- package/src/index.bundle.js +0 -1
- package/src/models/business.js +1 -0
- package/src/models/index.js +1 -0
- package/src/models/push.js +397 -0
- package/src/vanilla.js +2 -1
- package/styles/index.css +0 -30
|
@@ -1,292 +1,217 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
6
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
8
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
9
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
10
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
13
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
14
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
15
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
16
1
|
import { Controller } from '@hotwired/stimulus';
|
|
17
2
|
import Hellotext from '../hellotext';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static values = {
|
|
5
|
+
fadeDistance: {
|
|
6
|
+
type: Number,
|
|
7
|
+
default: 64
|
|
8
|
+
},
|
|
9
|
+
id: String,
|
|
10
|
+
kind: String,
|
|
11
|
+
pageStartOffset: {
|
|
12
|
+
type: Number,
|
|
13
|
+
default: 0
|
|
14
|
+
},
|
|
15
|
+
utm: Object
|
|
16
|
+
};
|
|
17
|
+
static targets = ['carouselContainer', 'leftFade', 'rightFade', 'carouselCard'];
|
|
18
|
+
connect() {
|
|
19
|
+
this.updateFades();
|
|
20
|
+
this.observeContainerSize();
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
value: function addToCart(_ref3) {
|
|
73
|
-
var {
|
|
74
|
-
currentTarget
|
|
75
|
-
} = _ref3;
|
|
76
|
-
var card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]');
|
|
77
|
-
var {
|
|
78
|
-
id,
|
|
79
|
-
reference,
|
|
80
|
-
source
|
|
81
|
-
} = card.dataset;
|
|
82
|
-
var item = {
|
|
83
|
-
product: id,
|
|
84
|
-
quantity: 1
|
|
85
|
-
};
|
|
86
|
-
if (this.hasUtmValue) Hellotext.page.utm.save(this.utmValue);
|
|
87
|
-
Hellotext.eventEmitter.dispatch('cart.added', {
|
|
88
|
-
object_parameters: {
|
|
89
|
-
items: [_objectSpread(_objectSpread(_objectSpread({}, item), reference && {
|
|
22
|
+
disconnect() {
|
|
23
|
+
this.resizeObserver?.disconnect();
|
|
24
|
+
}
|
|
25
|
+
setId({
|
|
26
|
+
detail: id
|
|
27
|
+
}) {
|
|
28
|
+
this.idValue = id;
|
|
29
|
+
this.element.id = id;
|
|
30
|
+
}
|
|
31
|
+
onScroll() {
|
|
32
|
+
this.updateFades();
|
|
33
|
+
}
|
|
34
|
+
quickReply({
|
|
35
|
+
currentTarget
|
|
36
|
+
}) {
|
|
37
|
+
const card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]');
|
|
38
|
+
const messageElement = currentTarget.closest('[data-controller~="hellotext--message"]');
|
|
39
|
+
const body = currentTarget.dataset.text || currentTarget.textContent.trim();
|
|
40
|
+
this.dispatch('quickReply', {
|
|
41
|
+
detail: {
|
|
42
|
+
id: this.idValue,
|
|
43
|
+
product: card?.dataset.id,
|
|
44
|
+
buttonId: currentTarget.dataset.id,
|
|
45
|
+
body,
|
|
46
|
+
cardElement: card || messageElement || currentTarget
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
addToCart({
|
|
51
|
+
currentTarget
|
|
52
|
+
}) {
|
|
53
|
+
const card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]');
|
|
54
|
+
const {
|
|
55
|
+
id,
|
|
56
|
+
reference,
|
|
57
|
+
source
|
|
58
|
+
} = card.dataset;
|
|
59
|
+
const item = {
|
|
60
|
+
product: id,
|
|
61
|
+
quantity: 1
|
|
62
|
+
};
|
|
63
|
+
if (this.hasUtmValue) Hellotext.page.utm.save(this.utmValue);
|
|
64
|
+
Hellotext.eventEmitter.dispatch('cart.added', {
|
|
65
|
+
object_parameters: {
|
|
66
|
+
items: [{
|
|
67
|
+
...item,
|
|
68
|
+
...(reference && {
|
|
90
69
|
reference
|
|
91
|
-
}),
|
|
70
|
+
}),
|
|
71
|
+
...(source && {
|
|
92
72
|
source
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}, {
|
|
103
|
-
key: "moveToLeft",
|
|
104
|
-
value: function moveToLeft() {
|
|
105
|
-
if (!this.hasCarouselContainerTarget) return;
|
|
106
|
-
var nextScrollLeft = this.getPreviousPageScrollLeft();
|
|
107
|
-
var scrollAmount = this.carouselContainerTarget.scrollLeft - nextScrollLeft;
|
|
108
|
-
if (scrollAmount < 1) return;
|
|
109
|
-
this.carouselContainerTarget.scrollBy({
|
|
110
|
-
left: -scrollAmount,
|
|
111
|
-
behavior: 'smooth'
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}, {
|
|
115
|
-
key: "moveToRight",
|
|
116
|
-
value: function moveToRight() {
|
|
117
|
-
if (!this.hasCarouselContainerTarget) return;
|
|
118
|
-
var nextScrollLeft = this.getNextPageScrollLeft();
|
|
119
|
-
var scrollAmount = nextScrollLeft - this.carouselContainerTarget.scrollLeft;
|
|
120
|
-
if (scrollAmount < 1) return;
|
|
121
|
-
this.carouselContainerTarget.scrollBy({
|
|
122
|
-
left: scrollAmount,
|
|
123
|
-
behavior: 'smooth'
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}, {
|
|
127
|
-
key: "getScrollAmount",
|
|
128
|
-
value: function getScrollAmount() {
|
|
129
|
-
return this.getCardScrollAmount();
|
|
130
|
-
}
|
|
131
|
-
}, {
|
|
132
|
-
key: "getCardScrollAmount",
|
|
133
|
-
value: function getCardScrollAmount() {
|
|
134
|
-
var firstCard = this.carouselContainerTarget.querySelector('.message__carousel_card');
|
|
135
|
-
if (!firstCard) {
|
|
136
|
-
return 280; // Fallback to default desktop card width
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
var cardWidth = firstCard.offsetWidth;
|
|
140
|
-
return cardWidth + this.getGap();
|
|
141
|
-
}
|
|
142
|
-
}, {
|
|
143
|
-
key: "getPageScrollAmount",
|
|
144
|
-
value: function getPageScrollAmount() {
|
|
145
|
-
var scrollAmount = this.carouselContainerTarget.clientWidth - this.getGap();
|
|
146
|
-
return scrollAmount > 0 ? scrollAmount : this.getCardScrollAmount();
|
|
147
|
-
}
|
|
148
|
-
}, {
|
|
149
|
-
key: "getNextPageScrollLeft",
|
|
150
|
-
value: function getNextPageScrollLeft() {
|
|
151
|
-
var currentScrollLeft = this.getCurrentScrollLeft();
|
|
152
|
-
var viewportRight = currentScrollLeft + this.carouselContainerTarget.clientWidth;
|
|
153
|
-
var cardMetrics = this.getCardMetrics();
|
|
154
|
-
var nextCard = cardMetrics.find(card => card.end > viewportRight + 1);
|
|
155
|
-
var targetScrollLeft = nextCard ? this.getPageAlignedScrollLeft(nextCard.start) : currentScrollLeft + this.getPageScrollAmount();
|
|
156
|
-
var fallbackScrollLeft = currentScrollLeft + this.getPageScrollAmount();
|
|
157
|
-
return this.clampScrollLeft(targetScrollLeft > currentScrollLeft + 1 ? targetScrollLeft : fallbackScrollLeft);
|
|
158
|
-
}
|
|
159
|
-
}, {
|
|
160
|
-
key: "getPreviousPageScrollLeft",
|
|
161
|
-
value: function getPreviousPageScrollLeft() {
|
|
162
|
-
var _ref4, _previousPageCard$sta;
|
|
163
|
-
var currentScrollLeft = this.getCurrentScrollLeft();
|
|
164
|
-
if (currentScrollLeft <= 1) return 0;
|
|
165
|
-
var targetThreshold = Math.max(currentScrollLeft - this.getPageScrollAmount(), 0);
|
|
166
|
-
if (targetThreshold <= 1) return 0;
|
|
167
|
-
var cardMetrics = this.getCardMetrics();
|
|
168
|
-
var previousPageCard = cardMetrics.find(card => card.start >= targetThreshold - 1 && card.start < currentScrollLeft - 1);
|
|
169
|
-
var previousCard = [...cardMetrics].reverse().find(card => card.start < currentScrollLeft - 1);
|
|
170
|
-
return this.getPageAlignedScrollLeft((_ref4 = (_previousPageCard$sta = previousPageCard === null || previousPageCard === void 0 ? void 0 : previousPageCard.start) !== null && _previousPageCard$sta !== void 0 ? _previousPageCard$sta : previousCard === null || previousCard === void 0 ? void 0 : previousCard.start) !== null && _ref4 !== void 0 ? _ref4 : 0);
|
|
171
|
-
}
|
|
172
|
-
}, {
|
|
173
|
-
key: "getPageAlignedScrollLeft",
|
|
174
|
-
value: function getPageAlignedScrollLeft(cardStart) {
|
|
175
|
-
var pageStartOffset = this.getPageStartOffset();
|
|
176
|
-
if (cardStart <= pageStartOffset + 1) return 0;
|
|
177
|
-
return this.clampScrollLeft(cardStart - pageStartOffset);
|
|
178
|
-
}
|
|
179
|
-
}, {
|
|
180
|
-
key: "getCardMetrics",
|
|
181
|
-
value: function getCardMetrics() {
|
|
182
|
-
return Array.from(this.carouselContainerTarget.querySelectorAll('.message__carousel_card')).map(card => {
|
|
183
|
-
var start = this.getCardScrollLeft(card);
|
|
184
|
-
return {
|
|
185
|
-
start,
|
|
186
|
-
end: start + card.offsetWidth
|
|
187
|
-
};
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}, {
|
|
191
|
-
key: "getCardScrollLeft",
|
|
192
|
-
value: function getCardScrollLeft(card) {
|
|
193
|
-
var cardRect = card.getBoundingClientRect();
|
|
194
|
-
var containerRect = this.carouselContainerTarget.getBoundingClientRect();
|
|
195
|
-
if (cardRect.left || cardRect.width || containerRect.left || containerRect.width) {
|
|
196
|
-
return cardRect.left - containerRect.left + this.carouselContainerTarget.scrollLeft;
|
|
73
|
+
})
|
|
74
|
+
}]
|
|
75
|
+
},
|
|
76
|
+
source: {
|
|
77
|
+
kind: this.kindValue,
|
|
78
|
+
message_id: this.idValue,
|
|
79
|
+
button_id: currentTarget.dataset.id
|
|
197
80
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return
|
|
227
|
-
}
|
|
228
|
-
}, {
|
|
229
|
-
key: "observeContainerSize",
|
|
230
|
-
value: function observeContainerSize() {
|
|
231
|
-
if (!this.hasCarouselContainerTarget || !window.ResizeObserver) return;
|
|
232
|
-
this.resizeObserver = new ResizeObserver(() => this.updateFades());
|
|
233
|
-
this.resizeObserver.observe(this.carouselContainerTarget);
|
|
234
|
-
}
|
|
235
|
-
}, {
|
|
236
|
-
key: "updateFades",
|
|
237
|
-
value: function updateFades() {
|
|
238
|
-
if (!this.hasCarouselContainerTarget) return;
|
|
239
|
-
var maxScroll = Math.max(this.carouselContainerTarget.scrollWidth - this.carouselContainerTarget.clientWidth, 0);
|
|
240
|
-
if (maxScroll <= 1) {
|
|
241
|
-
this.hideFade(this.leftFadeTarget);
|
|
242
|
-
this.hideFade(this.rightFadeTarget);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
var scrollLeft = Math.min(Math.max(this.carouselContainerTarget.scrollLeft, 0), maxScroll);
|
|
246
|
-
var fadeDistance = this.getFadeDistance();
|
|
247
|
-
this.setFadeOpacity(this.leftFadeTarget, scrollLeft / fadeDistance);
|
|
248
|
-
this.setFadeOpacity(this.rightFadeTarget, (maxScroll - scrollLeft) / fadeDistance);
|
|
249
|
-
}
|
|
250
|
-
}, {
|
|
251
|
-
key: "setFadeOpacity",
|
|
252
|
-
value: function setFadeOpacity(fadeTarget, opacity) {
|
|
253
|
-
var clampedOpacity = Math.min(Math.max(opacity, 0), 1);
|
|
254
|
-
if (clampedOpacity <= 0.05) {
|
|
255
|
-
this.hideFade(fadeTarget);
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
fadeTarget.classList.remove('hidden');
|
|
259
|
-
fadeTarget.removeAttribute('disabled');
|
|
260
|
-
fadeTarget.removeAttribute('tabindex');
|
|
261
|
-
fadeTarget.setAttribute('aria-hidden', 'false');
|
|
262
|
-
fadeTarget.style.opacity = clampedOpacity.toFixed(3);
|
|
263
|
-
fadeTarget.style.pointerEvents = 'auto';
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
moveToLeft() {
|
|
84
|
+
if (!this.hasCarouselContainerTarget) return;
|
|
85
|
+
const nextScrollLeft = this.getPreviousPageScrollLeft();
|
|
86
|
+
const scrollAmount = this.carouselContainerTarget.scrollLeft - nextScrollLeft;
|
|
87
|
+
if (scrollAmount < 1) return;
|
|
88
|
+
this.carouselContainerTarget.scrollBy({
|
|
89
|
+
left: -scrollAmount,
|
|
90
|
+
behavior: 'smooth'
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
moveToRight() {
|
|
94
|
+
if (!this.hasCarouselContainerTarget) return;
|
|
95
|
+
const nextScrollLeft = this.getNextPageScrollLeft();
|
|
96
|
+
const scrollAmount = nextScrollLeft - this.carouselContainerTarget.scrollLeft;
|
|
97
|
+
if (scrollAmount < 1) return;
|
|
98
|
+
this.carouselContainerTarget.scrollBy({
|
|
99
|
+
left: scrollAmount,
|
|
100
|
+
behavior: 'smooth'
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
getScrollAmount() {
|
|
104
|
+
return this.getCardScrollAmount();
|
|
105
|
+
}
|
|
106
|
+
getCardScrollAmount() {
|
|
107
|
+
const firstCard = this.carouselContainerTarget.querySelector('.message__carousel_card');
|
|
108
|
+
if (!firstCard) {
|
|
109
|
+
return 280; // Fallback to default desktop card width
|
|
264
110
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
111
|
+
|
|
112
|
+
const cardWidth = firstCard.offsetWidth;
|
|
113
|
+
return cardWidth + this.getGap();
|
|
114
|
+
}
|
|
115
|
+
getPageScrollAmount() {
|
|
116
|
+
const scrollAmount = this.carouselContainerTarget.clientWidth - this.getGap();
|
|
117
|
+
return scrollAmount > 0 ? scrollAmount : this.getCardScrollAmount();
|
|
118
|
+
}
|
|
119
|
+
getNextPageScrollLeft() {
|
|
120
|
+
const currentScrollLeft = this.getCurrentScrollLeft();
|
|
121
|
+
const viewportRight = currentScrollLeft + this.carouselContainerTarget.clientWidth;
|
|
122
|
+
const cardMetrics = this.getCardMetrics();
|
|
123
|
+
const nextCard = cardMetrics.find(card => card.end > viewportRight + 1);
|
|
124
|
+
const targetScrollLeft = nextCard ? this.getPageAlignedScrollLeft(nextCard.start) : currentScrollLeft + this.getPageScrollAmount();
|
|
125
|
+
const fallbackScrollLeft = currentScrollLeft + this.getPageScrollAmount();
|
|
126
|
+
return this.clampScrollLeft(targetScrollLeft > currentScrollLeft + 1 ? targetScrollLeft : fallbackScrollLeft);
|
|
127
|
+
}
|
|
128
|
+
getPreviousPageScrollLeft() {
|
|
129
|
+
const currentScrollLeft = this.getCurrentScrollLeft();
|
|
130
|
+
if (currentScrollLeft <= 1) return 0;
|
|
131
|
+
const targetThreshold = Math.max(currentScrollLeft - this.getPageScrollAmount(), 0);
|
|
132
|
+
if (targetThreshold <= 1) return 0;
|
|
133
|
+
const cardMetrics = this.getCardMetrics();
|
|
134
|
+
const previousPageCard = cardMetrics.find(card => card.start >= targetThreshold - 1 && card.start < currentScrollLeft - 1);
|
|
135
|
+
const previousCard = [...cardMetrics].reverse().find(card => card.start < currentScrollLeft - 1);
|
|
136
|
+
return this.getPageAlignedScrollLeft(previousPageCard?.start ?? previousCard?.start ?? 0);
|
|
137
|
+
}
|
|
138
|
+
getPageAlignedScrollLeft(cardStart) {
|
|
139
|
+
const pageStartOffset = this.getPageStartOffset();
|
|
140
|
+
if (cardStart <= pageStartOffset + 1) return 0;
|
|
141
|
+
return this.clampScrollLeft(cardStart - pageStartOffset);
|
|
142
|
+
}
|
|
143
|
+
getCardMetrics() {
|
|
144
|
+
return Array.from(this.carouselContainerTarget.querySelectorAll('.message__carousel_card')).map(card => {
|
|
145
|
+
const start = this.getCardScrollLeft(card);
|
|
146
|
+
return {
|
|
147
|
+
start,
|
|
148
|
+
end: start + card.offsetWidth
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
getCardScrollLeft(card) {
|
|
153
|
+
const cardRect = card.getBoundingClientRect();
|
|
154
|
+
const containerRect = this.carouselContainerTarget.getBoundingClientRect();
|
|
155
|
+
if (cardRect.left || cardRect.width || containerRect.left || containerRect.width) {
|
|
156
|
+
return cardRect.left - containerRect.left + this.carouselContainerTarget.scrollLeft;
|
|
274
157
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
158
|
+
return card.offsetLeft || 0;
|
|
159
|
+
}
|
|
160
|
+
getCurrentScrollLeft() {
|
|
161
|
+
return this.clampScrollLeft(this.carouselContainerTarget.scrollLeft);
|
|
162
|
+
}
|
|
163
|
+
clampScrollLeft(scrollLeft) {
|
|
164
|
+
const maxScroll = Math.max(this.carouselContainerTarget.scrollWidth - this.carouselContainerTarget.clientWidth, 0);
|
|
165
|
+
return Math.min(Math.max(scrollLeft, 0), maxScroll);
|
|
166
|
+
}
|
|
167
|
+
getGap() {
|
|
168
|
+
const styles = window.getComputedStyle(this.carouselContainerTarget);
|
|
169
|
+
const gap = Number.parseFloat(styles.columnGap || styles.gap);
|
|
170
|
+
return Number.isFinite(gap) ? gap : 16;
|
|
171
|
+
}
|
|
172
|
+
getFadeDistance() {
|
|
173
|
+
return Number.isFinite(this.fadeDistanceValue) ? this.fadeDistanceValue : 64;
|
|
174
|
+
}
|
|
175
|
+
getPageStartOffset() {
|
|
176
|
+
return Number.isFinite(this.pageStartOffsetValue) ? this.pageStartOffsetValue : 0;
|
|
177
|
+
}
|
|
178
|
+
observeContainerSize() {
|
|
179
|
+
if (!this.hasCarouselContainerTarget || !window.ResizeObserver) return;
|
|
180
|
+
this.resizeObserver = new ResizeObserver(() => this.updateFades());
|
|
181
|
+
this.resizeObserver.observe(this.carouselContainerTarget);
|
|
182
|
+
}
|
|
183
|
+
updateFades() {
|
|
184
|
+
if (!this.hasCarouselContainerTarget) return;
|
|
185
|
+
const maxScroll = Math.max(this.carouselContainerTarget.scrollWidth - this.carouselContainerTarget.clientWidth, 0);
|
|
186
|
+
if (maxScroll <= 1) {
|
|
187
|
+
this.hideFade(this.leftFadeTarget);
|
|
188
|
+
this.hideFade(this.rightFadeTarget);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const scrollLeft = Math.min(Math.max(this.carouselContainerTarget.scrollLeft, 0), maxScroll);
|
|
192
|
+
const fadeDistance = this.getFadeDistance();
|
|
193
|
+
this.setFadeOpacity(this.leftFadeTarget, scrollLeft / fadeDistance);
|
|
194
|
+
this.setFadeOpacity(this.rightFadeTarget, (maxScroll - scrollLeft) / fadeDistance);
|
|
195
|
+
}
|
|
196
|
+
setFadeOpacity(fadeTarget, opacity) {
|
|
197
|
+
const clampedOpacity = Math.min(Math.max(opacity, 0), 1);
|
|
198
|
+
if (clampedOpacity <= 0.05) {
|
|
199
|
+
this.hideFade(fadeTarget);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
fadeTarget.classList.remove('hidden');
|
|
203
|
+
fadeTarget.removeAttribute('disabled');
|
|
204
|
+
fadeTarget.removeAttribute('tabindex');
|
|
205
|
+
fadeTarget.setAttribute('aria-hidden', 'false');
|
|
206
|
+
fadeTarget.style.opacity = clampedOpacity.toFixed(3);
|
|
207
|
+
fadeTarget.style.pointerEvents = 'auto';
|
|
208
|
+
}
|
|
209
|
+
hideFade(fadeTarget) {
|
|
210
|
+
fadeTarget.style.opacity = '0';
|
|
211
|
+
fadeTarget.style.pointerEvents = 'none';
|
|
212
|
+
fadeTarget.setAttribute('aria-hidden', 'true');
|
|
213
|
+
fadeTarget.setAttribute('tabindex', '-1');
|
|
214
|
+
if ('disabled' in fadeTarget) fadeTarget.disabled = true;
|
|
215
|
+
fadeTarget.classList.add('hidden');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -9,16 +9,14 @@ var _core = require("../../core");
|
|
|
9
9
|
const usePopover = controller => {
|
|
10
10
|
Object.assign(controller, {
|
|
11
11
|
show() {
|
|
12
|
-
|
|
13
|
-
(_this$cancelBehaviour = this.cancelBehaviourOpen) === null || _this$cancelBehaviour === void 0 ? void 0 : _this$cancelBehaviour.call(this);
|
|
12
|
+
this.cancelBehaviourOpen?.();
|
|
14
13
|
this.openValue = true;
|
|
15
14
|
},
|
|
16
15
|
hide() {
|
|
17
16
|
this.openValue = false;
|
|
18
17
|
},
|
|
19
18
|
toggle() {
|
|
20
|
-
|
|
21
|
-
(_this$cancelBehaviour2 = this.cancelBehaviourOpen) === null || _this$cancelBehaviour2 === void 0 ? void 0 : _this$cancelBehaviour2.call(this);
|
|
19
|
+
this.cancelBehaviourOpen?.();
|
|
22
20
|
this.openValue = !this.openValue;
|
|
23
21
|
},
|
|
24
22
|
setupFloatingUI({
|
|
@@ -48,8 +46,7 @@ const usePopover = controller => {
|
|
|
48
46
|
openValueChanged() {
|
|
49
47
|
if (this.disabledValue) return;
|
|
50
48
|
if (this.openValue) {
|
|
51
|
-
|
|
52
|
-
(_this$preparePopoverO = this.preparePopoverOpenAnimation) === null || _this$preparePopoverO === void 0 ? void 0 : _this$preparePopoverO.call(this);
|
|
49
|
+
this.preparePopoverOpenAnimation?.();
|
|
53
50
|
this.popoverTarget.showPopover();
|
|
54
51
|
this.popoverTarget.setAttribute('aria-expanded', 'true');
|
|
55
52
|
if (this['onPopoverOpened']) {
|
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
import { autoUpdate, computePosition } from '@floating-ui/dom';
|
|
2
2
|
import { Configuration } from '../../core';
|
|
3
|
-
export
|
|
3
|
+
export const usePopover = controller => {
|
|
4
4
|
Object.assign(controller, {
|
|
5
5
|
show() {
|
|
6
|
-
|
|
7
|
-
(_this$cancelBehaviour = this.cancelBehaviourOpen) === null || _this$cancelBehaviour === void 0 ? void 0 : _this$cancelBehaviour.call(this);
|
|
6
|
+
this.cancelBehaviourOpen?.();
|
|
8
7
|
this.openValue = true;
|
|
9
8
|
},
|
|
10
9
|
hide() {
|
|
11
10
|
this.openValue = false;
|
|
12
11
|
},
|
|
13
12
|
toggle() {
|
|
14
|
-
|
|
15
|
-
(_this$cancelBehaviour2 = this.cancelBehaviourOpen) === null || _this$cancelBehaviour2 === void 0 ? void 0 : _this$cancelBehaviour2.call(this);
|
|
13
|
+
this.cancelBehaviourOpen?.();
|
|
16
14
|
this.openValue = !this.openValue;
|
|
17
15
|
},
|
|
18
|
-
setupFloatingUI(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} = _ref;
|
|
16
|
+
setupFloatingUI({
|
|
17
|
+
trigger,
|
|
18
|
+
popover,
|
|
19
|
+
strategy
|
|
20
|
+
}) {
|
|
24
21
|
this.floatingUICleanup = autoUpdate(trigger, popover, () => {
|
|
25
22
|
computePosition(trigger, popover, {
|
|
26
23
|
placement: this.placementValue,
|
|
27
24
|
middleware: this.middlewares,
|
|
28
25
|
strategy: strategy || Configuration.webchat.strategy
|
|
29
|
-
}).then(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
top: "".concat(y, "px"),
|
|
26
|
+
}).then(({
|
|
27
|
+
x,
|
|
28
|
+
y,
|
|
29
|
+
strategy
|
|
30
|
+
}) => {
|
|
31
|
+
const newStyle = {
|
|
32
|
+
left: `${x}px`,
|
|
33
|
+
top: `${y}px`,
|
|
38
34
|
position: strategy
|
|
39
35
|
};
|
|
40
36
|
Object.assign(popover.style, newStyle);
|
|
@@ -44,8 +40,7 @@ export var usePopover = controller => {
|
|
|
44
40
|
openValueChanged() {
|
|
45
41
|
if (this.disabledValue) return;
|
|
46
42
|
if (this.openValue) {
|
|
47
|
-
|
|
48
|
-
(_this$preparePopoverO = this.preparePopoverOpenAnimation) === null || _this$preparePopoverO === void 0 ? void 0 : _this$preparePopoverO.call(this);
|
|
43
|
+
this.preparePopoverOpenAnimation?.();
|
|
49
44
|
this.popoverTarget.showPopover();
|
|
50
45
|
this.popoverTarget.setAttribute('aria-expanded', 'true');
|
|
51
46
|
if (this['onPopoverOpened']) {
|