@trycourier/courier-ui-inbox 2.4.7 → 2.4.9
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/components/__tests__/info-state-style-scoping.test.d.ts +1 -0
- package/dist/components/courier-inbox-popup-menu.d.ts +12 -0
- package/dist/components/courier-inbox.d.ts +14 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +101 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -4625,6 +4625,9 @@ class CourierInbox extends CourierBaseElement {
|
|
|
4625
4625
|
__publicField(this, "_datastoreListener");
|
|
4626
4626
|
__publicField(this, "_authListener");
|
|
4627
4627
|
__publicField(this, "_feeds", defaultFeeds());
|
|
4628
|
+
/** When true, render injected preview messages and skip all network/realtime + the shared datastore. */
|
|
4629
|
+
__publicField(this, "_isPreview", false);
|
|
4630
|
+
__publicField(this, "_previewDataSet");
|
|
4628
4631
|
// Header
|
|
4629
4632
|
__publicField(this, "_header");
|
|
4630
4633
|
__publicField(this, "_headerFactory");
|
|
@@ -4749,7 +4752,7 @@ class CourierInbox extends CourierBaseElement {
|
|
|
4749
4752
|
this._themeManager.setMode(mode);
|
|
4750
4753
|
}
|
|
4751
4754
|
static get observedAttributes() {
|
|
4752
|
-
return ["height", "light-theme", "dark-theme", "mode", "feeds", "message-click", "message-action-click", "message-long-press"];
|
|
4755
|
+
return ["height", "light-theme", "dark-theme", "mode", "feeds", "message-click", "message-action-click", "message-long-press", "preview"];
|
|
4753
4756
|
}
|
|
4754
4757
|
resetInitialFeedAndTab() {
|
|
4755
4758
|
if (!this._feeds.length) {
|
|
@@ -4765,6 +4768,7 @@ class CourierInbox extends CourierBaseElement {
|
|
|
4765
4768
|
this._currentFeedId = this._feeds[0].feedId;
|
|
4766
4769
|
}
|
|
4767
4770
|
onComponentMounted() {
|
|
4771
|
+
this._isPreview = this.hasAttribute("preview") && this.getAttribute("preview") !== "false";
|
|
4768
4772
|
this.readInitialThemeAttributes();
|
|
4769
4773
|
this.attachElements();
|
|
4770
4774
|
this.setupThemeSubscription();
|
|
@@ -4802,6 +4806,7 @@ class CourierInbox extends CourierBaseElement {
|
|
|
4802
4806
|
}
|
|
4803
4807
|
setupAuthListener() {
|
|
4804
4808
|
this._authListener = Courier.shared.addAuthenticationListener(({ userId }) => {
|
|
4809
|
+
if (this._isPreview) return;
|
|
4805
4810
|
if (userId) {
|
|
4806
4811
|
this.refresh().catch((err) => {
|
|
4807
4812
|
var _a, _b, _c;
|
|
@@ -4812,6 +4817,10 @@ class CourierInbox extends CourierBaseElement {
|
|
|
4812
4817
|
}
|
|
4813
4818
|
initializeInboxData() {
|
|
4814
4819
|
this.resetInitialFeedAndTab();
|
|
4820
|
+
if (this._isPreview) {
|
|
4821
|
+
this.renderPreview();
|
|
4822
|
+
return;
|
|
4823
|
+
}
|
|
4815
4824
|
CourierInboxDatastore.shared.registerFeeds(this._feeds);
|
|
4816
4825
|
this._datastoreListener = new CourierInboxDataStoreListener({
|
|
4817
4826
|
onError: (error) => {
|
|
@@ -5056,6 +5065,10 @@ class CourierInbox extends CourierBaseElement {
|
|
|
5056
5065
|
async reloadListForTab() {
|
|
5057
5066
|
var _a;
|
|
5058
5067
|
(_a = this._list) == null ? void 0 : _a.selectDataset(this._currentTabId);
|
|
5068
|
+
if (this._isPreview) {
|
|
5069
|
+
this.renderPreview();
|
|
5070
|
+
return;
|
|
5071
|
+
}
|
|
5059
5072
|
await CourierInboxDatastore.shared.load({
|
|
5060
5073
|
canUseCache: true,
|
|
5061
5074
|
datasetIds: [this._currentTabId]
|
|
@@ -5144,13 +5157,19 @@ class CourierInbox extends CourierBaseElement {
|
|
|
5144
5157
|
var _a, _b, _c, _d;
|
|
5145
5158
|
this._feeds = feeds;
|
|
5146
5159
|
this.resetInitialFeedAndTab();
|
|
5147
|
-
|
|
5160
|
+
if (!this._isPreview) {
|
|
5161
|
+
CourierInboxDatastore.shared.registerFeeds(this._feeds);
|
|
5162
|
+
}
|
|
5148
5163
|
(_a = this._header) == null ? void 0 : _a.setFeeds(this._feeds);
|
|
5149
5164
|
(_b = this._header) == null ? void 0 : _b.selectFeed(this._currentFeedId, this._currentTabId);
|
|
5150
5165
|
this.updateHeader();
|
|
5151
5166
|
(_c = this._list) == null ? void 0 : _c.selectDataset(this._currentTabId);
|
|
5152
5167
|
(_d = this._list) == null ? void 0 : _d.scrollToTop(false);
|
|
5153
|
-
this.
|
|
5168
|
+
if (this._isPreview) {
|
|
5169
|
+
this.renderPreview();
|
|
5170
|
+
} else {
|
|
5171
|
+
this.refresh();
|
|
5172
|
+
}
|
|
5154
5173
|
}
|
|
5155
5174
|
/** Get the current set of feeds. */
|
|
5156
5175
|
getFeeds() {
|
|
@@ -5212,6 +5231,7 @@ class CourierInbox extends CourierBaseElement {
|
|
|
5212
5231
|
*/
|
|
5213
5232
|
async refresh() {
|
|
5214
5233
|
var _a, _b;
|
|
5234
|
+
if (this._isPreview) return;
|
|
5215
5235
|
if (!((_a = Courier.shared.client) == null ? void 0 : _a.options.userId)) {
|
|
5216
5236
|
(_b = Courier.shared.client) == null ? void 0 : _b.options.logger.error("No user signed in. Please call Courier.shared.signIn(...) to load the inbox.");
|
|
5217
5237
|
return;
|
|
@@ -5220,6 +5240,40 @@ class CourierInbox extends CourierBaseElement {
|
|
|
5220
5240
|
canUseCache: false
|
|
5221
5241
|
});
|
|
5222
5242
|
}
|
|
5243
|
+
/**
|
|
5244
|
+
* Render injected "dummy" inbox messages and skip all network/realtime + the
|
|
5245
|
+
* shared datastore (so a live inbox elsewhere is unaffected). Pass `null` to
|
|
5246
|
+
* clear preview mode.
|
|
5247
|
+
*/
|
|
5248
|
+
setPreviewData(messages, options) {
|
|
5249
|
+
this._isPreview = Boolean(messages);
|
|
5250
|
+
if (!messages) {
|
|
5251
|
+
this._previewDataSet = void 0;
|
|
5252
|
+
return;
|
|
5253
|
+
}
|
|
5254
|
+
if (this._datastoreListener) {
|
|
5255
|
+
CourierInboxDatastore.shared.removeDataStoreListener(this._datastoreListener);
|
|
5256
|
+
this._datastoreListener = void 0;
|
|
5257
|
+
}
|
|
5258
|
+
const unreadCount = (options == null ? void 0 : options.unreadCount) ?? messages.filter((m) => !m.read).length;
|
|
5259
|
+
this._previewDataSet = {
|
|
5260
|
+
id: this._currentTabId,
|
|
5261
|
+
messages,
|
|
5262
|
+
unreadCount,
|
|
5263
|
+
canPaginate: false,
|
|
5264
|
+
paginationCursor: null
|
|
5265
|
+
};
|
|
5266
|
+
this.renderPreview();
|
|
5267
|
+
}
|
|
5268
|
+
/** Render the current preview dataset into the list + header (preview mode only). */
|
|
5269
|
+
renderPreview() {
|
|
5270
|
+
var _a, _b, _c;
|
|
5271
|
+
if (!this._previewDataSet) return;
|
|
5272
|
+
const dataSet = { ...this._previewDataSet, id: this._currentTabId };
|
|
5273
|
+
(_a = this._list) == null ? void 0 : _a.setDataSet(dataSet);
|
|
5274
|
+
(_c = (_b = this._header) == null ? void 0 : _b.tabs) == null ? void 0 : _c.updateTabUnreadCount(this._currentTabId, dataSet.unreadCount);
|
|
5275
|
+
this.updateHeader();
|
|
5276
|
+
}
|
|
5223
5277
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
5224
5278
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
5225
5279
|
if (oldValue === newValue) return;
|
|
@@ -5288,6 +5342,9 @@ class CourierInbox extends CourierBaseElement {
|
|
|
5288
5342
|
case "mode":
|
|
5289
5343
|
this._themeManager.setMode(newValue);
|
|
5290
5344
|
break;
|
|
5345
|
+
case "preview":
|
|
5346
|
+
this._isPreview = newValue != null && newValue !== "false";
|
|
5347
|
+
break;
|
|
5291
5348
|
}
|
|
5292
5349
|
}
|
|
5293
5350
|
}
|
|
@@ -5399,6 +5456,10 @@ class CourierInboxPopupMenu extends CourierBaseElement {
|
|
|
5399
5456
|
__publicField(this, "_totalUnreadCount", 0);
|
|
5400
5457
|
// Feeds (stored from attribute before inner inbox is created)
|
|
5401
5458
|
__publicField(this, "_feeds");
|
|
5459
|
+
/** Preview mode: forward injected messages to the inner inbox; never touch the shared datastore. */
|
|
5460
|
+
__publicField(this, "_isPreview", false);
|
|
5461
|
+
__publicField(this, "_previewMessages");
|
|
5462
|
+
__publicField(this, "_previewUnreadCount");
|
|
5402
5463
|
// Factories
|
|
5403
5464
|
__publicField(this, "_popupMenuButtonFactory");
|
|
5404
5465
|
__publicField(this, "handleOutsideClick", (event) => {
|
|
@@ -5447,9 +5508,10 @@ class CourierInboxPopupMenu extends CourierBaseElement {
|
|
|
5447
5508
|
this._themeManager.setMode(mode);
|
|
5448
5509
|
}
|
|
5449
5510
|
static get observedAttributes() {
|
|
5450
|
-
return ["popup-alignment", "feeds", "message-click", "message-action-click", "message-long-press", "popup-width", "popup-height", "top", "right", "bottom", "left", "light-theme", "dark-theme", "mode"];
|
|
5511
|
+
return ["popup-alignment", "feeds", "message-click", "message-action-click", "message-long-press", "popup-width", "popup-height", "top", "right", "bottom", "left", "light-theme", "dark-theme", "mode", "preview"];
|
|
5451
5512
|
}
|
|
5452
5513
|
onComponentMounted() {
|
|
5514
|
+
this._isPreview = this.hasAttribute("preview") && this.getAttribute("preview") !== "false";
|
|
5453
5515
|
this.readInitialThemeAttributes();
|
|
5454
5516
|
this._style = injectGlobalStyle(CourierInboxPopupMenu.id, CourierInboxPopupMenu.getStyles(this.theme, this._width, this._height));
|
|
5455
5517
|
this._triggerButton = new CourierInboxMenuButton(this._themeManager);
|
|
@@ -5457,6 +5519,9 @@ class CourierInboxPopupMenu extends CourierBaseElement {
|
|
|
5457
5519
|
this._popup.className = "popup";
|
|
5458
5520
|
this._inbox = new CourierInbox(this._themeManager);
|
|
5459
5521
|
this._inbox.setAttribute("height", "100%");
|
|
5522
|
+
if (this._isPreview) {
|
|
5523
|
+
this._inbox.setAttribute("preview", "true");
|
|
5524
|
+
}
|
|
5460
5525
|
if (this._feeds) {
|
|
5461
5526
|
this._inbox.setAttribute("feeds", JSON.stringify(this._feeds));
|
|
5462
5527
|
}
|
|
@@ -5467,8 +5532,13 @@ class CourierInboxPopupMenu extends CourierBaseElement {
|
|
|
5467
5532
|
this._triggerButton.addEventListener("click", this.togglePopup.bind(this));
|
|
5468
5533
|
document.addEventListener("click", this.handleOutsideClick.bind(this));
|
|
5469
5534
|
this.updatePopupPosition();
|
|
5470
|
-
|
|
5471
|
-
|
|
5535
|
+
if (!this._isPreview) {
|
|
5536
|
+
this._datastoreListener = new CourierInboxDataStoreListener(this);
|
|
5537
|
+
CourierInboxDatastore.shared.addDataStoreListener(this._datastoreListener);
|
|
5538
|
+
} else if (this._previewMessages) {
|
|
5539
|
+
this._inbox.setPreviewData(this._previewMessages, { unreadCount: this._previewUnreadCount });
|
|
5540
|
+
this._totalUnreadCount = this._previewUnreadCount ?? this._previewMessages.filter((m) => !m.read).length;
|
|
5541
|
+
}
|
|
5472
5542
|
this.render();
|
|
5473
5543
|
}
|
|
5474
5544
|
onComponentUnmounted() {
|
|
@@ -5606,8 +5676,32 @@ class CourierInboxPopupMenu extends CourierBaseElement {
|
|
|
5606
5676
|
case "mode":
|
|
5607
5677
|
this._themeManager.setMode(newValue);
|
|
5608
5678
|
break;
|
|
5679
|
+
case "preview":
|
|
5680
|
+
this._isPreview = newValue != null && newValue !== "false";
|
|
5681
|
+
break;
|
|
5609
5682
|
}
|
|
5610
5683
|
}
|
|
5684
|
+
/**
|
|
5685
|
+
* Render injected "dummy" inbox messages in the popup and skip all
|
|
5686
|
+
* network/realtime + the shared datastore. Pass `null` to clear preview mode.
|
|
5687
|
+
*/
|
|
5688
|
+
setPreviewData(messages, options) {
|
|
5689
|
+
this._isPreview = Boolean(messages);
|
|
5690
|
+
this._previewMessages = messages ?? void 0;
|
|
5691
|
+
this._previewUnreadCount = options == null ? void 0 : options.unreadCount;
|
|
5692
|
+
if (messages) {
|
|
5693
|
+
if (this._datastoreListener) {
|
|
5694
|
+
CourierInboxDatastore.shared.removeDataStoreListener(this._datastoreListener);
|
|
5695
|
+
this._datastoreListener = void 0;
|
|
5696
|
+
}
|
|
5697
|
+
this._totalUnreadCount = (options == null ? void 0 : options.unreadCount) ?? messages.filter((m) => !m.read).length;
|
|
5698
|
+
}
|
|
5699
|
+
if (this._inbox) {
|
|
5700
|
+
if (messages) this._inbox.setAttribute("preview", "true");
|
|
5701
|
+
this._inbox.setPreviewData(messages, options);
|
|
5702
|
+
}
|
|
5703
|
+
this.render();
|
|
5704
|
+
}
|
|
5611
5705
|
/**
|
|
5612
5706
|
* Called when the per-dataset unread count changes.
|
|
5613
5707
|
* Triggers a render to update the factory with latest feeds data
|
|
@@ -6034,7 +6128,7 @@ class CourierInboxDatastoreEvents {
|
|
|
6034
6128
|
}
|
|
6035
6129
|
}
|
|
6036
6130
|
Courier.shared.courierUserAgentName = "courier-ui-inbox";
|
|
6037
|
-
Courier.shared.courierUserAgentVersion = "2.4.
|
|
6131
|
+
Courier.shared.courierUserAgentVersion = "2.4.9";
|
|
6038
6132
|
export {
|
|
6039
6133
|
Courier2 as Courier,
|
|
6040
6134
|
CourierInbox,
|