@trycourier/courier-ui-inbox 1.0.7-beta → 1.0.8-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,10 +1,18 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { Courier } from "@trycourier/courier-js";
4
+ import { Courier, InboxMessageEvent } from "@trycourier/courier-js";
5
5
  var __defProp2 = Object.defineProperty;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
6
9
  var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
10
  var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
11
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
12
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), member.get(obj));
13
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
14
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
15
+ var _isInitialised;
8
16
  const CourierColors = {
9
17
  black: {
10
18
  500: "#171717",
@@ -73,15 +81,52 @@ const addSystemThemeModeListener = (callback) => {
73
81
  mediaQuery.removeEventListener("change", handler);
74
82
  };
75
83
  };
76
- const BaseElement = typeof window === "undefined" ? class {
77
- constructor() {
84
+ const HTMLElementBase = (() => {
85
+ try {
86
+ return typeof HTMLElement === "undefined" ? class {
87
+ } : HTMLElement;
88
+ } catch {
89
+ return class {
90
+ };
78
91
  }
79
- } : class extends HTMLElement {
92
+ })();
93
+ class CourierBaseElement extends HTMLElementBase {
80
94
  constructor() {
81
- super();
95
+ super(...arguments);
96
+ __privateAdd(this, _isInitialised, false);
82
97
  }
83
- };
84
- class CourierSystemThemeElement extends BaseElement {
98
+ /** Tag-name you’ll use in `customElements.define()` */
99
+ static get id() {
100
+ return "courier-base-element";
101
+ }
102
+ /* ------------------------------------------------------------------ */
103
+ /* Custom-elements lifecycle hooks */
104
+ /* ------------------------------------------------------------------ */
105
+ connectedCallback() {
106
+ var _a;
107
+ if (__privateGet(this, _isInitialised)) return;
108
+ __privateSet(this, _isInitialised, true);
109
+ (_a = this.onComponentMounted) == null ? void 0 : _a.call(this);
110
+ }
111
+ disconnectedCallback() {
112
+ var _a;
113
+ __privateSet(this, _isInitialised, false);
114
+ (_a = this.onComponentUnmounted) == null ? void 0 : _a.call(this);
115
+ }
116
+ /* ------------------------------------------------------------------ */
117
+ /* Overridable hooks */
118
+ /* ------------------------------------------------------------------ */
119
+ /** Called **once** when the element first becomes part of the DOM. */
120
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
121
+ onComponentMounted() {
122
+ }
123
+ /** Called when the element is removed from the DOM. */
124
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
125
+ onComponentUnmounted() {
126
+ }
127
+ }
128
+ _isInitialised = /* @__PURE__ */ new WeakMap();
129
+ class CourierSystemThemeElement extends CourierBaseElement {
85
130
  constructor() {
86
131
  super();
87
132
  __publicField2(this, "_currentSystemTheme");
@@ -92,13 +137,16 @@ class CourierSystemThemeElement extends BaseElement {
92
137
  this.onSystemThemeChange(mode);
93
138
  });
94
139
  }
140
+ static get id() {
141
+ return "courier-system-theme-element";
142
+ }
95
143
  get currentSystemTheme() {
96
144
  return this._currentSystemTheme;
97
145
  }
98
- disconnectedCallback() {
99
- if (this._systemThemeCleanup) {
100
- this._systemThemeCleanup();
101
- }
146
+ onComponentUnmounted() {
147
+ var _a;
148
+ (_a = this._systemThemeCleanup) == null ? void 0 : _a.call(this);
149
+ super.onComponentUnmounted();
102
150
  }
103
151
  onSystemThemeChange(_) {
104
152
  }
@@ -153,6 +201,9 @@ class CourierButton extends CourierSystemThemeElement {
153
201
  }
154
202
  });
155
203
  }
204
+ static get id() {
205
+ return "courier-button";
206
+ }
156
207
  getStyles(props) {
157
208
  const defaultTextColor = () => {
158
209
  const secondary = CourierButtonVariants.secondary(this.currentSystemTheme);
@@ -254,7 +305,7 @@ const CourierIconSVGs = {
254
305
  <path d="M5.5 11C5.0625 11 4.75 10.6875 4.75 10.25V5.75C4.75 5.34375 5.0625 5 5.5 5C5.90625 5 6.25 5.34375 6.25 5.75V8.28125L6.875 7.53125C8.15625 6 10.0625 5 12.25 5C16.0938 5 19.25 8.15625 19.25 12C19.25 15.875 16.0938 19 12.25 19C10.6562 19 9.21875 18.5 8.03125 17.625C7.71875 17.375 7.625 16.9062 7.875 16.5625C8.125 16.2188 8.59375 16.1562 8.9375 16.4062C9.84375 17.0938 11 17.5 12.25 17.5C15.2812 17.5 17.75 15.0625 17.75 12C17.75 8.96875 15.2812 6.5 12.25 6.5C10.5312 6.5 9.03125 7.28125 8 8.5L7.15625 9.5H10C10.4062 9.5 10.75 9.84375 10.75 10.25C10.75 10.6875 10.4062 11 10 11H5.5Z" fill="currentColor"/>
255
306
  </svg>`
256
307
  };
257
- class CourierIcon extends BaseElement {
308
+ class CourierIcon extends CourierBaseElement {
258
309
  constructor(color, svg) {
259
310
  super();
260
311
  __publicField2(this, "_color");
@@ -271,6 +322,9 @@ class CourierIcon extends BaseElement {
271
322
  shadow.appendChild(this._style);
272
323
  this.refresh();
273
324
  }
325
+ static get id() {
326
+ return "courier-icon";
327
+ }
274
328
  getStyles(color) {
275
329
  return `
276
330
  :host {
@@ -305,7 +359,7 @@ class CourierIcon extends BaseElement {
305
359
  this.refresh();
306
360
  }
307
361
  }
308
- class CourierLink extends BaseElement {
362
+ class CourierLink extends CourierBaseElement {
309
363
  constructor() {
310
364
  super();
311
365
  __publicField2(this, "link");
@@ -369,6 +423,9 @@ class CourierLink extends BaseElement {
369
423
  this.updateUnderline();
370
424
  this.updateMode();
371
425
  }
426
+ static get id() {
427
+ return "courier-link";
428
+ }
372
429
  connectedCallback() {
373
430
  const slot = document.createElement("slot");
374
431
  this.link.appendChild(slot);
@@ -467,20 +524,18 @@ __publicField2(CourierLink, "observedAttributes", [
467
524
  "font-family",
468
525
  "font-size"
469
526
  ]);
470
- class CourierElement extends CourierSystemThemeElement {
527
+ class CourierFactoryElement extends CourierSystemThemeElement {
471
528
  constructor() {
472
529
  super();
473
- __publicField2(this, "shadow");
474
- this.shadow = this.attachShadow({ mode: "open" });
475
530
  }
476
531
  // Build the element with a factory function
477
532
  build(newElement) {
478
533
  if (newElement === null) {
479
- this.shadow.replaceChildren();
534
+ this.replaceChildren();
480
535
  return;
481
536
  }
482
537
  const element = newElement ?? this.defaultElement();
483
- this.shadow.replaceChildren(element);
538
+ this.replaceChildren(element);
484
539
  }
485
540
  // Default element to be used if no factory is provided
486
541
  defaultElement() {
@@ -494,7 +549,7 @@ class CourierElement extends CourierSystemThemeElement {
494
549
  return element;
495
550
  }
496
551
  }
497
- class CourierInfoState extends CourierElement {
552
+ class CourierInfoState extends CourierFactoryElement {
498
553
  constructor(props) {
499
554
  super();
500
555
  __publicField2(this, "_props");
@@ -504,6 +559,9 @@ class CourierInfoState extends CourierElement {
504
559
  __publicField2(this, "_buttonClickCallback", null);
505
560
  this._props = props;
506
561
  }
562
+ static get id() {
563
+ return "courier-info-state";
564
+ }
507
565
  defaultElement() {
508
566
  var _a, _b;
509
567
  const container = document.createElement("div");
@@ -518,7 +576,7 @@ class CourierInfoState extends CourierElement {
518
576
  container.appendChild(this._style);
519
577
  container.appendChild(this._title);
520
578
  container.appendChild(this._button);
521
- this.shadow.appendChild(container);
579
+ this.appendChild(container);
522
580
  (_b = this._button) == null ? void 0 : _b.addEventListener("click", () => {
523
581
  if (this._buttonClickCallback) {
524
582
  this._buttonClickCallback();
@@ -548,6 +606,8 @@ class CourierInfoState extends CourierElement {
548
606
  gap: 16px;
549
607
  text-align: center;
550
608
  padding: 24px;
609
+ box-sizing: border-box;
610
+ height: 100%;
551
611
  }
552
612
 
553
613
  .container h2 {
@@ -572,7 +632,7 @@ class CourierInfoState extends CourierElement {
572
632
  this._buttonClickCallback = callback;
573
633
  }
574
634
  }
575
- class CourierIconButton extends BaseElement {
635
+ class CourierIconButton extends CourierBaseElement {
576
636
  constructor(svg, color, backgroundColor, hoverBackgroundColor, activeBackgroundColor, borderRadius, height, width) {
577
637
  super();
578
638
  __publicField2(this, "_backgroundColor");
@@ -600,6 +660,9 @@ class CourierIconButton extends BaseElement {
600
660
  this._button.appendChild(this._icon);
601
661
  shadow.appendChild(this._button);
602
662
  }
663
+ static get id() {
664
+ return "courier-icon-button";
665
+ }
603
666
  refresh() {
604
667
  this._style.textContent = this.getStyles();
605
668
  }
@@ -665,20 +728,29 @@ class CourierIconButton extends BaseElement {
665
728
  this.refresh();
666
729
  }
667
730
  }
668
- function registerElement(name, element) {
669
- if (typeof window !== "undefined" && !customElements.get(name)) {
670
- customElements.define(name, element);
731
+ function registerElement(element) {
732
+ if (typeof window !== "undefined" && !customElements.get(element.id)) {
733
+ customElements.define(element.id, element);
734
+ }
735
+ }
736
+ function injectGlobalStyle(styleId, styles) {
737
+ const selector = `style[data-${styleId}]`;
738
+ const existingStyle = document.querySelector(selector);
739
+ if (!existingStyle) {
740
+ const style = document.createElement("style");
741
+ style.setAttribute(`data-${styleId}`, "");
742
+ style.textContent = styles;
743
+ document.head.appendChild(style);
744
+ return style;
671
745
  }
746
+ return existingStyle;
672
747
  }
673
- const components = [
674
- { name: "courier-button", class: CourierButton },
675
- { name: "courier-icon", class: CourierIcon },
676
- { name: "courier-link", class: CourierLink },
677
- { name: "courier-info-state", class: CourierInfoState },
678
- { name: "courier-icon-button", class: CourierIconButton },
679
- { name: "courier-system-theme", class: CourierSystemThemeElement }
680
- ];
681
- components.forEach(({ name, class: componentClass }) => registerElement(name, componentClass));
748
+ registerElement(CourierButton);
749
+ registerElement(CourierIcon);
750
+ registerElement(CourierLink);
751
+ registerElement(CourierInfoState);
752
+ registerElement(CourierIconButton);
753
+ registerElement(CourierSystemThemeElement);
682
754
  function copyMessage(message) {
683
755
  const copy = {
684
756
  ...message
@@ -707,6 +779,9 @@ function copyInboxAction(action) {
707
779
  return copy;
708
780
  }
709
781
  function copyInboxDataSet(dataSet) {
782
+ if (!dataSet) {
783
+ return void 0;
784
+ }
710
785
  return {
711
786
  ...dataSet,
712
787
  messages: dataSet.messages.map((message) => copyMessage(message))
@@ -717,6 +792,7 @@ function getMessageTime(message) {
717
792
  const now = /* @__PURE__ */ new Date();
718
793
  const messageDate = new Date(message.created);
719
794
  const diffInSeconds = Math.floor((now.getTime() - messageDate.getTime()) / 1e3);
795
+ if (diffInSeconds < 5) return "Now";
720
796
  if (diffInSeconds < 60) return `${diffInSeconds}s`;
721
797
  if (diffInSeconds < 3600) return `${Math.floor(diffInSeconds / 60)}m`;
722
798
  if (diffInSeconds < 86400) return `${Math.floor(diffInSeconds / 3600)}h`;
@@ -724,29 +800,28 @@ function getMessageTime(message) {
724
800
  if (diffInSeconds < 31536e3) return `${Math.floor(diffInSeconds / 604800)}w`;
725
801
  return `${Math.floor(diffInSeconds / 31536e3)}y`;
726
802
  }
727
- class CourierInboxListItemMenu extends BaseElement {
803
+ class CourierInboxListItemMenu extends CourierBaseElement {
728
804
  constructor(theme2) {
729
805
  super();
730
806
  // State
731
807
  __publicField(this, "_theme");
732
808
  __publicField(this, "_options", []);
733
- // Components
734
- __publicField(this, "_style");
735
809
  this._theme = theme2;
736
- const shadow = this.attachShadow({ mode: "open" });
737
- this._style = document.createElement("style");
738
- this._style.textContent = this.getStyles();
739
- shadow.appendChild(this._style);
810
+ }
811
+ static get id() {
812
+ return "courier-inbox-list-item-menu";
813
+ }
814
+ onComponentMounted() {
740
815
  const menu = document.createElement("ul");
741
816
  menu.className = "menu";
742
- shadow.appendChild(menu);
817
+ this.appendChild(menu);
743
818
  }
744
- getStyles() {
819
+ static getStyles(theme2) {
745
820
  var _a, _b, _c;
746
- const menu = (_c = (_b = (_a = this._theme.inbox) == null ? void 0 : _a.list) == null ? void 0 : _b.item) == null ? void 0 : _c.menu;
821
+ const menu = (_c = (_b = (_a = theme2.inbox) == null ? void 0 : _a.list) == null ? void 0 : _b.item) == null ? void 0 : _c.menu;
747
822
  return `
748
- :host {
749
- display: block;
823
+ ${CourierInboxListItemMenu.id} {
824
+ display: none;
750
825
  position: absolute;
751
826
  background: ${(menu == null ? void 0 : menu.backgroundColor) ?? "red"};
752
827
  border: ${(menu == null ? void 0 : menu.border) ?? "1px solid red"};
@@ -759,12 +834,13 @@ class CourierInboxListItemMenu extends BaseElement {
759
834
  overflow: hidden;
760
835
  }
761
836
 
762
- :host(.visible) {
837
+ ${CourierInboxListItemMenu.id}.visible {
838
+ display: block;
763
839
  opacity: 1;
764
840
  pointer-events: auto;
765
841
  }
766
842
 
767
- ul.menu {
843
+ ${CourierInboxListItemMenu.id} ul.menu {
768
844
  list-style: none;
769
845
  margin: 0;
770
846
  padding: 0;
@@ -772,7 +848,7 @@ class CourierInboxListItemMenu extends BaseElement {
772
848
  flex-direction: row;
773
849
  }
774
850
 
775
- li.menu-item {
851
+ ${CourierInboxListItemMenu.id} li.menu-item {
776
852
  display: flex;
777
853
  align-items: center;
778
854
  justify-content: center;
@@ -787,11 +863,11 @@ class CourierInboxListItemMenu extends BaseElement {
787
863
  this.renderMenu();
788
864
  }
789
865
  renderMenu() {
790
- var _a, _b, _c, _d;
791
- const menu = (_a = this.shadowRoot) == null ? void 0 : _a.querySelector("ul.menu");
866
+ var _a, _b, _c;
867
+ const menu = this.querySelector("ul.menu");
792
868
  if (!menu) return;
793
869
  menu.innerHTML = "";
794
- const menuTheme = (_d = (_c = (_b = this._theme.inbox) == null ? void 0 : _b.list) == null ? void 0 : _c.item) == null ? void 0 : _d.menu;
870
+ const menuTheme = (_c = (_b = (_a = this._theme.inbox) == null ? void 0 : _a.list) == null ? void 0 : _b.item) == null ? void 0 : _c.menu;
795
871
  const cancelEvent = (e) => {
796
872
  e.stopPropagation();
797
873
  e.preventDefault();
@@ -813,13 +889,15 @@ class CourierInboxListItemMenu extends BaseElement {
813
889
  });
814
890
  }
815
891
  show() {
892
+ this.style.display = "block";
816
893
  this.classList.add("visible");
817
894
  }
818
895
  hide() {
896
+ this.style.display = "none";
819
897
  this.classList.remove("visible");
820
898
  }
821
899
  }
822
- registerElement("courier-inbox-list-item-menu", CourierInboxListItemMenu);
900
+ registerElement(CourierInboxListItemMenu);
823
901
  const _CourierInboxDatastore = class _CourierInboxDatastore {
824
902
  constructor() {
825
903
  __publicField(this, "_inboxDataSet");
@@ -850,28 +928,22 @@ const _CourierInboxDatastore = class _CourierInboxDatastore {
850
928
  removeDataStoreListener(listener) {
851
929
  this._dataStoreListeners = this._dataStoreListeners.filter((l) => l !== listener);
852
930
  }
853
- async fetchDataSet(props) {
854
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
931
+ async fetchCachableDataSet(props) {
932
+ var _a, _b, _c, _d, _e, _f, _g, _h;
855
933
  if (props.canUseCache) {
856
- switch (props.feedType) {
857
- case "inbox":
858
- if (this._inboxDataSet) {
859
- return this._inboxDataSet;
860
- }
861
- break;
862
- case "archive":
863
- if (this._archiveDataSet) {
864
- return this._archiveDataSet;
865
- }
866
- break;
934
+ if (props.feedType === "inbox" && this._inboxDataSet) {
935
+ return this._inboxDataSet;
936
+ }
937
+ if (props.feedType === "archive" && this._archiveDataSet) {
938
+ return this._archiveDataSet;
867
939
  }
868
940
  }
869
- const response = props.feedType === "inbox" ? await ((_a = Courier.shared.client) == null ? void 0 : _a.inbox.getMessages()) : await ((_b = Courier.shared.client) == null ? void 0 : _b.inbox.getArchivedMessages());
941
+ const response = await props.fetch;
870
942
  return {
871
943
  feedType: props.feedType,
872
- messages: ((_d = (_c = response == null ? void 0 : response.data) == null ? void 0 : _c.messages) == null ? void 0 : _d.nodes) ?? [],
873
- canPaginate: ((_g = (_f = (_e = response == null ? void 0 : response.data) == null ? void 0 : _e.messages) == null ? void 0 : _f.pageInfo) == null ? void 0 : _g.hasNextPage) ?? false,
874
- paginationCursor: ((_j = (_i = (_h = response == null ? void 0 : response.data) == null ? void 0 : _h.messages) == null ? void 0 : _i.pageInfo) == null ? void 0 : _j.startCursor) ?? null
944
+ messages: ((_b = (_a = response.data) == null ? void 0 : _a.messages) == null ? void 0 : _b.nodes) ?? [],
945
+ canPaginate: ((_e = (_d = (_c = response.data) == null ? void 0 : _c.messages) == null ? void 0 : _d.pageInfo) == null ? void 0 : _e.hasNextPage) ?? false,
946
+ paginationCursor: ((_h = (_g = (_f = response.data) == null ? void 0 : _f.messages) == null ? void 0 : _g.pageInfo) == null ? void 0 : _h.startCursor) ?? null
875
947
  };
876
948
  }
877
949
  async fetchUnreadCount(props) {
@@ -883,43 +955,43 @@ const _CourierInboxDatastore = class _CourierInboxDatastore {
883
955
  return unreadCount ?? 0;
884
956
  }
885
957
  async load(props) {
886
- var _a, _b, _c;
958
+ var _a, _b;
887
959
  try {
888
- if (!((_a = Courier.shared.client) == null ? void 0 : _a.options.userId)) {
960
+ const client = Courier.shared.client;
961
+ if (!(client == null ? void 0 : client.options.userId)) {
889
962
  throw new Error("User is not signed in");
890
963
  }
891
- const properties = props ?? { feedType: "inbox", canUseCache: true };
892
- const [dataSet, unreadCount] = await Promise.all([
893
- this.fetchDataSet(properties),
964
+ const properties = props ?? { canUseCache: true };
965
+ const [inboxDataSet, archiveDataSet, unreadCount] = await Promise.all([
966
+ this.fetchCachableDataSet({ fetch: client.inbox.getMessages(), feedType: "inbox", canUseCache: properties.canUseCache }),
967
+ this.fetchCachableDataSet({ fetch: client.inbox.getArchivedMessages(), feedType: "archive", canUseCache: properties.canUseCache }),
894
968
  this.fetchUnreadCount(properties)
895
969
  ]);
896
- switch (properties.feedType) {
897
- case "inbox":
898
- this._inboxDataSet = dataSet;
899
- break;
900
- case "archive":
901
- this._archiveDataSet = dataSet;
902
- break;
903
- }
970
+ this._inboxDataSet = inboxDataSet;
971
+ this._archiveDataSet = archiveDataSet;
904
972
  this._unreadCount = unreadCount;
905
973
  this._dataStoreListeners.forEach((listener) => {
906
- var _a2, _b2, _c2, _d;
907
- (_b2 = (_a2 = listener.events).onDataSetChange) == null ? void 0 : _b2.call(_a2, dataSet, properties.feedType);
908
- (_d = (_c2 = listener.events).onUnreadCountChange) == null ? void 0 : _d.call(_c2, this._unreadCount ?? 0);
974
+ var _a2, _b2, _c, _d, _e, _f;
975
+ if (this._inboxDataSet) {
976
+ (_b2 = (_a2 = listener.events).onDataSetChange) == null ? void 0 : _b2.call(_a2, this._inboxDataSet, "inbox");
977
+ }
978
+ if (this._archiveDataSet) {
979
+ (_d = (_c = listener.events).onDataSetChange) == null ? void 0 : _d.call(_c, this._archiveDataSet, "archive");
980
+ }
981
+ (_f = (_e = listener.events).onUnreadCountChange) == null ? void 0 : _f.call(_e, this._unreadCount ?? 0);
909
982
  });
910
983
  } catch (error) {
911
- (_c = (_b = Courier.shared.client) == null ? void 0 : _b.options.logger) == null ? void 0 : _c.error("Error loading inbox:", error);
984
+ (_b = (_a = Courier.shared.client) == null ? void 0 : _a.options.logger) == null ? void 0 : _b.error("Error loading inbox:", error);
912
985
  this._dataStoreListeners.forEach((listener) => {
913
986
  var _a2, _b2;
914
987
  (_b2 = (_a2 = listener.events).onError) == null ? void 0 : _b2.call(_a2, error);
915
988
  });
916
989
  }
917
990
  }
918
- /** Listen for inbox and archive dataset updates. */
991
+ // Connect the socket
919
992
  async listenForUpdates() {
920
993
  var _a, _b;
921
994
  try {
922
- await this.ensureDataSetsLoaded();
923
995
  await this.connectSocket();
924
996
  } catch (error) {
925
997
  (_b = (_a = Courier.shared.client) == null ? void 0 : _a.options.logger) == null ? void 0 : _b.error("Error listening for updates:", error);
@@ -929,85 +1001,73 @@ const _CourierInboxDatastore = class _CourierInboxDatastore {
929
1001
  });
930
1002
  }
931
1003
  }
932
- /** Fetch either/both datasets if they aren't already loaded. */
933
- async ensureDataSetsLoaded() {
934
- let dataSetPromises = [];
935
- if (!this._inboxDataSet) {
936
- dataSetPromises.push(this.load({ feedType: "inbox", canUseCache: true }));
937
- }
938
- if (!this._archiveDataSet) {
939
- dataSetPromises.push(this.load({ feedType: "archive", canUseCache: true }));
940
- }
941
- await Promise.all(dataSetPromises);
942
- }
943
1004
  async connectSocket() {
944
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1005
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
945
1006
  const socket = (_a = Courier.shared.client) == null ? void 0 : _a.inbox.socket;
946
1007
  try {
947
1008
  if (!socket) {
948
1009
  (_c = (_b = Courier.shared.client) == null ? void 0 : _b.options.logger) == null ? void 0 : _c.info("CourierInbox socket not available");
949
1010
  return;
950
1011
  }
951
- (_f = (_d = Courier.shared.client) == null ? void 0 : _d.options.logger) == null ? void 0 : _f.info("CourierInbox socket connectionId:", (_e = Courier.shared.client) == null ? void 0 : _e.options.connectionId);
952
- if (socket.isConnected) {
953
- (_h = (_g = Courier.shared.client) == null ? void 0 : _g.options.logger) == null ? void 0 : _h.info("CourierInbox socket already connected. Socket will not attempt reconnection.");
1012
+ if (socket.isConnecting || socket.isOpen) {
1013
+ (_f = (_d = Courier.shared.client) == null ? void 0 : _d.options.logger) == null ? void 0 : _f.info(`Inbox socket already connecting or open for client ID: [${(_e = Courier.shared.client) == null ? void 0 : _e.options.connectionId}]`);
954
1014
  return;
955
1015
  }
956
- socket.receivedMessage = (message) => {
957
- this.addMessage(message, 0, "inbox");
958
- };
959
- socket.receivedMessageEvent = (event) => {
960
- let message;
961
- if (event.messageId) {
962
- message = this.getMessage({ messageId: event.messageId });
1016
+ socket.addMessageEventListener((event) => {
1017
+ if (event.event === InboxMessageEvent.NewMessage) {
1018
+ const message2 = event.data;
1019
+ this.addMessage(message2, 0, "inbox");
1020
+ return;
963
1021
  }
1022
+ const message = this.getMessage({ messageId: event.messageId });
964
1023
  switch (event.event) {
965
- case "mark-all-read":
1024
+ case InboxMessageEvent.MarkAllRead:
966
1025
  this.readAllMessages({ canCallApi: false });
967
1026
  break;
968
- case "read":
1027
+ case InboxMessageEvent.Read:
969
1028
  if (message) {
970
1029
  this.readMessage({ message, canCallApi: false });
971
1030
  }
972
1031
  break;
973
- case "unread":
1032
+ case InboxMessageEvent.Unread:
974
1033
  if (message) {
975
1034
  this.unreadMessage({ message, canCallApi: false });
976
1035
  }
977
1036
  break;
978
- case "opened":
1037
+ case InboxMessageEvent.Opened:
979
1038
  if (message) {
980
1039
  this.openMessage({ message, canCallApi: false });
981
1040
  }
982
1041
  break;
983
- case "archive":
1042
+ case InboxMessageEvent.Archive:
984
1043
  if (message) {
985
1044
  this.archiveMessage({ message, canCallApi: false });
986
1045
  }
987
1046
  break;
988
- case "archive-read":
1047
+ case InboxMessageEvent.ArchiveRead:
989
1048
  this.archiveReadMessages({ canCallApi: false });
990
1049
  break;
991
- case "click":
1050
+ case InboxMessageEvent.ArchiveAll:
1051
+ this.archiveAllMessages({ canCallApi: false });
1052
+ break;
1053
+ case InboxMessageEvent.Clicked:
992
1054
  if (message) {
993
1055
  this.clickMessage({ message, canCallApi: false });
994
1056
  }
995
1057
  break;
996
- case "unarchive":
1058
+ case InboxMessageEvent.Unarchive:
997
1059
  if (message) {
998
1060
  this.unarchiveMessage({ message, canCallApi: false });
999
1061
  }
1000
1062
  break;
1001
- case "unopened":
1063
+ case InboxMessageEvent.Unopened:
1002
1064
  break;
1003
1065
  }
1004
- };
1066
+ });
1005
1067
  await socket.connect();
1006
- await socket.sendSubscribe();
1007
- socket.keepAlive();
1008
- (_j = (_i = Courier.shared.client) == null ? void 0 : _i.options.logger) == null ? void 0 : _j.info("CourierInbox socket connected");
1068
+ (_i = (_g = Courier.shared.client) == null ? void 0 : _g.options.logger) == null ? void 0 : _i.info(`Inbox socket connected for client ID: [${(_h = Courier.shared.client) == null ? void 0 : _h.options.connectionId}]`);
1009
1069
  } catch (error) {
1010
- (_l = (_k = Courier.shared.client) == null ? void 0 : _k.options.logger) == null ? void 0 : _l.error("Failed to connect socket:", error);
1070
+ (_k = (_j = Courier.shared.client) == null ? void 0 : _j.options.logger) == null ? void 0 : _k.error("Failed to connect socket:", error);
1011
1071
  }
1012
1072
  }
1013
1073
  /**
@@ -1017,6 +1077,9 @@ const _CourierInboxDatastore = class _CourierInboxDatastore {
1017
1077
  */
1018
1078
  getMessage(props) {
1019
1079
  var _a, _b;
1080
+ if (!props.messageId) {
1081
+ return void 0;
1082
+ }
1020
1083
  return ((_a = this._inboxDataSet) == null ? void 0 : _a.messages.find((m) => m.messageId === props.messageId)) ?? ((_b = this._archiveDataSet) == null ? void 0 : _b.messages.find((m) => m.messageId === props.messageId));
1021
1084
  }
1022
1085
  /**
@@ -1444,8 +1507,12 @@ const _CourierInboxDatastore = class _CourierInboxDatastore {
1444
1507
  this._archiveDataSet = archive;
1445
1508
  this._dataStoreListeners.forEach((listener) => {
1446
1509
  var _a, _b, _c, _d, _e, _f;
1447
- (_b = (_a = listener.events).onDataSetChange) == null ? void 0 : _b.call(_a, inbox, "inbox");
1448
- (_d = (_c = listener.events).onDataSetChange) == null ? void 0 : _d.call(_c, archive, "archive");
1510
+ if (this._inboxDataSet) {
1511
+ (_b = (_a = listener.events).onDataSetChange) == null ? void 0 : _b.call(_a, this._inboxDataSet, "inbox");
1512
+ }
1513
+ if (this._archiveDataSet) {
1514
+ (_d = (_c = listener.events).onDataSetChange) == null ? void 0 : _d.call(_c, this._archiveDataSet, "archive");
1515
+ }
1449
1516
  (_f = (_e = listener.events).onUnreadCountChange) == null ? void 0 : _f.call(_e, unreadCount);
1450
1517
  });
1451
1518
  }
@@ -1511,7 +1578,7 @@ const _CourierInboxDatastore = class _CourierInboxDatastore {
1511
1578
  };
1512
1579
  __publicField(_CourierInboxDatastore, "instance");
1513
1580
  let CourierInboxDatastore = _CourierInboxDatastore;
1514
- class CourierListItem extends BaseElement {
1581
+ class CourierInboxListItem extends CourierBaseElement {
1515
1582
  constructor(theme2) {
1516
1583
  super();
1517
1584
  // State
@@ -1523,7 +1590,6 @@ class CourierListItem extends BaseElement {
1523
1590
  __publicField(this, "_titleElement");
1524
1591
  __publicField(this, "_subtitleElement");
1525
1592
  __publicField(this, "_timeElement");
1526
- __publicField(this, "_style");
1527
1593
  __publicField(this, "_menu");
1528
1594
  __publicField(this, "_unreadIndicator");
1529
1595
  __publicField(this, "_actionsContainer");
@@ -1536,27 +1602,30 @@ class CourierListItem extends BaseElement {
1536
1602
  __publicField(this, "onItemActionClick", null);
1537
1603
  this._theme = theme2;
1538
1604
  this._isMobile = "ontouchstart" in window;
1539
- const shadow = this.attachShadow({ mode: "open" });
1605
+ this.render();
1606
+ }
1607
+ static get id() {
1608
+ return "courier-inbox-list-item";
1609
+ }
1610
+ render() {
1540
1611
  const contentContainer = document.createElement("div");
1541
1612
  contentContainer.className = "content-container";
1542
1613
  this._titleElement = document.createElement("p");
1543
- this._titleElement.setAttribute("part", "title");
1614
+ this._titleElement.className = "title";
1544
1615
  this._subtitleElement = document.createElement("p");
1545
- this._subtitleElement.setAttribute("part", "subtitle");
1616
+ this._subtitleElement.className = "subtitle";
1546
1617
  this._actionsContainer = document.createElement("div");
1547
1618
  this._actionsContainer.className = "actions-container";
1548
1619
  contentContainer.appendChild(this._titleElement);
1549
1620
  contentContainer.appendChild(this._subtitleElement);
1550
1621
  contentContainer.appendChild(this._actionsContainer);
1551
1622
  this._timeElement = document.createElement("p");
1552
- this._timeElement.setAttribute("part", "time");
1623
+ this._timeElement.className = "time";
1553
1624
  this._unreadIndicator = document.createElement("div");
1554
1625
  this._unreadIndicator.className = "unread-indicator";
1555
- this._style = document.createElement("style");
1556
- this._refreshStyles();
1557
1626
  this._menu = new CourierInboxListItemMenu(this._theme);
1558
1627
  this._menu.setOptions(this._getMenuOptions());
1559
- shadow.append(this._style, this._unreadIndicator, contentContainer, this._timeElement, this._menu);
1628
+ this.append(this._unreadIndicator, contentContainer, this._timeElement, this._menu);
1560
1629
  const cancelPropagation = (e) => {
1561
1630
  e.stopPropagation();
1562
1631
  e.preventDefault();
@@ -1565,7 +1634,7 @@ class CourierListItem extends BaseElement {
1565
1634
  this._menu.addEventListener("pointerdown", cancelPropagation);
1566
1635
  this._menu.addEventListener("click", cancelPropagation);
1567
1636
  this.addEventListener("click", (e) => {
1568
- if (this._menu.contains(e.target) || e.composedPath().includes(this._menu)) {
1637
+ if (this._menu && (this._menu.contains(e.target) || e.composedPath().includes(this._menu))) {
1569
1638
  return;
1570
1639
  }
1571
1640
  if (this._message && this.onItemClick && !(e.target instanceof CourierIcon) && !this._isLongPress) {
@@ -1575,6 +1644,133 @@ class CourierListItem extends BaseElement {
1575
1644
  this._setupHoverBehavior();
1576
1645
  this._setupLongPressBehavior();
1577
1646
  }
1647
+ static getStyles(theme2) {
1648
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
1649
+ const list = (_a = theme2.inbox) == null ? void 0 : _a.list;
1650
+ return `
1651
+ ${CourierInboxListItem.id} {
1652
+ display: flex;
1653
+ flex-direction: row;
1654
+ align-items: flex-start;
1655
+ justify-content: space-between;
1656
+ border-bottom: ${((_b = list == null ? void 0 : list.item) == null ? void 0 : _b.divider) ?? "1px solid red"};
1657
+ font-family: inherit;
1658
+ cursor: pointer;
1659
+ transition: background-color 0.2s ease;
1660
+ margin: 0;
1661
+ width: 100%;
1662
+ box-sizing: border-box;
1663
+ padding: 12px 20px;
1664
+ position: relative;
1665
+ background-color: ${((_c = list == null ? void 0 : list.item) == null ? void 0 : _c.backgroundColor) ?? "transparent"};
1666
+ user-select: none;
1667
+ -webkit-user-select: none;
1668
+ -moz-user-select: none;
1669
+ -ms-user-select: none;
1670
+ touch-action: manipulation;
1671
+ }
1672
+
1673
+ /* Base hover / active */
1674
+ @media (hover: hover) {
1675
+ ${CourierInboxListItem.id}:hover {
1676
+ background-color: ${((_d = list == null ? void 0 : list.item) == null ? void 0 : _d.hoverBackgroundColor) ?? "red"};
1677
+ }
1678
+ }
1679
+
1680
+ ${CourierInboxListItem.id}:active {
1681
+ background-color: ${((_e = list == null ? void 0 : list.item) == null ? void 0 : _e.activeBackgroundColor) ?? "red"};
1682
+ }
1683
+
1684
+ /* Menu hover / active */
1685
+ @media (hover: hover) {
1686
+ ${CourierInboxListItem.id}:hover:has(courier-inbox-list-item-menu:hover, courier-inbox-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {
1687
+ background-color: ${((_f = list == null ? void 0 : list.item) == null ? void 0 : _f.backgroundColor) ?? "transparent"};
1688
+ }
1689
+ }
1690
+
1691
+ ${CourierInboxListItem.id}:active:has(courier-inbox-list-item-menu:active, courier-inbox-list-item-menu *:active, courier-button:active, courier-button *:active) {
1692
+ background-color: ${((_g = list == null ? void 0 : list.item) == null ? void 0 : _g.backgroundColor) ?? "transparent"};
1693
+ }
1694
+
1695
+ ${CourierInboxListItem.id}:last-child {
1696
+ border-bottom: none;
1697
+ }
1698
+
1699
+ ${CourierInboxListItem.id} .unread-indicator {
1700
+ position: absolute;
1701
+ top: 28px;
1702
+ left: 6px;
1703
+ width: 8px;
1704
+ height: 8px;
1705
+ border-radius: 50%;
1706
+ background-color: ${((_h = list == null ? void 0 : list.item) == null ? void 0 : _h.unreadIndicatorColor) ?? "red"};
1707
+ display: none;
1708
+ }
1709
+
1710
+ ${CourierInboxListItem.id}.unread .unread-indicator {
1711
+ display: block;
1712
+ }
1713
+
1714
+ ${CourierInboxListItem.id} .content-container {
1715
+ flex: 1;
1716
+ display: flex;
1717
+ flex-direction: column;
1718
+ margin-right: 12px;
1719
+ }
1720
+
1721
+ ${CourierInboxListItem.id} p {
1722
+ margin: 0;
1723
+ overflow-wrap: break-word;
1724
+ word-break: break-word;
1725
+ hyphens: auto;
1726
+ line-height: 1.4;
1727
+ user-select: none;
1728
+ -webkit-user-select: none;
1729
+ -moz-user-select: none;
1730
+ -ms-user-select: none;
1731
+ text-align: left;
1732
+ }
1733
+
1734
+ ${CourierInboxListItem.id} .title {
1735
+ font-family: ${((_j = (_i = list == null ? void 0 : list.item) == null ? void 0 : _i.title) == null ? void 0 : _j.family) ?? "inherit"};
1736
+ font-size: ${((_l = (_k = list == null ? void 0 : list.item) == null ? void 0 : _k.title) == null ? void 0 : _l.size) ?? "14px"};
1737
+ color: ${((_n = (_m = list == null ? void 0 : list.item) == null ? void 0 : _m.title) == null ? void 0 : _n.color) ?? "red"};
1738
+ margin-bottom: 4px;
1739
+ }
1740
+
1741
+ ${CourierInboxListItem.id} .subtitle {
1742
+ font-family: ${((_p = (_o = list == null ? void 0 : list.item) == null ? void 0 : _o.subtitle) == null ? void 0 : _p.family) ?? "inherit"};
1743
+ font-size: ${((_r = (_q = list == null ? void 0 : list.item) == null ? void 0 : _q.subtitle) == null ? void 0 : _r.size) ?? "14px"};
1744
+ color: ${((_t = (_s = list == null ? void 0 : list.item) == null ? void 0 : _s.subtitle) == null ? void 0 : _t.color) ?? "red"};
1745
+ }
1746
+
1747
+ ${CourierInboxListItem.id} .time {
1748
+ font-family: ${((_v = (_u = list == null ? void 0 : list.item) == null ? void 0 : _u.time) == null ? void 0 : _v.family) ?? "inherit"};
1749
+ font-size: ${((_x = (_w = list == null ? void 0 : list.item) == null ? void 0 : _w.time) == null ? void 0 : _x.size) ?? "14px"};
1750
+ color: ${((_z = (_y = list == null ? void 0 : list.item) == null ? void 0 : _y.time) == null ? void 0 : _z.color) ?? "red"};
1751
+ text-align: right;
1752
+ white-space: nowrap;
1753
+ }
1754
+
1755
+ ${CourierInboxListItem.id} courier-inbox-list-item-menu {
1756
+ z-index: 1;
1757
+ position: absolute;
1758
+ top: 8px;
1759
+ right: 8px;
1760
+ display: none;
1761
+ }
1762
+
1763
+ ${CourierInboxListItem.id} .actions-container {
1764
+ display: flex;
1765
+ margin-top: 10px;
1766
+ flex-wrap: wrap;
1767
+ flex-direction: row;
1768
+ align-items: center;
1769
+ gap: 8px;
1770
+ display: none;
1771
+ }
1772
+ `;
1773
+ }
1578
1774
  _setupHoverBehavior() {
1579
1775
  if (!this._isMobile) {
1580
1776
  this.addEventListener("mouseenter", () => {
@@ -1667,7 +1863,7 @@ class CourierListItem extends BaseElement {
1667
1863
  _showMenu() {
1668
1864
  var _a, _b, _c;
1669
1865
  const menu = (_c = (_b = (_a = this._theme.inbox) == null ? void 0 : _a.list) == null ? void 0 : _b.item) == null ? void 0 : _c.menu;
1670
- if (menu && menu.enabled) {
1866
+ if (menu && menu.enabled && this._menu && this._timeElement) {
1671
1867
  this._menu.setOptions(this._getMenuOptions());
1672
1868
  this._menu.style.display = "block";
1673
1869
  this._menu.show();
@@ -1677,158 +1873,12 @@ class CourierListItem extends BaseElement {
1677
1873
  _hideMenu() {
1678
1874
  var _a, _b, _c;
1679
1875
  const menu = (_c = (_b = (_a = this._theme.inbox) == null ? void 0 : _a.list) == null ? void 0 : _b.item) == null ? void 0 : _c.menu;
1680
- if (menu && menu.enabled) {
1876
+ if (menu && menu.enabled && this._menu && this._timeElement) {
1681
1877
  this._menu.hide();
1682
1878
  this._menu.style.display = "none";
1683
1879
  this._timeElement.style.opacity = "1";
1684
1880
  }
1685
1881
  }
1686
- _getStyles() {
1687
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1688
- const listItem = (_b = (_a = this._theme.inbox) == null ? void 0 : _a.list) == null ? void 0 : _b.item;
1689
- return `
1690
- :host {
1691
- display: flex;
1692
- flex-direction: row;
1693
- align-items: flex-start;
1694
- justify-content: space-between;
1695
- border-bottom: ${(listItem == null ? void 0 : listItem.divider) ?? "1px solid red"};
1696
- font-family: inherit;
1697
- cursor: pointer;
1698
- transition: background-color 0.2s ease;
1699
- margin: 0;
1700
- width: 100%;
1701
- box-sizing: border-box;
1702
- padding: 12px 20px;
1703
- position: relative;
1704
- background-color: ${(listItem == null ? void 0 : listItem.backgroundColor) ?? "transparent"};
1705
- user-select: none;
1706
- -webkit-user-select: none;
1707
- -moz-user-select: none;
1708
- -ms-user-select: none;
1709
- touch-action: manipulation;
1710
- }
1711
-
1712
- /* ───────────────────────── Base hover / active ────────────────── */
1713
- @media (hover: hover) {
1714
- :host(:hover) {
1715
- background-color: ${(listItem == null ? void 0 : listItem.hoverBackgroundColor) ?? "red"};
1716
- }
1717
- }
1718
- :host(:active) {
1719
- background-color: ${(listItem == null ? void 0 : listItem.activeBackgroundColor) ?? "red"};
1720
- }
1721
-
1722
- /* ───────────────────────── Menu hover / active ────────────────── */
1723
- @media (hover: hover) {
1724
- :host(:hover):has(courier-inbox-list-item-menu:hover, courier-inbox-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {
1725
- background-color: ${(listItem == null ? void 0 : listItem.backgroundColor) ?? "transparent"};
1726
- }
1727
- }
1728
- :host(:active):has(courier-inbox-list-item-menu:active, courier-inbox-list-item-menu *:active, courier-button:active, courier-button *:active) {
1729
- background-color: ${(listItem == null ? void 0 : listItem.backgroundColor) ?? "transparent"};
1730
- }
1731
-
1732
- :host(:last-child) {
1733
- border-bottom: none;
1734
- }
1735
-
1736
- .unread-indicator {
1737
- position: absolute;
1738
- top: 28px;
1739
- left: 6px;
1740
- width: 8px;
1741
- height: 8px;
1742
- border-radius: 50%;
1743
- background-color: ${(listItem == null ? void 0 : listItem.unreadIndicatorColor) ?? "red"};
1744
- display: none;
1745
- }
1746
-
1747
- :host(.unread) .unread-indicator {
1748
- display: block;
1749
- }
1750
-
1751
- .content-container {
1752
- flex: 1;
1753
- display: flex;
1754
- flex-direction: column;
1755
- margin-right: 12px;
1756
- }
1757
-
1758
- p {
1759
- margin: 0;
1760
- overflow-wrap: break-word;
1761
- word-break: break-word;
1762
- hyphens: auto;
1763
- line-height: 1.4;
1764
- user-select: none;
1765
- -webkit-user-select: none;
1766
- -moz-user-select: none;
1767
- -ms-user-select: none;
1768
- text-align: left;
1769
- }
1770
-
1771
- p[part='title'] {
1772
- font-family: ${((_c = listItem == null ? void 0 : listItem.title) == null ? void 0 : _c.family) ?? "inherit"};
1773
- font-size: ${((_d = listItem == null ? void 0 : listItem.title) == null ? void 0 : _d.size) ?? "14px"};
1774
- color: ${((_e = listItem == null ? void 0 : listItem.title) == null ? void 0 : _e.color) ?? "red"};
1775
- margin-bottom: 4px;
1776
- }
1777
-
1778
- p[part='subtitle'] {
1779
- font-family: ${((_f = listItem == null ? void 0 : listItem.subtitle) == null ? void 0 : _f.family) ?? "inherit"};
1780
- font-size: ${((_g = listItem == null ? void 0 : listItem.subtitle) == null ? void 0 : _g.size) ?? "14px"};
1781
- color: ${((_h = listItem == null ? void 0 : listItem.subtitle) == null ? void 0 : _h.color) ?? "red"};
1782
- }
1783
-
1784
- p[part='time'] {
1785
- font-family: ${((_i = listItem == null ? void 0 : listItem.time) == null ? void 0 : _i.family) ?? "inherit"};
1786
- font-size: ${((_j = listItem == null ? void 0 : listItem.time) == null ? void 0 : _j.size) ?? "14px"};
1787
- color: ${((_k = listItem == null ? void 0 : listItem.time) == null ? void 0 : _k.color) ?? "red"};
1788
- text-align: right;
1789
- white-space: nowrap;
1790
- }
1791
-
1792
- courier-inbox-list-item-menu {
1793
- z-index: 1;
1794
- position: absolute;
1795
- top: 8px;
1796
- right: 8px;
1797
- display: none; /* becomes block while visible */
1798
- }
1799
-
1800
- .actions-container {
1801
- display: flex;
1802
- margin-top: 10px;
1803
- flex-wrap: wrap;
1804
- flex-direction: row;
1805
- align-items: center;
1806
- gap: 8px;
1807
- display: none;
1808
- }
1809
-
1810
- `;
1811
- }
1812
- _refreshStyles() {
1813
- this._style.textContent = this._getStyles();
1814
- }
1815
- // Lifecycle hooks
1816
- connectedCallback() {
1817
- var _a, _b;
1818
- const messageAttr = this.getAttribute("message");
1819
- const feedTypeAttr = this.getAttribute("feed-type");
1820
- if (feedTypeAttr) {
1821
- this._feedType = feedTypeAttr;
1822
- }
1823
- if (messageAttr) {
1824
- try {
1825
- this._message = JSON.parse(messageAttr);
1826
- this._updateContent();
1827
- } catch (err) {
1828
- (_b = (_a = Courier.shared.client) == null ? void 0 : _a.options.logger) == null ? void 0 : _b.error("CourierListItem – failed to parse message:", err);
1829
- }
1830
- }
1831
- }
1832
1882
  // Public API
1833
1883
  setMessage(message, feedType) {
1834
1884
  this._message = message;
@@ -1846,90 +1896,134 @@ class CourierListItem extends BaseElement {
1846
1896
  }
1847
1897
  // Content rendering
1848
1898
  _updateContent() {
1849
- var _a, _b, _c, _d, _e, _f;
1899
+ var _a, _b, _c;
1850
1900
  if (!this._message) {
1851
- this._titleElement.textContent = "";
1852
- this._subtitleElement.textContent = "";
1901
+ if (this._titleElement) this._titleElement.textContent = "";
1902
+ if (this._subtitleElement) this._subtitleElement.textContent = "";
1853
1903
  return;
1854
1904
  }
1855
1905
  this.classList.toggle("unread", !this._message.read && this._feedType !== "archive");
1856
- this._titleElement.textContent = this._message.title || "Untitled Message";
1857
- this._subtitleElement.textContent = this._message.preview || this._message.body || "";
1858
- this._timeElement.textContent = getMessageTime(this._message);
1859
- this._menu.setOptions(this._getMenuOptions());
1860
- const hasActions = ((_a = this._message) == null ? void 0 : _a.actions) && this._message.actions.length > 0;
1861
- this._actionsContainer.style.display = hasActions ? "flex" : "none";
1862
- const actionsTheme = (_d = (_c = (_b = this._theme.inbox) == null ? void 0 : _b.list) == null ? void 0 : _c.item) == null ? void 0 : _d.actions;
1863
- (_f = (_e = this._message) == null ? void 0 : _e.actions) == null ? void 0 : _f.forEach((action) => {
1864
- var _a2, _b2, _c2, _d2;
1865
- const actionButton = new CourierButton({
1866
- text: action.content,
1867
- variant: "secondary",
1868
- backgroundColor: actionsTheme == null ? void 0 : actionsTheme.backgroundColor,
1869
- hoverBackgroundColor: actionsTheme == null ? void 0 : actionsTheme.hoverBackgroundColor,
1870
- activeBackgroundColor: actionsTheme == null ? void 0 : actionsTheme.activeBackgroundColor,
1871
- border: actionsTheme == null ? void 0 : actionsTheme.border,
1872
- borderRadius: actionsTheme == null ? void 0 : actionsTheme.borderRadius,
1873
- shadow: actionsTheme == null ? void 0 : actionsTheme.shadow,
1874
- fontFamily: (_a2 = actionsTheme == null ? void 0 : actionsTheme.font) == null ? void 0 : _a2.family,
1875
- fontSize: (_b2 = actionsTheme == null ? void 0 : actionsTheme.font) == null ? void 0 : _b2.size,
1876
- fontWeight: (_c2 = actionsTheme == null ? void 0 : actionsTheme.font) == null ? void 0 : _c2.weight,
1877
- textColor: (_d2 = actionsTheme == null ? void 0 : actionsTheme.font) == null ? void 0 : _d2.color,
1878
- onClick: () => {
1879
- if (this._message && this.onItemActionClick) {
1880
- this.onItemActionClick(this._message, action);
1906
+ if (this._titleElement) {
1907
+ this._titleElement.textContent = this._message.title || "Untitled Message";
1908
+ }
1909
+ if (this._subtitleElement) {
1910
+ this._subtitleElement.textContent = this._message.preview || this._message.body || "";
1911
+ }
1912
+ if (this._timeElement) {
1913
+ this._timeElement.textContent = getMessageTime(this._message);
1914
+ }
1915
+ if (this._menu) {
1916
+ this._menu.setOptions(this._getMenuOptions());
1917
+ }
1918
+ const hasActions = this._message.actions && this._message.actions.length > 0;
1919
+ if (this._actionsContainer) {
1920
+ this._actionsContainer.style.display = hasActions ? "flex" : "none";
1921
+ }
1922
+ const actionsTheme = (_c = (_b = (_a = this._theme.inbox) == null ? void 0 : _a.list) == null ? void 0 : _b.item) == null ? void 0 : _c.actions;
1923
+ if (this._actionsContainer && this._message.actions) {
1924
+ this._message.actions.forEach((action) => {
1925
+ var _a2, _b2, _c2, _d, _e;
1926
+ const actionButton = new CourierButton({
1927
+ text: action.content,
1928
+ variant: "secondary",
1929
+ backgroundColor: actionsTheme == null ? void 0 : actionsTheme.backgroundColor,
1930
+ hoverBackgroundColor: actionsTheme == null ? void 0 : actionsTheme.hoverBackgroundColor,
1931
+ activeBackgroundColor: actionsTheme == null ? void 0 : actionsTheme.activeBackgroundColor,
1932
+ border: actionsTheme == null ? void 0 : actionsTheme.border,
1933
+ borderRadius: actionsTheme == null ? void 0 : actionsTheme.borderRadius,
1934
+ shadow: actionsTheme == null ? void 0 : actionsTheme.shadow,
1935
+ fontFamily: (_a2 = actionsTheme == null ? void 0 : actionsTheme.font) == null ? void 0 : _a2.family,
1936
+ fontSize: (_b2 = actionsTheme == null ? void 0 : actionsTheme.font) == null ? void 0 : _b2.size,
1937
+ fontWeight: (_c2 = actionsTheme == null ? void 0 : actionsTheme.font) == null ? void 0 : _c2.weight,
1938
+ textColor: (_d = actionsTheme == null ? void 0 : actionsTheme.font) == null ? void 0 : _d.color,
1939
+ onClick: () => {
1940
+ if (this._message && this.onItemActionClick) {
1941
+ this.onItemActionClick(this._message, action);
1942
+ }
1881
1943
  }
1882
- }
1944
+ });
1945
+ (_e = this._actionsContainer) == null ? void 0 : _e.appendChild(actionButton);
1883
1946
  });
1884
- this._actionsContainer.appendChild(actionButton);
1885
- });
1947
+ }
1886
1948
  }
1887
1949
  }
1888
- registerElement("courier-inbox-list-item", CourierListItem);
1889
- class CourierInboxSkeletonListItem extends BaseElement {
1890
- constructor(theme2, opacity) {
1950
+ registerElement(CourierInboxListItem);
1951
+ class CourierInboxSkeletonListItem extends CourierBaseElement {
1952
+ constructor(theme2) {
1891
1953
  super();
1892
- // Shadow root
1893
- __publicField(this, "_shadow");
1894
- this._shadow = this.attachShadow({ mode: "open" });
1895
- const style = document.createElement("style");
1896
- style.textContent = this.getStyles(opacity);
1897
- this._shadow.appendChild(style);
1898
- const firstRow = new CourierSkeletonAnimatedRow(theme2, 35);
1899
- const secondRow = new CourierSkeletonAnimatedRow(theme2, 100);
1900
- const thirdRow = new CourierSkeletonAnimatedRow(theme2, 82);
1901
- this._shadow.appendChild(firstRow);
1902
- this._shadow.appendChild(secondRow);
1903
- this._shadow.appendChild(thirdRow);
1904
- }
1905
- getStyles(opacity) {
1954
+ __publicField(this, "_theme");
1955
+ __publicField(this, "_style");
1956
+ this._theme = theme2;
1957
+ }
1958
+ static get id() {
1959
+ return "courier-inbox-skeleton-list-item";
1960
+ }
1961
+ onComponentMounted() {
1962
+ this._style = injectGlobalStyle(CourierInboxSkeletonListItem.id, CourierInboxSkeletonListItem.getStyles(this._theme));
1963
+ this.render();
1964
+ }
1965
+ onComponentUnmounted() {
1966
+ var _a;
1967
+ (_a = this._style) == null ? void 0 : _a.remove();
1968
+ }
1969
+ render() {
1970
+ const firstRow = new CourierSkeletonAnimatedRow(this._theme);
1971
+ const secondRow = new CourierSkeletonAnimatedRow(this._theme);
1972
+ const thirdRow = new CourierSkeletonAnimatedRow(this._theme);
1973
+ this.appendChild(firstRow);
1974
+ this.appendChild(secondRow);
1975
+ this.appendChild(thirdRow);
1976
+ }
1977
+ static getStyles(_theme) {
1906
1978
  return `
1907
- :host {
1979
+ ${CourierInboxSkeletonListItem.id} {
1908
1980
  display: flex;
1909
1981
  flex-direction: column;
1910
1982
  gap: 12px;
1911
1983
  padding: 12px;
1912
1984
  width: 100%;
1913
1985
  box-sizing: border-box;
1914
- opacity: ${opacity};
1986
+ }
1987
+
1988
+ ${CourierInboxSkeletonListItem.id} > *:first-child {
1989
+ width: 35%;
1990
+ }
1991
+
1992
+ ${CourierInboxSkeletonListItem.id} > *:nth-child(2) {
1993
+ width: 100%;
1994
+ }
1995
+
1996
+ ${CourierInboxSkeletonListItem.id} > *:nth-child(3) {
1997
+ width: 82%;
1915
1998
  }
1916
1999
  `;
1917
2000
  }
1918
2001
  }
1919
- registerElement("courier-inbox-skeleton-list-item", CourierInboxSkeletonListItem);
1920
- class CourierSkeletonAnimatedRow extends BaseElement {
1921
- constructor(theme2, widthPercent) {
2002
+ registerElement(CourierInboxSkeletonListItem);
2003
+ class CourierSkeletonAnimatedRow extends CourierBaseElement {
2004
+ constructor(theme2) {
1922
2005
  super();
1923
- __publicField(this, "_shadow");
1924
- this._shadow = this.attachShadow({ mode: "open" });
1925
- const style = document.createElement("style");
1926
- style.textContent = this.getStyles(theme2, widthPercent);
1927
- this._shadow.appendChild(style);
2006
+ __publicField(this, "_theme");
2007
+ __publicField(this, "_style");
2008
+ this._theme = theme2;
2009
+ }
2010
+ static get id() {
2011
+ return "courier-skeleton-animated-row";
2012
+ }
2013
+ onComponentMounted() {
2014
+ this._style = injectGlobalStyle(CourierSkeletonAnimatedRow.id, CourierSkeletonAnimatedRow.getStyles(this._theme));
2015
+ this.render();
2016
+ }
2017
+ onComponentUnmounted() {
2018
+ var _a;
2019
+ (_a = this._style) == null ? void 0 : _a.remove();
2020
+ }
2021
+ render() {
1928
2022
  const skeletonItem = document.createElement("div");
1929
2023
  skeletonItem.className = "skeleton-item";
1930
- this._shadow.appendChild(skeletonItem);
2024
+ this.appendChild(skeletonItem);
1931
2025
  }
1932
- getStyles(theme2, widthPercent) {
2026
+ static getStyles(theme2) {
1933
2027
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1934
2028
  const color = ((_c = (_b = (_a = theme2.inbox) == null ? void 0 : _a.loading) == null ? void 0 : _b.animation) == null ? void 0 : _c.barColor) ?? "#000";
1935
2029
  const hexColor = color.length === 4 ? `#${color[1]}${color[1]}${color[2]}${color[2]}${color[3]}${color[3]}` : color;
@@ -1939,15 +2033,15 @@ class CourierSkeletonAnimatedRow extends BaseElement {
1939
2033
  const colorWithAlpha80 = `rgba(${r}, ${g}, ${b}, 0.8)`;
1940
2034
  const colorWithAlpha40 = `rgba(${r}, ${g}, ${b}, 0.4)`;
1941
2035
  return `
1942
- :host {
2036
+ ${CourierSkeletonAnimatedRow.id} {
1943
2037
  display: flex;
1944
2038
  height: 100%;
1945
- width: ${widthPercent}%;
2039
+ width: 100%;
1946
2040
  align-items: flex-start;
1947
2041
  justify-content: flex-start;
1948
2042
  }
1949
2043
 
1950
- .skeleton-item {
2044
+ ${CourierSkeletonAnimatedRow.id} .skeleton-item {
1951
2045
  height: ${((_f = (_e = (_d = theme2.inbox) == null ? void 0 : _d.loading) == null ? void 0 : _e.animation) == null ? void 0 : _f.barHeight) ?? "14px"};
1952
2046
  width: 100%;
1953
2047
  background: linear-gradient(
@@ -1957,11 +2051,11 @@ class CourierSkeletonAnimatedRow extends BaseElement {
1957
2051
  ${colorWithAlpha80} 75%
1958
2052
  );
1959
2053
  background-size: 200% 100%;
1960
- animation: shimmer ${((_i = (_h = (_g = theme2.inbox) == null ? void 0 : _g.loading) == null ? void 0 : _h.animation) == null ? void 0 : _i.duration) ?? "2s"} ease-in-out infinite;
2054
+ animation: ${CourierSkeletonAnimatedRow.id}-shimmer ${((_i = (_h = (_g = theme2.inbox) == null ? void 0 : _g.loading) == null ? void 0 : _h.animation) == null ? void 0 : _i.duration) ?? "2s"} ease-in-out infinite;
1961
2055
  border-radius: ${((_l = (_k = (_j = theme2.inbox) == null ? void 0 : _j.loading) == null ? void 0 : _k.animation) == null ? void 0 : _l.barBorderRadius) ?? "14px"};
1962
2056
  }
1963
2057
 
1964
- @keyframes shimmer {
2058
+ @keyframes ${CourierSkeletonAnimatedRow.id}-shimmer {
1965
2059
  0% {
1966
2060
  background-position: 200% 0;
1967
2061
  }
@@ -1972,30 +2066,38 @@ class CourierSkeletonAnimatedRow extends BaseElement {
1972
2066
  `;
1973
2067
  }
1974
2068
  }
1975
- registerElement("courier-skeleton-animated-row", CourierSkeletonAnimatedRow);
1976
- class CourierInboxSkeletonList extends CourierElement {
2069
+ registerElement(CourierSkeletonAnimatedRow);
2070
+ class CourierInboxSkeletonList extends CourierFactoryElement {
1977
2071
  constructor(theme2) {
1978
2072
  super();
1979
2073
  __publicField(this, "_theme");
2074
+ __publicField(this, "_style");
1980
2075
  this._theme = theme2;
1981
2076
  }
2077
+ static get id() {
2078
+ return "courier-inbox-skeleton-list";
2079
+ }
2080
+ onComponentMounted() {
2081
+ this._style = injectGlobalStyle(CourierInboxSkeletonList.id, CourierInboxSkeletonList.getStyles(this._theme));
2082
+ }
2083
+ onComponentUnmounted() {
2084
+ var _a;
2085
+ (_a = this._style) == null ? void 0 : _a.remove();
2086
+ }
1982
2087
  defaultElement() {
1983
2088
  const list = document.createElement("div");
1984
2089
  list.className = "list";
1985
- const style = document.createElement("style");
1986
- style.textContent = this.getStyles();
1987
- list.appendChild(style);
1988
2090
  for (let i = 0; i < 3; i++) {
1989
- const skeletonItem = new CourierInboxSkeletonListItem(this._theme, 1 / (i + 1));
2091
+ const skeletonItem = new CourierInboxSkeletonListItem(this._theme);
1990
2092
  list.appendChild(skeletonItem);
1991
2093
  }
1992
- this.shadow.appendChild(list);
2094
+ this.appendChild(list);
1993
2095
  return list;
1994
2096
  }
1995
- getStyles() {
1996
- var _a, _b;
2097
+ static getStyles(theme2) {
2098
+ var _a, _b, _c, _d;
1997
2099
  return `
1998
- :host {
2100
+ ${CourierInboxSkeletonList.id} {
1999
2101
  display: flex;
2000
2102
  height: 100%;
2001
2103
  width: 100%;
@@ -2004,78 +2106,92 @@ class CourierInboxSkeletonList extends CourierElement {
2004
2106
  overflow: hidden;
2005
2107
  }
2006
2108
 
2007
- .list {
2109
+ ${CourierInboxSkeletonList.id} .list {
2008
2110
  display: flex;
2009
2111
  flex-direction: column;
2010
- gap: 8px;
2011
2112
  width: 100%;
2012
2113
  overflow: hidden;
2013
2114
  }
2014
2115
 
2015
- .list > * {
2016
- border-bottom: ${((_b = (_a = this._theme.inbox) == null ? void 0 : _a.loading) == null ? void 0 : _b.divider) ?? "1px solid red"};
2116
+ ${CourierInboxSkeletonList.id} .list > * {
2117
+ border-bottom: ${((_b = (_a = theme2.inbox) == null ? void 0 : _a.loading) == null ? void 0 : _b.divider) ?? "1px solid red"};
2118
+ opacity: 100%;
2017
2119
  }
2018
2120
 
2019
- .list > *:last-child {
2121
+ ${CourierInboxSkeletonList.id} .list > *:nth-child(2) {
2122
+ border-bottom: ${((_d = (_c = theme2.inbox) == null ? void 0 : _c.loading) == null ? void 0 : _d.divider) ?? "1px solid red"};
2123
+ opacity: 88%;
2124
+ }
2125
+
2126
+ ${CourierInboxSkeletonList.id} .list > *:nth-child(3) {
2020
2127
  border-bottom: none;
2128
+ opacity: 50%;
2021
2129
  }
2022
2130
  `;
2023
2131
  }
2024
2132
  }
2025
- registerElement("courier-inbox-skeleton-list", CourierInboxSkeletonList);
2026
- class CourierInboxPaginationListItem extends BaseElement {
2133
+ registerElement(CourierInboxSkeletonList);
2134
+ class CourierInboxPaginationListItem extends CourierBaseElement {
2027
2135
  constructor(props) {
2028
2136
  super();
2137
+ // State
2138
+ __publicField(this, "_theme");
2029
2139
  // Components
2030
- __publicField(this, "skeletonLoadingList");
2031
- __publicField(this, "observer");
2032
- __publicField(this, "customItem");
2140
+ __publicField(this, "_style");
2141
+ __publicField(this, "_skeletonLoadingList");
2142
+ __publicField(this, "_observer");
2143
+ __publicField(this, "_customItem");
2033
2144
  // Handlers
2034
- __publicField(this, "onPaginationTrigger");
2035
- this.onPaginationTrigger = props.onPaginationTrigger;
2036
- this.customItem = props.customItem;
2037
- const shadow = this.attachShadow({ mode: "open" });
2038
- const style = document.createElement("style");
2039
- style.textContent = this.getStyles();
2040
- shadow.appendChild(style);
2041
- if (this.customItem) {
2042
- shadow.appendChild(this.customItem);
2145
+ __publicField(this, "_onPaginationTrigger");
2146
+ this._theme = props.theme;
2147
+ this._customItem = props.customItem;
2148
+ this._onPaginationTrigger = props.onPaginationTrigger;
2149
+ }
2150
+ static get id() {
2151
+ return "courier-inbox-pagination-list-item";
2152
+ }
2153
+ onComponentMounted() {
2154
+ this._style = injectGlobalStyle(CourierInboxPaginationListItem.id, CourierInboxPaginationListItem.getStyles(this._theme));
2155
+ if (this._customItem) {
2156
+ this.appendChild(this._customItem);
2043
2157
  } else {
2044
2158
  const container = document.createElement("div");
2045
2159
  container.className = "skeleton-container";
2046
- this.skeletonLoadingList = new CourierInboxSkeletonList(props.theme);
2047
- this.skeletonLoadingList.build(void 0);
2048
- container.appendChild(this.skeletonLoadingList);
2049
- shadow.appendChild(container);
2160
+ this._skeletonLoadingList = new CourierInboxSkeletonList(this._theme);
2161
+ this._skeletonLoadingList.build(void 0);
2162
+ container.appendChild(this._skeletonLoadingList);
2163
+ this.appendChild(container);
2050
2164
  }
2051
- this.observer = new IntersectionObserver((entries) => {
2165
+ this._observer = new IntersectionObserver((entries) => {
2052
2166
  entries.forEach((entry) => {
2053
2167
  if (entry.isIntersecting) {
2054
- this.onPaginationTrigger();
2168
+ this._onPaginationTrigger();
2055
2169
  }
2056
2170
  });
2057
2171
  });
2058
- this.observer.observe(this);
2172
+ this._observer.observe(this);
2059
2173
  }
2060
- getStyles() {
2174
+ onComponentUnmounted() {
2175
+ var _a, _b;
2176
+ (_a = this._observer) == null ? void 0 : _a.disconnect();
2177
+ (_b = this._style) == null ? void 0 : _b.remove();
2178
+ }
2179
+ static getStyles(_theme) {
2061
2180
  return `
2062
- :host {
2181
+ ${CourierInboxPaginationListItem.id} {
2063
2182
  padding: 0;
2064
2183
  margin: 0;
2065
2184
  box-sizing: border-box;
2066
2185
  }
2067
2186
 
2068
- .skeleton-container {
2187
+ ${CourierInboxPaginationListItem.id} .skeleton-container {
2069
2188
  height: 150%;
2070
2189
  }
2071
2190
  `;
2072
2191
  }
2073
- disconnectedCallback() {
2074
- this.observer.disconnect();
2075
- }
2076
2192
  }
2077
- registerElement("courier-inbox-pagination-list-item", CourierInboxPaginationListItem);
2078
- class CourierInboxList extends BaseElement {
2193
+ registerElement(CourierInboxPaginationListItem);
2194
+ class CourierInboxList extends CourierBaseElement {
2079
2195
  constructor(props) {
2080
2196
  super();
2081
2197
  // Theme
@@ -2098,34 +2214,53 @@ class CourierInboxList extends BaseElement {
2098
2214
  __publicField(this, "_loadingStateFactory");
2099
2215
  __publicField(this, "_emptyStateFactory");
2100
2216
  __publicField(this, "_errorStateFactory");
2101
- this._themeSubscription = props.themeManager.subscribe((_) => {
2102
- this.refreshTheme();
2103
- });
2217
+ // Components
2218
+ __publicField(this, "_listStyles");
2219
+ __publicField(this, "_listItemStyles");
2220
+ __publicField(this, "_listItemMenuStyles");
2104
2221
  this._onRefresh = props.onRefresh;
2105
2222
  this._onPaginationTrigger = props.onPaginationTrigger;
2106
2223
  this._onMessageClick = props.onMessageClick;
2107
2224
  this._onMessageActionClick = props.onMessageActionClick;
2108
2225
  this._onMessageLongPress = props.onMessageLongPress;
2109
- const shadow = this.attachShadow({ mode: "open" });
2110
- const style = document.createElement("style");
2111
- style.textContent = this.getStyles();
2112
- shadow.appendChild(style);
2226
+ this._themeSubscription = props.themeManager.subscribe((_) => {
2227
+ this.render();
2228
+ });
2229
+ }
2230
+ static get id() {
2231
+ return "courier-inbox-list";
2113
2232
  }
2114
2233
  // Getters
2115
2234
  get messages() {
2116
2235
  return this._messages;
2117
2236
  }
2118
- getStyles() {
2237
+ get theme() {
2238
+ return this._themeSubscription.manager.getTheme();
2239
+ }
2240
+ onComponentMounted() {
2241
+ this._listStyles = injectGlobalStyle(CourierInboxList.id, CourierInboxList.getStyles(this.theme));
2242
+ this._listItemStyles = injectGlobalStyle(CourierInboxListItem.id, CourierInboxListItem.getStyles(this.theme));
2243
+ this._listItemMenuStyles = injectGlobalStyle(CourierInboxListItemMenu.id, CourierInboxListItemMenu.getStyles(this.theme));
2244
+ this.render();
2245
+ }
2246
+ onComponentUnmounted() {
2247
+ var _a, _b, _c;
2248
+ this._themeSubscription.unsubscribe();
2249
+ (_a = this._listStyles) == null ? void 0 : _a.remove();
2250
+ (_b = this._listItemStyles) == null ? void 0 : _b.remove();
2251
+ (_c = this._listItemMenuStyles) == null ? void 0 : _c.remove();
2252
+ }
2253
+ static getStyles(theme2) {
2119
2254
  var _a;
2120
- const list = (_a = this._themeSubscription.manager.getTheme().inbox) == null ? void 0 : _a.list;
2255
+ const list = (_a = theme2.inbox) == null ? void 0 : _a.list;
2121
2256
  return `
2122
- :host {
2257
+ ${CourierInboxList.id} {
2123
2258
  flex: 1;
2124
2259
  width: 100%;
2125
- background-color: ${(list == null ? void 0 : list.backgroundColor) ?? CourierColors.white[500]};
2260
+ background-color: ${(list == null ? void 0 : list.backgroundColor) ?? "red"};
2126
2261
  }
2127
2262
 
2128
- ul {
2263
+ ${CourierInboxList.id} ul {
2129
2264
  list-style: none;
2130
2265
  padding: 0;
2131
2266
  margin: 0;
@@ -2133,15 +2268,6 @@ class CourierInboxList extends BaseElement {
2133
2268
  }
2134
2269
  `;
2135
2270
  }
2136
- reset() {
2137
- var _a, _b;
2138
- while ((_a = this.shadowRoot) == null ? void 0 : _a.firstChild) {
2139
- this.shadowRoot.removeChild(this.shadowRoot.firstChild);
2140
- }
2141
- const style = document.createElement("style");
2142
- style.textContent = this.getStyles();
2143
- (_b = this.shadowRoot) == null ? void 0 : _b.appendChild(style);
2144
- }
2145
2271
  setDataSet(dataSet) {
2146
2272
  this._messages = [...dataSet.messages];
2147
2273
  this._canPaginate = Boolean(dataSet.canPaginate);
@@ -2195,11 +2321,21 @@ class CourierInboxList extends BaseElement {
2195
2321
  this._onRefresh();
2196
2322
  }
2197
2323
  render() {
2198
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da;
2199
- this.reset();
2200
- const theme2 = this._themeSubscription.manager.getTheme();
2324
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$;
2325
+ while (this.firstChild) {
2326
+ this.removeChild(this.firstChild);
2327
+ }
2328
+ if (this._listStyles) {
2329
+ this._listStyles.textContent = CourierInboxList.getStyles(this.theme);
2330
+ }
2331
+ if (this._listItemStyles) {
2332
+ this._listItemStyles.textContent = CourierInboxListItem.getStyles(this.theme);
2333
+ }
2334
+ if (this._listItemMenuStyles) {
2335
+ this._listItemMenuStyles.textContent = CourierInboxListItemMenu.getStyles(this.theme);
2336
+ }
2201
2337
  if (this._error) {
2202
- const error = (_a = theme2.inbox) == null ? void 0 : _a.error;
2338
+ const error = (_a = this.theme.inbox) == null ? void 0 : _a.error;
2203
2339
  const errorElement = new CourierInfoState({
2204
2340
  title: {
2205
2341
  text: ((_b = error == null ? void 0 : error.title) == null ? void 0 : _b.text) ?? this._error.message,
@@ -2224,52 +2360,52 @@ class CourierInboxList extends BaseElement {
2224
2360
  });
2225
2361
  errorElement.build((_z = this._errorStateFactory) == null ? void 0 : _z.call(this, { feedType: this._feedType, error: this._error }));
2226
2362
  errorElement.setButtonClickCallback(() => this.handleRetry());
2227
- (_A = this.shadowRoot) == null ? void 0 : _A.appendChild(errorElement);
2363
+ this.appendChild(errorElement);
2228
2364
  return;
2229
2365
  }
2230
2366
  if (this._isLoading) {
2231
- const loadingElement = new CourierInboxSkeletonList(theme2);
2232
- loadingElement.build((_B = this._loadingStateFactory) == null ? void 0 : _B.call(this, { feedType: this._feedType }));
2233
- (_C = this.shadowRoot) == null ? void 0 : _C.appendChild(loadingElement);
2367
+ const loadingElement = new CourierInboxSkeletonList(this.theme);
2368
+ loadingElement.build((_A = this._loadingStateFactory) == null ? void 0 : _A.call(this, { feedType: this._feedType }));
2369
+ this.appendChild(loadingElement);
2234
2370
  return;
2235
2371
  }
2236
2372
  if (this._messages.length === 0) {
2237
- const empty = (_D = theme2.inbox) == null ? void 0 : _D.empty;
2373
+ const empty = (_B = this.theme.inbox) == null ? void 0 : _B.empty;
2238
2374
  const emptyElement = new CourierInfoState({
2239
2375
  title: {
2240
- text: ((_E = empty == null ? void 0 : empty.title) == null ? void 0 : _E.text) ?? `No ${this._feedType} messages yet`,
2241
- textColor: (_G = (_F = empty == null ? void 0 : empty.title) == null ? void 0 : _F.font) == null ? void 0 : _G.color,
2242
- fontFamily: (_I = (_H = empty == null ? void 0 : empty.title) == null ? void 0 : _H.font) == null ? void 0 : _I.family,
2243
- fontSize: (_K = (_J = empty == null ? void 0 : empty.title) == null ? void 0 : _J.font) == null ? void 0 : _K.size,
2244
- fontWeight: (_M = (_L = empty == null ? void 0 : empty.title) == null ? void 0 : _L.font) == null ? void 0 : _M.weight
2376
+ text: ((_C = empty == null ? void 0 : empty.title) == null ? void 0 : _C.text) ?? `No ${this._feedType} messages yet`,
2377
+ textColor: (_E = (_D = empty == null ? void 0 : empty.title) == null ? void 0 : _D.font) == null ? void 0 : _E.color,
2378
+ fontFamily: (_G = (_F = empty == null ? void 0 : empty.title) == null ? void 0 : _F.font) == null ? void 0 : _G.family,
2379
+ fontSize: (_I = (_H = empty == null ? void 0 : empty.title) == null ? void 0 : _H.font) == null ? void 0 : _I.size,
2380
+ fontWeight: (_K = (_J = empty == null ? void 0 : empty.title) == null ? void 0 : _J.font) == null ? void 0 : _K.weight
2245
2381
  },
2246
2382
  button: {
2247
- text: (_N = empty == null ? void 0 : empty.button) == null ? void 0 : _N.text,
2248
- backgroundColor: (_O = empty == null ? void 0 : empty.button) == null ? void 0 : _O.backgroundColor,
2249
- hoverBackgroundColor: (_P = empty == null ? void 0 : empty.button) == null ? void 0 : _P.hoverBackgroundColor,
2250
- activeBackgroundColor: (_Q = empty == null ? void 0 : empty.button) == null ? void 0 : _Q.activeBackgroundColor,
2251
- textColor: (_S = (_R = empty == null ? void 0 : empty.button) == null ? void 0 : _R.font) == null ? void 0 : _S.color,
2252
- fontFamily: (_U = (_T = empty == null ? void 0 : empty.button) == null ? void 0 : _T.font) == null ? void 0 : _U.family,
2253
- fontSize: (_W = (_V = empty == null ? void 0 : empty.button) == null ? void 0 : _V.font) == null ? void 0 : _W.size,
2254
- fontWeight: (_Y = (_X = empty == null ? void 0 : empty.button) == null ? void 0 : _X.font) == null ? void 0 : _Y.weight,
2255
- shadow: (_Z = empty == null ? void 0 : empty.button) == null ? void 0 : _Z.shadow,
2256
- border: (__ = empty == null ? void 0 : empty.button) == null ? void 0 : __.border,
2257
- borderRadius: (_$ = empty == null ? void 0 : empty.button) == null ? void 0 : _$.borderRadius
2383
+ text: (_L = empty == null ? void 0 : empty.button) == null ? void 0 : _L.text,
2384
+ backgroundColor: (_M = empty == null ? void 0 : empty.button) == null ? void 0 : _M.backgroundColor,
2385
+ hoverBackgroundColor: (_N = empty == null ? void 0 : empty.button) == null ? void 0 : _N.hoverBackgroundColor,
2386
+ activeBackgroundColor: (_O = empty == null ? void 0 : empty.button) == null ? void 0 : _O.activeBackgroundColor,
2387
+ textColor: (_Q = (_P = empty == null ? void 0 : empty.button) == null ? void 0 : _P.font) == null ? void 0 : _Q.color,
2388
+ fontFamily: (_S = (_R = empty == null ? void 0 : empty.button) == null ? void 0 : _R.font) == null ? void 0 : _S.family,
2389
+ fontSize: (_U = (_T = empty == null ? void 0 : empty.button) == null ? void 0 : _T.font) == null ? void 0 : _U.size,
2390
+ fontWeight: (_W = (_V = empty == null ? void 0 : empty.button) == null ? void 0 : _V.font) == null ? void 0 : _W.weight,
2391
+ shadow: (_X = empty == null ? void 0 : empty.button) == null ? void 0 : _X.shadow,
2392
+ border: (_Y = empty == null ? void 0 : empty.button) == null ? void 0 : _Y.border,
2393
+ borderRadius: (_Z = empty == null ? void 0 : empty.button) == null ? void 0 : _Z.borderRadius
2258
2394
  }
2259
2395
  });
2260
- emptyElement.build((_aa = this._emptyStateFactory) == null ? void 0 : _aa.call(this, { feedType: this._feedType }));
2396
+ emptyElement.build((__ = this._emptyStateFactory) == null ? void 0 : __.call(this, { feedType: this._feedType }));
2261
2397
  emptyElement.setButtonClickCallback(() => this.handleRefresh());
2262
- (_ba = this.shadowRoot) == null ? void 0 : _ba.appendChild(emptyElement);
2398
+ this.appendChild(emptyElement);
2263
2399
  return;
2264
2400
  }
2265
2401
  const list = document.createElement("ul");
2266
- (_ca = this.shadowRoot) == null ? void 0 : _ca.appendChild(list);
2402
+ this.appendChild(list);
2267
2403
  this._messages.forEach((message, index) => {
2268
2404
  if (this._listItemFactory) {
2269
2405
  list.appendChild(this._listItemFactory({ message, index }));
2270
2406
  return;
2271
2407
  }
2272
- const listItem = new CourierListItem(theme2);
2408
+ const listItem = new CourierInboxListItem(this.theme);
2273
2409
  listItem.setMessage(message, this._feedType);
2274
2410
  listItem.setOnItemClick((message2) => {
2275
2411
  var _a2;
@@ -2287,8 +2423,8 @@ class CourierInboxList extends BaseElement {
2287
2423
  });
2288
2424
  if (this._canPaginate) {
2289
2425
  const paginationItem = new CourierInboxPaginationListItem({
2290
- theme: theme2,
2291
- customItem: (_da = this._paginationItemFactory) == null ? void 0 : _da.call(this, { feedType: this._feedType }),
2426
+ theme: this.theme,
2427
+ customItem: (_$ = this._paginationItemFactory) == null ? void 0 : _$.call(this, { feedType: this._feedType }),
2292
2428
  onPaginationTrigger: () => {
2293
2429
  var _a2;
2294
2430
  return (_a2 = this._onPaginationTrigger) == null ? void 0 : _a2.call(this, this._feedType);
@@ -2318,34 +2454,28 @@ class CourierInboxList extends BaseElement {
2318
2454
  this._paginationItemFactory = factory;
2319
2455
  this.render();
2320
2456
  }
2321
- refreshTheme() {
2322
- this.render();
2323
- }
2324
- // Disconnect the theme subscription
2325
- disconnectedCallback() {
2326
- this._themeSubscription.unsubscribe();
2327
- }
2328
2457
  }
2329
- registerElement("courier-inbox-list", CourierInboxList);
2330
- class CourierInboxOptionMenuItem extends BaseElement {
2458
+ registerElement(CourierInboxList);
2459
+ class CourierInboxOptionMenuItem extends CourierBaseElement {
2331
2460
  constructor(props) {
2332
2461
  super();
2333
2462
  // State
2334
2463
  __publicField(this, "_option");
2464
+ __publicField(this, "_isSelectedable");
2335
2465
  __publicField(this, "_isSelected");
2336
2466
  // Components
2337
2467
  __publicField(this, "_content");
2338
2468
  __publicField(this, "_itemIcon");
2339
2469
  __publicField(this, "_title");
2340
2470
  __publicField(this, "_selectionIcon");
2341
- __publicField(this, "_style");
2342
- // Theme
2343
- __publicField(this, "_themeManager");
2344
2471
  this._option = props.option;
2345
2472
  this._isSelected = props.isSelected;
2346
- this._themeManager = props.themeManager;
2347
- const shadow = this.attachShadow({ mode: "open" });
2348
- this._style = document.createElement("style");
2473
+ this._isSelectedable = props.selectable;
2474
+ }
2475
+ static get id() {
2476
+ return "courier-inbox-option-menu-item";
2477
+ }
2478
+ onComponentMounted() {
2349
2479
  this._content = document.createElement("div");
2350
2480
  this._content.className = "menu-item";
2351
2481
  this._itemIcon = new CourierIcon(this._option.icon.svg ?? CourierIconSVGs.inbox);
@@ -2358,70 +2488,26 @@ class CourierInboxOptionMenuItem extends BaseElement {
2358
2488
  this._content.appendChild(this._itemIcon);
2359
2489
  this._content.appendChild(this._title);
2360
2490
  this._content.appendChild(spacer);
2361
- if (props.selectable) {
2491
+ if (this._isSelectedable) {
2362
2492
  this._content.appendChild(this._selectionIcon);
2363
2493
  }
2364
- shadow.appendChild(this._style);
2365
- shadow.appendChild(this._content);
2494
+ this.appendChild(this._content);
2366
2495
  this._selectionIcon.style.display = this._isSelected ? "block" : "none";
2367
2496
  this.refreshTheme();
2368
2497
  }
2369
- getStyles() {
2370
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H;
2371
- const theme2 = this._themeManager.getTheme();
2372
- return `
2373
- :host {
2374
- display: flex;
2375
- flex-direction: row;
2376
- padding: 6px 12px;
2377
- cursor: pointer;
2378
- }
2379
-
2380
- :host(:hover) {
2381
- background-color: ${((_e = (_d = (_c = (_b = (_a = theme2.inbox) == null ? void 0 : _a.header) == null ? void 0 : _b.menus) == null ? void 0 : _c.popup) == null ? void 0 : _d.list) == null ? void 0 : _e.hoverBackgroundColor) ?? "red"};
2382
- }
2383
-
2384
- :host(:active) {
2385
- background-color: ${((_j = (_i = (_h = (_g = (_f = theme2.inbox) == null ? void 0 : _f.header) == null ? void 0 : _g.menus) == null ? void 0 : _h.popup) == null ? void 0 : _i.list) == null ? void 0 : _j.activeBackgroundColor) ?? "red"};
2386
- }
2387
-
2388
- .menu-item {
2389
- display: flex;
2390
- align-items: center;
2391
- width: 100%;
2392
- gap: 12px;
2393
- }
2394
-
2395
- .spacer {
2396
- flex: 1;
2397
- }
2398
-
2399
- p {
2400
- margin: 0;
2401
- font-family: ${((_p = (_o = (_n = (_m = (_l = (_k = theme2.inbox) == null ? void 0 : _k.header) == null ? void 0 : _l.menus) == null ? void 0 : _m.popup) == null ? void 0 : _n.list) == null ? void 0 : _o.font) == null ? void 0 : _p.family) ?? "inherit"};
2402
- font-weight: ${((_v = (_u = (_t = (_s = (_r = (_q = theme2.inbox) == null ? void 0 : _q.header) == null ? void 0 : _r.menus) == null ? void 0 : _s.popup) == null ? void 0 : _t.list) == null ? void 0 : _u.font) == null ? void 0 : _v.weight) ?? "inherit"};
2403
- font-size: ${((_B = (_A = (_z = (_y = (_x = (_w = theme2.inbox) == null ? void 0 : _w.header) == null ? void 0 : _x.menus) == null ? void 0 : _y.popup) == null ? void 0 : _z.list) == null ? void 0 : _A.font) == null ? void 0 : _B.size) ?? "14px"};
2404
- color: ${((_H = (_G = (_F = (_E = (_D = (_C = theme2.inbox) == null ? void 0 : _C.header) == null ? void 0 : _D.menus) == null ? void 0 : _E.popup) == null ? void 0 : _F.list) == null ? void 0 : _G.font) == null ? void 0 : _H.color) ?? "red"};
2405
- white-space: nowrap;
2406
- }
2407
-
2408
- .check-icon {
2409
- display: none;
2410
- }
2411
- `;
2412
- }
2413
2498
  refreshTheme() {
2414
- var _a, _b, _c, _d;
2415
- this._style.textContent = this.getStyles();
2416
- this._selectionIcon.updateColor(((_a = this._option.selectionIcon) == null ? void 0 : _a.color) ?? "red");
2417
- this._selectionIcon.updateSVG(((_b = this._option.selectionIcon) == null ? void 0 : _b.svg) ?? CourierIconSVGs.check);
2418
- this._title.textContent = this._option.text ?? "Missing Text";
2419
- this._itemIcon.updateColor(((_c = this._option.icon) == null ? void 0 : _c.color) ?? "red");
2420
- this._itemIcon.updateSVG(((_d = this._option.icon) == null ? void 0 : _d.svg) ?? CourierIconSVGs.inbox);
2499
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2500
+ (_b = this._selectionIcon) == null ? void 0 : _b.updateColor(((_a = this._option.selectionIcon) == null ? void 0 : _a.color) ?? "red");
2501
+ (_d = this._selectionIcon) == null ? void 0 : _d.updateSVG(((_c = this._option.selectionIcon) == null ? void 0 : _c.svg) ?? CourierIconSVGs.check);
2502
+ if (this._title) {
2503
+ this._title.textContent = this._option.text ?? "Missing Text";
2504
+ }
2505
+ (_f = this._itemIcon) == null ? void 0 : _f.updateColor(((_e = this._option.icon) == null ? void 0 : _e.color) ?? "red");
2506
+ (_h = this._itemIcon) == null ? void 0 : _h.updateSVG(((_g = this._option.icon) == null ? void 0 : _g.svg) ?? CourierIconSVGs.inbox);
2421
2507
  }
2422
2508
  }
2423
- registerElement("courier-inbox-filter-menu-item", CourierInboxOptionMenuItem);
2424
- class CourierInboxOptionMenu extends BaseElement {
2509
+ registerElement(CourierInboxOptionMenuItem);
2510
+ class CourierInboxOptionMenu extends CourierBaseElement {
2425
2511
  constructor(themeManager, type, selectable, options, onMenuOpen) {
2426
2512
  super();
2427
2513
  // Theme
@@ -2441,31 +2527,39 @@ class CourierInboxOptionMenu extends BaseElement {
2441
2527
  this._options = options;
2442
2528
  this._selectedIndex = 0;
2443
2529
  this._onMenuOpen = onMenuOpen;
2444
- const shadow = this.attachShadow({ mode: "open" });
2445
- this._menuButton = new CourierIconButton(type === "filters" ? CourierIconSVGs.filter : CourierIconSVGs.overflow);
2446
- this._menu = document.createElement("div");
2447
- this._menu.className = `menu ${type}`;
2448
- this._style = document.createElement("style");
2449
- shadow.appendChild(this._style);
2450
- shadow.appendChild(this._menuButton);
2451
- shadow.appendChild(this._menu);
2452
- this._menuButton.addEventListener("click", this.toggleMenu.bind(this));
2453
- document.addEventListener("click", this.handleOutsideClick.bind(this));
2454
2530
  this._themeSubscription = themeManager.subscribe((_) => {
2455
2531
  this.refreshTheme();
2456
2532
  });
2533
+ }
2534
+ static get id() {
2535
+ return "courier-inbox-option-menu";
2536
+ }
2537
+ onComponentMounted() {
2538
+ this._style = injectGlobalStyle(CourierInboxOptionMenu.id, this.getStyles());
2539
+ this._menuButton = new CourierIconButton(this._type === "filters" ? CourierIconSVGs.filter : CourierIconSVGs.overflow);
2540
+ this._menu = document.createElement("div");
2541
+ this._menu.className = `menu ${this._type}`;
2542
+ this.appendChild(this._menuButton);
2543
+ this.appendChild(this._menu);
2544
+ this._menuButton.addEventListener("click", this.toggleMenu.bind(this));
2545
+ document.addEventListener("click", this.handleOutsideClick.bind(this));
2457
2546
  this.refreshTheme();
2458
2547
  }
2548
+ onComponentUnmounted() {
2549
+ var _a;
2550
+ this._themeSubscription.unsubscribe();
2551
+ (_a = this._style) == null ? void 0 : _a.remove();
2552
+ }
2459
2553
  getStyles() {
2460
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
2554
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa;
2461
2555
  const theme2 = this._themeSubscription.manager.getTheme();
2462
2556
  return `
2463
- :host {
2557
+ ${CourierInboxOptionMenu.id} {
2464
2558
  position: relative;
2465
2559
  display: inline-block;
2466
2560
  }
2467
2561
 
2468
- .menu {
2562
+ ${CourierInboxOptionMenu.id} .menu {
2469
2563
  display: none;
2470
2564
  position: absolute;
2471
2565
  top: 42px;
@@ -2480,28 +2574,69 @@ class CourierInboxOptionMenu extends BaseElement {
2480
2574
  padding: 4px 0;
2481
2575
  }
2482
2576
 
2483
- courier-inbox-filter-menu-item {
2577
+ ${CourierInboxOptionMenu.id} courier-inbox-filter-menu-item {
2484
2578
  border-bottom: ${((_u = (_t = (_s = (_r = (_q = theme2.inbox) == null ? void 0 : _q.header) == null ? void 0 : _r.menus) == null ? void 0 : _s.popup) == null ? void 0 : _t.list) == null ? void 0 : _u.divider) ?? "none"};
2485
2579
  }
2486
2580
 
2487
- courier-inbox-filter-menu-item:last-child {
2581
+ ${CourierInboxOptionMenu.id} courier-inbox-filter-menu-item:last-child {
2488
2582
  border-bottom: none;
2489
2583
  }
2584
+
2585
+ ${CourierInboxOptionMenuItem.id} {
2586
+ display: flex;
2587
+ flex-direction: row;
2588
+ padding: 6px 12px;
2589
+ cursor: pointer;
2590
+ }
2591
+
2592
+ ${CourierInboxOptionMenuItem.id}:hover {
2593
+ background-color: ${((_z = (_y = (_x = (_w = (_v = theme2.inbox) == null ? void 0 : _v.header) == null ? void 0 : _w.menus) == null ? void 0 : _x.popup) == null ? void 0 : _y.list) == null ? void 0 : _z.hoverBackgroundColor) ?? "red"};
2594
+ }
2595
+
2596
+ ${CourierInboxOptionMenuItem.id}:active {
2597
+ background-color: ${((_E = (_D = (_C = (_B = (_A = theme2.inbox) == null ? void 0 : _A.header) == null ? void 0 : _B.menus) == null ? void 0 : _C.popup) == null ? void 0 : _D.list) == null ? void 0 : _E.activeBackgroundColor) ?? "red"};
2598
+ }
2599
+
2600
+ ${CourierInboxOptionMenuItem.id} .menu-item {
2601
+ display: flex;
2602
+ align-items: center;
2603
+ width: 100%;
2604
+ gap: 12px;
2605
+ }
2606
+
2607
+ ${CourierInboxOptionMenuItem.id} .spacer {
2608
+ flex: 1;
2609
+ }
2610
+
2611
+ ${CourierInboxOptionMenuItem.id} p {
2612
+ margin: 0;
2613
+ font-family: ${((_K = (_J = (_I = (_H = (_G = (_F = theme2.inbox) == null ? void 0 : _F.header) == null ? void 0 : _G.menus) == null ? void 0 : _H.popup) == null ? void 0 : _I.list) == null ? void 0 : _J.font) == null ? void 0 : _K.family) ?? "inherit"};
2614
+ font-weight: ${((_Q = (_P = (_O = (_N = (_M = (_L = theme2.inbox) == null ? void 0 : _L.header) == null ? void 0 : _M.menus) == null ? void 0 : _N.popup) == null ? void 0 : _O.list) == null ? void 0 : _P.font) == null ? void 0 : _Q.weight) ?? "inherit"};
2615
+ font-size: ${((_W = (_V = (_U = (_T = (_S = (_R = theme2.inbox) == null ? void 0 : _R.header) == null ? void 0 : _S.menus) == null ? void 0 : _T.popup) == null ? void 0 : _U.list) == null ? void 0 : _V.font) == null ? void 0 : _W.size) ?? "14px"};
2616
+ color: ${((_aa = (_$ = (__ = (_Z = (_Y = (_X = theme2.inbox) == null ? void 0 : _X.header) == null ? void 0 : _Y.menus) == null ? void 0 : _Z.popup) == null ? void 0 : __.list) == null ? void 0 : _$.font) == null ? void 0 : _aa.color) ?? "red"};
2617
+ white-space: nowrap;
2618
+ }
2619
+
2620
+ ${CourierInboxOptionMenuItem.id} .check-icon {
2621
+ display: none;
2622
+ }
2490
2623
  `;
2491
2624
  }
2492
2625
  refreshTheme() {
2493
- var _a, _b, _c, _d, _e, _f;
2494
- this._style.textContent = this.getStyles();
2626
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2627
+ if (this._style) {
2628
+ this._style.textContent = this.getStyles();
2629
+ }
2495
2630
  const theme2 = this._themeSubscription.manager.getTheme();
2496
2631
  const menu = (_b = (_a = theme2.inbox) == null ? void 0 : _a.header) == null ? void 0 : _b.menus;
2497
2632
  const isFilter = this._type === "filters";
2498
2633
  const buttonConfig = isFilter ? (_c = menu == null ? void 0 : menu.filters) == null ? void 0 : _c.button : (_d = menu == null ? void 0 : menu.actions) == null ? void 0 : _d.button;
2499
2634
  const defaultIcon = isFilter ? CourierIconSVGs.filter : CourierIconSVGs.overflow;
2500
- this._menuButton.updateIconSVG(((_e = buttonConfig == null ? void 0 : buttonConfig.icon) == null ? void 0 : _e.svg) ?? defaultIcon);
2501
- this._menuButton.updateIconColor(((_f = buttonConfig == null ? void 0 : buttonConfig.icon) == null ? void 0 : _f.color) ?? "red");
2502
- this._menuButton.updateBackgroundColor((buttonConfig == null ? void 0 : buttonConfig.backgroundColor) ?? "transparent");
2503
- this._menuButton.updateHoverBackgroundColor((buttonConfig == null ? void 0 : buttonConfig.hoverBackgroundColor) ?? "red");
2504
- this._menuButton.updateActiveBackgroundColor((buttonConfig == null ? void 0 : buttonConfig.activeBackgroundColor) ?? "red");
2635
+ (_f = this._menuButton) == null ? void 0 : _f.updateIconSVG(((_e = buttonConfig == null ? void 0 : buttonConfig.icon) == null ? void 0 : _e.svg) ?? defaultIcon);
2636
+ (_h = this._menuButton) == null ? void 0 : _h.updateIconColor(((_g = buttonConfig == null ? void 0 : buttonConfig.icon) == null ? void 0 : _g.color) ?? "red");
2637
+ (_i = this._menuButton) == null ? void 0 : _i.updateBackgroundColor((buttonConfig == null ? void 0 : buttonConfig.backgroundColor) ?? "transparent");
2638
+ (_j = this._menuButton) == null ? void 0 : _j.updateHoverBackgroundColor((buttonConfig == null ? void 0 : buttonConfig.hoverBackgroundColor) ?? "red");
2639
+ (_k = this._menuButton) == null ? void 0 : _k.updateActiveBackgroundColor((buttonConfig == null ? void 0 : buttonConfig.activeBackgroundColor) ?? "red");
2505
2640
  this.refreshMenuItems();
2506
2641
  }
2507
2642
  setOptions(options) {
@@ -2509,8 +2644,11 @@ class CourierInboxOptionMenu extends BaseElement {
2509
2644
  this.refreshMenuItems();
2510
2645
  }
2511
2646
  refreshMenuItems() {
2512
- this._menu.innerHTML = "";
2647
+ if (this._menu) {
2648
+ this._menu.innerHTML = "";
2649
+ }
2513
2650
  this._options.forEach((option, index) => {
2651
+ var _a;
2514
2652
  const menuItem = new CourierInboxOptionMenuItem({
2515
2653
  option,
2516
2654
  selectable: this._selectable,
@@ -2523,13 +2661,16 @@ class CourierInboxOptionMenu extends BaseElement {
2523
2661
  this.refreshMenuItems();
2524
2662
  this.closeMenu();
2525
2663
  });
2526
- this._menu.appendChild(menuItem);
2664
+ (_a = this._menu) == null ? void 0 : _a.appendChild(menuItem);
2527
2665
  });
2528
2666
  }
2529
2667
  toggleMenu(event) {
2668
+ var _a;
2530
2669
  event.stopPropagation();
2531
- const isOpening = this._menu.style.display !== "block";
2532
- this._menu.style.display = isOpening ? "block" : "none";
2670
+ const isOpening = ((_a = this._menu) == null ? void 0 : _a.style.display) !== "block";
2671
+ if (this._menu) {
2672
+ this._menu.style.display = isOpening ? "block" : "none";
2673
+ }
2533
2674
  if (isOpening) {
2534
2675
  this._onMenuOpen();
2535
2676
  }
@@ -2540,18 +2681,17 @@ class CourierInboxOptionMenu extends BaseElement {
2540
2681
  }
2541
2682
  }
2542
2683
  closeMenu() {
2543
- this._menu.style.display = "none";
2684
+ if (this._menu) {
2685
+ this._menu.style.display = "none";
2686
+ }
2544
2687
  }
2545
2688
  selectOption(option) {
2546
2689
  this._selectedIndex = this._options.findIndex((o) => o.id === option.id);
2547
2690
  this.refreshMenuItems();
2548
2691
  }
2549
- disconnectedCallback() {
2550
- this._themeSubscription.unsubscribe();
2551
- }
2552
2692
  }
2553
- registerElement("courier-inbox-option-menu", CourierInboxOptionMenu);
2554
- class CourierUnreadCountBadge extends BaseElement {
2693
+ registerElement(CourierInboxOptionMenu);
2694
+ class CourierUnreadCountBadge extends CourierBaseElement {
2555
2695
  constructor(props) {
2556
2696
  super();
2557
2697
  // Theme
@@ -2566,37 +2706,51 @@ class CourierUnreadCountBadge extends BaseElement {
2566
2706
  this._themeSubscription = props.themeBus.subscribe((_) => {
2567
2707
  this.refreshTheme(this._location);
2568
2708
  });
2569
- const shadow = this.attachShadow({ mode: "open" });
2709
+ }
2710
+ static get id() {
2711
+ return "courier-unread-count-badge";
2712
+ }
2713
+ get theme() {
2714
+ return this._themeSubscription.manager.getTheme();
2715
+ }
2716
+ onComponentMounted() {
2570
2717
  this._badge = document.createElement("span");
2571
- this._badge.className = "unread-badge";
2572
- this._style = document.createElement("style");
2573
- this._style.textContent = this.getStyles(this._location);
2574
- shadow.appendChild(this._style);
2575
- shadow.appendChild(this._badge);
2718
+ this._badge.className = `unread-badge ${this._location}`;
2719
+ this.appendChild(this._badge);
2720
+ this.updateBadge();
2576
2721
  }
2577
- getStyles(location) {
2578
- var _a, _b, _c, _d, _e, _f, _g;
2579
- const theme2 = this._themeSubscription.manager.getTheme();
2580
- const indicator = location === "button" ? (_b = (_a = theme2.popup) == null ? void 0 : _a.button) == null ? void 0 : _b.unreadIndicator : (_e = (_d = (_c = theme2.inbox) == null ? void 0 : _c.header) == null ? void 0 : _d.filters) == null ? void 0 : _e.unreadIndicator;
2581
- const backgroundColor = indicator == null ? void 0 : indicator.backgroundColor;
2582
- const borderRadius = indicator == null ? void 0 : indicator.borderRadius;
2583
- const color = (_f = indicator == null ? void 0 : indicator.font) == null ? void 0 : _f.color;
2584
- const fontSize = (_g = indicator == null ? void 0 : indicator.font) == null ? void 0 : _g.size;
2722
+ onComponentUnmounted() {
2723
+ var _a;
2724
+ this._themeSubscription.unsubscribe();
2725
+ (_a = this._style) == null ? void 0 : _a.remove();
2726
+ }
2727
+ static getStyles(theme2) {
2728
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
2585
2729
  return `
2586
- :host {
2730
+ ${CourierUnreadCountBadge.id} {
2587
2731
  display: inline-block;
2588
2732
  }
2589
2733
 
2590
- .unread-badge {
2591
- background-color: ${backgroundColor};
2592
- color: ${color};
2593
- border-radius: ${borderRadius};
2734
+ ${CourierUnreadCountBadge.id} .unread-badge {
2594
2735
  padding: 4px 8px;
2595
- font-size: ${fontSize};
2596
2736
  text-align: center;
2597
2737
  display: none;
2598
2738
  pointer-events: none;
2599
2739
  }
2740
+
2741
+ ${CourierUnreadCountBadge.id} .button {
2742
+ background-color: ${(_c = (_b = (_a = theme2.popup) == null ? void 0 : _a.button) == null ? void 0 : _b.unreadIndicator) == null ? void 0 : _c.backgroundColor};
2743
+ color: ${(_g = (_f = (_e = (_d = theme2.popup) == null ? void 0 : _d.button) == null ? void 0 : _e.unreadIndicator) == null ? void 0 : _f.font) == null ? void 0 : _g.color};
2744
+ border-radius: ${(_j = (_i = (_h = theme2.popup) == null ? void 0 : _h.button) == null ? void 0 : _i.unreadIndicator) == null ? void 0 : _j.borderRadius};
2745
+ font-size: ${(_n = (_m = (_l = (_k = theme2.popup) == null ? void 0 : _k.button) == null ? void 0 : _l.unreadIndicator) == null ? void 0 : _m.font) == null ? void 0 : _n.size};
2746
+ }
2747
+
2748
+ ${CourierUnreadCountBadge.id} .header {
2749
+ background-color: ${(_r = (_q = (_p = (_o = theme2.inbox) == null ? void 0 : _o.header) == null ? void 0 : _p.filters) == null ? void 0 : _q.unreadIndicator) == null ? void 0 : _r.backgroundColor};
2750
+ color: ${(_w = (_v = (_u = (_t = (_s = theme2.inbox) == null ? void 0 : _s.header) == null ? void 0 : _t.filters) == null ? void 0 : _u.unreadIndicator) == null ? void 0 : _v.font) == null ? void 0 : _w.color};
2751
+ border-radius: ${(_A = (_z = (_y = (_x = theme2.inbox) == null ? void 0 : _x.header) == null ? void 0 : _y.filters) == null ? void 0 : _z.unreadIndicator) == null ? void 0 : _A.borderRadius};
2752
+ font-size: ${(_F = (_E = (_D = (_C = (_B = theme2.inbox) == null ? void 0 : _B.header) == null ? void 0 : _C.filters) == null ? void 0 : _D.unreadIndicator) == null ? void 0 : _E.font) == null ? void 0 : _F.size};
2753
+ }
2600
2754
  `;
2601
2755
  }
2602
2756
  setCount(count) {
@@ -2608,20 +2762,18 @@ class CourierUnreadCountBadge extends BaseElement {
2608
2762
  this.updateBadge();
2609
2763
  }
2610
2764
  updateBadge() {
2611
- this._style.textContent = this.getStyles(this._location);
2612
- if (this._count > 0) {
2613
- this._badge.textContent = this._count.toString();
2614
- this._badge.style.display = "block";
2615
- } else {
2616
- this._badge.style.display = "none";
2765
+ if (this._badge) {
2766
+ if (this._count > 0) {
2767
+ this._badge.textContent = this._count.toString();
2768
+ this._badge.style.display = "block";
2769
+ } else {
2770
+ this._badge.style.display = "none";
2771
+ }
2617
2772
  }
2618
2773
  }
2619
- disconnectedCallback() {
2620
- this._themeSubscription.unsubscribe();
2621
- }
2622
2774
  }
2623
- registerElement("courier-unread-count-badge", CourierUnreadCountBadge);
2624
- class CourierInboxHeaderTitle extends BaseElement {
2775
+ registerElement(CourierUnreadCountBadge);
2776
+ class CourierInboxHeaderTitle extends CourierBaseElement {
2625
2777
  constructor(themeManager, option) {
2626
2778
  super();
2627
2779
  // Theme
@@ -2630,49 +2782,37 @@ class CourierInboxHeaderTitle extends BaseElement {
2630
2782
  __publicField(this, "_option");
2631
2783
  __publicField(this, "_feedType");
2632
2784
  // Components
2785
+ __publicField(this, "_style");
2633
2786
  __publicField(this, "_titleElement");
2634
2787
  __publicField(this, "_iconElement");
2635
2788
  __publicField(this, "_unreadBadge");
2636
- __publicField(this, "_container");
2637
- __publicField(this, "_style");
2638
2789
  this._option = option;
2639
- const shadow = this.attachShadow({ mode: "open" });
2640
- this._style = document.createElement("style");
2641
- this._container = document.createElement("div");
2642
- this._container.className = "title-section";
2643
- this._iconElement = new CourierIcon(void 0, this._option.icon.svg);
2644
- this._titleElement = document.createElement("h2");
2645
- this._unreadBadge = new CourierUnreadCountBadge({
2646
- themeBus: themeManager,
2647
- location: "header"
2648
- });
2649
- this._container.appendChild(this._iconElement);
2650
- this._container.appendChild(this._titleElement);
2651
- this._container.appendChild(this._unreadBadge);
2652
- shadow.appendChild(this._style);
2653
- shadow.appendChild(this._container);
2654
2790
  this._themeSubscription = themeManager.subscribe((_) => {
2655
2791
  this.refreshTheme(this._feedType ?? "inbox");
2656
2792
  });
2657
- this.refreshTheme(this._feedType ?? "inbox");
2658
2793
  }
2659
- getStyles() {
2794
+ static get id() {
2795
+ return "courier-inbox-header-title";
2796
+ }
2797
+ get theme() {
2798
+ return this._themeSubscription.manager.getTheme();
2799
+ }
2800
+ static getStyles(theme2) {
2660
2801
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2661
- const theme2 = this._themeSubscription.manager.getTheme();
2662
2802
  return `
2663
- .title-section {
2803
+ ${CourierInboxHeaderTitle.id} {
2664
2804
  display: flex;
2665
2805
  align-items: center;
2666
2806
  gap: 8px;
2667
2807
  position: relative;
2668
2808
  }
2669
2809
 
2670
- courier-icon {
2810
+ ${CourierInboxHeaderTitle.id} courier-icon {
2671
2811
  display: flex;
2672
2812
  align-items: center;
2673
2813
  }
2674
2814
 
2675
- h2 {
2815
+ ${CourierInboxHeaderTitle.id} h2 {
2676
2816
  margin: 0;
2677
2817
  font-family: ${((_d = (_c = (_b = (_a = theme2.inbox) == null ? void 0 : _a.header) == null ? void 0 : _b.filters) == null ? void 0 : _c.font) == null ? void 0 : _d.family) ?? "inherit"};
2678
2818
  font-size: ${((_h = (_g = (_f = (_e = theme2.inbox) == null ? void 0 : _e.header) == null ? void 0 : _f.filters) == null ? void 0 : _g.font) == null ? void 0 : _h.size) ?? "18px"};
@@ -2680,46 +2820,68 @@ class CourierInboxHeaderTitle extends BaseElement {
2680
2820
  color: ${((_p = (_o = (_n = (_m = theme2.inbox) == null ? void 0 : _m.header) == null ? void 0 : _n.filters) == null ? void 0 : _o.font) == null ? void 0 : _p.color) ?? "red"};
2681
2821
  }
2682
2822
 
2683
- courier-unread-count-badge {
2823
+ ${CourierInboxHeaderTitle.id} courier-unread-count-badge {
2684
2824
  margin-left: 4px;
2685
2825
  }
2686
2826
  `;
2687
2827
  }
2828
+ onComponentMounted() {
2829
+ this._style = injectGlobalStyle(CourierInboxHeaderTitle.id, CourierInboxHeaderTitle.getStyles(this.theme));
2830
+ this._iconElement = new CourierIcon(void 0, this._option.icon.svg);
2831
+ this._titleElement = document.createElement("h2");
2832
+ this._unreadBadge = new CourierUnreadCountBadge({
2833
+ themeBus: this._themeSubscription.manager,
2834
+ location: "header"
2835
+ });
2836
+ this.appendChild(this._iconElement);
2837
+ this.appendChild(this._titleElement);
2838
+ this.appendChild(this._unreadBadge);
2839
+ this.refreshTheme(this._feedType ?? "inbox");
2840
+ }
2841
+ onComponentUnmounted() {
2842
+ var _a;
2843
+ this._themeSubscription.unsubscribe();
2844
+ (_a = this._style) == null ? void 0 : _a.remove();
2845
+ }
2688
2846
  refreshTheme(feedType) {
2847
+ var _a;
2689
2848
  this._feedType = feedType;
2690
- this._style.textContent = this.getStyles();
2691
- this._unreadBadge.refreshTheme("header");
2849
+ if (this._style) {
2850
+ this._style.textContent = CourierInboxHeaderTitle.getStyles(this.theme);
2851
+ }
2852
+ (_a = this._unreadBadge) == null ? void 0 : _a.refreshTheme("header");
2692
2853
  this.updateFilter();
2693
2854
  }
2694
2855
  updateSelectedOption(option, feedType, unreadCount) {
2856
+ var _a;
2695
2857
  this._option = option;
2696
2858
  this._feedType = feedType;
2697
- this._unreadBadge.setCount(unreadCount);
2859
+ (_a = this._unreadBadge) == null ? void 0 : _a.setCount(unreadCount);
2698
2860
  this.updateFilter();
2699
2861
  }
2700
2862
  updateFilter() {
2701
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
2863
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
2702
2864
  const theme2 = this._themeSubscription.manager.getTheme();
2703
2865
  switch (this._feedType) {
2704
2866
  case "inbox":
2705
- this._titleElement.textContent = ((_d = (_c = (_b = (_a = theme2.inbox) == null ? void 0 : _a.header) == null ? void 0 : _b.filters) == null ? void 0 : _c.inbox) == null ? void 0 : _d.text) ?? "Inbox";
2706
- this._iconElement.updateSVG(((_i = (_h = (_g = (_f = (_e = theme2.inbox) == null ? void 0 : _e.header) == null ? void 0 : _f.filters) == null ? void 0 : _g.inbox) == null ? void 0 : _h.icon) == null ? void 0 : _i.svg) ?? CourierIconSVGs.inbox);
2707
- this._iconElement.updateColor(((_n = (_m = (_l = (_k = (_j = theme2.inbox) == null ? void 0 : _j.header) == null ? void 0 : _k.filters) == null ? void 0 : _l.inbox) == null ? void 0 : _m.icon) == null ? void 0 : _n.color) ?? "red");
2867
+ if (this._titleElement) {
2868
+ this._titleElement.textContent = ((_d = (_c = (_b = (_a = theme2.inbox) == null ? void 0 : _a.header) == null ? void 0 : _b.filters) == null ? void 0 : _c.inbox) == null ? void 0 : _d.text) ?? "Inbox";
2869
+ }
2870
+ (_j = this._iconElement) == null ? void 0 : _j.updateSVG(((_i = (_h = (_g = (_f = (_e = theme2.inbox) == null ? void 0 : _e.header) == null ? void 0 : _f.filters) == null ? void 0 : _g.inbox) == null ? void 0 : _h.icon) == null ? void 0 : _i.svg) ?? CourierIconSVGs.inbox);
2871
+ (_p = this._iconElement) == null ? void 0 : _p.updateColor(((_o = (_n = (_m = (_l = (_k = theme2.inbox) == null ? void 0 : _k.header) == null ? void 0 : _l.filters) == null ? void 0 : _m.inbox) == null ? void 0 : _n.icon) == null ? void 0 : _o.color) ?? "red");
2708
2872
  break;
2709
2873
  case "archive":
2710
- this._titleElement.textContent = ((_r = (_q = (_p = (_o = theme2.inbox) == null ? void 0 : _o.header) == null ? void 0 : _p.filters) == null ? void 0 : _q.archive) == null ? void 0 : _r.text) ?? "Archive";
2711
- this._iconElement.updateSVG(((_w = (_v = (_u = (_t = (_s = theme2.inbox) == null ? void 0 : _s.header) == null ? void 0 : _t.filters) == null ? void 0 : _u.archive) == null ? void 0 : _v.icon) == null ? void 0 : _w.svg) ?? CourierIconSVGs.archive);
2712
- this._iconElement.updateColor(((_B = (_A = (_z = (_y = (_x = theme2.inbox) == null ? void 0 : _x.header) == null ? void 0 : _y.filters) == null ? void 0 : _z.archive) == null ? void 0 : _A.icon) == null ? void 0 : _B.color) ?? "red");
2874
+ if (this._titleElement) {
2875
+ this._titleElement.textContent = ((_t = (_s = (_r = (_q = theme2.inbox) == null ? void 0 : _q.header) == null ? void 0 : _r.filters) == null ? void 0 : _s.archive) == null ? void 0 : _t.text) ?? "Archive";
2876
+ }
2877
+ (_z = this._iconElement) == null ? void 0 : _z.updateSVG(((_y = (_x = (_w = (_v = (_u = theme2.inbox) == null ? void 0 : _u.header) == null ? void 0 : _v.filters) == null ? void 0 : _w.archive) == null ? void 0 : _x.icon) == null ? void 0 : _y.svg) ?? CourierIconSVGs.archive);
2878
+ (_F = this._iconElement) == null ? void 0 : _F.updateColor(((_E = (_D = (_C = (_B = (_A = theme2.inbox) == null ? void 0 : _A.header) == null ? void 0 : _B.filters) == null ? void 0 : _C.archive) == null ? void 0 : _D.icon) == null ? void 0 : _E.color) ?? "red");
2713
2879
  break;
2714
2880
  }
2715
2881
  }
2716
- // Disconnect the theme subscription
2717
- disconnectedCallback() {
2718
- this._themeSubscription.unsubscribe();
2719
- }
2720
2882
  }
2721
- registerElement("courier-inbox-header-title", CourierInboxHeaderTitle);
2722
- class CourierInboxHeader extends CourierElement {
2883
+ registerElement(CourierInboxHeaderTitle);
2884
+ class CourierInboxHeader extends CourierFactoryElement {
2723
2885
  constructor(props) {
2724
2886
  super();
2725
2887
  // Theme
@@ -2739,7 +2901,23 @@ class CourierInboxHeader extends CourierElement {
2739
2901
  });
2740
2902
  this._onFeedTypeChange = props.onFeedTypeChange;
2741
2903
  }
2742
- // Menu options
2904
+ static get id() {
2905
+ return "courier-inbox-header";
2906
+ }
2907
+ static get observedAttributes() {
2908
+ return ["icon", "title", "feed-type"];
2909
+ }
2910
+ get theme() {
2911
+ return this._themeSubscription.manager.getTheme();
2912
+ }
2913
+ onComponentMounted() {
2914
+ this._style = injectGlobalStyle(CourierInboxHeader.id, CourierInboxHeader.getStyles(this.theme));
2915
+ }
2916
+ onComponentUmounted() {
2917
+ var _a;
2918
+ this._themeSubscription.unsubscribe();
2919
+ (_a = this._style) == null ? void 0 : _a.remove();
2920
+ }
2743
2921
  getFilterOptions() {
2744
2922
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K;
2745
2923
  const theme2 = this._themeSubscription.manager.getTheme();
@@ -2820,19 +2998,13 @@ class CourierInboxHeader extends CourierElement {
2820
2998
  }
2821
2999
  ];
2822
3000
  }
2823
- static get observedAttributes() {
2824
- return ["icon", "title", "feed-type"];
2825
- }
2826
3001
  refreshTheme() {
2827
- var _a, _b, _c, _d, _e, _f, _g;
2828
- const theme2 = this._themeSubscription.manager.getTheme();
2829
- const header = (_a = this.shadow) == null ? void 0 : _a.querySelector(".courier-inbox-header");
2830
- if (header) {
2831
- header.style.backgroundColor = ((_c = (_b = theme2.inbox) == null ? void 0 : _b.header) == null ? void 0 : _c.backgroundColor) ?? CourierColors.white[500];
2832
- header.style.boxShadow = ((_e = (_d = theme2.inbox) == null ? void 0 : _d.header) == null ? void 0 : _e.shadow) ?? `0px 1px 0px 0px ${CourierColors.gray[500]}`;
3002
+ var _a, _b;
3003
+ if (this._style) {
3004
+ this._style.textContent = CourierInboxHeader.getStyles(this.theme);
2833
3005
  }
2834
- (_f = this._filterMenu) == null ? void 0 : _f.setOptions(this.getFilterOptions());
2835
- (_g = this._actionMenu) == null ? void 0 : _g.setOptions(this.getActionOptions());
3006
+ (_a = this._filterMenu) == null ? void 0 : _a.setOptions(this.getFilterOptions());
3007
+ (_b = this._actionMenu) == null ? void 0 : _b.setOptions(this.getActionOptions());
2836
3008
  }
2837
3009
  handleOptionMenuItemClick(feedType, option) {
2838
3010
  this._feedType = feedType;
@@ -2842,12 +3014,9 @@ class CourierInboxHeader extends CourierElement {
2842
3014
  this._onFeedTypeChange(feedType);
2843
3015
  }
2844
3016
  render(props) {
3017
+ var _a, _b;
2845
3018
  this._feedType = props.feedType;
2846
3019
  this._unreadCount = props.unreadCount;
2847
- this.refreshTitleSection();
2848
- }
2849
- refreshTitleSection() {
2850
- var _a, _b;
2851
3020
  const option = this.getFilterOptions().find((opt) => ["inbox", "archive"].includes(opt.id) && opt.id === this._feedType);
2852
3021
  if (option) {
2853
3022
  (_a = this._titleSection) == null ? void 0 : _a.updateSelectedOption(option, this._feedType, this._feedType === "inbox" ? this._unreadCount : 0);
@@ -2855,11 +3024,7 @@ class CourierInboxHeader extends CourierElement {
2855
3024
  }
2856
3025
  }
2857
3026
  build(newElement) {
2858
- var _a;
2859
3027
  super.build(newElement);
2860
- this._style = document.createElement("style");
2861
- this._style.textContent = this.getStyles();
2862
- (_a = this.shadow) == null ? void 0 : _a.appendChild(this._style);
2863
3028
  this.refreshTheme();
2864
3029
  }
2865
3030
  defaultElement() {
@@ -2880,51 +3045,46 @@ class CourierInboxHeader extends CourierElement {
2880
3045
  actions.className = "actions";
2881
3046
  actions.appendChild(this._filterMenu);
2882
3047
  actions.appendChild(this._actionMenu);
2883
- const container = document.createElement("div");
2884
- container.className = "courier-inbox-header";
2885
- container.appendChild(this._titleSection);
2886
- container.appendChild(spacer);
2887
- container.appendChild(actions);
2888
- return container;
2889
- }
2890
- getStyles() {
3048
+ const headerContent = document.createElement("div");
3049
+ headerContent.className = "header-content";
3050
+ headerContent.appendChild(this._titleSection);
3051
+ headerContent.appendChild(spacer);
3052
+ headerContent.appendChild(actions);
3053
+ return headerContent;
3054
+ }
3055
+ static getStyles(theme2) {
3056
+ var _a, _b, _c, _d;
2891
3057
  return `
2892
- :host {
2893
- z-index: 100;
2894
- }
2895
-
2896
- .courier-inbox-header {
3058
+ ${CourierInboxHeader.id} {
2897
3059
  display: flex;
2898
3060
  align-items: center;
2899
- justify-content: space-between;
2900
- padding: 10px 10px 10px 16px;
2901
- background-color: ${CourierColors.white[500]};
2902
- box-shadow: 0px 1px 0px 0px ${CourierColors.gray[500]};
3061
+ flex-shrink: 0;
2903
3062
  }
2904
3063
 
2905
- .header-content {
3064
+ ${CourierInboxHeader.id} .header-content {
3065
+ padding: 10px 10px 10px 16px;
3066
+ background-color: ${((_b = (_a = theme2.inbox) == null ? void 0 : _a.header) == null ? void 0 : _b.backgroundColor) ?? CourierColors.white[500]};
3067
+ box-shadow: ${((_d = (_c = theme2.inbox) == null ? void 0 : _c.header) == null ? void 0 : _d.shadow) ?? `0px 1px 0px 0px red`};
2906
3068
  display: flex;
2907
3069
  align-items: center;
3070
+ justify-content: space-between;
2908
3071
  flex: 1;
3072
+ z-index: 100;
2909
3073
  }
2910
3074
 
2911
- .spacer {
3075
+ ${CourierInboxHeader.id} .spacer {
2912
3076
  flex: 1;
2913
3077
  }
2914
3078
 
2915
- .actions {
3079
+ ${CourierInboxHeader.id} .actions {
2916
3080
  display: flex;
2917
3081
  align-items: center;
2918
3082
  gap: 4px;
2919
3083
  }
2920
3084
  `;
2921
3085
  }
2922
- // Disconnect the theme subscription
2923
- disconnectedCallback() {
2924
- this._themeSubscription.unsubscribe();
2925
- }
2926
3086
  }
2927
- registerElement("courier-inbox-header", CourierInboxHeader);
3087
+ registerElement(CourierInboxHeader);
2928
3088
  class CourierInboxDataStoreListener {
2929
3089
  constructor(events) {
2930
3090
  __publicField(this, "events");
@@ -3395,7 +3555,7 @@ const defaultDarkTheme = {
3395
3555
  },
3396
3556
  loading: {
3397
3557
  animation: {
3398
- barColor: CourierColors.white[500],
3558
+ barColor: CourierColors.gray[400],
3399
3559
  barHeight: "14px",
3400
3560
  barBorderRadius: "14px",
3401
3561
  duration: "2s"
@@ -3703,20 +3863,19 @@ class CourierInboxThemeManager {
3703
3863
  this._subscriptions = [];
3704
3864
  }
3705
3865
  }
3706
- class CourierInbox extends BaseElement {
3866
+ class CourierInbox extends CourierBaseElement {
3707
3867
  constructor(themeManager) {
3708
- var _a;
3709
3868
  super();
3710
3869
  // State
3711
3870
  __publicField(this, "_currentFeed", "inbox");
3712
3871
  // Theming
3713
3872
  __publicField(this, "_themeManager");
3714
3873
  // Components
3715
- __publicField(this, "_shadow");
3874
+ __publicField(this, "_inboxStyle");
3875
+ __publicField(this, "_unreadIndicatorStyle");
3716
3876
  __publicField(this, "_list");
3717
3877
  __publicField(this, "_datastoreListener");
3718
3878
  __publicField(this, "_authListener");
3719
- __publicField(this, "_style");
3720
3879
  // Header
3721
3880
  __publicField(this, "_header");
3722
3881
  __publicField(this, "_headerFactory");
@@ -3731,8 +3890,27 @@ class CourierInbox extends BaseElement {
3731
3890
  feedType: this._currentFeed,
3732
3891
  height: "768px"
3733
3892
  });
3734
- this._shadow = this.attachShadow({ mode: "open" });
3735
3893
  this._themeManager = themeManager ?? new CourierInboxThemeManager(defaultLightTheme);
3894
+ }
3895
+ static get id() {
3896
+ return "courier-inbox";
3897
+ }
3898
+ get theme() {
3899
+ return this._themeManager.getTheme();
3900
+ }
3901
+ setLightTheme(theme2) {
3902
+ this._themeManager.setLightTheme(theme2);
3903
+ }
3904
+ setDarkTheme(theme2) {
3905
+ this._themeManager.setDarkTheme(theme2);
3906
+ }
3907
+ static get observedAttributes() {
3908
+ return ["height", "light-theme", "dark-theme", "mode", "message-click", "message-action-click", "message-long-press"];
3909
+ }
3910
+ onComponentMounted() {
3911
+ var _a, _b;
3912
+ this._inboxStyle = injectGlobalStyle(CourierInbox.id, this.getStyles());
3913
+ this._unreadIndicatorStyle = injectGlobalStyle(CourierUnreadCountBadge.id, CourierUnreadCountBadge.getStyles(this.theme));
3736
3914
  this._header = new CourierInboxHeader({
3737
3915
  themeManager: this._themeManager,
3738
3916
  onFeedTypeChange: (feedType) => {
@@ -3740,20 +3918,20 @@ class CourierInbox extends BaseElement {
3740
3918
  }
3741
3919
  });
3742
3920
  this._header.build(void 0);
3743
- this._shadow.appendChild(this._header);
3921
+ this.appendChild(this._header);
3744
3922
  this._list = new CourierInboxList({
3745
3923
  themeManager: this._themeManager,
3746
3924
  onRefresh: () => {
3747
3925
  this.refresh();
3748
3926
  },
3749
3927
  onPaginationTrigger: async (feedType) => {
3750
- var _a2, _b;
3928
+ var _a2, _b2;
3751
3929
  try {
3752
3930
  await CourierInboxDatastore.shared.fetchNextPageOfMessages({
3753
3931
  feedType
3754
3932
  });
3755
3933
  } catch (error) {
3756
- (_b = (_a2 = Courier.shared.client) == null ? void 0 : _a2.options.logger) == null ? void 0 : _b.error("Failed to fetch next page of messages:", error);
3934
+ (_b2 = (_a2 = Courier.shared.client) == null ? void 0 : _a2.options.logger) == null ? void 0 : _b2.error("Failed to fetch next page of messages:", error);
3757
3935
  }
3758
3936
  },
3759
3937
  onMessageClick: (message, index) => {
@@ -3785,41 +3963,45 @@ class CourierInbox extends BaseElement {
3785
3963
  (_a2 = this._onMessageLongPress) == null ? void 0 : _a2.call(this, { message, index });
3786
3964
  }
3787
3965
  });
3788
- this._style = document.createElement("style");
3789
3966
  this.refreshTheme();
3790
- this._shadow.appendChild(this._style);
3791
- this._shadow.appendChild(this._list);
3967
+ this.appendChild(this._list);
3792
3968
  this._datastoreListener = new CourierInboxDataStoreListener({
3793
3969
  onError: (error) => {
3794
- this._list.setError(error);
3970
+ var _a2;
3971
+ (_a2 = this._list) == null ? void 0 : _a2.setError(error);
3795
3972
  },
3796
3973
  onDataSetChange: (dataSet, feedType) => {
3974
+ var _a2;
3797
3975
  if (this._currentFeed === feedType) {
3798
- this._list.setDataSet(dataSet);
3976
+ (_a2 = this._list) == null ? void 0 : _a2.setDataSet(dataSet);
3799
3977
  this.updateHeader();
3800
3978
  }
3801
3979
  },
3802
3980
  onPageAdded: (dataSet, feedType) => {
3981
+ var _a2;
3803
3982
  if (this._currentFeed === feedType) {
3804
- this._list.addPage(dataSet);
3983
+ (_a2 = this._list) == null ? void 0 : _a2.addPage(dataSet);
3805
3984
  this.updateHeader();
3806
3985
  }
3807
3986
  },
3808
3987
  onMessageAdd: (message, index, feedType) => {
3988
+ var _a2;
3809
3989
  if (this._currentFeed === feedType) {
3810
- this._list.addMessage(message, index);
3990
+ (_a2 = this._list) == null ? void 0 : _a2.addMessage(message, index);
3811
3991
  this.updateHeader();
3812
3992
  }
3813
3993
  },
3814
3994
  onMessageRemove: (_, index, feedType) => {
3995
+ var _a2;
3815
3996
  if (this._currentFeed === feedType) {
3816
- this._list.removeMessage(index);
3997
+ (_a2 = this._list) == null ? void 0 : _a2.removeMessage(index);
3817
3998
  this.updateHeader();
3818
3999
  }
3819
4000
  },
3820
4001
  onMessageUpdate: (message, index, feedType) => {
4002
+ var _a2;
3821
4003
  if (this._currentFeed === feedType) {
3822
- this._list.updateMessage(message, index);
4004
+ (_a2 = this._list) == null ? void 0 : _a2.updateMessage(message, index);
3823
4005
  this.updateHeader();
3824
4006
  }
3825
4007
  },
@@ -3834,39 +4016,38 @@ class CourierInbox extends BaseElement {
3834
4016
  this._authListener = Courier.shared.addAuthenticationListener((_) => {
3835
4017
  this.refresh();
3836
4018
  });
3837
- if ((_a = Courier.shared.client) == null ? void 0 : _a.options.userId) {
3838
- this.refresh();
4019
+ if (!((_a = Courier.shared.client) == null ? void 0 : _a.options.userId)) {
4020
+ (_b = Courier.shared.client) == null ? void 0 : _b.options.logger.error("No user signed in. Please call Courier.shared.signIn(...) to load the inbox.");
4021
+ return;
3839
4022
  }
4023
+ this.refresh();
3840
4024
  }
3841
- get theme() {
3842
- return this._themeManager.getTheme();
3843
- }
3844
- setLightTheme(theme2) {
3845
- this._themeManager.setLightTheme(theme2);
3846
- }
3847
- setDarkTheme(theme2) {
3848
- this._themeManager.setDarkTheme(theme2);
3849
- }
3850
- static get observedAttributes() {
3851
- return ["height", "light-theme", "dark-theme", "mode", "message-click", "message-action-click", "message-long-press"];
4025
+ onComponentUnmounted() {
4026
+ var _a, _b, _c, _d;
4027
+ this._themeManager.cleanup();
4028
+ (_a = this._datastoreListener) == null ? void 0 : _a.remove();
4029
+ (_b = this._authListener) == null ? void 0 : _b.remove();
4030
+ (_c = this._inboxStyle) == null ? void 0 : _c.remove();
4031
+ (_d = this._unreadIndicatorStyle) == null ? void 0 : _d.remove();
3852
4032
  }
3853
4033
  refreshTheme() {
3854
- this._style.textContent = this.getStyles();
4034
+ if (this._inboxStyle) {
4035
+ this._inboxStyle.textContent = this.getStyles();
4036
+ }
4037
+ if (this._unreadIndicatorStyle) {
4038
+ this._unreadIndicatorStyle.textContent = CourierUnreadCountBadge.getStyles(this.theme);
4039
+ }
3855
4040
  }
3856
4041
  getStyles() {
3857
4042
  return `
3858
- :host {
4043
+ ${CourierInbox.id} {
3859
4044
  display: flex;
3860
4045
  flex-direction: column;
3861
4046
  width: 100%;
3862
4047
  height: ${this._defaultProps.height};
3863
4048
  }
3864
4049
 
3865
- courier-inbox-header {
3866
- flex-shrink: 0;
3867
- }
3868
-
3869
- courier-inbox-list {
4050
+ ${CourierInbox.id} courier-inbox-list {
3870
4051
  flex: 1;
3871
4052
  overflow-y: auto;
3872
4053
  overflow-x: hidden;
@@ -3882,19 +4063,24 @@ class CourierInbox extends BaseElement {
3882
4063
  this.updateHeader();
3883
4064
  }
3884
4065
  setLoadingState(factory) {
3885
- this._list.setLoadingStateFactory(factory);
4066
+ var _a;
4067
+ (_a = this._list) == null ? void 0 : _a.setLoadingStateFactory(factory);
3886
4068
  }
3887
4069
  setEmptyState(factory) {
3888
- this._list.setEmptyStateFactory(factory);
4070
+ var _a;
4071
+ (_a = this._list) == null ? void 0 : _a.setEmptyStateFactory(factory);
3889
4072
  }
3890
4073
  setErrorState(factory) {
3891
- this._list.setErrorStateFactory(factory);
4074
+ var _a;
4075
+ (_a = this._list) == null ? void 0 : _a.setErrorStateFactory(factory);
3892
4076
  }
3893
4077
  setListItem(factory) {
3894
- this._list.setListItemFactory(factory);
4078
+ var _a;
4079
+ (_a = this._list) == null ? void 0 : _a.setListItemFactory(factory);
3895
4080
  }
3896
4081
  setPaginationItem(factory) {
3897
- this._list.setPaginationItemFactory(factory);
4082
+ var _a;
4083
+ (_a = this._list) == null ? void 0 : _a.setPaginationItemFactory(factory);
3898
4084
  }
3899
4085
  onMessageClick(handler) {
3900
4086
  this._onMessageClick = handler;
@@ -3906,30 +4092,31 @@ class CourierInbox extends BaseElement {
3906
4092
  this._onMessageLongPress = handler;
3907
4093
  }
3908
4094
  setFeedType(feedType) {
4095
+ var _a;
3909
4096
  this._currentFeed = feedType;
3910
- this._list.setFeedType(feedType);
4097
+ (_a = this._list) == null ? void 0 : _a.setFeedType(feedType);
3911
4098
  this.updateHeader();
3912
4099
  this.load({
3913
- feedType: this._currentFeed,
3914
4100
  canUseCache: true
3915
4101
  });
3916
4102
  }
3917
4103
  updateHeader() {
4104
+ var _a, _b, _c, _d;
3918
4105
  const props = {
3919
4106
  feedType: this._currentFeed,
3920
4107
  unreadCount: CourierInboxDatastore.shared.unreadCount,
3921
- messageCount: this._list.messages.length
4108
+ messageCount: ((_a = this._list) == null ? void 0 : _a.messages.length) ?? 0
3922
4109
  };
3923
4110
  switch (this._headerFactory) {
3924
4111
  case void 0:
3925
- this._header.render(props);
4112
+ (_b = this._header) == null ? void 0 : _b.render(props);
3926
4113
  break;
3927
4114
  case null:
3928
- this._header.build(null);
4115
+ (_c = this._header) == null ? void 0 : _c.build(null);
3929
4116
  break;
3930
4117
  default:
3931
4118
  const headerElement = this._headerFactory(props);
3932
- this._header.build(headerElement);
4119
+ (_d = this._header) == null ? void 0 : _d.build(headerElement);
3933
4120
  break;
3934
4121
  }
3935
4122
  }
@@ -3939,19 +4126,9 @@ class CourierInbox extends BaseElement {
3939
4126
  }
3940
4127
  refresh() {
3941
4128
  this.load({
3942
- feedType: this._currentFeed,
3943
4129
  canUseCache: false
3944
4130
  });
3945
4131
  }
3946
- connectedCallback() {
3947
- this.refresh();
3948
- }
3949
- disconnectedCallback() {
3950
- var _a, _b;
3951
- this._themeManager.cleanup();
3952
- (_a = this._datastoreListener) == null ? void 0 : _a.remove();
3953
- (_b = this._authListener) == null ? void 0 : _b.remove();
3954
- }
3955
4132
  attributeChangedCallback(name, oldValue, newValue) {
3956
4133
  var _a, _b, _c, _d, _e, _f;
3957
4134
  if (oldValue === newValue) return;
@@ -4009,20 +4186,35 @@ class CourierInbox extends BaseElement {
4009
4186
  }
4010
4187
  }
4011
4188
  }
4012
- registerElement("courier-inbox", CourierInbox);
4013
- class CourierInboxMenuButton extends CourierElement {
4189
+ registerElement(CourierInbox);
4190
+ class CourierInboxMenuButton extends CourierFactoryElement {
4014
4191
  constructor(themeBus) {
4015
4192
  super();
4016
4193
  // Theme
4017
4194
  __publicField(this, "_themeSubscription");
4018
4195
  // Components
4196
+ __publicField(this, "_style");
4019
4197
  __publicField(this, "_container");
4020
4198
  __publicField(this, "_triggerButton");
4021
4199
  __publicField(this, "_unreadCountBadge");
4022
4200
  this._themeSubscription = themeBus.subscribe((_) => {
4023
- this.updateTheme();
4201
+ this.refreshTheme();
4024
4202
  });
4025
4203
  }
4204
+ static get id() {
4205
+ return "courier-inbox-menu-button";
4206
+ }
4207
+ get theme() {
4208
+ return this._themeSubscription.manager.getTheme();
4209
+ }
4210
+ onComponentMounted() {
4211
+ this._style = injectGlobalStyle(CourierInboxMenuButton.id, CourierInboxMenuButton.getStyles(this.theme));
4212
+ }
4213
+ onComponentUnmounted() {
4214
+ var _a;
4215
+ this._themeSubscription.unsubscribe();
4216
+ (_a = this._style) == null ? void 0 : _a.remove();
4217
+ }
4026
4218
  defaultElement() {
4027
4219
  this._container = document.createElement("div");
4028
4220
  this._container.className = "menu-button-container";
@@ -4032,23 +4224,20 @@ class CourierInboxMenuButton extends CourierElement {
4032
4224
  location: "button"
4033
4225
  });
4034
4226
  this._unreadCountBadge.id = "unread-badge";
4035
- const style = document.createElement("style");
4036
- style.textContent = this.getStyles();
4037
- this._container.appendChild(style);
4038
4227
  this._container.appendChild(this._triggerButton);
4039
4228
  this._container.appendChild(this._unreadCountBadge);
4040
- this.shadow.appendChild(this._container);
4041
- this.updateTheme();
4229
+ this.appendChild(this._container);
4230
+ this.refreshTheme();
4042
4231
  return this._container;
4043
4232
  }
4044
- getStyles() {
4233
+ static getStyles(_theme) {
4045
4234
  return `
4046
- .menu-button-container {
4235
+ ${CourierInboxMenuButton.id} .menu-button-container {
4047
4236
  position: relative;
4048
4237
  display: inline-block;
4049
4238
  }
4050
4239
 
4051
- #unread-badge {
4240
+ ${CourierInboxMenuButton.id} #unread-badge {
4052
4241
  position: absolute;
4053
4242
  top: -8px;
4054
4243
  left: 50%;
@@ -4059,24 +4248,20 @@ class CourierInboxMenuButton extends CourierElement {
4059
4248
  onUnreadCountChange(unreadCount) {
4060
4249
  var _a;
4061
4250
  (_a = this._unreadCountBadge) == null ? void 0 : _a.setCount(unreadCount);
4062
- this.updateTheme();
4063
- }
4064
- updateTheme() {
4065
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
4066
- const theme2 = this._themeSubscription.manager.getTheme();
4067
- (_d = this._triggerButton) == null ? void 0 : _d.updateIconColor(((_c = (_b = (_a = theme2 == null ? void 0 : theme2.popup) == null ? void 0 : _a.button) == null ? void 0 : _b.icon) == null ? void 0 : _c.color) ?? CourierColors.black[500]);
4068
- (_h = this._triggerButton) == null ? void 0 : _h.updateIconSVG(((_g = (_f = (_e = theme2 == null ? void 0 : theme2.popup) == null ? void 0 : _e.button) == null ? void 0 : _f.icon) == null ? void 0 : _g.svg) ?? CourierIconSVGs.inbox);
4069
- (_k = this._triggerButton) == null ? void 0 : _k.updateBackgroundColor(((_j = (_i = theme2 == null ? void 0 : theme2.popup) == null ? void 0 : _i.button) == null ? void 0 : _j.backgroundColor) ?? "transparent");
4070
- (_n = this._triggerButton) == null ? void 0 : _n.updateHoverBackgroundColor(((_m = (_l = theme2 == null ? void 0 : theme2.popup) == null ? void 0 : _l.button) == null ? void 0 : _m.hoverBackgroundColor) ?? CourierColors.black[50010]);
4071
- (_q = this._triggerButton) == null ? void 0 : _q.updateActiveBackgroundColor(((_p = (_o = theme2 == null ? void 0 : theme2.popup) == null ? void 0 : _o.button) == null ? void 0 : _p.activeBackgroundColor) ?? CourierColors.black[50020]);
4072
- (_r = this._unreadCountBadge) == null ? void 0 : _r.refreshTheme("button");
4251
+ this.refreshTheme();
4073
4252
  }
4074
- disconnectedCallback() {
4075
- this._themeSubscription.unsubscribe();
4253
+ refreshTheme() {
4254
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
4255
+ (_e = this._triggerButton) == null ? void 0 : _e.updateIconColor(((_d = (_c = (_b = (_a = this.theme) == null ? void 0 : _a.popup) == null ? void 0 : _b.button) == null ? void 0 : _c.icon) == null ? void 0 : _d.color) ?? CourierColors.black[500]);
4256
+ (_j = this._triggerButton) == null ? void 0 : _j.updateIconSVG(((_i = (_h = (_g = (_f = this.theme) == null ? void 0 : _f.popup) == null ? void 0 : _g.button) == null ? void 0 : _h.icon) == null ? void 0 : _i.svg) ?? CourierIconSVGs.inbox);
4257
+ (_n = this._triggerButton) == null ? void 0 : _n.updateBackgroundColor(((_m = (_l = (_k = this.theme) == null ? void 0 : _k.popup) == null ? void 0 : _l.button) == null ? void 0 : _m.backgroundColor) ?? "transparent");
4258
+ (_r = this._triggerButton) == null ? void 0 : _r.updateHoverBackgroundColor(((_q = (_p = (_o = this.theme) == null ? void 0 : _o.popup) == null ? void 0 : _p.button) == null ? void 0 : _q.hoverBackgroundColor) ?? CourierColors.black[50010]);
4259
+ (_v = this._triggerButton) == null ? void 0 : _v.updateActiveBackgroundColor(((_u = (_t = (_s = this.theme) == null ? void 0 : _s.popup) == null ? void 0 : _t.button) == null ? void 0 : _u.activeBackgroundColor) ?? CourierColors.black[50020]);
4260
+ (_w = this._unreadCountBadge) == null ? void 0 : _w.refreshTheme("button");
4076
4261
  }
4077
4262
  }
4078
- registerElement("courier-inbox-menu-button", CourierInboxMenuButton);
4079
- class CourierInboxPopupMenu extends BaseElement {
4263
+ registerElement(CourierInboxMenuButton);
4264
+ class CourierInboxPopupMenu extends CourierBaseElement {
4080
4265
  constructor() {
4081
4266
  super();
4082
4267
  // State
@@ -4098,28 +4283,26 @@ class CourierInboxPopupMenu extends BaseElement {
4098
4283
  __publicField(this, "_datastoreListener");
4099
4284
  // Factories
4100
4285
  __publicField(this, "_popupMenuButtonFactory");
4101
- const shadow = this.attachShadow({ mode: "open" });
4102
- this._triggerButton = new CourierInboxMenuButton(this._themeManager);
4103
- this._triggerButton.build(void 0);
4104
- this._popup = document.createElement("div");
4105
- this._popup.className = "popup";
4106
- this._inbox = new CourierInbox(this._themeManager);
4107
- this._inbox.setAttribute("height", "100%");
4108
- this._style = document.createElement("style");
4109
- this.refreshTheme();
4110
- shadow.appendChild(this._style);
4111
- shadow.appendChild(this._triggerButton);
4112
- shadow.appendChild(this._popup);
4113
- this._popup.appendChild(this._inbox);
4114
- this._triggerButton.addEventListener("click", this.togglePopup.bind(this));
4115
- document.addEventListener("click", this.handleOutsideClick.bind(this));
4116
- this.updatePopupPosition();
4117
- this._datastoreListener = new CourierInboxDataStoreListener(this);
4118
- CourierInboxDatastore.shared.addDataStoreListener(this._datastoreListener);
4286
+ __publicField(this, "handleOutsideClick", (event) => {
4287
+ if (!this._popup) return;
4288
+ const SAFE_SELECTORS = [
4289
+ "courier-inbox-option-menu"
4290
+ ];
4291
+ const clickIsInsideAllowedArea = event.composedPath().some((node) => {
4292
+ if (!(node instanceof HTMLElement)) return false;
4293
+ if (node === this._popup || this._popup.contains(node)) return true;
4294
+ return SAFE_SELECTORS.some((sel) => node.matches(sel));
4295
+ });
4296
+ if (clickIsInsideAllowedArea) return;
4297
+ this._popup.style.display = "none";
4298
+ });
4119
4299
  this._themeManager.subscribe((_) => {
4120
4300
  this.refreshTheme();
4121
4301
  });
4122
4302
  }
4303
+ static get id() {
4304
+ return "courier-inbox-popup-menu";
4305
+ }
4123
4306
  get theme() {
4124
4307
  return this._themeManager.getTheme();
4125
4308
  }
@@ -4132,45 +4315,71 @@ class CourierInboxPopupMenu extends BaseElement {
4132
4315
  static get observedAttributes() {
4133
4316
  return ["popup-alignment", "message-click", "message-action-click", "message-long-press", "popup-width", "popup-height", "top", "right", "bottom", "left", "light-theme", "dark-theme", "mode"];
4134
4317
  }
4318
+ onComponentMounted() {
4319
+ this._style = injectGlobalStyle(CourierInboxPopupMenu.id, CourierInboxPopupMenu.getStyles(this.theme, this._width, this._height));
4320
+ this._triggerButton = new CourierInboxMenuButton(this._themeManager);
4321
+ this._triggerButton.build(void 0);
4322
+ this._popup = document.createElement("div");
4323
+ this._popup.className = "popup";
4324
+ this._inbox = new CourierInbox(this._themeManager);
4325
+ this._inbox.setAttribute("height", "100%");
4326
+ this.refreshTheme();
4327
+ this.appendChild(this._triggerButton);
4328
+ this.appendChild(this._popup);
4329
+ this._popup.appendChild(this._inbox);
4330
+ this._triggerButton.addEventListener("click", this.togglePopup.bind(this));
4331
+ document.addEventListener("click", this.handleOutsideClick.bind(this));
4332
+ this.updatePopupPosition();
4333
+ this._datastoreListener = new CourierInboxDataStoreListener(this);
4334
+ CourierInboxDatastore.shared.addDataStoreListener(this._datastoreListener);
4335
+ }
4336
+ onComponentUnmounted() {
4337
+ var _a, _b;
4338
+ (_a = this._style) == null ? void 0 : _a.remove();
4339
+ (_b = this._datastoreListener) == null ? void 0 : _b.remove();
4340
+ this._themeManager.cleanup();
4341
+ }
4135
4342
  refreshTheme() {
4136
- this._style.textContent = this.getStyles();
4343
+ if (this._style) {
4344
+ this._style.textContent = CourierInboxPopupMenu.getStyles(this.theme, this._width, this._height);
4345
+ }
4137
4346
  }
4138
- getStyles() {
4347
+ static getStyles(theme2, width, height) {
4139
4348
  var _a, _b, _c, _d, _e, _f, _g, _h;
4140
4349
  return `
4141
- :host {
4350
+ ${CourierInboxPopupMenu.id} {
4142
4351
  display: inline-block;
4143
4352
  position: relative;
4144
4353
  }
4145
4354
 
4146
- .menu-button-container {
4355
+ ${CourierInboxPopupMenu.id} .menu-button-container {
4147
4356
  position: relative;
4148
4357
  display: inline-block;
4149
4358
  }
4150
4359
 
4151
- .popup {
4360
+ ${CourierInboxPopupMenu.id} .popup {
4152
4361
  display: none;
4153
4362
  position: absolute;
4154
- background: ${((_b = (_a = this.theme.popup) == null ? void 0 : _a.window) == null ? void 0 : _b.backgroundColor) ?? "red"};
4155
- border-radius: ${((_d = (_c = this.theme.popup) == null ? void 0 : _c.window) == null ? void 0 : _d.borderRadius) ?? "8px"};
4156
- border: ${((_f = (_e = this.theme.popup) == null ? void 0 : _e.window) == null ? void 0 : _f.border) ?? `1px solid red`};
4157
- box-shadow: ${((_h = (_g = this.theme.popup) == null ? void 0 : _g.window) == null ? void 0 : _h.shadow) ?? `0px 8px 16px -4px red`};
4363
+ background: ${((_b = (_a = theme2.popup) == null ? void 0 : _a.window) == null ? void 0 : _b.backgroundColor) ?? "red"};
4364
+ border-radius: ${((_d = (_c = theme2.popup) == null ? void 0 : _c.window) == null ? void 0 : _d.borderRadius) ?? "8px"};
4365
+ border: ${((_f = (_e = theme2.popup) == null ? void 0 : _e.window) == null ? void 0 : _f.border) ?? `1px solid red`};
4366
+ box-shadow: ${((_h = (_g = theme2.popup) == null ? void 0 : _g.window) == null ? void 0 : _h.shadow) ?? `0px 8px 16px -4px red`};
4158
4367
  z-index: 1000;
4159
- width: ${this._width};
4160
- height: ${this._height};
4368
+ width: ${width};
4369
+ height: ${height};
4161
4370
  overflow: hidden;
4162
4371
  transform: translateZ(0);
4163
4372
  will-change: transform;
4164
4373
  }
4165
4374
 
4166
- #unread-badge {
4375
+ ${CourierInboxPopupMenu.id} #unread-badge {
4167
4376
  position: absolute;
4168
4377
  top: -8px;
4169
4378
  left: 50%;
4170
4379
  pointer-events: none;
4171
4380
  }
4172
4381
 
4173
- courier-inbox {
4382
+ ${CourierInboxPopupMenu.id} courier-inbox {
4174
4383
  height: 100%;
4175
4384
  }
4176
4385
  `;
@@ -4226,13 +4435,16 @@ class CourierInboxPopupMenu extends BaseElement {
4226
4435
  this.render();
4227
4436
  }
4228
4437
  onMessageClick(handler) {
4229
- this._inbox.onMessageClick(handler);
4438
+ var _a;
4439
+ (_a = this._inbox) == null ? void 0 : _a.onMessageClick(handler);
4230
4440
  }
4231
4441
  onMessageActionClick(handler) {
4232
- this._inbox.onMessageActionClick(handler);
4442
+ var _a;
4443
+ (_a = this._inbox) == null ? void 0 : _a.onMessageActionClick(handler);
4233
4444
  }
4234
4445
  onMessageLongPress(handler) {
4235
- this._inbox.onMessageLongPress(handler);
4446
+ var _a;
4447
+ (_a = this._inbox) == null ? void 0 : _a.onMessageLongPress(handler);
4236
4448
  }
4237
4449
  isValidPosition(value) {
4238
4450
  const validPositions = [
@@ -4249,6 +4461,7 @@ class CourierInboxPopupMenu extends BaseElement {
4249
4461
  return validPositions.includes(value);
4250
4462
  }
4251
4463
  updatePopupPosition() {
4464
+ if (!this._popup) return;
4252
4465
  this._popup.style.top = "";
4253
4466
  this._popup.style.bottom = "";
4254
4467
  this._popup.style.left = "";
@@ -4301,25 +4514,19 @@ class CourierInboxPopupMenu extends BaseElement {
4301
4514
  }
4302
4515
  togglePopup(event) {
4303
4516
  event.stopPropagation();
4517
+ if (!this._popup) return;
4304
4518
  const isVisible = this._popup.style.display === "block";
4305
- if (!isVisible) {
4306
- this._popup.style.display = "block";
4307
- } else {
4308
- this._popup.style.display = "none";
4309
- }
4310
- }
4311
- handleOutsideClick(event) {
4312
- if (!this.contains(event.target)) {
4313
- this._popup.style.display = "none";
4314
- }
4519
+ this._popup.style.display = isVisible ? "none" : "block";
4315
4520
  }
4316
4521
  setContent(element) {
4522
+ if (!this._inbox) return;
4317
4523
  this._inbox.innerHTML = "";
4318
4524
  this._inbox.appendChild(element);
4319
4525
  }
4320
4526
  setSize(width, height) {
4321
4527
  this._width = width;
4322
4528
  this._height = height;
4529
+ if (!this._popup) return;
4323
4530
  this._popup.style.width = width;
4324
4531
  this._popup.style.height = height;
4325
4532
  }
@@ -4333,29 +4540,37 @@ class CourierInboxPopupMenu extends BaseElement {
4333
4540
  }
4334
4541
  }
4335
4542
  setFeedType(feedType) {
4336
- this._inbox.setFeedType(feedType);
4543
+ var _a;
4544
+ (_a = this._inbox) == null ? void 0 : _a.setFeedType(feedType);
4337
4545
  }
4338
4546
  // Factory methods
4339
4547
  setPopupHeader(factory) {
4340
- this._inbox.setHeader(factory);
4548
+ var _a;
4549
+ (_a = this._inbox) == null ? void 0 : _a.setHeader(factory);
4341
4550
  }
4342
4551
  removePopupHeader() {
4343
- this._inbox.removeHeader();
4552
+ var _a;
4553
+ (_a = this._inbox) == null ? void 0 : _a.removeHeader();
4344
4554
  }
4345
4555
  setPopupLoadingState(factory) {
4346
- this._inbox.setLoadingState(factory);
4556
+ var _a;
4557
+ (_a = this._inbox) == null ? void 0 : _a.setLoadingState(factory);
4347
4558
  }
4348
4559
  setPopupEmptyState(factory) {
4349
- this._inbox.setEmptyState(factory);
4560
+ var _a;
4561
+ (_a = this._inbox) == null ? void 0 : _a.setEmptyState(factory);
4350
4562
  }
4351
4563
  setPopupErrorState(factory) {
4352
- this._inbox.setErrorState(factory);
4564
+ var _a;
4565
+ (_a = this._inbox) == null ? void 0 : _a.setErrorState(factory);
4353
4566
  }
4354
4567
  setPopupListItem(factory) {
4355
- this._inbox.setListItem(factory);
4568
+ var _a;
4569
+ (_a = this._inbox) == null ? void 0 : _a.setListItem(factory);
4356
4570
  }
4357
4571
  setPopupPaginationItem(factory) {
4358
- this._inbox.setPaginationItem(factory);
4572
+ var _a;
4573
+ (_a = this._inbox) == null ? void 0 : _a.setPaginationItem(factory);
4359
4574
  }
4360
4575
  setPopupMenuButton(factory) {
4361
4576
  this._popupMenuButtonFactory = factory;
@@ -4363,6 +4578,7 @@ class CourierInboxPopupMenu extends BaseElement {
4363
4578
  }
4364
4579
  render() {
4365
4580
  const unreadCount = CourierInboxDatastore.shared.unreadCount;
4581
+ if (!this._triggerButton) return;
4366
4582
  switch (this._popupMenuButtonFactory) {
4367
4583
  case void 0:
4368
4584
  case null:
@@ -4375,13 +4591,8 @@ class CourierInboxPopupMenu extends BaseElement {
4375
4591
  break;
4376
4592
  }
4377
4593
  }
4378
- disconnectedCallback() {
4379
- var _a;
4380
- (_a = this._datastoreListener) == null ? void 0 : _a.remove();
4381
- this._themeManager.cleanup();
4382
- }
4383
4594
  }
4384
- registerElement("courier-inbox-popup-menu", CourierInboxPopupMenu);
4595
+ registerElement(CourierInboxPopupMenu);
4385
4596
  function markAsRead(message) {
4386
4597
  return CourierInboxDatastore.shared.readMessage({ message });
4387
4598
  }
@@ -4419,9 +4630,9 @@ export {
4419
4630
  CourierInboxDatastore,
4420
4631
  CourierInboxDatastoreEvents,
4421
4632
  CourierInboxHeader,
4633
+ CourierInboxListItem,
4422
4634
  CourierInboxPopupMenu,
4423
4635
  CourierInboxThemeManager,
4424
- CourierListItem,
4425
4636
  archiveMessage,
4426
4637
  clickMessage,
4427
4638
  defaultDarkTheme,