@trycourier/courier-ui-inbox 1.0.11-beta → 1.0.12-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
@@ -1578,7 +1578,7 @@ const _CourierInboxDatastore = class _CourierInboxDatastore {
1578
1578
  __publicField(_CourierInboxDatastore, "instance");
1579
1579
  let CourierInboxDatastore = _CourierInboxDatastore;
1580
1580
  class CourierInboxListItem extends CourierBaseElement {
1581
- constructor(themeManager) {
1581
+ constructor(themeManager, canClick, _canLongPress) {
1582
1582
  super();
1583
1583
  // State
1584
1584
  __publicField(this, "_themeManager");
@@ -1586,6 +1586,8 @@ class CourierInboxListItem extends CourierBaseElement {
1586
1586
  __publicField(this, "_message", null);
1587
1587
  __publicField(this, "_feedType", "inbox");
1588
1588
  __publicField(this, "_isMobile", false);
1589
+ __publicField(this, "_canClick", false);
1590
+ // private _canLongPress: boolean = false; // Unused for now. But we can use this in the future if needed.
1589
1591
  // Elements
1590
1592
  __publicField(this, "_titleElement");
1591
1593
  __publicField(this, "_subtitleElement");
@@ -1600,6 +1602,7 @@ class CourierInboxListItem extends CourierBaseElement {
1600
1602
  __publicField(this, "onItemClick", null);
1601
1603
  __publicField(this, "onItemLongPress", null);
1602
1604
  __publicField(this, "onItemActionClick", null);
1605
+ this._canClick = canClick;
1603
1606
  this._themeManager = themeManager;
1604
1607
  this._theme = themeManager.getTheme();
1605
1608
  this._isMobile = "ontouchstart" in window;
@@ -1635,6 +1638,7 @@ class CourierInboxListItem extends CourierBaseElement {
1635
1638
  this._menu.addEventListener("pointerdown", cancelPropagation);
1636
1639
  this._menu.addEventListener("click", cancelPropagation);
1637
1640
  this.addEventListener("click", (e) => {
1641
+ if (!this._canClick) return;
1638
1642
  if (this._menu && (this._menu.contains(e.target) || e.composedPath().includes(this._menu))) {
1639
1643
  return;
1640
1644
  }
@@ -1644,6 +1648,9 @@ class CourierInboxListItem extends CourierBaseElement {
1644
1648
  });
1645
1649
  this._setupHoverBehavior();
1646
1650
  this._setupLongPressBehavior();
1651
+ if (this._canClick) {
1652
+ this.classList.add("clickable");
1653
+ }
1647
1654
  }
1648
1655
  static getStyles(theme2) {
1649
1656
  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;
@@ -1656,7 +1663,7 @@ class CourierInboxListItem extends CourierBaseElement {
1656
1663
  justify-content: space-between;
1657
1664
  border-bottom: ${((_b = list == null ? void 0 : list.item) == null ? void 0 : _b.divider) ?? "1px solid red"};
1658
1665
  font-family: inherit;
1659
- cursor: pointer;
1666
+ cursor: default;
1660
1667
  transition: background-color 0.2s ease;
1661
1668
  margin: 0;
1662
1669
  width: 100%;
@@ -1671,25 +1678,27 @@ class CourierInboxListItem extends CourierBaseElement {
1671
1678
  touch-action: manipulation;
1672
1679
  }
1673
1680
 
1674
- /* Base hover / active */
1681
+ /* Only apply hover/active background if clickable */
1675
1682
  @media (hover: hover) {
1676
- ${CourierInboxListItem.id}:hover {
1683
+ ${CourierInboxListItem.id}.clickable:hover {
1684
+ cursor: pointer;
1677
1685
  background-color: ${((_d = list == null ? void 0 : list.item) == null ? void 0 : _d.hoverBackgroundColor) ?? "red"};
1678
1686
  }
1679
1687
  }
1680
1688
 
1681
- ${CourierInboxListItem.id}:active {
1689
+ ${CourierInboxListItem.id}.clickable:active {
1690
+ cursor: pointer;
1682
1691
  background-color: ${((_e = list == null ? void 0 : list.item) == null ? void 0 : _e.activeBackgroundColor) ?? "red"};
1683
1692
  }
1684
1693
 
1685
1694
  /* Menu hover / active */
1686
1695
  @media (hover: hover) {
1687
- ${CourierInboxListItem.id}:hover:has(courier-inbox-list-item-menu:hover, courier-inbox-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {
1696
+ ${CourierInboxListItem.id}.clickable:hover:has(courier-inbox-list-item-menu:hover, courier-inbox-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {
1688
1697
  background-color: ${((_f = list == null ? void 0 : list.item) == null ? void 0 : _f.backgroundColor) ?? "transparent"};
1689
1698
  }
1690
1699
  }
1691
1700
 
1692
- ${CourierInboxListItem.id}:active:has(courier-inbox-list-item-menu:active, courier-inbox-list-item-menu *:active, courier-button:active, courier-button *:active) {
1701
+ ${CourierInboxListItem.id}.clickable:active:has(courier-inbox-list-item-menu:active, courier-inbox-list-item-menu *:active, courier-button:active, courier-button *:active) {
1693
1702
  background-color: ${((_g = list == null ? void 0 : list.item) == null ? void 0 : _g.backgroundColor) ?? "transparent"};
1694
1703
  }
1695
1704
 
@@ -1922,6 +1931,7 @@ class CourierInboxListItem extends CourierBaseElement {
1922
1931
  }
1923
1932
  const actionsTheme = (_c = (_b = (_a = this._theme.inbox) == null ? void 0 : _a.list) == null ? void 0 : _b.item) == null ? void 0 : _c.actions;
1924
1933
  if (this._actionsContainer && this._message.actions) {
1934
+ this._actionsContainer.innerHTML = "";
1925
1935
  this._message.actions.forEach((action) => {
1926
1936
  var _a2, _b2, _c2, _d, _e;
1927
1937
  const actionButton = new CourierButton({
@@ -2204,6 +2214,8 @@ class CourierInboxList extends CourierBaseElement {
2204
2214
  __publicField(this, "_isLoading", true);
2205
2215
  __publicField(this, "_error", null);
2206
2216
  __publicField(this, "_canPaginate", false);
2217
+ __publicField(this, "_canClickListItems", false);
2218
+ __publicField(this, "_canLongPressListItems", false);
2207
2219
  // Callbacks
2208
2220
  __publicField(this, "_onMessageClick", null);
2209
2221
  __publicField(this, "_onMessageActionClick", null);
@@ -2254,6 +2266,12 @@ class CourierInboxList extends CourierBaseElement {
2254
2266
  (_b = this._listItemStyles) == null ? void 0 : _b.remove();
2255
2267
  (_c = this._listItemMenuStyles) == null ? void 0 : _c.remove();
2256
2268
  }
2269
+ setCanClickListItems(canClick) {
2270
+ this._canClickListItems = canClick;
2271
+ }
2272
+ setCanLongPressListItems(canLongPress) {
2273
+ this._canLongPressListItems = canLongPress;
2274
+ }
2257
2275
  static getStyles(theme2) {
2258
2276
  var _a;
2259
2277
  const list = (_a = theme2.inbox) == null ? void 0 : _a.list;
@@ -2428,7 +2446,7 @@ class CourierInboxList extends CourierBaseElement {
2428
2446
  list.appendChild(this._listItemFactory({ message, index }));
2429
2447
  return;
2430
2448
  }
2431
- const listItem = new CourierInboxListItem(this._themeSubscription.manager);
2449
+ const listItem = new CourierInboxListItem(this._themeSubscription.manager, this._canClickListItems, this._canLongPressListItems);
2432
2450
  listItem.setMessage(message, this._feedType);
2433
2451
  listItem.setOnItemClick((message2) => {
2434
2452
  var _a2;
@@ -2748,31 +2766,27 @@ class CourierUnreadCountBadge extends CourierBaseElement {
2748
2766
  (_a = this._style) == null ? void 0 : _a.remove();
2749
2767
  }
2750
2768
  static getStyles(theme2) {
2751
- 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;
2769
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2752
2770
  return `
2753
2771
  ${CourierUnreadCountBadge.id} {
2754
2772
  display: inline-block;
2755
2773
  }
2756
2774
 
2757
2775
  ${CourierUnreadCountBadge.id} .unread-badge {
2758
- padding: 4px 8px;
2776
+ padding: 3px 8px;
2777
+ font-size: 12px;
2759
2778
  text-align: center;
2760
2779
  display: none;
2761
2780
  pointer-events: none;
2762
- }
2763
-
2764
- ${CourierUnreadCountBadge.id} .button {
2765
- background-color: ${(_c = (_b = (_a = theme2.popup) == null ? void 0 : _a.button) == null ? void 0 : _b.unreadIndicator) == null ? void 0 : _c.backgroundColor};
2766
- 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};
2767
- border-radius: ${(_j = (_i = (_h = theme2.popup) == null ? void 0 : _h.button) == null ? void 0 : _i.unreadIndicator) == null ? void 0 : _j.borderRadius};
2768
- 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};
2781
+ min-width: 20px;
2769
2782
  }
2770
2783
 
2771
2784
  ${CourierUnreadCountBadge.id} .header {
2772
- 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};
2773
- 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};
2774
- 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};
2775
- 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};
2785
+ background-color: ${(_d = (_c = (_b = (_a = theme2.inbox) == null ? void 0 : _a.header) == null ? void 0 : _b.filters) == null ? void 0 : _c.unreadIndicator) == null ? void 0 : _d.backgroundColor};
2786
+ color: ${(_i = (_h = (_g = (_f = (_e = theme2.inbox) == null ? void 0 : _e.header) == null ? void 0 : _f.filters) == null ? void 0 : _g.unreadIndicator) == null ? void 0 : _h.font) == null ? void 0 : _i.color};
2787
+ border-radius: ${(_m = (_l = (_k = (_j = theme2.inbox) == null ? void 0 : _j.header) == null ? void 0 : _k.filters) == null ? void 0 : _l.unreadIndicator) == null ? void 0 : _m.borderRadius};
2788
+ font-size: ${(_r = (_q = (_p = (_o = (_n = theme2.inbox) == null ? void 0 : _n.header) == null ? void 0 : _o.filters) == null ? void 0 : _p.unreadIndicator) == null ? void 0 : _q.font) == null ? void 0 : _r.size};
2789
+ padding: ${(_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.padding};
2776
2790
  }
2777
2791
  `;
2778
2792
  }
@@ -3127,15 +3141,11 @@ const defaultLightTheme = {
3127
3141
  backgroundColor: "transparent",
3128
3142
  hoverBackgroundColor: CourierColors.black[50010],
3129
3143
  activeBackgroundColor: CourierColors.black[50020],
3130
- unreadIndicator: {
3131
- font: {
3132
- color: CourierColors.white[500],
3133
- size: "14px",
3134
- family: void 0,
3135
- weight: void 0
3136
- },
3144
+ unreadDotIndicator: {
3137
3145
  backgroundColor: CourierColors.blue[500],
3138
- borderRadius: "12px"
3146
+ borderRadius: "50%",
3147
+ height: "8px",
3148
+ width: "8px"
3139
3149
  }
3140
3150
  },
3141
3151
  window: {
@@ -3173,10 +3183,11 @@ const defaultLightTheme = {
3173
3183
  font: {
3174
3184
  color: CourierColors.white[500],
3175
3185
  family: void 0,
3176
- size: "14px"
3186
+ size: "12px"
3177
3187
  },
3178
3188
  backgroundColor: CourierColors.blue[500],
3179
- borderRadius: "12px"
3189
+ borderRadius: "4px",
3190
+ padding: "2px 6px"
3180
3191
  }
3181
3192
  },
3182
3193
  menus: {
@@ -3374,15 +3385,11 @@ const defaultDarkTheme = {
3374
3385
  backgroundColor: "transparent",
3375
3386
  hoverBackgroundColor: CourierColors.white[50010],
3376
3387
  activeBackgroundColor: CourierColors.white[50020],
3377
- unreadIndicator: {
3378
- font: {
3379
- color: CourierColors.white[500],
3380
- size: "14px",
3381
- family: void 0,
3382
- weight: void 0
3383
- },
3388
+ unreadDotIndicator: {
3384
3389
  backgroundColor: CourierColors.blue[500],
3385
- borderRadius: "12px"
3390
+ borderRadius: "50%",
3391
+ height: "8px",
3392
+ width: "8px"
3386
3393
  }
3387
3394
  },
3388
3395
  window: {
@@ -3420,10 +3427,11 @@ const defaultDarkTheme = {
3420
3427
  font: {
3421
3428
  color: CourierColors.white[500],
3422
3429
  family: void 0,
3423
- size: "14px"
3430
+ size: "12px"
3424
3431
  },
3425
3432
  backgroundColor: CourierColors.blue[500],
3426
- borderRadius: "12px"
3433
+ borderRadius: "4px",
3434
+ padding: "3px 8px"
3427
3435
  }
3428
3436
  },
3429
3437
  menus: {
@@ -3623,9 +3631,9 @@ const mergeTheme = (mode, theme2) => {
3623
3631
  ...(_d = (_c = defaultTheme.popup) == null ? void 0 : _c.button) == null ? void 0 : _d.icon,
3624
3632
  ...(_f = (_e = theme2.popup) == null ? void 0 : _e.button) == null ? void 0 : _f.icon
3625
3633
  },
3626
- unreadIndicator: {
3627
- ...(_h = (_g = defaultTheme.popup) == null ? void 0 : _g.button) == null ? void 0 : _h.unreadIndicator,
3628
- ...(_j = (_i = theme2.popup) == null ? void 0 : _i.button) == null ? void 0 : _j.unreadIndicator
3634
+ unreadDotIndicator: {
3635
+ ...(_h = (_g = defaultTheme.popup) == null ? void 0 : _g.button) == null ? void 0 : _h.unreadDotIndicator,
3636
+ ...(_j = (_i = theme2.popup) == null ? void 0 : _i.button) == null ? void 0 : _j.unreadDotIndicator
3629
3637
  }
3630
3638
  },
3631
3639
  window: {
@@ -3950,6 +3958,8 @@ class CourierInbox extends CourierBaseElement {
3950
3958
  this.appendChild(this._header);
3951
3959
  this._list = new CourierInboxList({
3952
3960
  themeManager: this._themeManager,
3961
+ canClickListItems: false,
3962
+ canLongPressListItems: false,
3953
3963
  onRefresh: () => {
3954
3964
  this.refresh();
3955
3965
  },
@@ -4114,13 +4124,17 @@ class CourierInbox extends CourierBaseElement {
4114
4124
  (_a = this._list) == null ? void 0 : _a.setPaginationItemFactory(factory);
4115
4125
  }
4116
4126
  onMessageClick(handler) {
4127
+ var _a;
4117
4128
  this._onMessageClick = handler;
4129
+ (_a = this._list) == null ? void 0 : _a.setCanClickListItems(handler !== void 0);
4118
4130
  }
4119
4131
  onMessageActionClick(handler) {
4120
4132
  this._onMessageActionClick = handler;
4121
4133
  }
4122
4134
  onMessageLongPress(handler) {
4135
+ var _a;
4123
4136
  this._onMessageLongPress = handler;
4137
+ (_a = this._list) == null ? void 0 : _a.setCanLongPressListItems(handler !== void 0);
4124
4138
  }
4125
4139
  setFeedType(feedType) {
4126
4140
  var _a;
@@ -4227,7 +4241,7 @@ class CourierInboxMenuButton extends CourierFactoryElement {
4227
4241
  __publicField(this, "_style");
4228
4242
  __publicField(this, "_container");
4229
4243
  __publicField(this, "_triggerButton");
4230
- __publicField(this, "_unreadCountBadge");
4244
+ __publicField(this, "_unreadBadge");
4231
4245
  this._themeSubscription = themeBus.subscribe((_) => {
4232
4246
  this.refreshTheme();
4233
4247
  });
@@ -4250,45 +4264,50 @@ class CourierInboxMenuButton extends CourierFactoryElement {
4250
4264
  this._container = document.createElement("div");
4251
4265
  this._container.className = "menu-button-container";
4252
4266
  this._triggerButton = new CourierIconButton(CourierIconSVGs.inbox);
4253
- this._unreadCountBadge = new CourierUnreadCountBadge({
4254
- themeBus: this._themeSubscription.manager,
4255
- location: "button"
4256
- });
4257
- this._unreadCountBadge.id = "unread-badge";
4267
+ this._unreadBadge = document.createElement("div");
4268
+ this._unreadBadge.className = "unread-badge";
4269
+ this._unreadBadge.style.display = "none";
4258
4270
  this._container.appendChild(this._triggerButton);
4259
- this._container.appendChild(this._unreadCountBadge);
4271
+ this._container.appendChild(this._unreadBadge);
4260
4272
  this.appendChild(this._container);
4261
4273
  this.refreshTheme();
4262
4274
  return this._container;
4263
4275
  }
4264
- static getStyles(_theme) {
4276
+ static getStyles(theme2) {
4277
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
4265
4278
  return `
4266
4279
  ${CourierInboxMenuButton.id} .menu-button-container {
4267
4280
  position: relative;
4268
4281
  display: inline-block;
4269
4282
  }
4270
4283
 
4271
- ${CourierInboxMenuButton.id} #unread-badge {
4284
+ ${CourierInboxMenuButton.id} .unread-badge {
4272
4285
  position: absolute;
4273
- top: -8px;
4274
- left: 50%;
4286
+ top: 2px;
4287
+ right: 2px;
4275
4288
  pointer-events: none;
4289
+ width: ${((_c = (_b = (_a = theme2.popup) == null ? void 0 : _a.button) == null ? void 0 : _b.unreadDotIndicator) == null ? void 0 : _c.height) ?? "8px"};
4290
+ height: ${((_f = (_e = (_d = theme2.popup) == null ? void 0 : _d.button) == null ? void 0 : _e.unreadDotIndicator) == null ? void 0 : _f.width) ?? "8px"};
4291
+ background: ${((_i = (_h = (_g = theme2.popup) == null ? void 0 : _g.button) == null ? void 0 : _h.unreadDotIndicator) == null ? void 0 : _i.backgroundColor) ?? "red"};
4292
+ border-radius: ${((_l = (_k = (_j = theme2.popup) == null ? void 0 : _j.button) == null ? void 0 : _k.unreadDotIndicator) == null ? void 0 : _l.borderRadius) ?? "50%"};
4293
+ display: none;
4294
+ z-index: 1;
4276
4295
  }
4277
4296
  `;
4278
4297
  }
4279
4298
  onUnreadCountChange(unreadCount) {
4280
- var _a;
4281
- (_a = this._unreadCountBadge) == null ? void 0 : _a.setCount(unreadCount);
4299
+ if (this._unreadBadge) {
4300
+ this._unreadBadge.style.display = unreadCount > 0 ? "block" : "none";
4301
+ }
4282
4302
  this.refreshTheme();
4283
4303
  }
4284
4304
  refreshTheme() {
4285
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
4305
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
4286
4306
  (_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]);
4287
4307
  (_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);
4288
4308
  (_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");
4289
4309
  (_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]);
4290
4310
  (_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]);
4291
- (_w = this._unreadCountBadge) == null ? void 0 : _w.refreshTheme("button");
4292
4311
  }
4293
4312
  }
4294
4313
  registerElement(CourierInboxMenuButton);