@xapp/chat-widget 1.55.1 → 1.57.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.
Files changed (34) hide show
  1. package/dist/components/ActionItem/ActionItem.d.ts +0 -0
  2. package/dist/components/Carousel/Carousel.d.ts +0 -0
  3. package/dist/components/CarouselItem/CarouselItem.d.ts +0 -0
  4. package/dist/components/ChatMarkdownMessage/ChatMarkdownMessage.d.ts +0 -0
  5. package/dist/components/ChatWidget/ChatWidget.stories.d.ts +3 -0
  6. package/dist/components/List/List.d.ts +0 -0
  7. package/dist/components/ListItem/ListItem.d.ts +0 -0
  8. package/dist/components/MessageList/MessageList.d.ts +0 -0
  9. package/dist/components/OptionalLink/OptionalLink.d.ts +0 -0
  10. package/dist/hooks/useOpenUrlCallback.d.ts +0 -0
  11. package/dist/index.css +2 -2
  12. package/dist/index.es.js +205 -1354
  13. package/dist/index.es.js.map +1 -1
  14. package/dist/index.js +202 -1351
  15. package/dist/index.js.map +1 -1
  16. package/dist/middlewares/message-middleware.d.ts +0 -0
  17. package/dist/store/ChatAction.d.ts +0 -0
  18. package/dist/store/ChatState.d.ts +0 -0
  19. package/dist/store/actions/sendVisitorInfo.d.ts +0 -0
  20. package/dist/store/actions/setSessionId.d.ts +0 -0
  21. package/dist/store/actions/setVisualStatus.d.ts +0 -0
  22. package/dist/utils/PersistentStorage.d.ts +0 -0
  23. package/dist/utils/__tests__/insertSorted.test.d.ts +1 -0
  24. package/dist/utils/index.d.ts +0 -0
  25. package/dist/utils/insertSorted.d.ts +0 -0
  26. package/dist/xapp/ChatServer.d.ts +0 -0
  27. package/dist/xapp/LogChat.d.ts +0 -0
  28. package/dist/xapp/StentorDirectChat.d.ts +0 -0
  29. package/dist/xapp/StentorRouterChat.d.ts +0 -0
  30. package/dist/xapp/StentorServerChat.d.ts +0 -0
  31. package/dist/xapp-chat-widget.css +1 -1
  32. package/dist/xapp-chat-widget.js +5 -3
  33. package/dist/xapp-chat-widget.js.map +1 -1
  34. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -127,6 +127,7 @@ function __spreadArray$1(to, from, pack) {
127
127
  return to.concat(ar || Array.prototype.slice.call(from));
128
128
  }
129
129
 
