stream-chat-react 11.1.0 → 11.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/dist/browser.full-bundle.js +110 -73
  2. package/dist/browser.full-bundle.js.map +1 -1
  3. package/dist/browser.full-bundle.min.js +4 -4
  4. package/dist/browser.full-bundle.min.js.map +1 -1
  5. package/dist/components/AutoCompleteTextarea/Textarea.d.ts +1 -0
  6. package/dist/components/AutoCompleteTextarea/Textarea.d.ts.map +1 -1
  7. package/dist/components/AutoCompleteTextarea/Textarea.js +10 -8
  8. package/dist/components/Channel/Channel.d.ts.map +1 -1
  9. package/dist/components/Channel/Channel.js +17 -10
  10. package/dist/components/Gallery/ModalGallery.d.ts.map +1 -1
  11. package/dist/components/Gallery/ModalGallery.js +11 -1
  12. package/dist/components/MessageInput/CooldownTimer.d.ts +1 -1
  13. package/dist/components/MessageInput/CooldownTimer.d.ts.map +1 -1
  14. package/dist/components/MessageInput/CooldownTimer.js +14 -11
  15. package/dist/components/MessageInput/hooks/useCooldownTimer.d.ts.map +1 -1
  16. package/dist/components/MessageInput/hooks/useCooldownTimer.js +11 -2
  17. package/dist/components/MessageList/hooks/VirtualizedMessageList/usePrependMessagesCount.d.ts.map +1 -1
  18. package/dist/components/MessageList/hooks/VirtualizedMessageList/usePrependMessagesCount.js +31 -32
  19. package/dist/css/v2/index.css +1 -1
  20. package/dist/css/v2/index.layout.css +1 -1
  21. package/dist/index.cjs.js +109 -72
  22. package/dist/scss/v2/AttachmentList/AttachmentList-layout.scss +1 -0
  23. package/dist/scss/v2/vendor/react-image-gallery.scss +19 -0
  24. package/dist/version.d.ts +1 -1
  25. package/dist/version.js +1 -1
  26. package/package.json +2 -2
@@ -10007,7 +10007,16 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
10007
10007
 
10008
10008
  var ImageGallery = /*@__PURE__*/getDefaultExportFromCjs(imageGallery.exports);
10009
10009
 
10010
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var ModalGallery = function (props) {
10010
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var onError = function (e) {
10011
+ // Prevent having alt attribute on img as the img takes the height of the alt text
10012
+ // instead of the CSS / element width & height when the CSS mask (fallback) is applied.
10013
+ e.target.alt = '';
10014
+ };
10015
+ var renderItem = function (_a) {
10016
+ var original = _a.original, originalAlt = _a.originalAlt;
10017
+ return (React__default["default"].createElement(BaseImage, { alt: originalAlt, className: 'image-gallery-image', onError: onError, src: original }));
10018
+ };
10019
+ var ModalGallery = function (props) {
10011
10020
  var images = props.images, index = props.index;
10012
10021
  var t = useTranslationContext('ModalGallery').t;
10013
10022
  var formattedArray = React$2.useMemo(function () {
@@ -10020,7 +10029,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
10020
10029
  };
10021
10030
  });
10022
10031
  }, [images]);
10023
- return (React__default["default"].createElement(ImageGallery, { items: formattedArray, showIndex: true, showPlayButton: false, showThumbnails: false, startIndex: index }));
10032
+ return (React__default["default"].createElement(ImageGallery, { items: formattedArray, renderItem: renderItem, showIndex: true, showPlayButton: false, showThumbnails: false, startIndex: index }));
10024
10033
  };
10025
10034
 
10026
10035
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var UnMemoizedGallery = function (props) {
@@ -43590,6 +43599,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
43590
43599
  currentTrigger: null,
43591
43600
  data: null,
43592
43601
  dataLoading: false,
43602
+ isComposing: false,
43593
43603
  left: null,
43594
43604
  selectionEnd: 0,
43595
43605
  selectionStart: 0,
@@ -43640,22 +43650,23 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
43640
43650
  SuggestionItem,
43641
43651
  SuggestionList = List$1
43642
43652
  } = this.props;
43653
+ const {
43654
+ isComposing
43655
+ } = this.state;
43643
43656
  const triggerProps = this.getTriggerProps();
