@morgan-and-morgan/intake-agent 1.0.0-alpha.12 → 1.0.0-alpha.14

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.
@@ -328,6 +328,10 @@
328
328
  const PROMPT_COOLDOWN_KEY = "mm-intake-widget-prompt-dismissed-at";
329
329
  const PROMPT_SESSION_KEY = "mm-intake-widget-prompt-dismissed";
330
330
  const CHAT_CHROME_COLOR = "#e8eef2";
331
+ const matchMediaQuery = (query) => {
332
+ var _a;
333
+ return (_a = globalThis.matchMedia) == null ? void 0 : _a.call(globalThis, query);
334
+ };
331
335
  const KEYBOARD_MIN_SHRINK_PX = 100;
332
336
  const CHAT_READY_FALLBACK_MS = 4e3;
333
337
  const cleanSigningReturnUrl = () => {
@@ -361,13 +365,12 @@
361
365
  }
362
366
  };
363
367
  const mountIntakeWidget = (config, onDestroy) => {
364
- var _a;
365
368
  const mount = document.createElement("div");
366
369
  mount.dataset.mmIntakeWidget = "";
367
370
  const shadow = mount.attachShadow({ mode: "open" });
368
371
  const assetUrl = (fileName) => {
369
- var _a2;
370
- return new URL(fileName, (_a2 = config.assetBaseUrl) != null ? _a2 : `${config.chatOrigin}/intake-widget/`).href;
372
+ var _a;
373
+ return new URL(fileName, (_a = config.assetBaseUrl) != null ? _a : `${config.chatOrigin}/intake-widget/`).href;
371
374
  };
372
375
  const elements = renderWidgetShell(shadow, assetUrl("button-text-us.png"), assetUrl("consultation-prompt.webp"));
373
376
  document.body.append(mount);
@@ -393,8 +396,8 @@
393
396
  elements.launcher.setAttribute("aria-label", isOpen ? "Close intake chat" : "Open intake chat");
394
397
  };
395
398
  const postToChat = (message) => {
396
- var _a2;
397
- (_a2 = elements.chatFrame.contentWindow) == null ? void 0 : _a2.postMessage(message, config.chatOrigin);
399
+ var _a;
400
+ (_a = elements.chatFrame.contentWindow) == null ? void 0 : _a.postMessage(message, config.chatOrigin);
398
401
  };
399
402
  const postHostReady = () => {
400
403
  const currentUrl = globalThis.location.href;
@@ -422,10 +425,10 @@
422
425
  postToChat(createEmbedProtocolMessage(EMBED_MESSAGE_TYPE.FOCUS_COMPOSER));
423
426
  };
424
427
  const answerAuthTokenRequest = async () => {
425
- var _a2;
428
+ var _a;
426
429
  let token;
427
430
  try {
428
- token = await ((_a2 = config.getAuthToken) == null ? void 0 : _a2.call(config));
431
+ token = await ((_a = config.getAuthToken) == null ? void 0 : _a.call(config));
429
432
  } catch {
430
433
  token = void 0;
431
434
  }
@@ -446,7 +449,7 @@
446
449
  const dismissPrompt = (returnFocus = false) => {
447
450
  globalThis.clearTimeout(promptTimer);
448
451
  promptTimer = void 0;
449
- const wasVisible = !elements.promptBackdrop.hidden;
452
+ const wasVisible = elements.promptBackdrop.hidden === false;
450
453
  elements.promptBackdrop.hidden = true;
451
454
  elements.promptBackdrop.setAttribute("inert", "");
452
455
  rememberPromptDismissal();
@@ -457,11 +460,11 @@
457
460
  }
458
461
  };
459
462
  const showPrompt = () => {
460
- var _a2, _b, _c;
463
+ var _a, _b, _c;
461
464
  globalThis.clearTimeout(promptTimer);
462
465
  promptTimer = void 0;
463
466
  const host = globalThis;
464
- const mxPopup = (_c = (_a2 = host.drupalSettings) == null ? void 0 : _a2.mxPopup) != null ? _c : (_b = host.mxChatbotSettings) == null ? void 0 : _b.mxPopup;
467
+ const mxPopup = (_c = (_a = host.drupalSettings) == null ? void 0 : _a.mxPopup) != null ? _c : (_b = host.mxChatbotSettings) == null ? void 0 : _b.mxPopup;
465
468
  if (mxPopup === false || hasPromptCooldown() || elements.chatDialog.dataset.state === "open") {
466
469
  return;
467
470
  }
@@ -495,7 +498,7 @@
495
498
  hasReleasedKeyboardEarly = true;
496
499
  setKeyboardOpen(false);
497
500
  };
498
- const fullPagePanelQuery = (_a = globalThis.matchMedia) == null ? void 0 : _a.call(globalThis, FULL_PAGE_PANEL_QUERY);
501
+ const fullPagePanelQuery = matchMediaQuery(FULL_PAGE_PANEL_QUERY);
499
502
  let themeColorBackup = null;