130
+ /*! Copyright (c) 2021, XAPPmedia */
130
131
  function insertSorted(array, obj, comparer) {
131
132
  if (!array.length) {
132
133
  array.push(obj);
@@ -137,11 +138,19 @@ function insertSorted(array, obj, comparer) {
137
138
  while ((rightIndex - leftIndex) > 0) {
138
139
  var left = array[leftIndex];
139
140
  var right = array[rightIndex];
140
- if (comparer(obj, left) <= 0) {
141
+ var compLeft = comparer(obj, left);
142
+ if (compLeft === 0) {
143
+ return array; // exist
144
+ }
145
+ if (compLeft < 0) {
141
146
  array.splice(leftIndex, 0, obj);
142
147
  return array;
143
148
  }
144
- if (comparer(obj, right) >= 0) {
149
+ var compRight = comparer(obj, right);
150
+ if (compRight === 0) {
151
+ return array; // exist
152
+ }
153
+ if (compRight > 0) {
145
154
  array.splice(rightIndex + 1, 0, obj);
146
155
  return array;
147
156
  }
@@ -178,1279 +187,6 @@ function isAgent(nick) {
178
187
  return nick.startsWith("agent:");
179
188
  }
180
189
 
181
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
182
-
183
- var assign$1 = make_assign();
184
- var create$1 = make_create();
185
- var trim$1 = make_trim();
186
- var Global$5 = (typeof window !== 'undefined' ? window : commonjsGlobal);
187
-
188
- var util$6 = {
189
- assign: assign$1,
190
- create: create$1,
191
- trim: trim$1,
192
- bind: bind$1,
193
- slice: slice$1,
194
- each: each$7,
195
- map: map$1,
196
- pluck: pluck$1,
197
- isList: isList$2,
198
- isFunction: isFunction$1,
199
- isObject: isObject$1,
200
- Global: Global$5
201
- };
202
-
203
- function make_assign() {
204
- if (Object.assign) {
205
- return Object.assign
206
- } else {
207
- return function shimAssign(obj, props1, props2, etc) {
208
- for (var i = 1; i < arguments.length; i++) {
209
- each$7(Object(arguments[i]), function(val, key) {
210
- obj[key] = val;
211
- });
212
- }
213
- return obj
214
- }
215
- }
216
- }
217
-
218
- function make_create() {
219
- if (Object.create) {
220
- return function create(obj, assignProps1, assignProps2, etc) {
221
- var assignArgsList = slice$1(arguments, 1);
222
- return assign$1.apply(this, [Object.create(obj)].concat(assignArgsList))
223
- }
224
- } else {
225
- function F() {} // eslint-disable-line no-inner-declarations
226
- return function create(obj, assignProps1, assignProps2, etc) {
227
- var assignArgsList = slice$1(arguments, 1);
228
- F.prototype = obj;
229
- return assign$1.apply(this, [new F()].concat(assignArgsList))
230
- }
231
- }
232
- }
233
-
234
- function make_trim() {
235
- if (String.prototype.trim) {
236
- return function trim(str) {
237
- return String.prototype.trim.call(str)
238
- }
239
- } else {
240
- return function trim(str) {
241
- return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '')
242
- }
243
- }
244
- }
245
-
246
- function bind$1(obj, fn) {
247
- return function() {
248
- return fn.apply(obj, Array.prototype.slice.call(arguments, 0))
249
- }
250
- }
251
-
252
- function slice$1(arr, index) {
253
- return Array.prototype.slice.call(arr, index || 0)
254
- }
255
-
256
- function each$7(obj, fn) {
257
- pluck$1(obj, function(val, key) {
258
- fn(val, key);
259
- return false
260
- });
261
- }
262
-
263
- function map$1(obj, fn) {
264
- var res = (isList$2(obj) ? [] : {});
265
- pluck$1(obj, function(v, k) {
266
- res[k] = fn(v, k);
267
- return false
268
- });
269
- return res
270
- }
271
-
272
- function pluck$1(obj, fn) {
273
- if (isList$2(obj)) {
274
- for (var i=0; i<obj.length; i++) {
275
- if (fn(obj[i], i)) {
276
- return obj[i]
277
- }
278
- }
279
- } else {
280
- for (var key in obj) {
281
- if (obj.hasOwnProperty(key)) {
282
- if (fn(obj[key], key)) {
283
- return obj[key]
284
- }
285
- }
286
- }
287
- }
288
- }
289
-
290
- function isList$2(val) {
291
- return (val != null && typeof val != 'function' && typeof val.length == 'number')
292
- }
293
-
294
- function isFunction$1(val) {
295
- return val && {}.toString.call(val) === '[object Function]'
296
- }
297
-
298
- function isObject$1(val) {
299
- return val && {}.toString.call(val) === '[object Object]'
300
- }
301
-
302
- var util$5 = util$6;
303
- var slice = util$5.slice;
304
- var pluck = util$5.pluck;
305
- var each$6 = util$5.each;
306
- var bind = util$5.bind;
307
- var create = util$5.create;
308
- var isList$1 = util$5.isList;
309
- var isFunction = util$5.isFunction;
310
- var isObject = util$5.isObject;
311
-
312
- var storeEngine = {
313
- createStore: createStore
314
- };
315
-
316
- var storeAPI = {
317
- version: '2.0.12',
318
- enabled: false,
319
-
320
- // get returns the value of the given key. If that value
321
- // is undefined, it returns optionalDefaultValue instead.
322
- get: function(key, optionalDefaultValue) {
323
- var data = this.storage.read(this._namespacePrefix + key);
324
- return this._deserialize(data, optionalDefaultValue)
325
- },
326
-
327
- // set will store the given value at key and returns value.
328
- // Calling set with value === undefined is equivalent to calling remove.
329
- set: function(key, value) {
330
- if (value === undefined) {
331
- return this.remove(key)
332
- }
333
- this.storage.write(this._namespacePrefix + key, this._serialize(value));
334
- return value
335
- },
336
-
337
- // remove deletes the key and value stored at the given key.
338
- remove: function(key) {
339
- this.storage.remove(this._namespacePrefix + key);
340
- },
341
-
342
- // each will call the given callback once for each key-value pair
343
- // in this store.
344
- each: function(callback) {
345
- var self = this;
346
- this.storage.each(function(val, namespacedKey) {
347
- callback.call(self, self._deserialize(val), (namespacedKey || '').replace(self._namespaceRegexp, ''));
348
- });
349
- },
350
-
351
- // clearAll will remove all the stored key-value pairs in this store.
352
- clearAll: function() {
353
- this.storage.clearAll();
354
- },
355
-
356
- // additional functionality that can't live in plugins
357
- // ---------------------------------------------------
358
-
359
- // hasNamespace returns true if this store instance has the given namespace.
360
- hasNamespace: function(namespace) {
361
- return (this._namespacePrefix == '__storejs_'+namespace+'_')
362
- },
363
-
364
- // createStore creates a store.js instance with the first
365
- // functioning storage in the list of storage candidates,
366
- // and applies the the given mixins to the instance.
367
- createStore: function() {
368
- return createStore.apply(this, arguments)
369
- },
370
-
371
- addPlugin: function(plugin) {
372
- this._addPlugin(plugin);
373
- },
374
-
375
- namespace: function(namespace) {
376
- return createStore(this.storage, this.plugins, namespace)
377
- }
378
- };
379
-
380
- function _warn() {
381
- var _console = (typeof console == 'undefined' ? null : console);
382
- if (!_console) { return }
383
- var fn = (_console.warn ? _console.warn : _console.log);
384
- fn.apply(_console, arguments);
385
- }
386
-
387
- function createStore(storages, plugins, namespace) {
388
- if (!namespace) {
389
- namespace = '';
390
- }
391
- if (storages && !isList$1(storages)) {
392
- storages = [storages];
393
- }
394
- if (plugins && !isList$1(plugins)) {
395
- plugins = [plugins];
396
- }
397
-
398
- var namespacePrefix = (namespace ? '__storejs_'+namespace+'_' : '');
399
- var namespaceRegexp = (namespace ? new RegExp('^'+namespacePrefix) : null);
400
- var legalNamespaces = /^[a-zA-Z0-9_\-]*$/; // alpha-numeric + underscore and dash
401
- if (!legalNamespaces.test(namespace)) {
402
- throw new Error('store.js namespaces can only have alphanumerics + underscores and dashes')
403
- }
404
-
405
- var _privateStoreProps = {
406
- _namespacePrefix: namespacePrefix,
407
- _namespaceRegexp: namespaceRegexp,
408
-
409
- _testStorage: function(storage) {
410
- try {
411
- var testStr = '__storejs__test__';
412
- storage.write(testStr, testStr);
413
- var ok = (storage.read(testStr) === testStr);
414
- storage.remove(testStr);
415
- return ok
416
- } catch(e) {
417
- return false
418
- }
419
- },
420
-
421
- _assignPluginFnProp: function(pluginFnProp, propName) {
422
- var oldFn = this[propName];
423
- this[propName] = function pluginFn() {
424
- var args = slice(arguments, 0);
425
- var self = this;
426
-
427
- // super_fn calls the old function which was overwritten by
428
- // this mixin.
429
- function super_fn() {
430
- if (!oldFn) { return }
431
- each$6(arguments, function(arg, i) {
432
- args[i] = arg;
433
- });
434
- return oldFn.apply(self, args)
435
- }
436
-
437
- // Give mixing function access to super_fn by prefixing all mixin function
438
- // arguments with super_fn.
439
- var newFnArgs = [super_fn].concat(args);
440
-
441
- return pluginFnProp.apply(self, newFnArgs)
442
- };
443
- },
444
-
445
- _serialize: function(obj) {
446
- return JSON.stringify(obj)
447
- },
448
-
449
- _deserialize: function(strVal, defaultVal) {
450
- if (!strVal) { return defaultVal }
451
- // It is possible that a raw string value has been previously stored
452
- // in a storage without using store.js, meaning it will be a raw
453
- // string value instead of a JSON serialized string. By defaulting
454
- // to the raw string value in case of a JSON parse error, we allow
455
- // for past stored values to be forwards-compatible with store.js
456
- var val = '';
457
- try { val = JSON.parse(strVal); }
458
- catch(e) { val = strVal; }
459
-
460
- return (val !== undefined ? val : defaultVal)
461
- },
462
-
463
- _addStorage: function(storage) {
464
- if (this.enabled) { return }
465
- if (this._testStorage(storage)) {
466
- this.storage = storage;
467
- this.enabled = true;
468
- }
469
- },
470
-
471
- _addPlugin: function(plugin) {
472
- var self = this;
473
-
474
- // If the plugin is an array, then add all plugins in the array.
475
- // This allows for a plugin to depend on other plugins.
476
- if (isList$1(plugin)) {
477
- each$6(plugin, function(plugin) {
478
- self._addPlugin(plugin);
479
- });
480
- return
481
- }
482
-
483
- // Keep track of all plugins we've seen so far, so that we
484
- // don't add any of them twice.
485
- var seenPlugin = pluck(this.plugins, function(seenPlugin) {
486
- return (plugin === seenPlugin)
487
- });
488
- if (seenPlugin) {
489
- return
490
- }
491
- this.plugins.push(plugin);
492
-
493
- // Check that the plugin is properly formed
494
- if (!isFunction(plugin)) {
495
- throw new Error('Plugins must be function values that return objects')
496
- }
497
-
498
- var pluginProperties = plugin.call(this);
499
- if (!isObject(pluginProperties)) {
500
- throw new Error('Plugins must return an object of function properties')
501
- }
502
-
503
- // Add the plugin function properties to this store instance.
504
- each$6(pluginProperties, function(pluginFnProp, propName) {
505
- if (!isFunction(pluginFnProp)) {
506
- throw new Error('Bad plugin property: '+propName+' from plugin '+plugin.name+'. Plugins should only return functions.')
507
- }
508
- self._assignPluginFnProp(pluginFnProp, propName);
509
- });
510
- },
511
-
512
- // Put deprecated properties in the private API, so as to not expose it to accidential
513
- // discovery through inspection of the store object.
514
-
515
- // Deprecated: addStorage
516
- addStorage: function(storage) {
517
- _warn('store.addStorage(storage) is deprecated. Use createStore([storages])');
518
- this._addStorage(storage);
519
- }
520
- };
521
-
522
- var store = create(_privateStoreProps, storeAPI, {
523
- plugins: []
524
- });
525
- store.raw = {};
526
- each$6(store, function(prop, propName) {
527
- if (isFunction(prop)) {
528
- store.raw[propName] = bind(store, prop);
529
- }
530
- });
531
- each$6(storages, function(storage) {
532
- store._addStorage(storage);
533
- });
534
- each$6(plugins, function(plugin) {
535
- store._addPlugin(plugin);
536
- });
537
- return store
538
- }
539
-
540
- var util$4 = util$6;
541
- var Global$4 = util$4.Global;
542
-
543
- var localStorage_1 = {
544
- name: 'localStorage',
545
- read: read$5,
546
- write: write$5,
547
- each: each$5,
548
- remove: remove$5,
549
- clearAll: clearAll$5,
550
- };
551
-
552
- function localStorage$1() {
553
- return Global$4.localStorage
554
- }
555
-
556
- function read$5(key) {
557
- return localStorage$1().getItem(key)
558
- }
559
-
560
- function write$5(key, data) {
561
- return localStorage$1().setItem(key, data)
562
- }
563
-
564
- function each$5(fn) {
565
- for (var i = localStorage$1().length - 1; i >= 0; i--) {
566
- var key = localStorage$1().key(i);
567
- fn(read$5(key), key);
568
- }
569
- }
570
-
571
- function remove$5(key) {
572
- return localStorage$1().removeItem(key)
573
- }
574
-
575
- function clearAll$5() {
576
- return localStorage$1().clear()
577
- }
578
-
579
- // oldFF-globalStorage provides storage for Firefox
580
- // versions 6 and 7, where no localStorage, etc
581
- // is available.
582
-
583
- var util$3 = util$6;
584
- var Global$3 = util$3.Global;
585
-
586
- var oldFFGlobalStorage = {
587
- name: 'oldFF-globalStorage',
588
- read: read$4,
589
- write: write$4,
590
- each: each$4,
591
- remove: remove$4,
592
- clearAll: clearAll$4,
593
- };
594
-
595
- var globalStorage = Global$3.globalStorage;
596
-
597
- function read$4(key) {
598
- return globalStorage[key]
599
- }
600
-
601
- function write$4(key, data) {
602
- globalStorage[key] = data;
603
- }
604
-
605
- function each$4(fn) {
606
- for (var i = globalStorage.length - 1; i >= 0; i--) {
607
- var key = globalStorage.key(i);
608
- fn(globalStorage[key], key);
609
- }
610
- }
611
-
612
- function remove$4(key) {
613
- return globalStorage.removeItem(key)
614
- }
615
-
616
- function clearAll$4() {
617
- each$4(function(key, _) {
618
- delete globalStorage[key];
619
- });
620
- }
621
-
622
- // oldIE-userDataStorage provides storage for Internet Explorer
623
- // versions 6 and 7, where no localStorage, sessionStorage, etc
624
- // is available.
625
-
626
- var util$2 = util$6;
627
- var Global$2 = util$2.Global;
628
-
629
- var oldIEUserDataStorage = {
630
- name: 'oldIE-userDataStorage',
631
- write: write$3,
632
- read: read$3,
633
- each: each$3,
634
- remove: remove$3,
635
- clearAll: clearAll$3,
636
- };
637
-
638
- var storageName = 'storejs';
639
- var doc$1 = Global$2.document;
640
- var _withStorageEl = _makeIEStorageElFunction();
641
- var disable = (Global$2.navigator ? Global$2.navigator.userAgent : '').match(/ (MSIE 8|MSIE 9|MSIE 10)\./); // MSIE 9.x, MSIE 10.x
642
-
643
- function write$3(unfixedKey, data) {
644
- if (disable) { return }
645
- var fixedKey = fixKey(unfixedKey);
646
- _withStorageEl(function(storageEl) {
647
- storageEl.setAttribute(fixedKey, data);
648
- storageEl.save(storageName);
649
- });
650
- }
651
-
652
- function read$3(unfixedKey) {
653
- if (disable) { return }
654
- var fixedKey = fixKey(unfixedKey);
655
- var res = null;
656
- _withStorageEl(function(storageEl) {
657
- res = storageEl.getAttribute(fixedKey);
658
- });
659
- return res
660
- }
661
-
662
- function each$3(callback) {
663
- _withStorageEl(function(storageEl) {
664
- var attributes = storageEl.XMLDocument.documentElement.attributes;
665
- for (var i=attributes.length-1; i>=0; i--) {
666
- var attr = attributes[i];
667
- callback(storageEl.getAttribute(attr.name), attr.name);
668
- }
669
- });
670
- }
671
-
672
- function remove$3(unfixedKey) {
673
- var fixedKey = fixKey(unfixedKey);
674
- _withStorageEl(function(storageEl) {
675
- storageEl.removeAttribute(fixedKey);
676
- storageEl.save(storageName);
677
- });
678
- }
679
-
680
- function clearAll$3() {
681
- _withStorageEl(function(storageEl) {
682
- var attributes = storageEl.XMLDocument.documentElement.attributes;
683
- storageEl.load(storageName);
684
- for (var i=attributes.length-1; i>=0; i--) {
685
- storageEl.removeAttribute(attributes[i].name);
686
- }
687
- storageEl.save(storageName);
688
- });
689
- }
690
-
691
- // Helpers
692
- //////////
693
-
694
- // In IE7, keys cannot start with a digit or contain certain chars.
695
- // See https://github.com/marcuswestin/store.js/issues/40
696
- // See https://github.com/marcuswestin/store.js/issues/83
697
- var forbiddenCharsRegex = new RegExp("[!\"#$%&'()*+,/\\\\:;<=>?@[\\]^`{|}~]", "g");
698
- function fixKey(key) {
699
- return key.replace(/^\d/, '___$&').replace(forbiddenCharsRegex, '___')
700
- }
701
-
702
- function _makeIEStorageElFunction() {
703
- if (!doc$1 || !doc$1.documentElement || !doc$1.documentElement.addBehavior) {
704
- return null
705
- }
706
- var scriptTag = 'script',
707
- storageOwner,
708
- storageContainer,
709
- storageEl;
710
-
711
- // Since #userData storage applies only to specific paths, we need to
712
- // somehow link our data to a specific path. We choose /favicon.ico
713
- // as a pretty safe option, since all browsers already make a request to
714
- // this URL anyway and being a 404 will not hurt us here. We wrap an
715
- // iframe pointing to the favicon in an ActiveXObject(htmlfile) object
716
- // (see: http://msdn.microsoft.com/en-us/library/aa752574(v=VS.85).aspx)
717
- // since the iframe access rules appear to allow direct access and
718
- // manipulation of the document element, even for a 404 page. This
719
- // document can be used instead of the current document (which would
720
- // have been limited to the current path) to perform #userData storage.
721
- try {
722
- /* global ActiveXObject */
723
- storageContainer = new ActiveXObject('htmlfile');
724
- storageContainer.open();
725
- storageContainer.write('<'+scriptTag+'>document.w=window</'+scriptTag+'><iframe src="/favicon.ico"></iframe>');
726
- storageContainer.close();
727
- storageOwner = storageContainer.w.frames[0].document;
728
- storageEl = storageOwner.createElement('div');
729
- } catch(e) {
730
- // somehow ActiveXObject instantiation failed (perhaps some special
731
- // security settings or otherwse), fall back to per-path storage
732
- storageEl = doc$1.createElement('div');
733
- storageOwner = doc$1.body;
734
- }
735
-
736
- return function(storeFunction) {
737
- var args = [].slice.call(arguments, 0);
738
- args.unshift(storageEl);
739
- // See http://msdn.microsoft.com/en-us/library/ms531081(v=VS.85).aspx
740
- // and http://msdn.microsoft.com/en-us/library/ms531424(v=VS.85).aspx
741
- storageOwner.appendChild(storageEl);
742
- storageEl.addBehavior('#default#userData');
743
- storageEl.load(storageName);
744
- storeFunction.apply(this, args);
745
- storageOwner.removeChild(storageEl);
746
- return
747
- }
748
- }
749
-
750
- // cookieStorage is useful Safari private browser mode, where localStorage
751
- // doesn't work but cookies do. This implementation is adopted from
752
- // https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage
753
-
754
- var util$1 = util$6;
755
- var Global$1 = util$1.Global;
756
- var trim = util$1.trim;
757
-
758
- var cookieStorage = {
759
- name: 'cookieStorage',
760
- read: read$2,
761
- write: write$2,
762
- each: each$2,
763
- remove: remove$2,
764
- clearAll: clearAll$2,
765
- };
766
-
767
- var doc = Global$1.document;
768
-
769
- function read$2(key) {
770
- if (!key || !_has(key)) { return null }
771
- var regexpStr = "(?:^|.*;\\s*)" +
772
- escape(key).replace(/[\-\.\+\*]/g, "\\$&") +
773
- "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";
774
- return unescape(doc.cookie.replace(new RegExp(regexpStr), "$1"))
775
- }
776
-
777
- function each$2(callback) {
778
- var cookies = doc.cookie.split(/; ?/g);
779
- for (var i = cookies.length - 1; i >= 0; i--) {
780
- if (!trim(cookies[i])) {
781
- continue
782
- }
783
- var kvp = cookies[i].split('=');
784
- var key = unescape(kvp[0]);
785
- var val = unescape(kvp[1]);
786
- callback(val, key);
787
- }
788
- }
789
-
790
- function write$2(key, data) {
791
- if(!key) { return }
792
- doc.cookie = escape(key) + "=" + escape(data) + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/";
793
- }
794
-
795
- function remove$2(key) {
796
- if (!key || !_has(key)) {
797
- return
798
- }
799
- doc.cookie = escape(key) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
800
- }
801
-
802
- function clearAll$2() {
803
- each$2(function(_, key) {
804
- remove$2(key);
805
- });
806
- }
807
-
808
- function _has(key) {
809
- return (new RegExp("(?:^|;\\s*)" + escape(key).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(doc.cookie)
810
- }
811
-
812
- var util = util$6;
813
- var Global = util.Global;
814
-
815
- var sessionStorage_1 = {
816
- name: 'sessionStorage',
817
- read: read$1,
818
- write: write$1,
819
- each: each$1,
820
- remove: remove$1,
821
- clearAll: clearAll$1
822
- };
823
-
824
- function sessionStorage() {
825
- return Global.sessionStorage
826
- }
827
-
828
- function read$1(key) {
829
- return sessionStorage().getItem(key)
830
- }
831
-
832
- function write$1(key, data) {
833
- return sessionStorage().setItem(key, data)
834
- }
835
-
836
- function each$1(fn) {
837
- for (var i = sessionStorage().length - 1; i >= 0; i--) {
838
- var key = sessionStorage().key(i);
839
- fn(read$1(key), key);
840
- }
841
- }
842
-
843
- function remove$1(key) {
844
- return sessionStorage().removeItem(key)
845
- }
846
-
847
- function clearAll$1() {
848
- return sessionStorage().clear()
849
- }
850
-
851
- // memoryStorage is a useful last fallback to ensure that the store
852
- // is functions (meaning store.get(), store.set(), etc will all function).
853
- // However, stored values will not persist when the browser navigates to
854
- // a new page or reloads the current page.
855
-
856
- var memoryStorage_1 = {
857
- name: 'memoryStorage',
858
- read: read,
859
- write: write,
860
- each: each,
861
- remove: remove,
862
- clearAll: clearAll,
863
- };
864
-
865
- var memoryStorage = {};
866
-
867
- function read(key) {
868
- return memoryStorage[key]
869
- }
870
-
871
- function write(key, data) {
872
- memoryStorage[key] = data;
873
- }
874
-
875
- function each(callback) {
876
- for (var key in memoryStorage) {
877
- if (memoryStorage.hasOwnProperty(key)) {
878
- callback(memoryStorage[key], key);
879
- }
880
- }
881
- }
882
-
883
- function remove(key) {
884
- delete memoryStorage[key];
885
- }
886
-
887
- function clearAll(key) {
888
- memoryStorage = {};
889
- }
890
-
891
- var all = [
892
- // Listed in order of usage preference
893
- localStorage_1,
894
- oldFFGlobalStorage,
895
- oldIEUserDataStorage,
896
- cookieStorage,
897
- sessionStorage_1,
898
- memoryStorage_1
899
- ];
900
-
901
- var json2$1 = {};
902
-
903
- /* eslint-disable */
904
-
905
- var hasRequiredJson2;
906
-
907
- function requireJson2 () {
908
- if (hasRequiredJson2) return json2$1;
909
- hasRequiredJson2 = 1;
910
- // json2.js
911
- // 2016-10-28
912
- // Public Domain.
913
- // NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
914
- // See http://www.JSON.org/js.html
915
- // This code should be minified before deployment.
916
- // See http://javascript.crockford.com/jsmin.html
917
-
918
- // USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
919
- // NOT CONTROL.
920
-
921
- // This file creates a global JSON object containing two methods: stringify
922
- // and parse. This file provides the ES5 JSON capability to ES3 systems.
923
- // If a project might run on IE8 or earlier, then this file should be included.
924
- // This file does nothing on ES5 systems.
925
-
926
- // JSON.stringify(value, replacer, space)
927
- // value any JavaScript value, usually an object or array.
928
- // replacer an optional parameter that determines how object
929
- // values are stringified for objects. It can be a
930
- // function or an array of strings.
931
- // space an optional parameter that specifies the indentation
932
- // of nested structures. If it is omitted, the text will
933
- // be packed without extra whitespace. If it is a number,
934
- // it will specify the number of spaces to indent at each
935
- // level. If it is a string (such as "\t" or "&nbsp;"),
936
- // it contains the characters used to indent at each level.
937
- // This method produces a JSON text from a JavaScript value.
938
- // When an object value is found, if the object contains a toJSON
939
- // method, its toJSON method will be called and the result will be
940
- // stringified. A toJSON method does not serialize: it returns the
941
- // value represented by the name/value pair that should be serialized,
942
- // or undefined if nothing should be serialized. The toJSON method
943
- // will be passed the key associated with the value, and this will be
944
- // bound to the value.
945
-
946
- // For example, this would serialize Dates as ISO strings.
947
-
948
- // Date.prototype.toJSON = function (key) {
949
- // function f(n) {
950
- // // Format integers to have at least two digits.
951
- // return (n < 10)
952
- // ? "0" + n
953
- // : n;
954
- // }
955
- // return this.getUTCFullYear() + "-" +
956
- // f(this.getUTCMonth() + 1) + "-" +
957
- // f(this.getUTCDate()) + "T" +
958
- // f(this.getUTCHours()) + ":" +
959
- // f(this.getUTCMinutes()) + ":" +
960
- // f(this.getUTCSeconds()) + "Z";
961
- // };
962
-
963
- // You can provide an optional replacer method. It will be passed the
964
- // key and value of each member, with this bound to the containing
965
- // object. The value that is returned from your method will be
966
- // serialized. If your method returns undefined, then the member will
967
- // be excluded from the serialization.
968
-
969
- // If the replacer parameter is an array of strings, then it will be
970
- // used to select the members to be serialized. It filters the results
971
- // such that only members with keys listed in the replacer array are
972
- // stringified.
973
-
974
- // Values that do not have JSON representations, such as undefined or
975
- // functions, will not be serialized. Such values in objects will be
976
- // dropped; in arrays they will be replaced with null. You can use
977
- // a replacer function to replace those with JSON values.
978
-
979
- // JSON.stringify(undefined) returns undefined.
980
-
981
- // The optional space parameter produces a stringification of the
982
- // value that is filled with line breaks and indentation to make it
983
- // easier to read.
984
-
985
- // If the space parameter is a non-empty string, then that string will
986
- // be used for indentation. If the space parameter is a number, then
987
- // the indentation will be that many spaces.
988
-
989
- // Example:
990
-
991
- // text = JSON.stringify(["e", {pluribus: "unum"}]);
992
- // // text is '["e",{"pluribus":"unum"}]'
993
-
994
- // text = JSON.stringify(["e", {pluribus: "unum"}], null, "\t");
995
- // // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
996
-
997
- // text = JSON.stringify([new Date()], function (key, value) {
998
- // return this[key] instanceof Date
999
- // ? "Date(" + this[key] + ")"
1000
- // : value;
1001
- // });
1002
- // // text is '["Date(---current time---)"]'
1003
-
1004
- // JSON.parse(text, reviver)
1005
- // This method parses a JSON text to produce an object or array.
1006
- // It can throw a SyntaxError exception.
1007
-
1008
- // The optional reviver parameter is a function that can filter and
1009
- // transform the results. It receives each of the keys and values,
1010
- // and its return value is used instead of the original value.
1011
- // If it returns what it received, then the structure is not modified.
1012
- // If it returns undefined then the member is deleted.
1013
-
1014
- // Example:
1015
-
1016
- // // Parse the text. Values that look like ISO date strings will
1017
- // // be converted to Date objects.
1018
-
1019
- // myData = JSON.parse(text, function (key, value) {
1020
- // var a;
1021
- // if (typeof value === "string") {
1022
- // a =
1023
- // /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
1024
- // if (a) {
1025
- // return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
1026
- // +a[5], +a[6]));
1027
- // }
1028
- // }
1029
- // return value;
1030
- // });
1031
-
1032
- // myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
1033
- // var d;
1034
- // if (typeof value === "string" &&
1035
- // value.slice(0, 5) === "Date(" &&
1036
- // value.slice(-1) === ")") {
1037
- // d = new Date(value.slice(5, -1));
1038
- // if (d) {
1039
- // return d;
1040
- // }
1041
- // }
1042
- // return value;
1043
- // });
1044
-
1045
- // This is a reference implementation. You are free to copy, modify, or
1046
- // redistribute.
1047
-
1048
- /*jslint
1049
- eval, for, this
1050
- */
1051
-
1052
- /*property
1053
- JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
1054
- getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
1055
- lastIndex, length, parse, prototype, push, replace, slice, stringify,
1056
- test, toJSON, toString, valueOf
1057
- */
1058
-
1059
-
1060
- // Create a JSON object only if one does not already exist. We create the
1061
- // methods in a closure to avoid creating global variables.
1062
-
1063
- if (typeof JSON !== "object") {
1064
- JSON = {};
1065
- }
1066
-
1067
- (function () {
1068
-
1069
- var rx_one = /^[\],:{}\s]*$/;
1070
- var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
1071
- var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
1072
- var rx_four = /(?:^|:|,)(?:\s*\[)+/g;
1073
- var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
1074
- var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
1075
-
1076
- function f(n) {
1077
- // Format integers to have at least two digits.
1078
- return n < 10
1079
- ? "0" + n
1080
- : n;
1081
- }
1082
-
1083
- function this_value() {
1084
- return this.valueOf();
1085
- }
1086
-
1087
- if (typeof Date.prototype.toJSON !== "function") {
1088
-
1089
- Date.prototype.toJSON = function () {
1090
-
1091
- return isFinite(this.valueOf())
1092
- ? this.getUTCFullYear() + "-" +
1093
- f(this.getUTCMonth() + 1) + "-" +
1094
- f(this.getUTCDate()) + "T" +
1095
- f(this.getUTCHours()) + ":" +
1096
- f(this.getUTCMinutes()) + ":" +
1097
- f(this.getUTCSeconds()) + "Z"
1098
- : null;
1099
- };
1100
-
1101
- Boolean.prototype.toJSON = this_value;
1102
- Number.prototype.toJSON = this_value;
1103
- String.prototype.toJSON = this_value;
1104
- }
1105
-
1106
- var gap;
1107
- var indent;
1108
- var meta;
1109
- var rep;
1110
-
1111
-
1112
- function quote(string) {
1113
-
1114
- // If the string contains no control characters, no quote characters, and no
1115
- // backslash characters, then we can safely slap some quotes around it.
1116
- // Otherwise we must also replace the offending characters with safe escape
1117
- // sequences.
1118
-
1119
- rx_escapable.lastIndex = 0;
1120
- return rx_escapable.test(string)
1121
- ? "\"" + string.replace(rx_escapable, function (a) {
1122
- var c = meta[a];
1123
- return typeof c === "string"
1124
- ? c
1125
- : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
1126
- }) + "\""
1127
- : "\"" + string + "\"";
1128
- }
1129
-
1130
-
1131
- function str(key, holder) {
1132
-
1133
- // Produce a string from holder[key].
1134
-
1135
- var i; // The loop counter.
1136
- var k; // The member key.
1137
- var v; // The member value.
1138
- var length;
1139
- var mind = gap;
1140
- var partial;
1141
- var value = holder[key];
1142
-
1143
- // If the value has a toJSON method, call it to obtain a replacement value.
1144
-
1145
- if (value && typeof value === "object" &&
1146
- typeof value.toJSON === "function") {
1147
- value = value.toJSON(key);
1148
- }
1149
-
1150
- // If we were called with a replacer function, then call the replacer to
1151
- // obtain a replacement value.
1152
-
1153
- if (typeof rep === "function") {
1154
- value = rep.call(holder, key, value);
1155
- }
1156
-
1157
- // What happens next depends on the value's type.
1158
-
1159
- switch (typeof value) {
1160
- case "string":
1161
- return quote(value);
1162
-
1163
- case "number":
1164
-
1165
- // JSON numbers must be finite. Encode non-finite numbers as null.
1166
-
1167
- return isFinite(value)
1168
- ? String(value)
1169
- : "null";
1170
-
1171
- case "boolean":
1172
- case "null":
1173
-
1174
- // If the value is a boolean or null, convert it to a string. Note:
1175
- // typeof null does not produce "null". The case is included here in
1176
- // the remote chance that this gets fixed someday.
1177
-
1178
- return String(value);
1179
-
1180
- // If the type is "object", we might be dealing with an object or an array or
1181
- // null.
1182
-
1183
- case "object":
1184
-
1185
- // Due to a specification blunder in ECMAScript, typeof null is "object",
1186
- // so watch out for that case.
1187
-
1188
- if (!value) {
1189
- return "null";
1190
- }
1191
-
1192
- // Make an array to hold the partial results of stringifying this object value.
1193
-
1194
- gap += indent;
1195
- partial = [];
1196
-
1197
- // Is the value an array?
1198
-
1199
- if (Object.prototype.toString.apply(value) === "[object Array]") {
1200
-
1201
- // The value is an array. Stringify every element. Use null as a placeholder
1202
- // for non-JSON values.
1203
-
1204
- length = value.length;
1205
- for (i = 0; i < length; i += 1) {
1206
- partial[i] = str(i, value) || "null";
1207
- }
1208
-
1209
- // Join all of the elements together, separated with commas, and wrap them in
1210
- // brackets.
1211
-
1212
- v = partial.length === 0
1213
- ? "[]"
1214
- : gap
1215
- ? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]"
1216
- : "[" + partial.join(",") + "]";
1217
- gap = mind;
1218
- return v;
1219
- }
1220
-
1221
- // If the replacer is an array, use it to select the members to be stringified.
1222
-
1223
- if (rep && typeof rep === "object") {
1224
- length = rep.length;
1225
- for (i = 0; i < length; i += 1) {
1226
- if (typeof rep[i] === "string") {
1227
- k = rep[i];
1228
- v = str(k, value);
1229
- if (v) {
1230
- partial.push(quote(k) + (
1231
- gap
1232
- ? ": "
1233
- : ":"
1234
- ) + v);
1235
- }
1236
- }
1237
- }
1238
- } else {
1239
-
1240
- // Otherwise, iterate through all of the keys in the object.
1241
-
1242
- for (k in value) {
1243
- if (Object.prototype.hasOwnProperty.call(value, k)) {
1244
- v = str(k, value);
1245
- if (v) {
1246
- partial.push(quote(k) + (
1247
- gap
1248
- ? ": "
1249
- : ":"
1250
- ) + v);
1251
- }
1252
- }
1253
- }
1254
- }
1255
-
1256
- // Join all of the member texts together, separated with commas,
1257
- // and wrap them in braces.
1258
-
1259
- v = partial.length === 0
1260
- ? "{}"
1261
- : gap
1262
- ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}"
1263
- : "{" + partial.join(",") + "}";
1264
- gap = mind;
1265
- return v;
1266
- }
1267
- }
1268
-
1269
- // If the JSON object does not yet have a stringify method, give it one.
1270
-
1271
- if (typeof JSON.stringify !== "function") {
1272
- meta = { // table of character substitutions
1273
- "\b": "\\b",
1274
- "\t": "\\t",
1275
- "\n": "\\n",
1276
- "\f": "\\f",
1277
- "\r": "\\r",
1278
- "\"": "\\\"",
1279
- "\\": "\\\\"
1280
- };
1281
- JSON.stringify = function (value, replacer, space) {
1282
-
1283
- // The stringify method takes a value and an optional replacer, and an optional
1284
- // space parameter, and returns a JSON text. The replacer can be a function
1285
- // that can replace values, or an array of strings that will select the keys.
1286
- // A default replacer method can be provided. Use of the space parameter can
1287
- // produce text that is more easily readable.
1288
-
1289
- var i;
1290
- gap = "";
1291
- indent = "";
1292
-
1293
- // If the space parameter is a number, make an indent string containing that
1294
- // many spaces.
1295
-
1296
- if (typeof space === "number") {
1297
- for (i = 0; i < space; i += 1) {
1298
- indent += " ";
1299
- }
1300
-
1301
- // If the space parameter is a string, it will be used as the indent string.
1302
-
1303
- } else if (typeof space === "string") {
1304
- indent = space;
1305
- }
1306
-
1307
- // If there is a replacer, it must be a function or an array.
1308
- // Otherwise, throw an error.
1309
-
1310
- rep = replacer;
1311
- if (replacer && typeof replacer !== "function" &&
1312
- (typeof replacer !== "object" ||
1313
- typeof replacer.length !== "number")) {
1314
- throw new Error("JSON.stringify");
1315
- }
1316
-
1317
- // Make a fake root object containing our value under the key of "".
1318
- // Return the result of stringifying the value.
1319
-
1320
- return str("", {"": value});
1321
- };
1322
- }
1323
-
1324
-
1325
- // If the JSON object does not yet have a parse method, give it one.
1326
-
1327
- if (typeof JSON.parse !== "function") {
1328
- JSON.parse = function (text, reviver) {
1329
-
1330
- // The parse method takes a text and an optional reviver function, and returns
1331
- // a JavaScript value if the text is a valid JSON text.
1332
-
1333
- var j;
1334
-
1335
- function walk(holder, key) {
1336
-
1337
- // The walk method is used to recursively walk the resulting structure so
1338
- // that modifications can be made.
1339
-
1340
- var k;
1341
- var v;
1342
- var value = holder[key];
1343
- if (value && typeof value === "object") {
1344
- for (k in value) {
1345
- if (Object.prototype.hasOwnProperty.call(value, k)) {
1346
- v = walk(value, k);
1347
- if (v !== undefined) {
1348
- value[k] = v;
1349
- } else {
1350
- delete value[k];
1351
- }
1352
- }
1353
- }
1354
- }
1355
- return reviver.call(holder, key, value);
1356
- }
1357
-
1358
-
1359
- // Parsing happens in four stages. In the first stage, we replace certain
1360
- // Unicode characters with escape sequences. JavaScript handles many characters
1361
- // incorrectly, either silently deleting them, or treating them as line endings.
1362
-
1363
- text = String(text);
1364
- rx_dangerous.lastIndex = 0;
1365
- if (rx_dangerous.test(text)) {
1366
- text = text.replace(rx_dangerous, function (a) {
1367
- return "\\u" +
1368
- ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
1369
- });
1370
- }
1371
-
1372
- // In the second stage, we run the text against regular expressions that look
1373
- // for non-JSON patterns. We are especially concerned with "()" and "new"
1374
- // because they can cause invocation, and "=" because it can cause mutation.
1375
- // But just to be safe, we want to reject all unexpected forms.
1376
-
1377
- // We split the second stage into 4 regexp operations in order to work around
1378
- // crippling inefficiencies in IE's and Safari's regexp engines. First we
1379
- // replace the JSON backslash pairs with "@" (a non-JSON character). Second, we
1380
- // replace all simple value tokens with "]" characters. Third, we delete all
1381
- // open brackets that follow a colon or comma or that begin the text. Finally,
1382
- // we look to see that the remaining characters are only whitespace or "]" or
1383
- // "," or ":" or "{" or "}". If that is so, then the text is safe for eval.
1384
-
1385
- if (
1386
- rx_one.test(
1387
- text
1388
- .replace(rx_two, "@")
1389
- .replace(rx_three, "]")
1390
- .replace(rx_four, "")
1391
- )
1392
- ) {
1393
-
1394
- // In the third stage we use the eval function to compile the text into a
1395
- // JavaScript structure. The "{" operator is subject to a syntactic ambiguity
1396
- // in JavaScript: it can begin a block or an object literal. We wrap the text
1397
- // in parens to eliminate the ambiguity.
1398
-
1399
- j = eval("(" + text + ")");
1400
-
1401
- // In the optional fourth stage, we recursively walk the new structure, passing
1402
- // each name/value pair to a reviver function for possible transformation.
1403
-
1404
- return (typeof reviver === "function")
1405
- ? walk({"": j}, "")
1406
- : j;
1407
- }
1408
-
1409
- // If the text is not JSON parseable, then a SyntaxError is thrown.
1410
-
1411
- throw new SyntaxError("JSON.parse");
1412
- };
1413
- }
1414
- }());
1415
- return json2$1;
1416
- }
1417
-
1418
- var json2 = json2Plugin;
1419
-
1420
- function json2Plugin() {
1421
- requireJson2();
1422
- return {}
1423
- }
1424
-
1425
- var engine = storeEngine;
1426
-
1427
- var storages = all;
1428
- var plugins = [json2];
1429
-
1430
- var store_legacy = engine.createStore(storages, plugins);
1431
-
1432
- var PREFIX = "xappWidget.";
1433
- /**
1434
- * Get an item off of local storage by key
1435
- *
1436
- * @param key
1437
- */
1438
- function get(key) {
1439
- if (store_legacy.enabled)
1440
- return store_legacy.get(PREFIX + key);
1441
- return undefined;
1442
- }
1443
- /**
1444
- * Set an item on local storage by key
1445
- *
1446
- * @param key
1447
- * @param value
1448
- */
1449
- function set$1(key, value) {
1450
- if (store_legacy.enabled)
1451
- return store_legacy.set(PREFIX + key, value);
1452
- }
1453
-
1454
190
  function useIsMounted() {
1455
191
  var ref = React$1.useRef(false);
1456
192
  React$1.useEffect(function () {
@@ -1632,11 +368,17 @@ function getItemUrl(item) {
1632
368
  return item.url || item.imageActionUrl;
1633
369
  }
1634
370
 
371
+ function useChatDispatch() {
372
+ return reactRedux.useDispatch();
373
+ }
374
+
1635
375
  var OptionalLink = function (props) {
376
+ var chatDispatch = useChatDispatch();
377
+ var visuals = reactRedux.useSelector(function (state) { return state.visuals; });
1636
378
  var url = props.url, className = props.className, onOpen = props.onOpen;
1637
379
  var handleOpenUrl = React$1.useCallback(function () {
1638
380
  if (onOpen) {
1639
- onOpen(url);
381
+ onOpen(url, chatDispatch, visuals);
1640
382
  }
1641
383
  }, [url, onOpen]);
1642
384
  if (url) {
@@ -2010,24 +752,43 @@ function throwBadKind$1(x) {
2010
752
  throw new Error("Unknown kind " + x);
2011
753
  }
2012
754
 
2013
- function execute(url, behavior) {
755
+ function setVisualStatus(status) {
756
+ return {
757
+ type: "visual_status",
758
+ detail: {
759
+ status: status,
760
+ timestamp: new Date().getTime()
761
+ }
762
+ };
763
+ }
764
+
765
+ function execute(url, dispatch, visuals, behavior) {
766
+ if (!dispatch || !visuals) {
767
+ throw new Error("OpenUrl: No dispatch and/or visual.");
768
+ }
2014
769
  var type = behavior.type;
2015
770
  switch (type) {
2016
771
  case "newWindow":
2017
- if (get("opened")) {
2018
- set$1("opened", false);
772
+ if (visuals.opened) {
773
+ dispatch(setVisualStatus({
774
+ opened: false
775
+ }));
2019
776
  }
2020
777
  window.open(url, "callout-option", "toolbar=0,status=0,width=".concat(behavior.width || 1000, ",height=").concat(behavior.height || 700));
2021
778
  break;
2022
779
  case "newTab":
2023
- if (get("opened")) {
2024
- set$1("opened", false);
780
+ if (visuals.opened) {
781
+ dispatch(setVisualStatus({
782
+ opened: false
783
+ }));
2025
784
  }
2026
785
  window.open(url, "_blank");
2027
786
  break;
2028
787
  case "sameWindow":
2029
- if (!get("opened")) {
2030
- set$1("opened", true);
788
+ if (!visuals.opened) {
789
+ dispatch(setVisualStatus({
790
+ opened: true
791
+ }));
2031
792
  }
2032
793
  window.open(url, "_self");
2033
794
  break;
@@ -2037,11 +798,11 @@ function execute(url, behavior) {
2037
798
  }
2038
799
  function useOpenUrlCallback() {
2039
800
  var env = useWidgetEnv();
2040
- return React$1.useCallback(function (url, behavior) {
801
+ return React$1.useCallback(function (url, dispatch, visuals, behavior) {
2041
802
  if (!behavior) {
2042
803
  behavior = (env === null || env === void 0 ? void 0 : env.urls) ? resolveUrlPolicy(url, env.urls) : defaultBehavior;
2043
804
  }
2044
- execute(url, behavior);
805
+ execute(url, dispatch, visuals, behavior);
2045
806
  }, [env]);
2046
807
  }
2047
808
 
@@ -2176,9 +937,9 @@ function sendTyping(typing) {
2176
937
  }; };
2177
938
  }
2178
939
 
2179
- function sendVisitorInfo(msg) {
940
+ function sendVisitorInfo(msg, sessionId) {
2180
941
  return function (chatServer) { return function () {
2181
- chatServer.setVisitorInfo(msg, function (err) {
942
+ chatServer.setVisitorInfo(msg, sessionId, function (err) {
2182
943
  if (err) {
2183
944
  log(err);
2184
945
  }
@@ -2232,10 +993,6 @@ function reset() {
2232
993
  };
2233
994
  }
2234
995
 
2235
- function useChatDispatch() {
2236
- return reactRedux.useDispatch();
2237
- }
2238
-
2239
996
  var LogChat = /** @class */ (function () {
2240
997
  function LogChat(inner) {
2241
998
  this.inner = inner;
@@ -2267,9 +1024,9 @@ var LogChat = /** @class */ (function () {
2267
1024
  log("CLIENT: sendTyping: ".concat(JSON.stringify(isTyping)));
2268
1025
  this.inner.sendTyping(isTyping);
2269
1026
  };
2270
- LogChat.prototype.setVisitorInfo = function (visitorInfo, cb) {
2271
- log("CLIENT: setVisitorInfo: ".concat(JSON.stringify(visitorInfo)));
2272
- this.inner.setVisitorInfo(visitorInfo, cb);
1027
+ LogChat.prototype.setVisitorInfo = function (visitorInfo, sessionId, cb) {
1028
+ log("CLIENT: setVisitorInfo: ".concat(JSON.stringify(visitorInfo), " session id: ").concat(sessionId));
1029
+ this.inner.setVisitorInfo(visitorInfo, sessionId, cb);
2273
1030
  };
2274
1031
  LogChat.prototype.sendChatRating = function (rating) {
2275
1032
  log("CLIENT: sendChatRating: ".concat(JSON.stringify(rating)));
@@ -2294,6 +1051,8 @@ var LogChat = /** @class */ (function () {
2294
1051
  return LogChat;
2295
1052
  }());
2296
1053
 
1054
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
1055
+
2297
1056
  var dist = {};
2298
1057
 
2299
1058
  Object.defineProperty(dist, '__esModule', { value: true });
@@ -3182,6 +1941,16 @@ function getConfigurableMessagesConfig(messages) {
3182
1941
  return config;
3183
1942
  }
3184
1943
 
1944
+ function setSessionId(sessionId) {
1945
+ return {
1946
+ type: "session_id",
1947
+ detail: {
1948
+ sessionId: sessionId,
1949
+ timestamp: new Date().getTime()
1950
+ }
1951
+ };
1952
+ }
1953
+
3185
1954
  var PERMISSION_QUESTION_EXPIRATION_MS$1 = 300000; // 5 minutes
3186
1955
  // interface UserLeaveMessage {
3187
1956
  // readonly user: ChatUserInfo;
@@ -3371,7 +2140,7 @@ var StentorDirectChat = /** @class */ (function () {
3371
2140
  };
3372
2141
  StentorDirectChat.prototype.sendTyping = function () {
3373
2142
  };
3374
- StentorDirectChat.prototype.setVisitorInfo = function (visitorInfo, cb) {
2143
+ StentorDirectChat.prototype.setVisitorInfo = function (visitorInfo, sessionId, cb) {
3375
2144
  this.visitorInfo = visitorInfo;
3376
2145
  this._attributes = __assign({}, this.visitorInfo.attributes);
3377
2146
  // do not set currentUrl if localhost, localhost is not liked by some firewalls, like AWS WAF
@@ -3390,7 +2159,7 @@ var StentorDirectChat = /** @class */ (function () {
3390
2159
  user: this.getBot(undefined),
3391
2160
  token: ""
3392
2161
  });
3393
- this.startSession();
2162
+ this.startSession(sessionId);
3394
2163
  cb();
3395
2164
  };
3396
2165
  StentorDirectChat.prototype.sendChatRating = function () {
@@ -3535,7 +2304,8 @@ var StentorDirectChat = /** @class */ (function () {
3535
2304
  _f.label = 1;
3536
2305
  case 1:
3537
2306
  if (!(i < configurableMessages.length)) return [3 /*break*/, 4];
3538
- timeout = configurableMessages[i - 1].delay * 1000;
2307
+ timeout = this.config.timeout || 15000;
2308
+ console.log("using timeout of ".concat(timeout));
3539
2309
  this.typing();
3540
2310
  // We don't start typing IF we have a failure message displayed and we are waiting on the timeout
3541
2311
  return [4 /*yield*/, new RetryRequest({ retries: 1, timeout: timeout })
@@ -3585,7 +2355,7 @@ var StentorDirectChat = /** @class */ (function () {
3585
2355
  });
3586
2356
  });
3587
2357
  };
3588
- StentorDirectChat.prototype.startSession = function () {
2358
+ StentorDirectChat.prototype.startSession = function (sessionId) {
3589
2359
  if (this.visitorInfo.visitorId) {
3590
2360
  this._userId = "".concat(this.visitorInfo.visitorId);
3591
2361
  }
@@ -3595,12 +2365,14 @@ var StentorDirectChat = /** @class */ (function () {
3595
2365
  else {
3596
2366
  this._userId = "stentor-widget-user-".concat(uuid_1());
3597
2367
  }
3598
- if (get("sessionId") !== "") {
3599
- this._sessionId = get("sessionId");
2368
+ if (sessionId) {
2369
+ this._sessionId = sessionId;
2370
+ log("Using persisted session id: ".concat(this._sessionId));
3600
2371
  }
3601
2372
  else {
3602
2373
  this._sessionId = "stentor-widget-session-".concat(uuid_1());
3603
- set$1("sessionId", this._sessionId);
2374
+ this.dispatch(setSessionId(this._sessionId));
2375
+ log("Using generated session id: ".concat(this._sessionId));
3604
2376
  }
3605
2377
  // This is a flag that is cleared after the first message is sent
3606
2378
  this.isNewSession = true;
@@ -3799,7 +2571,7 @@ function requestToMessage(botRequest, now) {
3799
2571
 
3800
2572
  var StentorRouterChat = /** @class */ (function () {
3801
2573
  function StentorRouterChat(config, options) {
3802
- var _a;
2574
+ var _a, _b;
3803
2575
  this._userId = "";
3804
2576
  this._sessionId = "";
3805
2577
  this.accessToken = "";
@@ -3812,13 +2584,23 @@ var StentorRouterChat = /** @class */ (function () {
3812
2584
  // Dig out the path parameters. Put them into the attributes.
3813
2585
  // The WS url is the barebone domain.
3814
2586
  var url = new URL(this.config.url);
3815
- var urlPath = (_a = url.pathname) === null || _a === void 0 ? void 0 : _a.split("/");
2587
+ var appId = url.searchParams.get("appId");
3816
2588
  var locationUrl = new URL(window.location.href);
3817
2589
  this.isAdmin = locationUrl.searchParams.get("isAdmin") === "true";
3818
- this.serverUrl = "".concat(url.origin);
3819
- if (urlPath && urlPath.length > 1) {
3820
- this.serverUrl = "".concat(this.serverUrl, "/").concat(urlPath[1]); // the first path (after the initial "") is the "dev" or "prod"
3821
- this.urlAttributes.path = urlPath.slice(1);
2590
+ if (appId) {
2591
+ // New Path if we have the appId on the query string
2592
+ this.serverUrl = this.config.url;
2593
+ this.urlAttributes.path = (_a = url.pathname) === null || _a === void 0 ? void 0 : _a.split("/");
2594
+ // keep the server url
2595
+ }
2596
+ else {
2597
+ // Old path
2598
+ this.serverUrl = "".concat(url.origin);
2599
+ var urlPath = (_b = url.pathname) === null || _b === void 0 ? void 0 : _b.split("/");
2600
+ if (urlPath && urlPath.length > 1) {
2601
+ this.serverUrl = "".concat(this.serverUrl, "/").concat(urlPath[1]);
2602
+ this.urlAttributes.path = urlPath.slice(1);
2603
+ }
3822
2604
  }
3823
2605
  log("WS url: ".concat(this.serverUrl, " isAdmin: ").concat(this.isAdmin, " attributes: ").concat(JSON.stringify(this.attributes)));
3824
2606
  this.configurableMessages = getConfigurableMessagesConfig(options.configurableMessages);
@@ -3986,7 +2768,10 @@ var StentorRouterChat = /** @class */ (function () {
3986
2768
  StentorRouterChat.prototype.wsCreate = function () {
3987
2769
  var _this = this;
3988
2770
  this.setConnectionStatus("pending");
3989
- this.ws = new WebSocket("".concat(this.serverUrl, "?userId=").concat(this._userId, "&isAdmin=").concat(this.isAdmin));
2771
+ var url = new URL(this.serverUrl);
2772
+ url.searchParams.set("userId", this._userId);
2773
+ url.searchParams.set("isAdmin", "".concat(this.isAdmin));
2774
+ this.ws = new WebSocket(url.toString());
3990
2775
  this.ws.onerror = function (ev) {
3991
2776
  var _a;
3992
2777
  log("Error in WS connection. Type: ".concat(!ev ? "?" : ev.type, " Ready State: ").concat((_a = _this.ws) === null || _a === void 0 ? void 0 : _a.readyState));
@@ -4020,6 +2805,7 @@ var StentorRouterChat = /** @class */ (function () {
4020
2805
  data: data,
4021
2806
  sender: this.visitorInfo,
4022
2807
  sessionId: this._sessionId,
2808
+ timeMs: new Date().getTime()
4023
2809
  });
4024
2810
  log("Widget says: ".concat(payloadData));
4025
2811
  if (!this.ws) {
@@ -4121,7 +2907,7 @@ var StentorRouterChat = /** @class */ (function () {
4121
2907
  // TODO: Is this too much traffic?
4122
2908
  // this.emit(isTyping ? "typing" : "stop typing");
4123
2909
  };
4124
- StentorRouterChat.prototype.setVisitorInfo = function (visitorInfoMessage, cb) {
2910
+ StentorRouterChat.prototype.setVisitorInfo = function (visitorInfoMessage, sessionId, cb) {
4125
2911
  log("Visitor Info Message = ".concat(JSON.stringify(visitorInfoMessage)));
4126
2912
  this.visitorInfo = {
4127
2913
  deviceId: "Widget",
@@ -4133,7 +2919,7 @@ var StentorRouterChat = /** @class */ (function () {
4133
2919
  };
4134
2920
  this.attributes = __assign(__assign(__assign({}, visitorInfoMessage.attributes), this.attributes), { currentUrl: window.location.href });
4135
2921
  this.accessToken = visitorInfoMessage.accessToken;
4136
- this.startSession();
2922
+ this.startSession(sessionId);
4137
2923
  this.postVisitorInfo(); // we, the widget, joined the server
4138
2924
  cb();
4139
2925
  };
@@ -4186,7 +2972,7 @@ var StentorRouterChat = /** @class */ (function () {
4186
2972
  });
4187
2973
  });
4188
2974
  };
4189
- StentorRouterChat.prototype.startSession = function () {
2975
+ StentorRouterChat.prototype.startSession = function (sessionId) {
4190
2976
  if (this.visitorInfo.userId) {
4191
2977
  this._userId = "".concat(this.visitorInfo.userId);
4192
2978
  }
@@ -4199,16 +2985,16 @@ var StentorRouterChat = /** @class */ (function () {
4199
2985
  var joinSessionId = new URL(window.location.href).searchParams.get("sessionId");
4200
2986
  if (joinSessionId) {
4201
2987
  this._sessionId = joinSessionId;
4202
- set$1("sessionId", this._sessionId);
2988
+ this.dispatch(setSessionId(this._sessionId));
4203
2989
  log("Using enforced session id: ".concat(this._sessionId));
4204
2990
  }
4205
- else if (get("sessionId")) {
4206
- this._sessionId = get("sessionId");
2991
+ else if (sessionId) {
2992
+ this._sessionId = sessionId;
4207
2993
  log("Using persisted session id: ".concat(this._sessionId));
4208
2994
  }
4209
2995
  else {
4210
2996
  this._sessionId = "stentor-widget-session-".concat(uuid_1());
4211
- set$1("sessionId", this._sessionId);
2997
+ this.dispatch(setSessionId(this._sessionId));
4212
2998
  log("Using generated session id: ".concat(this._sessionId));
4213
2999
  }
4214
3000
  // Always. This triggers a LAUNCH_REQUEST most of the time
@@ -7759,7 +6545,7 @@ var StentorServerChat = /** @class */ (function () {
7759
6545
  StentorServerChat.prototype.sendTyping = function (isTyping) {
7760
6546
  this.socket.emit(isTyping ? "typing" : "stop typing");
7761
6547
  };
7762
- StentorServerChat.prototype.setVisitorInfo = function (visitorInfo, cb) {
6548
+ StentorServerChat.prototype.setVisitorInfo = function (visitorInfo, _sessionId, cb) {
7763
6549
  this.visitorInfo = visitorInfo;
7764
6550
  this.socket.emit("add user", visitorInfo);
7765
6551
  cb();
@@ -7800,7 +6586,8 @@ function createChatServerCore(config, options) {
7800
6586
  case "direct":
7801
6587
  return new StentorDirectChat({
7802
6588
  url: config.serverUrl,
7803
- key: config.accountKey
6589
+ key: config.accountKey,
6590
+ timeout: config.timeout
7804
6591
  }, options);
7805
6592
  case "websocket":
7806
6593
  return new StentorServerChat({
@@ -7854,11 +6641,13 @@ function useChatServerDispatch() {
7854
6641
  var ChatChipsContainer = function (_) {
7855
6642
  var dispatch = useChatServerDispatch();
7856
6643
  var chips = reactRedux.useSelector(function (state) { return state.chips; });
6644
+ var chatDispatch = useChatDispatch();
6645
+ var visuals = reactRedux.useSelector(function (state) { return state.visuals; });
7857
6646
  var openUrl = useOpenUrlCallback();
7858
6647
  function optionOnChange(option) {
7859
6648
  var actionUrl = isChatServerActionLink(option) && option.actionUrl;
7860
6649
  if (actionUrl) {
7861
- openUrl(actionUrl);
6650
+ openUrl(actionUrl, chatDispatch, visuals);
7862
6651
  }
7863
6652
  else {
7864
6653
  dispatch(executeAction(getChatServerActionLinkLabel(option)));
@@ -7962,6 +6751,8 @@ var ChatMenu = function (props) {
7962
6751
  var items = props.items, opened = props.opened;
7963
6752
  var openFrom = props.openFrom || "bottom";
7964
6753
  var handleOpenUrl = useOpenUrlCallback();
6754
+ var chatDispatch = useChatDispatch();
6755
+ var visuals = reactRedux.useSelector(function (state) { return state.visuals; });
7965
6756
  return (React__default$1["default"].createElement("div", { className: "chat-menu-".concat(openFrom, " ").concat(opened ? "chat-menu-".concat(openFrom, "--opened") : "chat-menu-".concat(openFrom, "--closed")) }, items.map(function (item, i) {
7966
6757
  if (lib.isStandardMenuItem(item)) {
7967
6758
  return React__default$1["default"].createElement(ChatMenuItem, { key: i, onClick: props.onItemClick, label: item.label, subtitle: item.subtitle });
@@ -7980,7 +6771,7 @@ var ChatMenu = function (props) {
7980
6771
  React__default$1["default"].createElement("div", { className: "chat-menu-item-static-text--body" }, item.body))));
7981
6772
  }
7982
6773
  else if (lib.isOpenURLMenuItem(item)) {
7983
- return React__default$1["default"].createElement("button", { key: i, className: "chat-menu-item", onClick: handleOpenUrl.bind(_this, item.url, item.behavior) }, item.text);
6774
+ return React__default$1["default"].createElement("button", { key: i, className: "chat-menu-item", onClick: handleOpenUrl.bind(_this, item.url, chatDispatch, visuals, item.behavior) }, item.text);
7984
6775
  }
7985
6776
  return React__default$1["default"].createElement("p", null, "Unknown");
7986
6777
  })));
@@ -8007,15 +6798,17 @@ function useExecuteActionCallback() {
8007
6798
 
8008
6799
  function useButtonCallback() {
8009
6800
  var handleOpenUrl = useOpenUrlCallback();
6801
+ var chatDispatch = useChatDispatch();
6802
+ var visuals = reactRedux.useSelector(function (state) { return state.visuals; });
8010
6803
  var executeAction = useExecuteActionCallback();
8011
6804
  return React$1.useCallback(function (button) {
8012
6805
  if (button.actionUrl) {
8013
- handleOpenUrl(button.actionUrl);
6806
+ handleOpenUrl(button.actionUrl, chatDispatch, visuals);
8014
6807
  }
8015
6808
  else {
8016
6809
  executeAction(button.label);
8017
6810
  }
8018
- }, [executeAction, handleOpenUrl]);
6811
+ }, [chatDispatch, executeAction, handleOpenUrl, visuals]);
8019
6812
  }
8020
6813
 
8021
6814
  /**
@@ -8409,12 +7202,14 @@ var ChatMarkdownMessage = function (props) {
8409
7202
  var onOpenUrl = props.onOpenUrl;
8410
7203
  var agentMessage = isAgent(props.message.user.nick);
8411
7204
  var ref = React$1.useRef();
7205
+ var chatDispatch = useChatDispatch();
7206
+ var visuals = reactRedux.useSelector(function (state) { return state.visuals; });
8412
7207
  var html = props.message.msg.html;
8413
7208
  var handleLinkClick = React$1.useCallback(function (ev) {
8414
7209
  if (onOpenUrl) {
8415
7210
  var link = ev.target;
8416
7211
  ev.preventDefault();
8417
- onOpenUrl(link.href);
7212
+ onOpenUrl(link.href, chatDispatch, visuals);
8418
7213
  }
8419
7214
  }, [onOpenUrl]);
8420
7215
  React$1.useEffect(function () {
@@ -8674,6 +7469,7 @@ function useGreeting(active) {
8674
7469
  var snapshotRef = React$1.useRef(null);
8675
7470
  var ctx = React$1.useContext(ChatConfigContext);
8676
7471
  var isAdmin = ctx.env.isAdmin;
7472
+ var sessionId = reactRedux.useSelector(function (state) { return state.sessionId; });
8677
7473
  React$1.useEffect(function () {
8678
7474
  if (active) {
8679
7475
  if (snapshotRef.current !== curr) {
@@ -8685,7 +7481,7 @@ function useGreeting(active) {
8685
7481
  userId: curr.userId,
8686
7482
  accessToken: curr.accessToken,
8687
7483
  attributes: __assign(__assign({}, curr.attributes), { currentUrl: window.location.href })
8688
- }));
7484
+ }, sessionId));
8689
7485
  if (!isAdmin) {
8690
7486
  var timeoutId_1 = setTimeout(function () {
8691
7487
  var greetingAction = sendGreeting();
@@ -8968,6 +7764,7 @@ var Suggestions = function (props) {
8968
7764
 
8969
7765
  var ChatFooter = function (props) {
8970
7766
  var _a, _b, _c;
7767
+ var innerDispatch = useChatDispatch();
8971
7768
  var placeholder = props.placeholder, sendButtonIcon = props.sendButtonIcon, footerConfig = props.footerConfig, menuConfig = props.menuConfig, inputConfig = props.inputConfig, onSubmit = props.onSubmit;
8972
7769
  var _d = React$1.useState(false), drawerOpen = _d[0], setDrawerState = _d[1]; // false initially
8973
7770
  var _e = React$1.useState(), suggestionSearch = _e[0], setSuggestionSearch = _e[1];
@@ -8988,7 +7785,9 @@ var ChatFooter = function (props) {
8988
7785
  function toggleDrawer() {
8989
7786
  var newDrawer = !drawerOpen;
8990
7787
  setDrawerState(newDrawer);
8991
- set$1("drawer", newDrawer);
7788
+ innerDispatch(setVisualStatus({
7789
+ drawer: newDrawer
7790
+ }));
8992
7791
  }
8993
7792
  function handleMenuItem(label) {
8994
7793
  setDrawerState(false);
@@ -31367,16 +30166,17 @@ var PrechatForm = function (props) {
31367
30166
 
31368
30167
  var PrechatFormContainer = function (props) {
31369
30168
  var dispatch = useChatServerDispatch();
30169
+ var sessionId = reactRedux.useSelector(function (state) { return state.sessionId; });
31370
30170
  var handleSubmit = React$1.useCallback(function (data) {
31371
30171
  // Don't send empty messages
31372
30172
  if (!data.message)
31373
30173
  return;
31374
30174
  dispatch(sendVisitorInfo({
31375
30175
  displayName: data.name,
31376
- email: data.email
31377
- }));
30176
+ email: data.email,
30177
+ }, sessionId));
31378
30178
  dispatch(executeAction(data.message));
31379
- }, [dispatch]);
30179
+ }, [dispatch, sessionId]);
31380
30180
  return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null,
31381
30181
  React__default$1["default"].createElement("span", { className: "message-sr-only" }, "at " + props.time + " system message"),
31382
30182
  React__default$1["default"].createElement(PrechatForm, { onSubmit: handleSubmit })));
@@ -31492,14 +30292,14 @@ var MessageList = function (props) {
31492
30292
  * @param addClass
31493
30293
  */
31494
30294
  function renderByType(msg, sibling) {
31495
- var _a;
30295
+ var _a, _b, _c;
31496
30296
  var user;
31497
30297
  // visitor is this widget
31498
- if (msg.user.nick.startsWith("visitor:")) {
30298
+ if ((_b = (_a = msg.user) === null || _a === void 0 ? void 0 : _a.nick) === null || _b === void 0 ? void 0 : _b.startsWith("visitor:")) {
31499
30299
  user = msg.user;
31500
30300
  }
31501
30301
  else {
31502
- user = ((_a = props.agents[msg.user.nick]) === null || _a === void 0 ? void 0 : _a.user) || props.agent;
30302
+ user = ((_c = props.agents[msg.user.nick]) === null || _c === void 0 ? void 0 : _c.user) || props.agent;
31503
30303
  // Still nothing?
31504
30304
  if (!user) {
31505
30305
  log("Could not get a user from agents list with nick: \"".concat(msg.user.nick, "\""));
@@ -31637,6 +30437,7 @@ var minimizeButtonAriaLabel = "To minimize widget click on minus icon in top rig
31637
30437
  var closeButtonAriaLabel = "To close widget click on close icon in top right side of widget.";
31638
30438
  var ChatHeader = function (props) {
31639
30439
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
30440
+ var innerDispatch = useChatDispatch();
31640
30441
  var menuConfig = props.menuConfig, onSubmit = props.onSubmit;
31641
30442
  var _s = React$1.useState(false), drawerOpen = _s[0], setDrawerState = _s[1]; // false initially
31642
30443
  var menuPosition = (menuConfig === null || menuConfig === void 0 ? void 0 : menuConfig.menuButtonLocation) || "FOOTER";
@@ -31648,7 +30449,9 @@ var ChatHeader = function (props) {
31648
30449
  function toggleDrawer() {
31649
30450
  var newDrawer = !drawerOpen;
31650
30451
  setDrawerState(newDrawer);
31651
- set$1("drawer", newDrawer);
30452
+ innerDispatch(setVisualStatus({
30453
+ drawer: newDrawer
30454
+ }));
31652
30455
  }
31653
30456
  function handleMenuItem(label) {
31654
30457
  setDrawerState(false);
@@ -31983,7 +30786,7 @@ var ChatWidgetWrapper = function (props) {
31983
30786
  React__default$1["default"].createElement(ChatWidget, __assign({}, props)))));
31984
30787
  };
31985
30788
  var ChatWidget = function (props) {
31986
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
30789
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
31987
30790
  var innerDispatch = useChatDispatch();
31988
30791
  var dispatch = useChatServerDispatch();
31989
30792
  // From Redux
@@ -32009,20 +30812,34 @@ var ChatWidget = function (props) {
32009
30812
  else {
32010
30813
  canCancel = !dockedMode && !staticMode;
32011
30814
  }
30815
+ // For backward compatibility. Note: the action will create the actual "visuals" object" (this is a copy).
30816
+ if (!chatState.visuals) {
30817
+ chatState.visuals = {};
30818
+ }
32012
30819
  // Our state - pull from storage
32013
- var _x = React$1.useState((!canMinimize && !canCancel) ||
32014
- !!get("visible") ||
30820
+ var _1 = React$1.useState((!canMinimize && !canCancel) ||
30821
+ // !!get("visible") ||
30822
+ chatState.visuals.visible ||
32015
30823
  (((_k = props.config) === null || _k === void 0 ? void 0 : _k.autoOpenOnWidth) &&
32016
- window.matchMedia("(min-width: ".concat((_l = props.config) === null || _l === void 0 ? void 0 : _l.autoOpenOnWidth, ")")).matches)), visible = _x[0], setVisibleState = _x[1];
32017
- var _y = React$1.useState(false), typing = _y[0], setTypingState = _y[1]; // false initially
30824
+ window.matchMedia("(min-width: ".concat((_l = props.config) === null || _l === void 0 ? void 0 : _l.autoOpenOnWidth, ")")).matches)), visible = _1[0], setVisibleState = _1[1];
30825
+ var _2 = React$1.useState(false), typing = _2[0], setTypingState = _2[1]; // false initially
32018
30826
  var chatServer = React$1.useContext(ChatServerContext);
30827
+ var patternsConfig = (_o = (_m = props.config) === null || _m === void 0 ? void 0 : _m.autoOpenOnPattern) === null || _o === void 0 ? void 0 : _o.patterns;
30828
+ var currentUrl = window.location.href;
30829
+ var patternExist = patternsConfig && patternsConfig.length > 0;
30830
+ var patternMatches = patternsConfig === null || patternsConfig === void 0 ? void 0 : patternsConfig.some(function (pattern) { return currentUrl.includes(pattern); });
30831
+ var configWidth = (_q = (_p = props.config) === null || _p === void 0 ? void 0 : _p.autoOpenOnPattern) === null || _q === void 0 ? void 0 : _q.minimumWidth;
30832
+ // eslint-disable-next-line no-restricted-globals
30833
+ var currentWidth = screen.width;
32019
30834
  var setVisible = React$1.useCallback(function (newVisible) {
32020
30835
  if (staticMode) {
32021
30836
  return;
32022
30837
  }
32023
30838
  setVisibleState(newVisible);
32024
- set$1("visible", newVisible);
32025
- }, [staticMode]);
30839
+ innerDispatch(setVisualStatus({
30840
+ visible: newVisible
30841
+ }));
30842
+ }, [innerDispatch, staticMode]);
32026
30843
  React$1.useEffect(function () {
32027
30844
  var _a, _b;
32028
30845
  document.addEventListener("keydown", function (event) {
@@ -32033,17 +30850,26 @@ var ChatWidget = function (props) {
32033
30850
  }
32034
30851
  });
32035
30852
  if (checkSessionExpiration((chatState === null || chatState === void 0 ? void 0 : chatState.sessionExpiration) || ((_a = props.config) === null || _a === void 0 ? void 0 : _a.sessionExpiration), (_b = chatState === null || chatState === void 0 ? void 0 : chatState.chats[chatState.chats.length - 1]) === null || _b === void 0 ? void 0 : _b.timestamp, chatState === null || chatState === void 0 ? void 0 : chatState.lastTimestamp)) {
32036
- set$1("sessionId", ""); // force new session
30853
+ innerDispatch(setSessionId(undefined));
32037
30854
  innerDispatch(reset());
32038
30855
  }
32039
30856
  // eslint-disable-next-line react-hooks/exhaustive-deps
32040
30857
  }, []);
32041
30858
  React$1.useEffect(function () {
32042
30859
  // For reopen widget after move on same windowyar
32043
- if (get("opened")) {
30860
+ // if (get("opened")) {
30861
+ // setVisible(true);
30862
+ // }
30863
+ if (chatState.visuals.opened) {
30864
+ setVisible(true);
30865
+ }
30866
+ if (patternExist && patternMatches) {
32044
30867
  setVisible(true);
32045
30868
  }
32046
- }, [setVisible]);
30869
+ if (currentWidth < +configWidth) {
30870
+ setVisible(false);
30871
+ }
30872
+ }, [currentWidth, patternExist, patternMatches, configWidth, setVisible, chatState.visuals.opened]);
32047
30873
  function handleOnChange() {
32048
30874
  if (!typing) {
32049
30875
  dispatch(sendTyping(true));
@@ -32094,16 +30920,23 @@ var ChatWidget = function (props) {
32094
30920
  innerDispatch(reset());
32095
30921
  }
32096
30922
  function minimizeOnClick() {
32097
- set$1("opened", false);
30923
+ innerDispatch(setVisualStatus({
30924
+ opened: false
30925
+ }));
32098
30926
  setVisible(false);
32099
30927
  }
32100
30928
  function cancelOnClick() {
32101
- set$1("opened", false);
30929
+ //set("opened", false);
30930
+ innerDispatch(setVisualStatus({
30931
+ opened: false
30932
+ }));
32102
30933
  innerDispatch(reset());
32103
30934
  setVisible(false);
32104
30935
  }
32105
30936
  function chatButtonOnClick() {
32106
- set$1("opened", true);
30937
+ innerDispatch(setVisualStatus({
30938
+ opened: true
30939
+ }));
32107
30940
  setVisible(true);
32108
30941
  setTimeout(function () {
32109
30942
  document.getElementById("chatWidgetInput").focus();
@@ -32151,22 +30984,22 @@ var ChatWidget = function (props) {
32151
30984
  onConnectionStatusChange(connectionStatus);
32152
30985
  }
32153
30986
  }, [connectionStatus, onConnectionStatusChange]);
32154
- useExternalScript((_m = props.config) === null || _m === void 0 ? void 0 : _m.middlewareUrl);
30987
+ useExternalScript((_r = props.config) === null || _r === void 0 ? void 0 : _r.middlewareUrl);
32155
30988
  // This is a pseudo agent. It represent's the widget (shown in the header avatar for instance)
32156
- var widgetAgent = ((_o = chatState.agents["agent:robot"]) === null || _o === void 0 ? void 0 : _o.user) || (config === null || config === void 0 ? void 0 : config.agent)
30989
+ var widgetAgent = ((_s = chatState.agents["agent:robot"]) === null || _s === void 0 ? void 0 : _s.user) || (config === null || config === void 0 ? void 0 : config.agent)
32157
30990
  || { nick: "agent:robot", avatarPath: config.avatarUrl, display_name: "Agent" };
32158
30991
  return (React__default$1["default"].createElement(React__default$1["default"].Fragment, null,
32159
30992
  React__default$1["default"].createElement("div", { className: "widget-container ".concat(modeClass, " ").concat(getVisibilityClass()) },
32160
30993
  React__default$1["default"].createElement(WidgetStylesheet, { theme: config === null || config === void 0 ? void 0 : config.theme }),
32161
30994
  React__default$1["default"].createElement(ChatHeader, { accountStatus: chatState.accountStatus, refreshOnClick: openModal, minimizeOnClick: minimizeOnClick, cancelOnClick: cancelOnClick, agent: widgetAgent, canRefresh: canRefresh, canMinimize: canMinimize, canCancel: canCancel, config: config === null || config === void 0 ? void 0 : config.header, menuConfig: config.menu, onSubmit: handleOnSubmit }),
32162
- React__default$1["default"].createElement(MessageList, { visible: visible, queuePosition: chatState.queuePosition, isChatting: chatState.isChatting, isOffline: isOffline, messages: messages, agents: chatState.agents, agent: config === null || config === void 0 ? void 0 : config.agent, lastRatingRequestTimestamp: chatState.lastRatingRequestTimestamp, hasRating: chatState.hasRating, visitorId: chatState.visitorId, messageMiddleware: props.messageMiddleware, textTypingStatusEnabled: (_q = (_p = props.config) === null || _p === void 0 ? void 0 : _p.typingStatus) === null || _q === void 0 ? void 0 : _q.textTypingStatusEnabled, onSend: handleSendMessage, onWrite: handleWriteMessage, onOpenUrl: handleOpenUrl }),
30995
+ React__default$1["default"].createElement(MessageList, { visible: visible, queuePosition: chatState.queuePosition, isChatting: chatState.isChatting, isOffline: isOffline, messages: messages, agents: chatState.agents, agent: config === null || config === void 0 ? void 0 : config.agent, lastRatingRequestTimestamp: chatState.lastRatingRequestTimestamp, hasRating: chatState.hasRating, visitorId: chatState.visitorId, messageMiddleware: props.messageMiddleware, textTypingStatusEnabled: (_u = (_t = props.config) === null || _t === void 0 ? void 0 : _t.typingStatus) === null || _u === void 0 ? void 0 : _u.textTypingStatusEnabled, onSend: handleSendMessage, onWrite: handleWriteMessage, onOpenUrl: handleOpenUrl }),
32163
30996
  React__default$1["default"].createElement("div", { className: "spinner-container ".concat(visible && connectionStatus === "pending" ? "visible" : "") },
32164
30997
  React__default$1["default"].createElement("div", { className: "spinner" })),
32165
30998
  connectionStatus === "offline" && React__default$1["default"].createElement(ServerOffline, null),
32166
- React__default$1["default"].createElement(ChatFooter, { isAdmin: config === null || config === void 0 ? void 0 : config.isAdmin, isChatting: chatState.isChatting, placeholder: (_r = config === null || config === void 0 ? void 0 : config.input) === null || _r === void 0 ? void 0 : _r.placeholder, sendButtonIcon: (_t = (_s = config === null || config === void 0 ? void 0 : config.footer) === null || _s === void 0 ? void 0 : _s.sendButton) === null || _t === void 0 ? void 0 : _t.icon, visible: visible, menuConfig: props.config.menu, footerConfig: (_u = props.config) === null || _u === void 0 ? void 0 : _u.footer, inputConfig: (_v = props.config) === null || _v === void 0 ? void 0 : _v.input, onChange: handleOnChange, onSubmit: handleOnSubmit, onFileUpload: handleFileUpload }),
30999
+ React__default$1["default"].createElement(ChatFooter, { isAdmin: config === null || config === void 0 ? void 0 : config.isAdmin, isChatting: chatState.isChatting, placeholder: (_v = config === null || config === void 0 ? void 0 : config.input) === null || _v === void 0 ? void 0 : _v.placeholder, sendButtonIcon: (_x = (_w = config === null || config === void 0 ? void 0 : config.footer) === null || _w === void 0 ? void 0 : _w.sendButton) === null || _x === void 0 ? void 0 : _x.icon, visible: visible, menuConfig: props.config.menu, footerConfig: (_y = props.config) === null || _y === void 0 ? void 0 : _y.footer, inputConfig: (_z = props.config) === null || _z === void 0 ? void 0 : _z.input, onChange: handleOnChange, onSubmit: handleOnSubmit, onFileUpload: handleFileUpload }),
32167
31000
  React__default$1["default"].createElement("div", { className: "restartModal", ref: modalRef, onClick: closeModal },
32168
31001
  React__default$1["default"].createElement(ModalContent, { onClose: closeModal, onReset: refreshOnClick }))),
32169
- React__default$1["default"].createElement(ChatButton, { addClass: getVisibilityClass(), onClick: chatButtonOnClick, config: (_w = props.config) === null || _w === void 0 ? void 0 : _w.cta, visible: visible })));
31002
+ React__default$1["default"].createElement(ChatButton, { addClass: getVisibilityClass(), onClick: chatButtonOnClick, config: (_0 = props.config) === null || _0 === void 0 ? void 0 : _0.cta, visible: visible })));
32170
31003
  };
32171
31004
 
32172
31005
  function tryParseJson(str) {
@@ -32223,7 +31056,7 @@ function createDefaultState(state) {
32223
31056
  connectionStatus: "offline",
32224
31057
  token: null,
32225
31058
  greetingRequested: false
32226
- }, accountStatus: "offline", departments: {}, visitor: DEFAULT_VISITOR, agents: {}, chats: [], lastTimestamp: 0, lastRatingRequestTimestamp: 0, hasRating: false, isChatting: false, queuePosition: 0, failureMsg: null, visitorId: visitorFingerprint(), chips: [], sessionExpiration: "24h" }, state);
31059
+ }, accountStatus: "offline", departments: {}, visitor: DEFAULT_VISITOR, agents: {}, chats: [], lastTimestamp: 0, lastRatingRequestTimestamp: 0, hasRating: false, isChatting: false, queuePosition: 0, failureMsg: null, visitorId: visitorFingerprint(), chips: [], sessionExpiration: "24h", visuals: {} }, state);
32227
31060
  }
32228
31061
  var DEFAULT_STATE = createDefaultState();
32229
31062
 
@@ -32369,6 +31202,24 @@ function update(state, action) {
32369
31202
  return state;
32370
31203
  case "account_status":
32371
31204
  return __assign(__assign({}, state), { accountStatus: action.detail.status });
31205
+ case "session_id":
31206
+ return __assign(__assign({}, state), { sessionId: action.detail.sessionId });
31207
+ case "visual_status":
31208
+ var newVisualState = __assign({}, state);
31209
+ // Backward compatibility
31210
+ if (!newVisualState.visuals) {
31211
+ newVisualState.visuals = {};
31212
+ }
31213
+ if (action.detail.status.drawer !== undefined) {
31214
+ newVisualState.visuals.drawer = action.detail.status.drawer;
31215
+ }
31216
+ if (action.detail.status.opened !== undefined) {
31217
+ newVisualState.visuals.opened = action.detail.status.opened;
31218
+ }
31219
+ if (action.detail.status.visible !== undefined) {
31220
+ newVisualState.visuals.visible = action.detail.status.visible;
31221
+ }
31222
+ return newVisualState;
32372
31223
  case "department_update":
32373
31224
  return __assign(__assign({}, state), { departments: __assign(__assign({}, state.departments), (_a = {}, _a[action.detail.id] = __assign({}, action.detail), _a)) });
32374
31225
  case "visitor_update":
@@ -32618,7 +31469,7 @@ var StaticChatWidgetContainer = function (props) {
32618
31469
 
32619
31470
  function createStateFromMessages(messages) {
32620
31471
  var def = createDefaultState();
32621
- return __assign(__assign({}, def), { connection: __assign(__assign({}, def.connection), { connectionStatus: "online" }), accountStatus: "online", chats: __spreadArray$1([], messages, true), isChatting: true });
31472
+ return __assign(__assign({}, def), { connection: __assign(__assign({}, def.connection), { connectionStatus: "online" }), accountStatus: "online", chats: __spreadArray$1([], messages, true), isChatting: true, visuals: {} });
32622
31473
  }
32623
31474
 
32624
31475
  var StaticMessagesChatWidgetContainer = function (props) {