@hellotext/hellotext 2.1.1 → 2.1.2
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.
|
@@ -169,9 +169,11 @@ let _default = /*#__PURE__*/function (_Controller) {
|
|
|
169
169
|
value: function onPopoverOpened() {
|
|
170
170
|
this.inputTarget.focus();
|
|
171
171
|
if (!this.scrolled) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
requestAnimationFrame(() => {
|
|
173
|
+
this.messagesContainerTarget.scroll({
|
|
174
|
+
top: this.messagesContainerTarget.scrollHeight,
|
|
175
|
+
behavior: 'instant'
|
|
176
|
+
});
|
|
175
177
|
});
|
|
176
178
|
this.scrolled = true;
|
|
177
179
|
}
|
|
@@ -277,7 +279,14 @@ let _default = /*#__PURE__*/function (_Controller) {
|
|
|
277
279
|
body: this.inputTarget.value,
|
|
278
280
|
attachments: this.files
|
|
279
281
|
};
|
|
280
|
-
|
|
282
|
+
if (this.inputTarget.value.trim().length === 0 && this.files.length === 0) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (this.inputTarget.value.trim().length > 0) {
|
|
286
|
+
formData.append('message[body]', this.inputTarget.value);
|
|
287
|
+
} else {
|
|
288
|
+
delete message.body;
|
|
289
|
+
}
|
|
281
290
|
this.files.forEach(file => {
|
|
282
291
|
formData.append('message[attachments][]', file);
|
|
283
292
|
});
|
|
@@ -287,7 +296,11 @@ let _default = /*#__PURE__*/function (_Controller) {
|
|
|
287
296
|
element.classList.add('received');
|
|
288
297
|
element.style.removeProperty('display');
|
|
289
298
|
element.setAttribute('data-hellotext--webchat-target', 'message');
|
|
290
|
-
|
|
299
|
+
if (this.inputTarget.value.trim().length > 0) {
|
|
300
|
+
element.querySelector('[data-body]').innerText = this.inputTarget.value;
|
|
301
|
+
} else {
|
|
302
|
+
element.querySelector('[data-message-bubble]').remove();
|
|
303
|
+
}
|
|
291
304
|
const attachments = this.attachmentContainerTarget.querySelectorAll('img');
|
|
292
305
|
if (attachments.length > 0) {
|
|
293
306
|
attachments.forEach(attachment => {
|
|
@@ -304,6 +317,8 @@ let _default = /*#__PURE__*/function (_Controller) {
|
|
|
304
317
|
});
|
|
305
318
|
this.inputTarget.value = '';
|
|
306
319
|
this.files = [];
|
|
320
|
+
this.attachmentInputTarget.value = '';
|
|
321
|
+
this.attachmentContainerTarget.innerHTML = '';
|
|
307
322
|
this.attachmentContainerTarget.style.display = 'none';
|
|
308
323
|
this.errorMessageContainerTarget.style.display = 'none';
|
|
309
324
|
this.inputTarget.focus();
|
|
@@ -334,8 +349,9 @@ let _default = /*#__PURE__*/function (_Controller) {
|
|
|
334
349
|
key: "onFileInputChange",
|
|
335
350
|
value: function onFileInputChange() {
|
|
336
351
|
this.errorMessageContainerTarget.style.display = 'none';
|
|
337
|
-
|
|
338
|
-
|
|
352
|
+
const newFiles = Array.from(this.attachmentInputTarget.files);
|
|
353
|
+
this.attachmentInputTarget.value = '';
|
|
354
|
+
const fileMaxSizeTooMuch = newFiles.find(file => {
|
|
339
355
|
const type = file.type.split('/')[0];
|
|
340
356
|
if (['image', 'video', 'audio'].includes(type)) {
|
|
341
357
|
return this.mediaValue[type].max_size < file.size;
|
|
@@ -347,10 +363,11 @@ let _default = /*#__PURE__*/function (_Controller) {
|
|
|
347
363
|
const type = fileMaxSizeTooMuch.type.split('/')[0];
|
|
348
364
|
const mediaType = ['image', 'audio', 'video'].includes(type) ? type : 'document';
|
|
349
365
|
this.errorMessageContainerTarget.innerText = this.fileSizeErrorMessageValue.replace('%{limit}', this.byteToMegabyte(this.mediaValue[mediaType].max_size));
|
|
350
|
-
return;
|
|
366
|
+
return this.errorMessageContainerTarget.style.display = 'block';
|
|
351
367
|
}
|
|
368
|
+
this.files = [...this.files, ...newFiles];
|
|
352
369
|
this.errorMessageContainerTarget.innerText = '';
|
|
353
|
-
|
|
370
|
+
newFiles.forEach(file => this.createAttachmentElement(file));
|
|
354
371
|
this.inputTarget.focus();
|
|
355
372
|
}
|
|
356
373
|
}, {
|
|
@@ -373,6 +390,8 @@ let _default = /*#__PURE__*/function (_Controller) {
|
|
|
373
390
|
main.style.backgroundColor = '#e5e7eb';
|
|
374
391
|
main.style.padding = '0.25rem';
|
|
375
392
|
element.querySelector('p[data-attachment-name]').innerText = file.name;
|
|
393
|
+
this.attachmentContainerTarget.appendChild(element);
|
|
394
|
+
this.attachmentContainerTarget.style.display = 'flex';
|
|
376
395
|
}
|
|
377
396
|
}
|
|
378
397
|
}, {
|
|
@@ -382,6 +401,7 @@ let _default = /*#__PURE__*/function (_Controller) {
|
|
|
382
401
|
}) {
|
|
383
402
|
const attachment = currentTarget.closest("[data-hellotext--webchat-target='attachment']");
|
|
384
403
|
this.files = this.files.filter(file => file.name !== attachment.dataset.name);
|
|
404
|
+
this.attachmentInputTarget.value = '';
|
|
385
405
|
attachment.remove();
|
|
386
406
|
this.inputTarget.focus();
|
|
387
407
|
}
|
|
@@ -173,9 +173,11 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
173
173
|
value: function onPopoverOpened() {
|
|
174
174
|
this.inputTarget.focus();
|
|
175
175
|
if (!this.scrolled) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
requestAnimationFrame(() => {
|
|
177
|
+
this.messagesContainerTarget.scroll({
|
|
178
|
+
top: this.messagesContainerTarget.scrollHeight,
|
|
179
|
+
behavior: 'instant'
|
|
180
|
+
});
|
|
179
181
|
});
|
|
180
182
|
this.scrolled = true;
|
|
181
183
|
}
|
|
@@ -281,7 +283,14 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
281
283
|
body: this.inputTarget.value,
|
|
282
284
|
attachments: this.files
|
|
283
285
|
};
|
|
284
|
-
|
|
286
|
+
if (this.inputTarget.value.trim().length === 0 && this.files.length === 0) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (this.inputTarget.value.trim().length > 0) {
|
|
290
|
+
formData.append('message[body]', this.inputTarget.value);
|
|
291
|
+
} else {
|
|
292
|
+
delete message.body;
|
|
293
|
+
}
|
|
285
294
|
this.files.forEach(file => {
|
|
286
295
|
formData.append('message[attachments][]', file);
|
|
287
296
|
});
|
|
@@ -291,7 +300,11 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
291
300
|
element.classList.add('received');
|
|
292
301
|
element.style.removeProperty('display');
|
|
293
302
|
element.setAttribute('data-hellotext--webchat-target', 'message');
|
|
294
|
-
|
|
303
|
+
if (this.inputTarget.value.trim().length > 0) {
|
|
304
|
+
element.querySelector('[data-body]').innerText = this.inputTarget.value;
|
|
305
|
+
} else {
|
|
306
|
+
element.querySelector('[data-message-bubble]').remove();
|
|
307
|
+
}
|
|
295
308
|
var attachments = this.attachmentContainerTarget.querySelectorAll('img');
|
|
296
309
|
if (attachments.length > 0) {
|
|
297
310
|
attachments.forEach(attachment => {
|
|
@@ -308,6 +321,8 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
308
321
|
});
|
|
309
322
|
this.inputTarget.value = '';
|
|
310
323
|
this.files = [];
|
|
324
|
+
this.attachmentInputTarget.value = '';
|
|
325
|
+
this.attachmentContainerTarget.innerHTML = '';
|
|
311
326
|
this.attachmentContainerTarget.style.display = 'none';
|
|
312
327
|
this.errorMessageContainerTarget.style.display = 'none';
|
|
313
328
|
this.inputTarget.focus();
|
|
@@ -343,8 +358,9 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
343
358
|
key: "onFileInputChange",
|
|
344
359
|
value: function onFileInputChange() {
|
|
345
360
|
this.errorMessageContainerTarget.style.display = 'none';
|
|
346
|
-
|
|
347
|
-
|
|
361
|
+
var newFiles = Array.from(this.attachmentInputTarget.files);
|
|
362
|
+
this.attachmentInputTarget.value = '';
|
|
363
|
+
var fileMaxSizeTooMuch = newFiles.find(file => {
|
|
348
364
|
var type = file.type.split('/')[0];
|
|
349
365
|
if (['image', 'video', 'audio'].includes(type)) {
|
|
350
366
|
return this.mediaValue[type].max_size < file.size;
|
|
@@ -356,10 +372,11 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
356
372
|
var type = fileMaxSizeTooMuch.type.split('/')[0];
|
|
357
373
|
var mediaType = ['image', 'audio', 'video'].includes(type) ? type : 'document';
|
|
358
374
|
this.errorMessageContainerTarget.innerText = this.fileSizeErrorMessageValue.replace('%{limit}', this.byteToMegabyte(this.mediaValue[mediaType].max_size));
|
|
359
|
-
return;
|
|
375
|
+
return this.errorMessageContainerTarget.style.display = 'block';
|
|
360
376
|
}
|
|
377
|
+
this.files = [...this.files, ...newFiles];
|
|
361
378
|
this.errorMessageContainerTarget.innerText = '';
|
|
362
|
-
|
|
379
|
+
newFiles.forEach(file => this.createAttachmentElement(file));
|
|
363
380
|
this.inputTarget.focus();
|
|
364
381
|
}
|
|
365
382
|
}, {
|
|
@@ -382,6 +399,8 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
382
399
|
main.style.backgroundColor = '#e5e7eb';
|
|
383
400
|
main.style.padding = '0.25rem';
|
|
384
401
|
element.querySelector('p[data-attachment-name]').innerText = file.name;
|
|
402
|
+
this.attachmentContainerTarget.appendChild(element);
|
|
403
|
+
this.attachmentContainerTarget.style.display = 'flex';
|
|
385
404
|
}
|
|
386
405
|
}
|
|
387
406
|
}, {
|
|
@@ -392,6 +411,7 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
392
411
|
} = _ref;
|
|
393
412
|
var attachment = currentTarget.closest("[data-hellotext--webchat-target='attachment']");
|
|
394
413
|
this.files = this.files.filter(file => file.name !== attachment.dataset.name);
|
|
414
|
+
this.attachmentInputTarget.value = '';
|
|
395
415
|
attachment.remove();
|
|
396
416
|
this.inputTarget.focus();
|
|
397
417
|
}
|
package/package.json
CHANGED
|
@@ -209,9 +209,11 @@ export default class extends Controller {
|
|
|
209
209
|
this.inputTarget.focus()
|
|
210
210
|
|
|
211
211
|
if (!this.scrolled) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
requestAnimationFrame(() => {
|
|
213
|
+
this.messagesContainerTarget.scroll({
|
|
214
|
+
top: this.messagesContainerTarget.scrollHeight,
|
|
215
|
+
behavior: 'instant',
|
|
216
|
+
})
|
|
215
217
|
})
|
|
216
218
|
|
|
217
219
|
this.scrolled = true
|
|
@@ -328,7 +330,15 @@ export default class extends Controller {
|
|
|
328
330
|
attachments: this.files,
|
|
329
331
|
}
|
|
330
332
|
|
|
331
|
-
|
|
333
|
+
if (this.inputTarget.value.trim().length === 0 && this.files.length === 0) {
|
|
334
|
+
return
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (this.inputTarget.value.trim().length > 0) {
|
|
338
|
+
formData.append('message[body]', this.inputTarget.value)
|
|
339
|
+
} else {
|
|
340
|
+
delete message.body
|
|
341
|
+
}
|
|
332
342
|
|
|
333
343
|
this.files.forEach(file => {
|
|
334
344
|
formData.append('message[attachments][]', file)
|
|
@@ -344,7 +354,12 @@ export default class extends Controller {
|
|
|
344
354
|
element.style.removeProperty('display')
|
|
345
355
|
|
|
346
356
|
element.setAttribute('data-hellotext--webchat-target', 'message')
|
|
347
|
-
|
|
357
|
+
|
|
358
|
+
if (this.inputTarget.value.trim().length > 0) {
|
|
359
|
+
element.querySelector('[data-body]').innerText = this.inputTarget.value
|
|
360
|
+
} else {
|
|
361
|
+
element.querySelector('[data-message-bubble]').remove()
|
|
362
|
+
}
|
|
348
363
|
|
|
349
364
|
const attachments = this.attachmentContainerTarget.querySelectorAll('img')
|
|
350
365
|
|
|
@@ -364,6 +379,10 @@ export default class extends Controller {
|
|
|
364
379
|
|
|
365
380
|
this.inputTarget.value = ''
|
|
366
381
|
this.files = []
|
|
382
|
+
|
|
383
|
+
this.attachmentInputTarget.value = ''
|
|
384
|
+
this.attachmentContainerTarget.innerHTML = ''
|
|
385
|
+
|
|
367
386
|
this.attachmentContainerTarget.style.display = 'none'
|
|
368
387
|
this.errorMessageContainerTarget.style.display = 'none'
|
|
369
388
|
|
|
@@ -401,9 +420,10 @@ export default class extends Controller {
|
|
|
401
420
|
onFileInputChange() {
|
|
402
421
|
this.errorMessageContainerTarget.style.display = 'none'
|
|
403
422
|
|
|
404
|
-
|
|
423
|
+
const newFiles = Array.from(this.attachmentInputTarget.files)
|
|
424
|
+
this.attachmentInputTarget.value = ''
|
|
405
425
|
|
|
406
|
-
const fileMaxSizeTooMuch =
|
|
426
|
+
const fileMaxSizeTooMuch = newFiles.find(file => {
|
|
407
427
|
const type = file.type.split('/')[0]
|
|
408
428
|
|
|
409
429
|
if (['image', 'video', 'audio'].includes(type)) {
|
|
@@ -421,11 +441,14 @@ export default class extends Controller {
|
|
|
421
441
|
'%{limit}',
|
|
422
442
|
this.byteToMegabyte(this.mediaValue[mediaType].max_size),
|
|
423
443
|
)
|
|
424
|
-
|
|
444
|
+
|
|
445
|
+
return (this.errorMessageContainerTarget.style.display = 'block')
|
|
425
446
|
}
|
|
426
447
|
|
|
448
|
+
this.files = [...this.files, ...newFiles]
|
|
427
449
|
this.errorMessageContainerTarget.innerText = ''
|
|
428
|
-
|
|
450
|
+
|
|
451
|
+
newFiles.forEach(file => this.createAttachmentElement(file))
|
|
429
452
|
this.inputTarget.focus()
|
|
430
453
|
}
|
|
431
454
|
|
|
@@ -448,12 +471,16 @@ export default class extends Controller {
|
|
|
448
471
|
this.attachmentContainerTarget.style.display = 'flex'
|
|
449
472
|
} else {
|
|
450
473
|
const main = element.querySelector('main')
|
|
474
|
+
|
|
451
475
|
main.style.height = '5rem'
|
|
452
476
|
main.style.borderRadius = '0.375rem'
|
|
453
477
|
main.style.backgroundColor = '#e5e7eb'
|
|
454
478
|
main.style.padding = '0.25rem'
|
|
455
479
|
|
|
456
480
|
element.querySelector('p[data-attachment-name]').innerText = file.name
|
|
481
|
+
|
|
482
|
+
this.attachmentContainerTarget.appendChild(element)
|
|
483
|
+
this.attachmentContainerTarget.style.display = 'flex'
|
|
457
484
|
}
|
|
458
485
|
}
|
|
459
486
|
|
|
@@ -461,6 +488,7 @@ export default class extends Controller {
|
|
|
461
488
|
const attachment = currentTarget.closest("[data-hellotext--webchat-target='attachment']")
|
|
462
489
|
|
|
463
490
|
this.files = this.files.filter(file => file.name !== attachment.dataset.name)
|
|
491
|
+
this.attachmentInputTarget.value = ''
|
|
464
492
|
|
|
465
493
|
attachment.remove()
|
|
466
494
|
this.inputTarget.focus()
|