500
503
  let createdThemeColor = null;
501
504
  const hostRoots = [document.documentElement, document.body];
@@ -523,7 +526,7 @@
523
526
  }
524
527
  };
525
528
  const restoreHostChrome = () => {
526
- var _a2, _b;
529
+ var _a, _b;
527
530
  if (themeColorBackup === null) {
528
531
  return;
529
532
  }
@@ -534,7 +537,7 @@
534
537
  createdThemeColor = null;
535
538
  themeColorBackup = null;
536
539
  for (const [index, root] of hostRoots.entries()) {
537
- root.style.backgroundColor = (_a2 = hostBackgroundColorBackup == null ? void 0 : hostBackgroundColorBackup[index]) != null ? _a2 : "";
540
+ root.style.backgroundColor = (_a = hostBackgroundColorBackup == null ? void 0 : hostBackgroundColorBackup[index]) != null ? _a : "";
538
541
  root.style.overflow = (_b = hostOverflowBackup == null ? void 0 : hostOverflowBackup[index]) != null ? _b : "";
539
542
  }
540
543
  hostBackgroundColorBackup = null;
@@ -544,7 +547,7 @@
544
547
  if (elements.chatDialog.dataset.state !== "open") {
545
548
  return;
546
549
  }
547
- if (fullPagePanelQuery == null ? void 0 : fullPagePanelQuery.matches) {
550
+ if ((fullPagePanelQuery == null ? void 0 : fullPagePanelQuery.matches) === true) {
548
551
  borrowHostChrome();
549
552
  } else {
550
553
  restoreHostChrome();
@@ -560,16 +563,16 @@
560
563
  syncHostChrome();
561
564
  }
562
565
  const startViewportTracking = () => {
563
- var _a2, _b;
564
- (_a2 = globalThis.visualViewport) == null ? void 0 : _a2.addEventListener("resize", syncViewport);
566
+ var _a, _b;
567
+ (_a = globalThis.visualViewport) == null ? void 0 : _a.addEventListener("resize", syncViewport);
565
568
  (_b = globalThis.visualViewport) == null ? void 0 : _b.addEventListener("scroll", syncViewport);
566
569
  fullPagePanelQuery == null ? void 0 : fullPagePanelQuery.addEventListener("change", syncHostChrome);
567
570
  syncViewport();
568
571
  syncHostChrome();
569
572
  };
570
573
  const stopViewportTracking = () => {
571
- var _a2, _b;
572
- (_a2 = globalThis.visualViewport) == null ? void 0 : _a2.removeEventListener("resize", syncViewport);
574
+ var _a, _b;
575
+ (_a = globalThis.visualViewport) == null ? void 0 : _a.removeEventListener("resize", syncViewport);
573
576
  (_b = globalThis.visualViewport) == null ? void 0 : _b.removeEventListener("scroll", syncViewport);
574
577
  fullPagePanelQuery == null ? void 0 : fullPagePanelQuery.removeEventListener("change", syncHostChrome);
575
578
  setKeyboardOpen(false);
@@ -606,7 +609,7 @@
606
609
  }
607
610
  };
608
611
  const closeChat = () => {
609
- var _a2;
612
+ var _a;
610
613
  elements.launcher.focus();
611
614
  writeOpenState(false);
612
615
  const wasOpen = elements.chatDialog.dataset.state === "open";
@@ -619,7 +622,7 @@
619
622
  if (!wasOpen) {
620
623
  return;
621
624
  }
622
- if ((_a2 = globalThis.matchMedia) == null ? void 0 : _a2.call(globalThis, "(prefers-reduced-motion: reduce)").matches) {
625
+ if (((_a = matchMediaQuery("(prefers-reduced-motion: reduce)")) == null ? void 0 : _a.matches) === true) {
623
626
  finishChatClose();
624
627
  return;
625
628
  }
@@ -672,7 +675,7 @@
672
675
  }
673
676
  };
674
677
  const handleKeydown = (event) => {
675
- if (event.key === "Tab" && !elements.promptBackdrop.hidden) {
678
+ if (event.key === "Tab" && elements.promptBackdrop.hidden === false) {
676
679
  const { activeElement } = shadow;
677
680
  if (!event.shiftKey && activeElement === elements.promptClose) {
678
681
  event.preventDefault();
@@ -686,7 +689,7 @@
686
689
  if (event.key !== "Escape") {
687
690
  return;
688
691
  }
689
- if (!elements.promptBackdrop.hidden) {
692
+ if (elements.promptBackdrop.hidden === false) {
690
693
  dismissPrompt(true);
691
694
  return;
692
695
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morgan-and-morgan/intake-agent",
3
- "version": "1.0.0-alpha.12",
3
+ "version": "1.0.0-alpha.14",
4
4
  "description": "Embeddable chat widget loader.",
5
5
  "license": "UNLICENSED",
6
6
  "files": [