43644
- if (triggerProps.values && triggerProps.currentTrigger && !(disableMentions && triggerProps.currentTrigger === '@')) {
43645
- return /*#__PURE__*/React__default["default"].createElement("div", {
43646
- className: clsx('rta__autocomplete', 'str-chat__suggestion-list-container', dropdownClassName),
43647
- ref: this.setDropdownRef,
43648
- style: dropdownStyle
43649
- }, /*#__PURE__*/React__default["default"].createElement(SuggestionList, _extends$2({
43650
- className: clsx('str-chat__suggestion-list', listClassName),
43651
- dropdownScroll: this._dropdownScroll,
43652
- itemClassName: clsx('str-chat__suggestion-list-item', itemClassName),
43653
- itemStyle: itemStyle,
43654
- onSelect: this._onSelect,
43655
- SuggestionItem: SuggestionItem
43656
- }, triggerProps)));
43657
- }
43658
- return null;
43657
+ if (isComposing || !triggerProps.values || !triggerProps.currentTrigger || disableMentions && triggerProps.currentTrigger === '@') return null;
43658
+ return /*#__PURE__*/React__default["default"].createElement("div", {
43659
+ className: clsx('rta__autocomplete', 'str-chat__suggestion-list-container', dropdownClassName),
43660
+ ref: this.setDropdownRef,
43661
+ style: dropdownStyle
43662
+ }, /*#__PURE__*/React__default["default"].createElement(SuggestionList, _extends$2({
43663
+ className: clsx('str-chat__suggestion-list', listClassName),
43664
+ dropdownScroll: this._dropdownScroll,
43665
+ itemClassName: clsx('str-chat__suggestion-list-item', itemClassName),
43666
+ itemStyle: itemStyle,
43667
+ onSelect: this._onSelect,
43668
+ SuggestionItem: SuggestionItem
43669
+ }, triggerProps)));
43659
43670
  }
43660
43671
  render() {
43661
43672
  const {
@@ -43709,6 +43720,14 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
43709
43720
  this._onClickAndBlurHandler(e);
43710
43721
  onClick === null || onClick === void 0 ? void 0 : onClick(e);
43711
43722
  },
43723
+ onCompositionEnd: () => this.setState(pv => ({
43724
+ ...pv,
43725
+ isComposing: false
43726
+ })),
43727
+ onCompositionStart: () => this.setState(pv => ({
43728
+ ...pv,
43729
+ isComposing: true
43730
+ })),
43712
43731
  onFocus: e => {
43713
43732
  var _this$props$onFocus, _this$props;
43714
43733
  (_this$props$onFocus = (_this$props = this.props).onFocus) === null || _this$props$onFocus === void 0 ? void 0 : _this$props$onFocus.call(_this$props, e);
@@ -47788,19 +47807,22 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
47788
47807
  };
47789
47808
 
47790
47809
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var CooldownTimer = function (_a) {
47791
- var cooldownInterval = _a.cooldownInterval, setCooldownRemaining = _a.setCooldownRemaining;
47792
- var _b = React$2.useState(cooldownInterval), seconds = _b[0], setSeconds = _b[1];
47810
+ var cooldownInterval = _a.cooldownInterval;
47811
+ var _b = React$2.useState(), seconds = _b[0], setSeconds = _b[1];
47793
47812
  React$2.useEffect(function () {
47794
- var countdownInterval = setInterval(function () {
47795
- if (seconds > 0) {
47813
+ var countdownTimeout;
47814
+ if (typeof seconds === 'number' && seconds > 0) {
47815
+ countdownTimeout = setTimeout(function () {
47796
47816
  setSeconds(seconds - 1);
47797
- }
47798
- else {
47799
- setCooldownRemaining(0);
47800
- }
47801
- }, 1000);
47802
- return function () { return clearInterval(countdownInterval); };
47803
- });
47817
+ }, 1000);
47818
+ }
47819
+ return function () {
47820
+ clearTimeout(countdownTimeout);
47821
+ };
47822
+ }, [seconds]);
47823
+ React$2.useEffect(function () {
47824
+ setSeconds(cooldownInterval !== null && cooldownInterval !== void 0 ? cooldownInterval : 0);
47825
+ }, [cooldownInterval]);
47804
47826
  return (React__default["default"].createElement("div", { className: 'str-chat__message-input-cooldown', "data-testid": 'cooldown-timer' }, seconds));
47805
47827
  };
47806
47828
 
@@ -48530,11 +48552,20 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
48530
48552
  ? // prevent negative values
48531
48553
  Math.max(0, (new Date().getTime() - ownLatestMessageDate.getTime()) / 1000)
48532
48554
  : undefined;
48533
- setCooldownRemaining(!skipCooldown &&
48555
+ var remaining = !skipCooldown &&
48534
48556
  typeof timeSinceOwnLastMessage !== 'undefined' &&
48535
48557
  cooldownInterval > timeSinceOwnLastMessage
48536
48558
  ? Math.round(cooldownInterval - timeSinceOwnLastMessage)
48537
- : 0);
48559
+ : 0;
48560
+ setCooldownRemaining(remaining);
48561
+ if (!remaining)
48562
+ return;
48563
+ var timeout = setTimeout(function () {
48564
+ setCooldownRemaining(0);
48565
+ }, remaining * 1000);
48566
+ return function () {
48567
+ clearTimeout(timeout);
48568
+ };
48538
48569
  }, [cooldownInterval, ownLatestMessageDate, skipCooldown]);
48539
48570
  return {
48540
48571
  cooldownInterval: cooldownInterval,
@@ -50461,9 +50492,9 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50461
50492
  var markReadThrottled = lodash_throttle(markRead, 500, { leading: true, trailing: true });
50462
50493
  var handleEvent = function (event) { return __awaiter(void 0, void 0, void 0, function () {
50463
50494
  var mainChannelUpdated, unread, messageDate, cid, oldestID;
50464
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
50465
- return __generator(this, function (_m) {
50466
- switch (_m.label) {
50495
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
50496
+ return __generator(this, function (_k) {
50497
+ switch (_k.label) {
50467
50498
  case 0:
50468
50499
  if (event.message) {
50469
50500
  dispatch({
@@ -50485,7 +50516,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50485
50516
  if (((_a = event.message) === null || _a === void 0 ? void 0 : _a.parent_id) && !((_b = event.message) === null || _b === void 0 ? void 0 : _b.show_in_channel)) {
50486
50517
  mainChannelUpdated = false;
50487
50518
  }
50488
- if (mainChannelUpdated && ((_d = (_c = event.message) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.id) !== client.userID) {
50519
+ if (mainChannelUpdated) {
50489
50520
  if (!document.hidden) {
50490
50521
  markReadThrottled();
50491
50522
  }
@@ -50499,9 +50530,9 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50499
50530
  }
50500
50531
  }
50501
50532
  }
50502
- if (((_f = (_e = event.message) === null || _e === void 0 ? void 0 : _e.user) === null || _f === void 0 ? void 0 : _f.id) === client.userID &&
50503
- ((_g = event === null || event === void 0 ? void 0 : event.message) === null || _g === void 0 ? void 0 : _g.created_at) &&
50504
- ((_h = event === null || event === void 0 ? void 0 : event.message) === null || _h === void 0 ? void 0 : _h.cid)) {
50533
+ if (((_d = (_c = event.message) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.id) === client.userID &&
50534
+ ((_e = event === null || event === void 0 ? void 0 : event.message) === null || _e === void 0 ? void 0 : _e.created_at) &&
50535
+ ((_f = event === null || event === void 0 ? void 0 : event.message) === null || _f === void 0 ? void 0 : _f.cid)) {
50505
50536
  messageDate = new Date(event.message.created_at);
50506
50537
  cid = event.message.cid;
50507
50538
  if (!latestMessageDatesByChannels[cid] ||
@@ -50511,7 +50542,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50511
50542
  }
50512
50543
  }
50513
50544
  if (!(event.type === 'user.deleted')) return [3 /*break*/, 2];
50514
- oldestID = (_l = (_k = (_j = channel.state) === null || _j === void 0 ? void 0 : _j.messages) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.id;
50545
+ oldestID = (_j = (_h = (_g = channel.state) === null || _g === void 0 ? void 0 : _g.messages) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.id;
50515
50546
  /**
50516
50547
  * As the channel state is not normalized we re-fetch the channel data. Thus, we avoid having to search for user references in the channel state.
50517
50548
  */
@@ -50525,8 +50556,8 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50525
50556
  * As the channel state is not normalized we re-fetch the channel data. Thus, we avoid having to search for user references in the channel state.
50526
50557
  */
50527
50558
  // FIXME: we should use channelQueryOptions if they are available
50528
- _m.sent();
50529
- _m.label = 2;
50559
+ _k.sent();
50560
+ _k.label = 2;
50530
50561
  case 2:
50531
50562
  throttledCopyStateFromChannel();
50532
50563
  return [2 /*return*/];
@@ -50588,6 +50619,13 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
50588
50619
  hasMore: hasMoreMessagesProbably(channel.state.messages.length, (_e = (_d = channelQueryOptions === null || channelQueryOptions === void 0 ? void 0 : channelQueryOptions.messages) === null || _d === void 0 ? void 0 : _d.limit) !== null && _e !== void 0 ? _e : DEFAULT_INITIAL_CHANNEL_PAGE_SIZE),
50589
50620
  type: 'initStateFromChannel',
50590
50621
  });
50622
+ /**
50623
+ * TODO: maybe pass last_read to the countUnread method to get proper value
50624
+ * combined with channel.countUnread adjustment (_countMessageAsUnread)
50625
+ * to allow counting own messages too
50626
+ *
50627
+ * const lastRead = channel.state.read[client.userID as string].last_read;
50628
+ */
50591
50629
  if (channel.countUnread() > 0)
50592
50630
  markRead();
50593
50631
  // The more complex sync logic is done in Chat
@@ -52387,7 +52425,7 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
52387
52425
 
52388
52426
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};
52389
52427
 
52390
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '11.1.0';
52428
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var version$1 = '11.1.2';
52391
52429
 
52392
52430
  window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var useChat = function (_a) {
52393
52431
  var _b, _c;
@@ -55183,11 +55221,14 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
55183
55221
  };
55184
55222
  }
55185
55223
 
55186
- window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var STATUSES_EXCLUDED_FROM_PREPEND = ['sending', 'failed'];
55224
+ window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};var STATUSES_EXCLUDED_FROM_PREPEND = {
55225
+ failed: true,
55226
+ sending: true,
55227
+ };
55187
55228
  function usePrependedMessagesCount(messages, hasDateSeparator) {
55188
55229
  var firstRealMessageIndex = hasDateSeparator ? 1 : 0;
55189
- var firstMessageId = React$2.useRef();
55190
- var earliestMessageId = React$2.useRef();
55230
+ var firstMessageOnFirstLoadedPage = React$2.useRef();
55231
+ var previousFirstMessageOnFirstLoadedPage = React$2.useRef();
55191
55232
  var previousNumItemsPrepended = React$2.useRef(0);
55192
55233
  var numItemsPrepended = React$2.useMemo(function () {
55193
55234
  var _a, _b;
@@ -55195,47 +55236,43 @@ var StreamChatReact = (function (exports, React$2, jsxRuntime, streamChat, React
55195
55236
  previousNumItemsPrepended.current = 0;
55196
55237
  return 0;
55197
55238
  }
55198
- var currentFirstMessageId = (_a = messages === null || messages === void 0 ? void 0 : messages[firstRealMessageIndex]) === null || _a === void 0 ? void 0 : _a.id;
55199
- // if no new messages were prepended, return early (same amount as before)
55200
- if (currentFirstMessageId === earliestMessageId.current) {
55239
+ var currentFirstMessage = messages === null || messages === void 0 ? void 0 : messages[firstRealMessageIndex];
55240
+ var noNewMessages = (currentFirstMessage === null || currentFirstMessage === void 0 ? void 0 : currentFirstMessage.id) === ((_a = previousFirstMessageOnFirstLoadedPage.current) === null || _a === void 0 ? void 0 : _a.id);
55241
+ // This is possible only, when sending messages very quickly (basically single char messages submitted like a crazy) in empty channel (first page)
55242
+ // Optimistic UI update, when sending messages, can lead to a situation, when
55243
+ // the order of the messages changes for a moment. This can happen, when a user
55244
+ // sends multiple messages withing few milliseconds. E.g. we send a message A
55245
+ // then message B. At first we have message array with both messages of status "sending"
55246
+ // then response for message A is received with a new - later - created_at timestamp
55247
+ // this leads to rearrangement of 1.B ("sending"), 2.A ("received"). Still firstMessageOnFirstLoadedPage.current
55248
+ // points to message A, but now this message has index 1 => previousNumItemsPrepended.current === 1
55249
+ // That in turn leads to incorrect index calculation in VirtualizedMessageList trying to access a message
55250
+ // at non-existent index. Therefore, we ignore messages of status "sending" / "failed" in order they are
55251
+ // not considered as prepended messages.
55252
+ var firstMsgMovedAfterMessagesInExcludedStatus = (currentFirstMessage === null || currentFirstMessage === void 0 ? void 0 : currentFirstMessage.status) && STATUSES_EXCLUDED_FROM_PREPEND[currentFirstMessage.status];
55253
+ if (noNewMessages || firstMsgMovedAfterMessagesInExcludedStatus) {
55201
55254
  return previousNumItemsPrepended.current;
55202
55255
  }
55203
- if (!firstMessageId.current) {
55204
- firstMessageId.current = currentFirstMessageId;
55256
+ if (!firstMessageOnFirstLoadedPage.current) {
55257
+ firstMessageOnFirstLoadedPage.current = currentFirstMessage;
55205
55258
  }
55206
- earliestMessageId.current = currentFirstMessageId;
55259
+ previousFirstMessageOnFirstLoadedPage.current = currentFirstMessage;
55207
55260
  // if new messages were prepended, find out how many
55208
55261
  // start with this number because there cannot be fewer prepended items than before
55209
- var adjustPrependedMessageCount = 0;
55210
- for (var i = previousNumItemsPrepended.current; i < messages.length; i += 1) {
55211
- // Optimistic UI update, when sending messages, can lead to a situation, when
55212
- // the order of the messages changes for a moment. This can happen, when a user
55213
- // sends multiple messages withing few milliseconds. E.g. we send a message A
55214
- // then message B. At first we have message array with both messages of status "sending"
55215
- // then response for message A is received with a new - later - created_at timestamp
55216
- // this leads to rearrangement of 1.B ("sending"), 2.A ("received"). Still firstMessageId.current
55217
- // points to message A, but now this message has index 1 => previousNumItemsPrepended.current === 1
55218
- // That in turn leads to incorrect index calculation in VirtualizedMessageList trying to access a message
55219
- // at non-existent index. Therefore, we ignore messages of status "sending" / "failed" in order they are
55220
- // not considered as prepended messages.
55221
- if (((_b = messages[i]) === null || _b === void 0 ? void 0 : _b.status) &&
55222
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
55223
- STATUSES_EXCLUDED_FROM_PREPEND.includes(messages[i].status) &&
55224
- messages[i].id !== firstMessageId.current) {
55225
- adjustPrependedMessageCount++;
55226
- }
55227
- if (messages[i].id === firstMessageId.current) {
55228
- previousNumItemsPrepended.current = i - adjustPrependedMessageCount;
55229
- return previousNumItemsPrepended.current;
55262
+ for (var prependedMessageCount = previousNumItemsPrepended.current; prependedMessageCount < messages.length; prependedMessageCount += 1) {
55263
+ var messageIsFirstOnFirstLoadedPage = messages[prependedMessageCount].id === ((_b = firstMessageOnFirstLoadedPage.current) === null || _b === void 0 ? void 0 : _b.id);
55264
+ if (messageIsFirstOnFirstLoadedPage) {
55265
+ previousNumItemsPrepended.current = prependedMessageCount;
55266
+ return prependedMessageCount;
55230
55267
  }
55231
55268
  }
55232
55269
  // if no match has found, we have jumped - reset the prepended item count.
55233
- firstMessageId.current = currentFirstMessageId;
55270
+ firstMessageOnFirstLoadedPage.current = currentFirstMessage;
55234
55271
  previousNumItemsPrepended.current = 0;
55235
55272
  return 0;
55236
55273
  // TODO: there's a bug here, the messages prop is the same array instance (something mutates it)
55237
55274
  // that's why the second dependency is necessary
55238
- }, [messages, messages === null || messages === void 0 ? void 0 : messages.length]);
55275
+ }, [firstRealMessageIndex, messages, messages === null || messages === void 0 ? void 0 : messages.length]);
55239
55276
  return numItemsPrepended;
55240
55277
  }
55241
55278