stream-chat-react-native-core 4.7.0 → 4.7.1-beta.1

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 (167) hide show
  1. package/lib/commonjs/components/Attachment/Card.js +61 -21
  2. package/lib/commonjs/components/Attachment/Card.js.map +1 -1
  3. package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
  4. package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
  5. package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
  6. package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
  7. package/lib/commonjs/components/Reply/Reply.js +12 -12
  8. package/lib/commonjs/components/Reply/Reply.js.map +1 -1
  9. package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
  10. package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
  11. package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
  12. package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
  13. package/lib/commonjs/contexts/channelContext/ChannelContext.js +14 -4
  14. package/lib/commonjs/contexts/channelContext/ChannelContext.js.map +1 -1
  15. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js +14 -4
  16. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js.map +1 -1
  17. package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
  18. package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
  19. package/lib/commonjs/contexts/chatContext/ChatContext.js +14 -4
  20. package/lib/commonjs/contexts/chatContext/ChatContext.js.map +1 -1
  21. package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
  22. package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
  23. package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js +2 -2
  24. package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js.map +1 -1
  25. package/lib/commonjs/contexts/messageContext/MessageContext.js +14 -4
  26. package/lib/commonjs/contexts/messageContext/MessageContext.js.map +1 -1
  27. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +14 -4
  28. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  29. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
  30. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  31. package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
  32. package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
  33. package/lib/commonjs/contexts/messagesContext/MessagesContext.js +14 -4
  34. package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
  35. package/lib/commonjs/contexts/overlayContext/OverlayContext.js +13 -3
  36. package/lib/commonjs/contexts/overlayContext/OverlayContext.js.map +1 -1
  37. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +12 -12
  38. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
  39. package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
  40. package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
  41. package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
  42. package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
  43. package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js +14 -4
  44. package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
  45. package/lib/commonjs/contexts/themeContext/ThemeContext.js +13 -7
  46. package/lib/commonjs/contexts/themeContext/ThemeContext.js.map +1 -1
  47. package/lib/commonjs/contexts/themeContext/utils/theme.js +9 -0
  48. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  49. package/lib/commonjs/contexts/threadContext/ThreadContext.js +14 -4
  50. package/lib/commonjs/contexts/threadContext/ThreadContext.js.map +1 -1
  51. package/lib/commonjs/contexts/translationContext/TranslationContext.js +15 -6
  52. package/lib/commonjs/contexts/translationContext/TranslationContext.js.map +1 -1
  53. package/lib/commonjs/contexts/typingContext/TypingContext.js +14 -4
  54. package/lib/commonjs/contexts/typingContext/TypingContext.js.map +1 -1
  55. package/lib/commonjs/contexts/utils/defaultBaseContextValue.js +7 -0
  56. package/lib/commonjs/contexts/utils/defaultBaseContextValue.js.map +1 -0
  57. package/lib/commonjs/contexts/utils/isTestEnvironment.js +11 -0
  58. package/lib/commonjs/contexts/utils/isTestEnvironment.js.map +1 -0
  59. package/lib/commonjs/mock-builders/mock.js +30 -5
  60. package/lib/commonjs/mock-builders/mock.js.map +1 -1
  61. package/lib/commonjs/version.json +1 -1
  62. package/lib/module/components/Attachment/Card.js +61 -21
  63. package/lib/module/components/Attachment/Card.js.map +1 -1
  64. package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
  65. package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
  66. package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
  67. package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
  68. package/lib/module/components/Reply/Reply.js +12 -12
  69. package/lib/module/components/Reply/Reply.js.map +1 -1
  70. package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
  71. package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
  72. package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
  73. package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
  74. package/lib/module/contexts/channelContext/ChannelContext.js +14 -4
  75. package/lib/module/contexts/channelContext/ChannelContext.js.map +1 -1
  76. package/lib/module/contexts/channelsContext/ChannelsContext.js +14 -4
  77. package/lib/module/contexts/channelsContext/ChannelsContext.js.map +1 -1
  78. package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
  79. package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
  80. package/lib/module/contexts/chatContext/ChatContext.js +14 -4
  81. package/lib/module/contexts/chatContext/ChatContext.js.map +1 -1
  82. package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
  83. package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
  84. package/lib/module/contexts/keyboardContext/KeyboardContext.js +2 -2
  85. package/lib/module/contexts/keyboardContext/KeyboardContext.js.map +1 -1
  86. package/lib/module/contexts/messageContext/MessageContext.js +14 -4
  87. package/lib/module/contexts/messageContext/MessageContext.js.map +1 -1
  88. package/lib/module/contexts/messageInputContext/MessageInputContext.js +14 -4
  89. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  90. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
  91. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  92. package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
  93. package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
  94. package/lib/module/contexts/messagesContext/MessagesContext.js +14 -4
  95. package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
  96. package/lib/module/contexts/overlayContext/OverlayContext.js +13 -3
  97. package/lib/module/contexts/overlayContext/OverlayContext.js.map +1 -1
  98. package/lib/module/contexts/overlayContext/OverlayProvider.js +12 -12
  99. package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
  100. package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
  101. package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
  102. package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
  103. package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
  104. package/lib/module/contexts/suggestionsContext/SuggestionsContext.js +14 -4
  105. package/lib/module/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
  106. package/lib/module/contexts/themeContext/ThemeContext.js +13 -7
  107. package/lib/module/contexts/themeContext/ThemeContext.js.map +1 -1
  108. package/lib/module/contexts/themeContext/utils/theme.js +9 -0
  109. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  110. package/lib/module/contexts/threadContext/ThreadContext.js +14 -4
  111. package/lib/module/contexts/threadContext/ThreadContext.js.map +1 -1
  112. package/lib/module/contexts/translationContext/TranslationContext.js +15 -6
  113. package/lib/module/contexts/translationContext/TranslationContext.js.map +1 -1
  114. package/lib/module/contexts/typingContext/TypingContext.js +14 -4
  115. package/lib/module/contexts/typingContext/TypingContext.js.map +1 -1
  116. package/lib/module/contexts/utils/defaultBaseContextValue.js +7 -0
  117. package/lib/module/contexts/utils/defaultBaseContextValue.js.map +1 -0
  118. package/lib/module/contexts/utils/isTestEnvironment.js +11 -0
  119. package/lib/module/contexts/utils/isTestEnvironment.js.map +1 -0
  120. package/lib/module/mock-builders/mock.js +30 -5
  121. package/lib/module/mock-builders/mock.js.map +1 -1
  122. package/lib/module/version.json +1 -1
  123. package/lib/typescript/contexts/__tests__/index.test.d.ts +1 -0
  124. package/lib/typescript/contexts/keyboardContext/KeyboardContext.d.ts +6 -2
  125. package/lib/typescript/contexts/themeContext/ThemeContext.d.ts +5 -2
  126. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +6 -0
  127. package/lib/typescript/contexts/utils/defaultBaseContextValue.d.ts +1 -0
  128. package/lib/typescript/contexts/utils/isTestEnvironment.d.ts +1 -0
  129. package/lib/typescript/mock-builders/mock.d.ts +2 -2
  130. package/package.json +1 -1
  131. package/src/components/Attachment/Card.tsx +29 -6
  132. package/src/components/Attachment/__tests__/Attachment.test.js +0 -14
  133. package/src/components/Attachment/__tests__/Giphy.test.js +9 -5
  134. package/src/components/AutoCompleteInput/AutoCompleteSuggestionList.tsx +1 -0
  135. package/src/components/ImageGallery/components/__tests__/ImageGalleryHeader.test.tsx +5 -3
  136. package/src/components/MessageInput/SendMessageDisallowedIndicator.tsx +1 -0
  137. package/src/components/MessageInput/__tests__/FileUploadPreview.test.js +1 -1
  138. package/src/components/Reply/Reply.tsx +6 -3
  139. package/src/contexts/__tests__/index.test.tsx +103 -0
  140. package/src/contexts/activeChannelsRefContext/ActiveChannelsRefContext.tsx +1 -0
  141. package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx +18 -4
  142. package/src/contexts/channelContext/ChannelContext.tsx +18 -2
  143. package/src/contexts/channelsContext/ChannelsContext.tsx +18 -2
  144. package/src/contexts/channelsStateContext/ChannelsStateContext.tsx +19 -10
  145. package/src/contexts/chatContext/ChatContext.tsx +15 -2
  146. package/src/contexts/imageGalleryContext/ImageGalleryContext.tsx +18 -3
  147. package/src/contexts/keyboardContext/KeyboardContext.tsx +2 -1
  148. package/src/contexts/messageContext/MessageContext.tsx +19 -2
  149. package/src/contexts/messageInputContext/MessageInputContext.tsx +20 -2
  150. package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +19 -3
  151. package/src/contexts/messageOverlayContext/hooks/useResettableState.test.tsx +1 -0
  152. package/src/contexts/messagesContext/MessagesContext.tsx +19 -2
  153. package/src/contexts/overlayContext/OverlayContext.tsx +17 -2
  154. package/src/contexts/overlayContext/OverlayProvider.tsx +1 -0
  155. package/src/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.tsx +18 -3
  156. package/src/contexts/paginatedMessageListContext/PaginatedMessageListContext.tsx +15 -3
  157. package/src/contexts/suggestionsContext/SuggestionsContext.tsx +19 -2
  158. package/src/contexts/suggestionsContext/__tests__/Suggestions.test.js +1 -0
  159. package/src/contexts/themeContext/ThemeContext.tsx +19 -5
  160. package/src/contexts/themeContext/utils/theme.ts +15 -0
  161. package/src/contexts/threadContext/ThreadContext.tsx +16 -2
  162. package/src/contexts/translationContext/TranslationContext.tsx +18 -4
  163. package/src/contexts/typingContext/TypingContext.tsx +17 -2
  164. package/src/contexts/utils/defaultBaseContextValue.ts +1 -0
  165. package/src/contexts/utils/isTestEnvironment.ts +1 -0
  166. package/src/mock-builders/mock.js +16 -3
  167. package/src/version.json +1 -1
@@ -32,7 +32,7 @@ var ActiveChannelsProvider = function ActiveChannelsProvider(_ref) {
32
32
  __self: _this,
33
33
  __source: {
34
34
  fileName: _jsxFileName,
35
- lineNumber: 15,
35
+ lineNumber: 16,
36
36
  columnNumber: 8
37
37
  }
38
38
  }, children);
@@ -54,7 +54,7 @@ var withActiveChannelsRefContext = function withActiveChannelsRefContext(Compone
54
54
  __self: _this,
55
55
  __source: {
56
56
  fileName: _jsxFileName,
57
- lineNumber: 26,
57
+ lineNumber: 27,
58
58
  columnNumber: 12
59
59
  }
60
60
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["ActiveChannelsRefContext.tsx"],"names":["ActiveChannelsContext","React","createContext","current","ActiveChannelsProvider","children","value","useActiveChannelsRefContext","withActiveChannelsRefContext","Component","WithActiveChannelsContextComponent","props","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAGA;;;;;;;;;AAIA,IAAMA,qBAAqB,GAAGC,kBAAMC,aAAN,CAAoB;AAAEC,EAAAA,OAAO,EAAE;AAAX,CAApB,CAA9B;;AAEO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB;AAAA,MACpCC,QADoC,QACpCA,QADoC;AAAA,MAEpCC,KAFoC,QAEpCA,KAFoC;AAAA,SAK/B,gCAAC,qBAAD,CAAuB,QAAvB;AAAgC,IAAA,KAAK,EAAEA,KAAvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAA+CD,QAA/C,CAL+B;AAAA,CAA/B;;;;AAOA,IAAME,2BAA2B,GAAG,SAA9BA,2BAA8B;AAAA,SACzC,uBAAWP,qBAAX,CADyC;AAAA,CAApC;;;;AAGA,IAAMQ,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,SAD0C,EAEF;AACxC,MAAMC,kCAAkC,GAAG,SAArCA,kCAAqC,CAACC,KAAD,EAAsC;AAC/E,QAAMX,qBAAqB,GAAGO,2BAA2B,EAAzD;AAEA,WAAO,gCAAC,SAAD,gCAAgBI,KAAhB;AAA6B,MAAA,cAAc,EAAEX,qBAA7C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAJD;;AAKAU,EAAAA,kCAAkC,CAACE,WAAnC,iCAA6E,oCAC3EH,SAD2E,CAA7E;AAGA,SAAOC,kCAAP;AACD,CAZM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { UnknownType } from '../../types/types';\nimport { getDisplayName } from '../utils/getDisplayName';\n\ntype ActiveChannels = React.MutableRefObject<string[]>;\n\nconst ActiveChannelsContext = React.createContext({ current: [] } as ActiveChannels);\n\nexport const ActiveChannelsProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value: ActiveChannels;\n}>) => <ActiveChannelsContext.Provider value={value}>{children}</ActiveChannelsContext.Provider>;\n\nexport const useActiveChannelsRefContext = () =>\n useContext(ActiveChannelsContext) as unknown as ActiveChannels;\n\nexport const withActiveChannelsRefContext = <P extends UnknownType>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, 'activeChannels'>> => {\n const WithActiveChannelsContextComponent = (props: Omit<P, 'activeChannels'>) => {\n const ActiveChannelsContext = useActiveChannelsRefContext();\n\n return <Component {...(props as P)} activeChannels={ActiveChannelsContext} />;\n };\n WithActiveChannelsContextComponent.displayName = `WithActiveChannelsContext${getDisplayName(\n Component,\n )}`;\n return WithActiveChannelsContextComponent;\n};\n"]}
1
+ {"version":3,"sources":["ActiveChannelsRefContext.tsx"],"names":["ActiveChannelsContext","React","createContext","current","ActiveChannelsProvider","children","value","useActiveChannelsRefContext","withActiveChannelsRefContext","Component","WithActiveChannelsContextComponent","props","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAIA;;;;;;;;;AAIA,IAAMA,qBAAqB,GAAGC,kBAAMC,aAAN,CAAoB;AAAEC,EAAAA,OAAO,EAAE;AAAX,CAApB,CAA9B;;AAEO,IAAMC,sBAAsB,GAAG,SAAzBA,sBAAyB;AAAA,MACpCC,QADoC,QACpCA,QADoC;AAAA,MAEpCC,KAFoC,QAEpCA,KAFoC;AAAA,SAK/B,gCAAC,qBAAD,CAAuB,QAAvB;AAAgC,IAAA,KAAK,EAAEA,KAAvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAA+CD,QAA/C,CAL+B;AAAA,CAA/B;;;;AAOA,IAAME,2BAA2B,GAAG,SAA9BA,2BAA8B;AAAA,SACzC,uBAAWP,qBAAX,CADyC;AAAA,CAApC;;;;AAGA,IAAMQ,4BAA4B,GAAG,SAA/BA,4BAA+B,CAC1CC,SAD0C,EAEF;AACxC,MAAMC,kCAAkC,GAAG,SAArCA,kCAAqC,CAACC,KAAD,EAAsC;AAC/E,QAAMX,qBAAqB,GAAGO,2BAA2B,EAAzD;AAEA,WAAO,gCAAC,SAAD,gCAAgBI,KAAhB;AAA6B,MAAA,cAAc,EAAEX,qBAA7C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAJD;;AAKAU,EAAAA,kCAAkC,CAACE,WAAnC,iCAA6E,oCAC3EH,SAD2E,CAA7E;AAGA,SAAOC,kCAAP;AACD,CAZM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { UnknownType } from '../../types/types';\n\nimport { getDisplayName } from '../utils/getDisplayName';\n\ntype ActiveChannels = React.MutableRefObject<string[]>;\n\nconst ActiveChannelsContext = React.createContext({ current: [] } as ActiveChannels);\n\nexport const ActiveChannelsProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value: ActiveChannels;\n}>) => <ActiveChannelsContext.Provider value={value}>{children}</ActiveChannelsContext.Provider>;\n\nexport const useActiveChannelsRefContext = () =>\n useContext(ActiveChannelsContext) as unknown as ActiveChannels;\n\nexport const withActiveChannelsRefContext = <P extends UnknownType>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, 'activeChannels'>> => {\n const WithActiveChannelsContextComponent = (props: Omit<P, 'activeChannels'>) => {\n const ActiveChannelsContext = useActiveChannelsRefContext();\n\n return <Component {...(props as P)} activeChannels={ActiveChannelsContext} />;\n };\n WithActiveChannelsContextComponent.displayName = `WithActiveChannelsContext${getDisplayName(\n Component,\n )}`;\n return WithActiveChannelsContextComponent;\n};\n"]}
@@ -13,8 +13,12 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
13
13
 
14
14
  var _react = _interopRequireWildcard(require("react"));
15
15
 
16
+ var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
17
+
16
18
  var _getDisplayName = require("../utils/getDisplayName");
17
19
 
20
+ var _isTestEnvironment = require("../utils/isTestEnvironment");
21
+
18
22
  var _this = this,
19
23
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx";
20
24
 
@@ -22,7 +26,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
22
26
 
23
27
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
28
 
25
- var AttachmentPickerContext = _react["default"].createContext({});
29
+ var AttachmentPickerContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
26
30
 
27
31
  exports.AttachmentPickerContext = AttachmentPickerContext;
28
32
 
@@ -90,7 +94,7 @@ var AttachmentPickerProvider = function AttachmentPickerProvider(_ref) {
90
94
  __self: _this,
91
95
  __source: {
92
96
  fileName: _jsxFileName,
93
- lineNumber: 113,
97
+ lineNumber: 116,
94
98
  columnNumber: 5
95
99
  }
96
100
  }, children);
@@ -99,7 +103,13 @@ var AttachmentPickerProvider = function AttachmentPickerProvider(_ref) {
99
103
  exports.AttachmentPickerProvider = AttachmentPickerProvider;
100
104
 
101
105
  var useAttachmentPickerContext = function useAttachmentPickerContext() {
102
- return (0, _react.useContext)(AttachmentPickerContext);
106
+ var contextValue = (0, _react.useContext)(AttachmentPickerContext);
107
+
108
+ if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
109
+ throw new Error("The useAttachmentPickerContext hook was called outside the AttachmentPickerContext provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider");
110
+ }
111
+
112
+ return contextValue;
103
113
  };
104
114
 
105
115
  exports.useAttachmentPickerContext = useAttachmentPickerContext;
@@ -111,7 +121,7 @@ var withAttachmentPickerContext = function withAttachmentPickerContext(Component
111
121
  __self: _this,
112
122
  __source: {
113
123
  fileName: _jsxFileName,
114
- lineNumber: 134,
124
+ lineNumber: 148,
115
125
  columnNumber: 12
116
126
  }
117
127
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["AttachmentPickerContext.tsx"],"names":["AttachmentPickerContext","React","createContext","AttachmentPickerProvider","children","value","bottomInsetValue","bottomInset","topInsetValue","topInset","setBottomInset","maxNumberOfFiles","setMaxNumberOfFiles","selectedImages","setSelectedImages","selectedFiles","setSelectedFiles","selectedPicker","setSelectedPicker","setTopInset","combinedValue","useAttachmentPickerContext","withAttachmentPickerContext","Component","WithAttachmentPickerContextComponent","props","attachmentPickerContext","displayName"],"mappings":";;;;;;;;;;;;;AAAA;;AAGA;;;;;;;;;AAsDO,IAAMA,uBAAuB,GAAGC,kBAAMC,aAAN,CACrC,EADqC,CAAhC;;;;AAIA,IAAMC,wBAAwB,GAAG,SAA3BA,wBAA2B,OAejC;AAAA;;AAAA,MAdLC,QAcK,QAdLA,QAcK;AAAA,MAbLC,KAaK,QAbLA,KAaK;AACL,MAAMC,gBAAgB,GAAGD,KAAH,oBAAGA,KAAK,CAAEE,WAAhC;AACA,MAAMC,aAAa,GAAGH,KAAH,oBAAGA,KAAK,CAAEI,QAA7B;;AAEA,kBAAsC,qBAAiBH,gBAAjB,WAAiBA,gBAAjB,GAAqC,CAArC,CAAtC;AAAA;AAAA,MAAOC,WAAP;AAAA,MAAoBG,cAApB;;AACA,mBAAgD,qBAAS,EAAT,CAAhD;AAAA;AAAA,MAAOC,gBAAP;AAAA,MAAyBC,mBAAzB;;AACA,mBAA4C,qBAAkB,EAAlB,CAA5C;AAAA;AAAA,MAAOC,cAAP;AAAA,MAAuBC,iBAAvB;;AACA,mBAA0C,qBAAiB,EAAjB,CAA1C;AAAA;AAAA,MAAOC,aAAP;AAAA,MAAsBC,gBAAtB;;AACA,mBAA4C,sBAA5C;AAAA;AAAA,MAAOC,cAAP;AAAA,MAAuBC,iBAAvB;;AACA,oBAAgC,wCAAiBb,KAAjB,oBAAiBA,KAAK,CAAEI,QAAxB,8BAAoC,CAApC,CAAhC;AAAA;AAAA,MAAOA,QAAP;AAAA,MAAiBU,WAAjB;;AAEA,wBAAU,YAAM;AACdT,IAAAA,cAAc,CAACJ,gBAAD,WAACA,gBAAD,GAAqB,CAArB,CAAd;AACD,GAFD,EAEG,CAACA,gBAAD,CAFH;AAIA,wBAAU,YAAM;AACda,IAAAA,WAAW,CAACX,aAAD,WAACA,aAAD,GAAkB,CAAlB,CAAX;AACD,GAFD,EAEG,CAACA,aAAD,CAFH;AAIA,MAAMY,aAAa;AACjBT,IAAAA,gBAAgB,EAAhBA,gBADiB;AAEjBI,IAAAA,aAAa,EAAbA,aAFiB;AAGjBF,IAAAA,cAAc,EAAdA,cAHiB;AAIjBI,IAAAA,cAAc,EAAdA,cAJiB;AAKjBP,IAAAA,cAAc,EAAdA,cALiB;AAMjBE,IAAAA,mBAAmB,EAAnBA,mBANiB;AAOjBI,IAAAA,gBAAgB,EAAhBA,gBAPiB;AAQjBF,IAAAA,iBAAiB,EAAjBA,iBARiB;AASjBI,IAAAA,iBAAiB,EAAjBA,iBATiB;AAUjBC,IAAAA,WAAW,EAAXA;AAViB,KAWdd,KAXc;AAYjBE,IAAAA,WAAW,EAAXA,WAZiB;AAajBE,IAAAA,QAAQ,EAARA;AAbiB,IAAnB;AAgBA,SACE,gCAAC,uBAAD,CAAyB,QAAzB;AACE,IAAA,KAAK,EAAEW,aADT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAGGhB,QAHH,CADF;AAOD,CAzDM;;;;AA2DA,IAAMiB,0BAA0B,GAAG,SAA7BA,0BAA6B;AAAA,SACxC,uBAAWrB,uBAAX,CADwC;AAAA,CAAnC;;;;AAGA,IAAMsB,2BAA2B,GAAG,SAA9BA,2BAA8B,CAGzCC,SAHyC,EAIkC;AAC3E,MAAMC,oCAAoC,GAAG,SAAvCA,oCAAuC,CAC3CC,KAD2C,EAExC;AACH,QAAMC,uBAAuB,GAAGL,0BAA0B,EAA1D;AAEA,WAAO,gCAAC,SAAD,gCAAgBI,KAAhB,EAAkDC,uBAAlD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,oCAAoC,CAACG,WAArC,mCAAiF,oCAC/EJ,SAD+E,CAAjF;AAGA,SAAOC,oCAAP;AACD,CAhBM","sourcesContent":["import React, { PropsWithChildren, useContext, useEffect, useState } from 'react';\n\nimport type { Asset, DefaultStreamChatGenerics, File } from '../../types/types';\nimport { getDisplayName } from '../utils/getDisplayName';\n\nexport type AttachmentPickerIconProps = {\n numberOfImageUploads: number;\n selectedPicker?: 'images';\n};\n\nexport type AttachmentPickerContextValue = {\n /**\n * `bottomInset` determine the height of the `AttachmentPicker` and the underlying shift to the `MessageList` when it is opened.\n * This can also be set via the `setBottomInset` function provided by the `useAttachmentPickerContext` hook.\n *\n * Please check [OverlayProvider](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#overlayprovider) section in Cookbook\n * for more details.\n */\n bottomInset: number;\n /**\n * Custom UI component for [camera selector icon](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png)\n *\n * **Default: ** [CameraSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/CameraSelectorIcon.tsx)\n */\n CameraSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;\n closePicker: () => void;\n /**\n * Custom UI component for [file selector icon](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png)\n *\n * **Default: ** [FileSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/FileSelectorIcon.tsx)\n */\n FileSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;\n /**\n * Custom UI component for [image selector icon](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png)\n *\n * **Default: ** [ImageSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/ImageSelectorIcon.tsx)\n */\n ImageSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;\n /**\n * Limit for maximum files that can be attached per message.\n */\n maxNumberOfFiles: number;\n openPicker: () => void;\n selectedFiles: File[];\n selectedImages: Asset[];\n setBottomInset: React.Dispatch<React.SetStateAction<number>>;\n setMaxNumberOfFiles: React.Dispatch<React.SetStateAction<number>>;\n setSelectedFiles: React.Dispatch<React.SetStateAction<File[]>>;\n setSelectedImages: React.Dispatch<React.SetStateAction<Asset[]>>;\n setSelectedPicker: React.Dispatch<React.SetStateAction<'images' | undefined>>;\n setTopInset: React.Dispatch<React.SetStateAction<number>>;\n topInset: number;\n attachmentPickerBottomSheetHeight?: number;\n attachmentSelectionBarHeight?: number;\n selectedPicker?: 'images';\n};\n\nexport const AttachmentPickerContext = React.createContext<AttachmentPickerContextValue>(\n {} as AttachmentPickerContextValue,\n);\n\nexport const AttachmentPickerProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value?: Pick<\n AttachmentPickerContextValue,\n | 'attachmentSelectionBarHeight'\n | 'attachmentPickerBottomSheetHeight'\n | 'CameraSelectorIcon'\n | 'closePicker'\n | 'FileSelectorIcon'\n | 'ImageSelectorIcon'\n | 'openPicker'\n > &\n Partial<Pick<AttachmentPickerContextValue, 'bottomInset' | 'topInset'>>;\n}>) => {\n const bottomInsetValue = value?.bottomInset;\n const topInsetValue = value?.topInset;\n\n const [bottomInset, setBottomInset] = useState<number>(bottomInsetValue ?? 0);\n const [maxNumberOfFiles, setMaxNumberOfFiles] = useState(10);\n const [selectedImages, setSelectedImages] = useState<Asset[]>([]);\n const [selectedFiles, setSelectedFiles] = useState<File[]>([]);\n const [selectedPicker, setSelectedPicker] = useState<'images'>();\n const [topInset, setTopInset] = useState<number>(value?.topInset ?? 0);\n\n useEffect(() => {\n setBottomInset(bottomInsetValue ?? 0);\n }, [bottomInsetValue]);\n\n useEffect(() => {\n setTopInset(topInsetValue ?? 0);\n }, [topInsetValue]);\n\n const combinedValue = {\n maxNumberOfFiles,\n selectedFiles,\n selectedImages,\n selectedPicker,\n setBottomInset,\n setMaxNumberOfFiles,\n setSelectedFiles,\n setSelectedImages,\n setSelectedPicker,\n setTopInset,\n ...value,\n bottomInset,\n topInset,\n };\n\n return (\n <AttachmentPickerContext.Provider\n value={combinedValue as unknown as AttachmentPickerContextValue}\n >\n {children}\n </AttachmentPickerContext.Provider>\n );\n};\n\nexport const useAttachmentPickerContext = () =>\n useContext(AttachmentPickerContext) as unknown as AttachmentPickerContextValue;\n\nexport const withAttachmentPickerContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<StreamChatGenerics>,\n): React.FC<Omit<StreamChatGenerics, keyof AttachmentPickerContextValue>> => {\n const WithAttachmentPickerContextComponent = (\n props: Omit<StreamChatGenerics, keyof AttachmentPickerContextValue>,\n ) => {\n const attachmentPickerContext = useAttachmentPickerContext();\n\n return <Component {...(props as StreamChatGenerics)} {...attachmentPickerContext} />;\n };\n WithAttachmentPickerContextComponent.displayName = `WithAttachmentPickerContext${getDisplayName(\n Component as React.ComponentType,\n )}`;\n return WithAttachmentPickerContextComponent;\n};\n"]}
1
+ {"version":3,"sources":["AttachmentPickerContext.tsx"],"names":["AttachmentPickerContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","AttachmentPickerProvider","children","value","bottomInsetValue","bottomInset","topInsetValue","topInset","setBottomInset","maxNumberOfFiles","setMaxNumberOfFiles","selectedImages","setSelectedImages","selectedFiles","setSelectedFiles","selectedPicker","setSelectedPicker","setTopInset","combinedValue","useAttachmentPickerContext","contextValue","Error","withAttachmentPickerContext","Component","WithAttachmentPickerContextComponent","props","attachmentPickerContext","displayName"],"mappings":"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","sourcesContent":["import React, { PropsWithChildren, useContext, useEffect, useState } from 'react';\n\nimport type { Asset, DefaultStreamChatGenerics, File } from '../../types/types';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type AttachmentPickerIconProps = {\n numberOfImageUploads: number;\n selectedPicker?: 'images';\n};\n\nexport type AttachmentPickerContextValue = {\n /**\n * `bottomInset` determine the height of the `AttachmentPicker` and the underlying shift to the `MessageList` when it is opened.\n * This can also be set via the `setBottomInset` function provided by the `useAttachmentPickerContext` hook.\n *\n * Please check [OverlayProvider](https://github.com/GetStream/stream-chat-react-native/wiki/Cookbook-v3.0#overlayprovider) section in Cookbook\n * for more details.\n */\n bottomInset: number;\n /**\n * Custom UI component for [camera selector icon](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png)\n *\n * **Default: ** [CameraSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/CameraSelectorIcon.tsx)\n */\n CameraSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;\n closePicker: () => void;\n /**\n * Custom UI component for [file selector icon](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png)\n *\n * **Default: ** [FileSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/FileSelectorIcon.tsx)\n */\n FileSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;\n /**\n * Custom UI component for [image selector icon](https://github.com/GetStream/stream-chat-react-native/blob/main/screenshots/docs/1.png)\n *\n * **Default: ** [ImageSelectorIcon](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/AttachmentPicker/components/ImageSelectorIcon.tsx)\n */\n ImageSelectorIcon: React.ComponentType<AttachmentPickerIconProps>;\n /**\n * Limit for maximum files that can be attached per message.\n */\n maxNumberOfFiles: number;\n openPicker: () => void;\n selectedFiles: File[];\n selectedImages: Asset[];\n setBottomInset: React.Dispatch<React.SetStateAction<number>>;\n setMaxNumberOfFiles: React.Dispatch<React.SetStateAction<number>>;\n setSelectedFiles: React.Dispatch<React.SetStateAction<File[]>>;\n setSelectedImages: React.Dispatch<React.SetStateAction<Asset[]>>;\n setSelectedPicker: React.Dispatch<React.SetStateAction<'images' | undefined>>;\n setTopInset: React.Dispatch<React.SetStateAction<number>>;\n topInset: number;\n attachmentPickerBottomSheetHeight?: number;\n attachmentSelectionBarHeight?: number;\n selectedPicker?: 'images';\n};\n\nexport const AttachmentPickerContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as AttachmentPickerContextValue,\n);\n\nexport const AttachmentPickerProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value?: Pick<\n AttachmentPickerContextValue,\n | 'attachmentSelectionBarHeight'\n | 'attachmentPickerBottomSheetHeight'\n | 'CameraSelectorIcon'\n | 'closePicker'\n | 'FileSelectorIcon'\n | 'ImageSelectorIcon'\n | 'openPicker'\n > &\n Partial<Pick<AttachmentPickerContextValue, 'bottomInset' | 'topInset'>>;\n}>) => {\n const bottomInsetValue = value?.bottomInset;\n const topInsetValue = value?.topInset;\n\n const [bottomInset, setBottomInset] = useState<number>(bottomInsetValue ?? 0);\n const [maxNumberOfFiles, setMaxNumberOfFiles] = useState(10);\n const [selectedImages, setSelectedImages] = useState<Asset[]>([]);\n const [selectedFiles, setSelectedFiles] = useState<File[]>([]);\n const [selectedPicker, setSelectedPicker] = useState<'images'>();\n const [topInset, setTopInset] = useState<number>(value?.topInset ?? 0);\n\n useEffect(() => {\n setBottomInset(bottomInsetValue ?? 0);\n }, [bottomInsetValue]);\n\n useEffect(() => {\n setTopInset(topInsetValue ?? 0);\n }, [topInsetValue]);\n\n const combinedValue = {\n maxNumberOfFiles,\n selectedFiles,\n selectedImages,\n selectedPicker,\n setBottomInset,\n setMaxNumberOfFiles,\n setSelectedFiles,\n setSelectedImages,\n setSelectedPicker,\n setTopInset,\n ...value,\n bottomInset,\n topInset,\n };\n\n return (\n <AttachmentPickerContext.Provider\n value={combinedValue as unknown as AttachmentPickerContextValue}\n >\n {children}\n </AttachmentPickerContext.Provider>\n );\n};\n\nexport const useAttachmentPickerContext = () => {\n const contextValue = useContext(\n AttachmentPickerContext,\n ) as unknown as AttachmentPickerContextValue;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useAttachmentPickerContext hook was called outside the AttachmentPickerContext provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,\n );\n }\n\n return contextValue;\n};\n\nexport const withAttachmentPickerContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<StreamChatGenerics>,\n): React.FC<Omit<StreamChatGenerics, keyof AttachmentPickerContextValue>> => {\n const WithAttachmentPickerContextComponent = (\n props: Omit<StreamChatGenerics, keyof AttachmentPickerContextValue>,\n ) => {\n const attachmentPickerContext = useAttachmentPickerContext();\n\n return <Component {...(props as StreamChatGenerics)} {...attachmentPickerContext} />;\n };\n WithAttachmentPickerContextComponent.displayName = `WithAttachmentPickerContext${getDisplayName(\n Component as React.ComponentType,\n )}`;\n return WithAttachmentPickerContextComponent;\n};\n"]}
@@ -11,8 +11,12 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
11
11
 
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
 
14
+ var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
15
+
14
16
  var _getDisplayName = require("../utils/getDisplayName");
15
17
 
18
+ var _isTestEnvironment = require("../utils/isTestEnvironment");
19
+
16
20
  var _this = this,
17
21
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/channelContext/ChannelContext.tsx";
18
22
 
@@ -20,7 +24,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
20
24
 
21
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
26
 
23
- var ChannelContext = _react["default"].createContext({});
27
+ var ChannelContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
24
28
 
25
29
  exports.ChannelContext = ChannelContext;
26
30
 
@@ -32,7 +36,7 @@ var ChannelProvider = function ChannelProvider(_ref) {
32
36
  __self: _this,
33
37
  __source: {
34
38
  fileName: _jsxFileName,
35
- lineNumber: 180,
39
+ lineNumber: 185,
36
40
  columnNumber: 3
37
41
  }
38
42
  }, children);
@@ -41,7 +45,13 @@ var ChannelProvider = function ChannelProvider(_ref) {
41
45
  exports.ChannelProvider = ChannelProvider;
42
46
 
43
47
  var useChannelContext = function useChannelContext() {
44
- return (0, _react.useContext)(ChannelContext);
48
+ var contextValue = (0, _react.useContext)(ChannelContext);
49
+
50
+ if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
51
+ throw new Error("The useChannelContext hook was called outside of the ChannelContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel");
52
+ }
53
+
54
+ return contextValue;
45
55
  };
46
56
 
47
57
  exports.useChannelContext = useChannelContext;
@@ -53,7 +63,7 @@ var withChannelContext = function withChannelContext(Component) {
53
63
  __self: _this,
54
64
  __source: {
55
65
  fileName: _jsxFileName,
56
- lineNumber: 205,
66
+ lineNumber: 221,
57
67
  columnNumber: 12
58
68
  }
59
69
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["ChannelContext.tsx"],"names":["ChannelContext","React","createContext","ChannelProvider","children","value","useChannelContext","withChannelContext","Component","WithChannelContextComponent","props","channelContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAOA;;;;;;;;;AAkKO,IAAMA,cAAc,GAAGC,kBAAMC,aAAN,CAAoB,EAApB,CAAvB;;;;AAEA,IAAMC,eAAe,GAAG,SAAlBA,eAAkB;AAAA,MAG7BC,QAH6B,QAG7BA,QAH6B;AAAA,MAI7BC,KAJ6B,QAI7BA,KAJ6B;AAAA,SAQ7B,gCAAC,cAAD,CAAgB,QAAhB;AAAyB,IAAA,KAAK,EAAEA,KAAhC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KACGD,QADH,CAR6B;AAAA,CAAxB;;;;AAaA,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB;AAAA,SAE1B,uBAAWN,cAAX,CAF0B;AAAA,CAA1B;;;;AASA,IAAMO,kBAAkB,GAAG,SAArBA,kBAAqB,CAIhCC,SAJgC,EAKqC;AACrE,MAAMC,2BAA2B,GAAG,SAA9BA,2BAA8B,CAClCC,KADkC,EAE/B;AACH,QAAMC,cAAc,GAAGL,iBAAiB,EAAxC;AAEA,WAAO,gCAAC,SAAD,gCAAgBI,KAAhB,EAAiCC,cAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,2BAA2B,CAACG,WAA5B,0BAA+D,oCAAeJ,SAAf,CAA/D;AACA,SAAOC,2BAAP;AACD,CAfM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { Channel, ChannelState } from 'stream-chat';\n\nimport type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndicator';\nimport type { LoadingProps } from '../../components/Indicators/LoadingIndicator';\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { getDisplayName } from '../utils/getDisplayName';\n\nexport type ChannelContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * Instance of channel object from stream-chat package.\n *\n * Please check the docs around how to create or query channel - https://getstream.io/chat/docs/javascript/creating_channels/?language=javascript\n *\n * ```\n * import { StreamChat, Channel } from 'stream-chat';\n * import { Chat, Channel} from 'stream-chat-react-native';\n *\n * const client = StreamChat.getInstance('api_key');\n * await client.connectUser('user_id', 'user_token');\n * const channel = client.channel('messaging', 'channel_id');\n * await channel.watch();\n *\n * <Chat client={client}>\n * <Channel channel={channel}>\n * </Channel>\n * </Chat>\n * ```\n *\n * @overrideType Channel\n */\n channel: Channel<StreamChatGenerics>;\n /**\n * Custom UI component to display empty state when channel has no messages.\n *\n * **Default** [EmptyStateIndicator](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Indicators/EmptyStateIndicator.tsx)\n */\n EmptyStateIndicator: React.ComponentType<EmptyStateProps>;\n /**\n * When set to true, reactions will be limited to 1 per user. If user selects another reaction\n * then his previous reaction will be removed and replaced with new one.\n *\n * This is similar to reaction UX on [iMessage application](https://en.wikipedia.org/wiki/IMessage).\n */\n enforceUniqueReaction: boolean;\n error: boolean | Error;\n /**\n * When set to false, it will disable giphy command on MessageInput component.\n */\n giphyEnabled: boolean;\n /**\n * Hide inline date separators on channel\n */\n hideDateSeparators: boolean;\n hideStickyDateHeader: boolean;\n /**\n * Returns true if the current user has admin privileges\n */\n isAdmin: boolean;\n /**\n * Returns true if the current user is a moderator\n */\n isModerator: boolean;\n /**\n * Returns true if the current user is a owner\n */\n isOwner: boolean;\n loadChannelAtMessage: ({\n after,\n before,\n messageId,\n }: {\n after?: number;\n before?: number;\n messageId?: string;\n }) => Promise<void>;\n loading: boolean;\n /**\n * Custom loading indicator to override the Stream default\n */\n LoadingIndicator: React.ComponentType<LoadingProps>;\n markRead: () => void;\n /**\n *\n * ```json\n * {\n * \"thierry-123\": {\n * \"id\": \"thierry-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-04-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-04-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-04-16T11:23:51.168113408+02:00\",\n * \"online\": true\n * },\n * \"vishal-123\": {\n * \"id\": \"vishal-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-05-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-05-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-06-16T11:23:51.168113408+02:00\",\n * \"online\": false\n * }\n * }\n * ```\n */\n members: ChannelState<StreamChatGenerics>['members'];\n /**\n * Custom network down indicator to override the Stream default\n */\n NetworkDownIndicator: React.ComponentType;\n read: ChannelState<StreamChatGenerics>['read'];\n reloadChannel: () => Promise<void>;\n /**\n * When true, messagelist will be scrolled to first unread message, when opened.\n */\n scrollToFirstUnreadThreshold: number;\n setLastRead: React.Dispatch<React.SetStateAction<Date | undefined>>;\n setTargetedMessage: (messageId: string) => void;\n /**\n *\n * ```json\n * {\n * \"thierry-123\": {\n * \"id\": \"thierry-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-04-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-04-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-04-16T11:23:51.168113408+02:00\",\n * \"online\": true\n * },\n * \"vishal-123\": {\n * \"id\": \"vishal-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-05-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-05-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-06-16T11:23:51.168113408+02:00\",\n * \"online\": false\n * }\n * }\n * ```\n */\n watchers: ChannelState<StreamChatGenerics>['watchers'];\n disabled?: boolean;\n enableMessageGroupingByUser?: boolean;\n isChannelActive?: boolean;\n lastRead?: Date;\n /**\n * Maximum time in milliseconds that should occur between messages\n * to still consider them grouped together\n */\n maxTimeBetweenGroupedMessages?: number;\n /**\n * Custom UI component for sticky header of channel.\n *\n * **Default** [DateHeader](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageList/DateHeader.tsx)\n */\n StickyHeader?: React.ComponentType<{ dateString: string }>;\n /**\n * Id of message, around which Channel/MessageList gets loaded when opened.\n * You will see a highlighted background for targetted message, when opened.\n */\n targetedMessage?: string;\n threadList?: boolean;\n watcherCount?: ChannelState<StreamChatGenerics>['watcher_count'];\n};\n\nexport const ChannelContext = React.createContext({} as ChannelContextValue);\n\nexport const ChannelProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value: ChannelContextValue<StreamChatGenerics>;\n}>) => (\n <ChannelContext.Provider value={value as unknown as ChannelContextValue}>\n {children}\n </ChannelContext.Provider>\n);\n\nexport const useChannelContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => useContext(ChannelContext) as unknown as ChannelContextValue<StreamChatGenerics>;\n\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChannelContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChannelContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelContextValue<StreamChatGenerics>>> => {\n const WithChannelContextComponent = (\n props: Omit<P, keyof ChannelContextValue<StreamChatGenerics>>,\n ) => {\n const channelContext = useChannelContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelContext} />;\n };\n WithChannelContextComponent.displayName = `WithChannelContext${getDisplayName(Component)}`;\n return WithChannelContextComponent;\n};\n"]}
1
+ {"version":3,"sources":["ChannelContext.tsx"],"names":["ChannelContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","ChannelProvider","children","value","useChannelContext","contextValue","Error","withChannelContext","Component","WithChannelContextComponent","props","channelContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAOA;;AAEA;;AACA;;;;;;;;;AAkKO,IAAMA,cAAc,GAAGC,kBAAMC,aAAN,CAC5BC,mDAD4B,CAAvB;;;;AAIA,IAAMC,eAAe,GAAG,SAAlBA,eAAkB;AAAA,MAG7BC,QAH6B,QAG7BA,QAH6B;AAAA,MAI7BC,KAJ6B,QAI7BA,KAJ6B;AAAA,SAQ7B,gCAAC,cAAD,CAAgB,QAAhB;AAAyB,IAAA,KAAK,EAAEA,KAAhC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KACGD,QADH,CAR6B;AAAA,CAAxB;;;;AAaA,IAAME,iBAAiB,GAAG,SAApBA,iBAAoB,GAE1B;AACL,MAAMC,YAAY,GAAG,uBACnBR,cADmB,CAArB;;AAIA,MAAIQ,YAAY,KAAKL,mDAAjB,IAA+C,CAAC,2CAApD,EAAyE;AACvE,UAAM,IAAIM,KAAJ,8NAAN;AAGD;;AAED,SAAOD,YAAP;AACD,CAdM;;;;AAoBA,IAAME,kBAAkB,GAAG,SAArBA,kBAAqB,CAIhCC,SAJgC,EAKqC;AACrE,MAAMC,2BAA2B,GAAG,SAA9BA,2BAA8B,CAClCC,KADkC,EAE/B;AACH,QAAMC,cAAc,GAAGP,iBAAiB,EAAxC;AAEA,WAAO,gCAAC,SAAD,gCAAgBM,KAAhB,EAAiCC,cAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,2BAA2B,CAACG,WAA5B,0BAA+D,oCAAeJ,SAAf,CAA/D;AACA,SAAOC,2BAAP;AACD,CAfM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { Channel, ChannelState } from 'stream-chat';\n\nimport type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndicator';\nimport type { LoadingProps } from '../../components/Indicators/LoadingIndicator';\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type ChannelContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * Instance of channel object from stream-chat package.\n *\n * Please check the docs around how to create or query channel - https://getstream.io/chat/docs/javascript/creating_channels/?language=javascript\n *\n * ```\n * import { StreamChat, Channel } from 'stream-chat';\n * import { Chat, Channel} from 'stream-chat-react-native';\n *\n * const client = StreamChat.getInstance('api_key');\n * await client.connectUser('user_id', 'user_token');\n * const channel = client.channel('messaging', 'channel_id');\n * await channel.watch();\n *\n * <Chat client={client}>\n * <Channel channel={channel}>\n * </Channel>\n * </Chat>\n * ```\n *\n * @overrideType Channel\n */\n channel: Channel<StreamChatGenerics>;\n /**\n * Custom UI component to display empty state when channel has no messages.\n *\n * **Default** [EmptyStateIndicator](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/Indicators/EmptyStateIndicator.tsx)\n */\n EmptyStateIndicator: React.ComponentType<EmptyStateProps>;\n /**\n * When set to true, reactions will be limited to 1 per user. If user selects another reaction\n * then his previous reaction will be removed and replaced with new one.\n *\n * This is similar to reaction UX on [iMessage application](https://en.wikipedia.org/wiki/IMessage).\n */\n enforceUniqueReaction: boolean;\n error: boolean | Error;\n /**\n * When set to false, it will disable giphy command on MessageInput component.\n */\n giphyEnabled: boolean;\n /**\n * Hide inline date separators on channel\n */\n hideDateSeparators: boolean;\n hideStickyDateHeader: boolean;\n /**\n * Returns true if the current user has admin privileges\n */\n isAdmin: boolean;\n /**\n * Returns true if the current user is a moderator\n */\n isModerator: boolean;\n /**\n * Returns true if the current user is a owner\n */\n isOwner: boolean;\n loadChannelAtMessage: ({\n after,\n before,\n messageId,\n }: {\n after?: number;\n before?: number;\n messageId?: string;\n }) => Promise<void>;\n loading: boolean;\n /**\n * Custom loading indicator to override the Stream default\n */\n LoadingIndicator: React.ComponentType<LoadingProps>;\n markRead: () => void;\n /**\n *\n * ```json\n * {\n * \"thierry-123\": {\n * \"id\": \"thierry-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-04-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-04-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-04-16T11:23:51.168113408+02:00\",\n * \"online\": true\n * },\n * \"vishal-123\": {\n * \"id\": \"vishal-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-05-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-05-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-06-16T11:23:51.168113408+02:00\",\n * \"online\": false\n * }\n * }\n * ```\n */\n members: ChannelState<StreamChatGenerics>['members'];\n /**\n * Custom network down indicator to override the Stream default\n */\n NetworkDownIndicator: React.ComponentType;\n read: ChannelState<StreamChatGenerics>['read'];\n reloadChannel: () => Promise<void>;\n /**\n * When true, messagelist will be scrolled to first unread message, when opened.\n */\n scrollToFirstUnreadThreshold: number;\n setLastRead: React.Dispatch<React.SetStateAction<Date | undefined>>;\n setTargetedMessage: (messageId: string) => void;\n /**\n *\n * ```json\n * {\n * \"thierry-123\": {\n * \"id\": \"thierry-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-04-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-04-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-04-16T11:23:51.168113408+02:00\",\n * \"online\": true\n * },\n * \"vishal-123\": {\n * \"id\": \"vishal-123\",\n * \"role\": \"user\",\n * \"created_at\": \"2019-05-03T14:42:47.087869Z\",\n * \"updated_at\": \"2019-05-16T09:20:03.982283Z\",\n * \"last_active\": \"2019-06-16T11:23:51.168113408+02:00\",\n * \"online\": false\n * }\n * }\n * ```\n */\n watchers: ChannelState<StreamChatGenerics>['watchers'];\n disabled?: boolean;\n enableMessageGroupingByUser?: boolean;\n isChannelActive?: boolean;\n lastRead?: Date;\n /**\n * Maximum time in milliseconds that should occur between messages\n * to still consider them grouped together\n */\n maxTimeBetweenGroupedMessages?: number;\n /**\n * Custom UI component for sticky header of channel.\n *\n * **Default** [DateHeader](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageList/DateHeader.tsx)\n */\n StickyHeader?: React.ComponentType<{ dateString: string }>;\n /**\n * Id of message, around which Channel/MessageList gets loaded when opened.\n * You will see a highlighted background for targetted message, when opened.\n */\n targetedMessage?: string;\n threadList?: boolean;\n watcherCount?: ChannelState<StreamChatGenerics>['watcher_count'];\n};\n\nexport const ChannelContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as ChannelContextValue,\n);\n\nexport const ChannelProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value: ChannelContextValue<StreamChatGenerics>;\n}>) => (\n <ChannelContext.Provider value={value as unknown as ChannelContextValue}>\n {children}\n </ChannelContext.Provider>\n);\n\nexport const useChannelContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => {\n const contextValue = useContext(\n ChannelContext,\n ) as unknown as ChannelContextValue<StreamChatGenerics>;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useChannelContext hook was called outside of the ChannelContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,\n );\n }\n\n return contextValue;\n};\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChannelContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChannelContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelContextValue<StreamChatGenerics>>> => {\n const WithChannelContextComponent = (\n props: Omit<P, keyof ChannelContextValue<StreamChatGenerics>>,\n ) => {\n const channelContext = useChannelContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelContext} />;\n };\n WithChannelContextComponent.displayName = `WithChannelContext${getDisplayName(Component)}`;\n return WithChannelContextComponent;\n};\n"]}
@@ -11,8 +11,12 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
11
11
 
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
 
14
+ var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
15
+
14
16
  var _getDisplayName = require("../utils/getDisplayName");
15
17
 
18
+ var _isTestEnvironment = require("../utils/isTestEnvironment");
19
+
16
20
  var _this = this,
17
21
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/channelsContext/ChannelsContext.tsx";
18
22
 
@@ -20,7 +24,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
20
24
 
21
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
26
 
23
- var ChannelsContext = _react["default"].createContext({});
27
+ var ChannelsContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
24
28
 
25
29
  exports.ChannelsContext = ChannelsContext;
26
30
 
@@ -32,7 +36,7 @@ var ChannelsProvider = function ChannelsProvider(_ref) {
32
36
  __self: _this,
33
37
  __source: {
34
38
  fileName: _jsxFileName,
35
- lineNumber: 220,
39
+ lineNumber: 225,
36
40
  columnNumber: 3
37
41
  }
38
42
  }, children);
@@ -41,7 +45,13 @@ var ChannelsProvider = function ChannelsProvider(_ref) {
41
45
  exports.ChannelsProvider = ChannelsProvider;
42
46
 
43
47
  var useChannelsContext = function useChannelsContext() {
44
- return (0, _react.useContext)(ChannelsContext);
48
+ var contextValue = (0, _react.useContext)(ChannelsContext);
49
+
50
+ if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
51
+ throw new Error("The useChannelsContext hook was called outside of the ChannelsContext provider. Make sure you have configured ChannelList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel-list");
52
+ }
53
+
54
+ return contextValue;
45
55
  };
46
56
 
47
57
  exports.useChannelsContext = useChannelsContext;
@@ -53,7 +63,7 @@ var withChannelsContext = function withChannelsContext(Component) {
53
63
  __self: _this,
54
64
  __source: {
55
65
  fileName: _jsxFileName,
56
- lineNumber: 245,
66
+ lineNumber: 261,
57
67
  columnNumber: 12
58
68
  }
59
69
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["ChannelsContext.tsx"],"names":["ChannelsContext","React","createContext","ChannelsProvider","children","value","useChannelsContext","withChannelsContext","Component","WithChannelsContextComponent","props","channelsContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAqBA;;;;;;;;;AA4LO,IAAMA,eAAe,GAAGC,kBAAMC,aAAN,CAAoB,EAApB,CAAxB;;;;AAEA,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB;AAAA,MAG9BC,QAH8B,QAG9BA,QAH8B;AAAA,MAI9BC,KAJ8B,QAI9BA,KAJ8B;AAAA,SAQ9B,gCAAC,eAAD,CAAiB,QAAjB;AAA0B,IAAA,KAAK,EAAEA,KAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KACGD,QADH,CAR8B;AAAA,CAAzB;;;;AAaA,IAAME,kBAAkB,GAAG,SAArBA,kBAAqB;AAAA,SAE3B,uBAAWN,eAAX,CAF2B;AAAA,CAA3B;;;;AASA,IAAMO,mBAAmB,GAAG,SAAtBA,mBAAsB,CAIjCC,SAJiC,EAKqC;AACtE,MAAMC,4BAA4B,GAAG,SAA/BA,4BAA+B,CACnCC,KADmC,EAEhC;AACH,QAAMC,eAAe,GAAGL,kBAAkB,EAA1C;AAEA,WAAO,gCAAC,SAAD,gCAAgBI,KAAhB,EAAiCC,eAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,4BAA4B,CAACG,WAA7B,2BAAiE,oCAAeJ,SAAf,CAAjE;AACA,SAAOC,4BAAP;AACD,CAfM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { FlatListProps } from 'react-native';\nimport type { FlatList } from 'react-native-gesture-handler';\n\nimport type { ChannelPreviewMutedStatusProps } from 'src/components/ChannelPreview/ChannelPreviewMutedStatus';\n\nimport type { Channel } from 'stream-chat';\n\nimport type { HeaderErrorProps } from '../../components/ChannelList/ChannelListHeaderErrorIndicator';\nimport type { QueryChannels } from '../../components/ChannelList/hooks/usePaginatedChannels';\nimport type { ChannelAvatarProps } from '../../components/ChannelPreview/ChannelAvatar';\nimport type { ChannelPreviewMessageProps } from '../../components/ChannelPreview/ChannelPreviewMessage';\nimport type { ChannelPreviewMessengerProps } from '../../components/ChannelPreview/ChannelPreviewMessenger';\nimport type { ChannelPreviewStatusProps } from '../../components/ChannelPreview/ChannelPreviewStatus';\nimport type { ChannelPreviewTitleProps } from '../../components/ChannelPreview/ChannelPreviewTitle';\nimport type { ChannelPreviewUnreadCountProps } from '../../components/ChannelPreview/ChannelPreviewUnreadCount';\nimport type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndicator';\nimport type { LoadingErrorProps } from '../../components/Indicators/LoadingErrorIndicator';\nimport type { LoadingProps } from '../../components/Indicators/LoadingIndicator';\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { getDisplayName } from '../utils/getDisplayName';\n\nexport type ChannelsContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * Besides the existing default behavior of the ChannelListMessenger component, you can attach\n * additional props to the underlying React Native FlatList.\n *\n * You can find list of all the available FlatList props here - https://facebook.github.io/react-native/docs/flatlist#props\n *\n * **EXAMPLE:**\n *\n * ```\n * <ChannelListMessenger\n * channels={channels}\n * additionalFlatListProps={{ bounces: true }}\n * />\n * ```\n *\n * **Note:** Don't use `additionalFlatListProps` to access the FlatList ref, use `setFlatListRef`\n */\n additionalFlatListProps: Partial<FlatListProps<Channel<StreamChatGenerics>>>;\n /**\n * Channels can be either an array of channels or a promise which resolves to an array of channels\n */\n channels: Channel<StreamChatGenerics>[];\n /**\n * Custom indicator to use when channel list is empty\n *\n * Default: [EmptyStateIndicator](https://getstream.github.io/stream-chat-react-native/v3/#emptystateindicator)\n * */\n EmptyStateIndicator: React.ComponentType<EmptyStateProps>;\n /**\n * Custom loading indicator to display at bottom of the list, while loading further pages\n *\n * Default: [ChannelListFooterLoadingIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListFooterLoadingIndicator)\n */\n FooterLoadingIndicator: React.ComponentType;\n /**\n * Incremental number change to force update the FlatList\n */\n forceUpdate: number;\n /**\n * Whether or not the FlatList has another page to render\n */\n hasNextPage: boolean;\n /**\n * Custom indicator to display error at top of list, if loading/pagination error occurs\n *\n * Default: [ChannelListHeaderErrorIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListHeaderErrorIndicator)\n */\n HeaderErrorIndicator: React.ComponentType<HeaderErrorProps>;\n /**\n * Custom indicator to display network-down error at top of list, if there is connectivity issue\n *\n * Default: [ChannelListHeaderNetworkDownIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListHeaderNetworkDownIndicator)\n */\n HeaderNetworkDownIndicator: React.ComponentType;\n /**\n * Initial channels query loading state, triggers the LoadingIndicator\n */\n loadingChannels: boolean;\n /**\n * Custom indicator to use when there is error in fetching channels\n *\n * Default: [LoadingErrorIndicator](https://getstream.github.io/stream-chat-react-native/v3/#loadingerrorindicator)\n * */\n LoadingErrorIndicator: React.ComponentType<LoadingErrorProps>;\n /**\n * Custom loading indicator to use on Channel List\n *\n * */\n LoadingIndicator: React.ComponentType<Pick<LoadingProps, 'listType'>>;\n /**\n * Whether or not additional channels are being loaded, triggers the FooterLoadingIndicator\n */\n loadingNextPage: boolean;\n /**\n * The React Native FlatList threshold to fetch more data\n * @see See loadMoreThreshold [doc](https://facebook.github.io/react-native/docs/flatlist#onendreachedthreshold)\n * */\n loadMoreThreshold: number;\n /**\n * Loads the next page of `channels`, which is present as a required prop\n */\n loadNextPage: QueryChannels | undefined;\n /**\n * Max number to display within notification badge. Default: 255 and it cannot be higher than that for now due to backend limitations\n */\n maxUnreadCount: number;\n /**\n * Number of skeletons that should show when loading. Default: 6\n */\n numberOfSkeletons: number;\n /**\n * Custom UI component to display individual channel list items\n *\n * Default: [ChannelPreviewMessenger](https://getstream.github.io/stream-chat-react-native/v3/#channelpreviewmessenger)\n */\n Preview: React.ComponentType<ChannelPreviewMessengerProps<StreamChatGenerics>>;\n /**\n * Triggered when the channel list is refreshing, displays a loading spinner at the top of the list\n */\n refreshing: boolean;\n /**\n * Function to refresh the channel list that is similar to `reloadList`, but it doesn't wipe out existing channels\n * from UI before loading the new ones\n */\n refreshList: () => void | Promise<void>;\n /**\n * Removes all the existing channels from UI and loads fresh channels\n * */\n reloadList: () => Promise<void>;\n // /**\n // * Function to set the currently active channel, acts as a bridge between ChannelList and Channel components\n // *\n // * @param channel A channel object\n // */\n // setActiveChannel?: (channel: Channel<StreamChatGenerics>) => void;\n /**\n * Function to gain access to the inner FlatList ref\n *\n * **Example:**\n *\n * ```\n * <ChannelListMessenger\n * setFlatListRef={(ref) => {\n * // Use ref for your own good\n * }}\n * ```\n */\n setFlatListRef: (ref: FlatList<Channel<StreamChatGenerics>> | null) => void;\n /**\n * Custom UI component to display loading channel skeletons\n *\n * Default: [Skeleton](https://getstream.github.io/stream-chat-react-native/v3/#skeleton)\n */\n Skeleton: React.ComponentType;\n /**\n * Error in channels query, if any\n */\n error?: Error;\n ListHeaderComponent?: React.ComponentType;\n /**\n * Function to set the currently active channel, acts as a bridge between ChannelList and Channel components\n *\n * @param channel A channel object\n */\n onSelect?: (channel: Channel<StreamChatGenerics>) => void;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelAvatar](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelAvatar.tsx)\n */\n PreviewAvatar?: React.ComponentType<ChannelAvatarProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview of latest message on channel.\n *\n * **Default** [ChannelPreviewMessage](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewMessage.tsx)\n */\n PreviewMessage?: React.ComponentType<ChannelPreviewMessageProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render muted status.\n *\n * **Default** [ChannelMutedStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewMutedStatus.tsx)\n */\n PreviewMutedStatus?: React.ComponentType<ChannelPreviewMutedStatusProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewStatus.tsx)\n */\n PreviewStatus?: React.ComponentType<ChannelPreviewStatusProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewTitle](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewTitle.tsx)\n */\n PreviewTitle?: React.ComponentType<ChannelPreviewTitleProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewUnreadCount](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewUnreadCount.tsx)\n */\n PreviewUnreadCount?: React.ComponentType<ChannelPreviewUnreadCountProps<StreamChatGenerics>>;\n};\n\nexport const ChannelsContext = React.createContext({} as ChannelsContextValue);\n\nexport const ChannelsProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value: ChannelsContextValue<StreamChatGenerics>;\n}>) => (\n <ChannelsContext.Provider value={value as unknown as ChannelsContextValue}>\n {children}\n </ChannelsContext.Provider>\n);\n\nexport const useChannelsContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => useContext(ChannelsContext) as unknown as ChannelsContextValue<StreamChatGenerics>;\n\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChannelContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChannelsContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelsContextValue<StreamChatGenerics>>> => {\n const WithChannelsContextComponent = (\n props: Omit<P, keyof ChannelsContextValue<StreamChatGenerics>>,\n ) => {\n const channelsContext = useChannelsContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelsContext} />;\n };\n WithChannelsContextComponent.displayName = `WithChannelsContext${getDisplayName(Component)}`;\n return WithChannelsContextComponent;\n};\n"]}
1
+ {"version":3,"sources":["ChannelsContext.tsx"],"names":["ChannelsContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","ChannelsProvider","children","value","useChannelsContext","contextValue","Error","withChannelsContext","Component","WithChannelsContextComponent","props","channelsContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAqBA;;AAEA;;AACA;;;;;;;;;AA4LO,IAAMA,eAAe,GAAGC,kBAAMC,aAAN,CAC7BC,mDAD6B,CAAxB;;;;AAIA,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB;AAAA,MAG9BC,QAH8B,QAG9BA,QAH8B;AAAA,MAI9BC,KAJ8B,QAI9BA,KAJ8B;AAAA,SAQ9B,gCAAC,eAAD,CAAiB,QAAjB;AAA0B,IAAA,KAAK,EAAEA,KAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KACGD,QADH,CAR8B;AAAA,CAAzB;;;;AAaA,IAAME,kBAAkB,GAAG,SAArBA,kBAAqB,GAE3B;AACL,MAAMC,YAAY,GAAG,uBACnBR,eADmB,CAArB;;AAIA,MAAIQ,YAAY,KAAKL,mDAAjB,IAA+C,CAAC,2CAApD,EAAyE;AACvE,UAAM,IAAIM,KAAJ,yOAAN;AAGD;;AAED,SAAOD,YAAP;AACD,CAdM;;;;AAoBA,IAAME,mBAAmB,GAAG,SAAtBA,mBAAsB,CAIjCC,SAJiC,EAKqC;AACtE,MAAMC,4BAA4B,GAAG,SAA/BA,4BAA+B,CACnCC,KADmC,EAEhC;AACH,QAAMC,eAAe,GAAGP,kBAAkB,EAA1C;AAEA,WAAO,gCAAC,SAAD,gCAAgBM,KAAhB,EAAiCC,eAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,4BAA4B,CAACG,WAA7B,2BAAiE,oCAAeJ,SAAf,CAAjE;AACA,SAAOC,4BAAP;AACD,CAfM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { FlatListProps } from 'react-native';\nimport type { FlatList } from 'react-native-gesture-handler';\n\nimport type { ChannelPreviewMutedStatusProps } from 'src/components/ChannelPreview/ChannelPreviewMutedStatus';\n\nimport type { Channel } from 'stream-chat';\n\nimport type { HeaderErrorProps } from '../../components/ChannelList/ChannelListHeaderErrorIndicator';\nimport type { QueryChannels } from '../../components/ChannelList/hooks/usePaginatedChannels';\nimport type { ChannelAvatarProps } from '../../components/ChannelPreview/ChannelAvatar';\nimport type { ChannelPreviewMessageProps } from '../../components/ChannelPreview/ChannelPreviewMessage';\nimport type { ChannelPreviewMessengerProps } from '../../components/ChannelPreview/ChannelPreviewMessenger';\nimport type { ChannelPreviewStatusProps } from '../../components/ChannelPreview/ChannelPreviewStatus';\nimport type { ChannelPreviewTitleProps } from '../../components/ChannelPreview/ChannelPreviewTitle';\nimport type { ChannelPreviewUnreadCountProps } from '../../components/ChannelPreview/ChannelPreviewUnreadCount';\nimport type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndicator';\nimport type { LoadingErrorProps } from '../../components/Indicators/LoadingErrorIndicator';\nimport type { LoadingProps } from '../../components/Indicators/LoadingIndicator';\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type ChannelsContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * Besides the existing default behavior of the ChannelListMessenger component, you can attach\n * additional props to the underlying React Native FlatList.\n *\n * You can find list of all the available FlatList props here - https://facebook.github.io/react-native/docs/flatlist#props\n *\n * **EXAMPLE:**\n *\n * ```\n * <ChannelListMessenger\n * channels={channels}\n * additionalFlatListProps={{ bounces: true }}\n * />\n * ```\n *\n * **Note:** Don't use `additionalFlatListProps` to access the FlatList ref, use `setFlatListRef`\n */\n additionalFlatListProps: Partial<FlatListProps<Channel<StreamChatGenerics>>>;\n /**\n * Channels can be either an array of channels or a promise which resolves to an array of channels\n */\n channels: Channel<StreamChatGenerics>[];\n /**\n * Custom indicator to use when channel list is empty\n *\n * Default: [EmptyStateIndicator](https://getstream.github.io/stream-chat-react-native/v3/#emptystateindicator)\n * */\n EmptyStateIndicator: React.ComponentType<EmptyStateProps>;\n /**\n * Custom loading indicator to display at bottom of the list, while loading further pages\n *\n * Default: [ChannelListFooterLoadingIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListFooterLoadingIndicator)\n */\n FooterLoadingIndicator: React.ComponentType;\n /**\n * Incremental number change to force update the FlatList\n */\n forceUpdate: number;\n /**\n * Whether or not the FlatList has another page to render\n */\n hasNextPage: boolean;\n /**\n * Custom indicator to display error at top of list, if loading/pagination error occurs\n *\n * Default: [ChannelListHeaderErrorIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListHeaderErrorIndicator)\n */\n HeaderErrorIndicator: React.ComponentType<HeaderErrorProps>;\n /**\n * Custom indicator to display network-down error at top of list, if there is connectivity issue\n *\n * Default: [ChannelListHeaderNetworkDownIndicator](https://getstream.github.io/stream-chat-react-native/v3/#ChannelListHeaderNetworkDownIndicator)\n */\n HeaderNetworkDownIndicator: React.ComponentType;\n /**\n * Initial channels query loading state, triggers the LoadingIndicator\n */\n loadingChannels: boolean;\n /**\n * Custom indicator to use when there is error in fetching channels\n *\n * Default: [LoadingErrorIndicator](https://getstream.github.io/stream-chat-react-native/v3/#loadingerrorindicator)\n * */\n LoadingErrorIndicator: React.ComponentType<LoadingErrorProps>;\n /**\n * Custom loading indicator to use on Channel List\n *\n * */\n LoadingIndicator: React.ComponentType<Pick<LoadingProps, 'listType'>>;\n /**\n * Whether or not additional channels are being loaded, triggers the FooterLoadingIndicator\n */\n loadingNextPage: boolean;\n /**\n * The React Native FlatList threshold to fetch more data\n * @see See loadMoreThreshold [doc](https://facebook.github.io/react-native/docs/flatlist#onendreachedthreshold)\n * */\n loadMoreThreshold: number;\n /**\n * Loads the next page of `channels`, which is present as a required prop\n */\n loadNextPage: QueryChannels | undefined;\n /**\n * Max number to display within notification badge. Default: 255 and it cannot be higher than that for now due to backend limitations\n */\n maxUnreadCount: number;\n /**\n * Number of skeletons that should show when loading. Default: 6\n */\n numberOfSkeletons: number;\n /**\n * Custom UI component to display individual channel list items\n *\n * Default: [ChannelPreviewMessenger](https://getstream.github.io/stream-chat-react-native/v3/#channelpreviewmessenger)\n */\n Preview: React.ComponentType<ChannelPreviewMessengerProps<StreamChatGenerics>>;\n /**\n * Triggered when the channel list is refreshing, displays a loading spinner at the top of the list\n */\n refreshing: boolean;\n /**\n * Function to refresh the channel list that is similar to `reloadList`, but it doesn't wipe out existing channels\n * from UI before loading the new ones\n */\n refreshList: () => void | Promise<void>;\n /**\n * Removes all the existing channels from UI and loads fresh channels\n * */\n reloadList: () => Promise<void>;\n // /**\n // * Function to set the currently active channel, acts as a bridge between ChannelList and Channel components\n // *\n // * @param channel A channel object\n // */\n // setActiveChannel?: (channel: Channel<StreamChatGenerics>) => void;\n /**\n * Function to gain access to the inner FlatList ref\n *\n * **Example:**\n *\n * ```\n * <ChannelListMessenger\n * setFlatListRef={(ref) => {\n * // Use ref for your own good\n * }}\n * ```\n */\n setFlatListRef: (ref: FlatList<Channel<StreamChatGenerics>> | null) => void;\n /**\n * Custom UI component to display loading channel skeletons\n *\n * Default: [Skeleton](https://getstream.github.io/stream-chat-react-native/v3/#skeleton)\n */\n Skeleton: React.ComponentType;\n /**\n * Error in channels query, if any\n */\n error?: Error;\n ListHeaderComponent?: React.ComponentType;\n /**\n * Function to set the currently active channel, acts as a bridge between ChannelList and Channel components\n *\n * @param channel A channel object\n */\n onSelect?: (channel: Channel<StreamChatGenerics>) => void;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelAvatar](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelAvatar.tsx)\n */\n PreviewAvatar?: React.ComponentType<ChannelAvatarProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview of latest message on channel.\n *\n * **Default** [ChannelPreviewMessage](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewMessage.tsx)\n */\n PreviewMessage?: React.ComponentType<ChannelPreviewMessageProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render muted status.\n *\n * **Default** [ChannelMutedStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewMutedStatus.tsx)\n */\n PreviewMutedStatus?: React.ComponentType<ChannelPreviewMutedStatusProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewStatus](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewStatus.tsx)\n */\n PreviewStatus?: React.ComponentType<ChannelPreviewStatusProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewTitle](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewTitle.tsx)\n */\n PreviewTitle?: React.ComponentType<ChannelPreviewTitleProps<StreamChatGenerics>>;\n /**\n * Custom UI component to render preview avatar.\n *\n * **Default** [ChannelPreviewUnreadCount](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/ChannelPreview/ChannelPreviewUnreadCount.tsx)\n */\n PreviewUnreadCount?: React.ComponentType<ChannelPreviewUnreadCountProps<StreamChatGenerics>>;\n};\n\nexport const ChannelsContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as ChannelsContextValue,\n);\n\nexport const ChannelsProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value: ChannelsContextValue<StreamChatGenerics>;\n}>) => (\n <ChannelsContext.Provider value={value as unknown as ChannelsContextValue}>\n {children}\n </ChannelsContext.Provider>\n);\n\nexport const useChannelsContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => {\n const contextValue = useContext(\n ChannelsContext,\n ) as unknown as ChannelsContextValue<StreamChatGenerics>;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useChannelsContext hook was called outside of the ChannelsContext provider. Make sure you have configured ChannelList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel-list`,\n );\n }\n\n return contextValue;\n};\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChannelContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChannelsContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelsContextValue<StreamChatGenerics>>> => {\n const WithChannelsContextComponent = (\n props: Omit<P, keyof ChannelsContextValue<StreamChatGenerics>>,\n ) => {\n const channelsContext = useChannelsContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelsContext} />;\n };\n WithChannelsContextComponent.displayName = `WithChannelsContext${getDisplayName(Component)}`;\n return WithChannelsContextComponent;\n};\n"]}
@@ -17,8 +17,12 @@ var _react = _interopRequireWildcard(require("react"));
17
17
 
18
18
  var _ActiveChannelsRefContext = require("../activeChannelsRefContext/ActiveChannelsRefContext");
19
19
 
20
+ var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
21
+
20
22
  var _getDisplayName = require("../utils/getDisplayName");
21
23
 
24
+ var _isTestEnvironment = require("../utils/isTestEnvironment");
25
+
22
26
  var _this = this,
23
27
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/channelsStateContext/ChannelsStateContext.tsx";
24
28
 
@@ -63,11 +67,7 @@ function reducer(state, action) {
63
67
  }
64
68
  }
65
69
 
66
- var ChannelsStateContext = _react["default"].createContext({
67
- removeChannelState: function removeChannelState() {},
68
- setState: function setState() {},
69
- state: {}
70
- });
70
+ var ChannelsStateContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
71
71
 
72
72
  var ChannelsStateProvider = function ChannelsStateProvider(_ref) {
73
73
  var children = _ref.children;
@@ -112,7 +112,7 @@ var ChannelsStateProvider = function ChannelsStateProvider(_ref) {
112
112
  __self: _this,
113
113
  __source: {
114
114
  fileName: _jsxFileName,
115
- lineNumber: 182,
115
+ lineNumber: 179,
116
116
  columnNumber: 5
117
117
  }
118
118
  }, _react["default"].createElement(_ActiveChannelsRefContext.ActiveChannelsProvider, {
@@ -120,7 +120,7 @@ var ChannelsStateProvider = function ChannelsStateProvider(_ref) {
120
120
  __self: _this,
121
121
  __source: {
122
122
  fileName: _jsxFileName,
123
- lineNumber: 183,
123
+ lineNumber: 180,
124
124
  columnNumber: 7
125
125
  }
126
126
  }, children));
@@ -129,7 +129,13 @@ var ChannelsStateProvider = function ChannelsStateProvider(_ref) {
129
129
  exports.ChannelsStateProvider = ChannelsStateProvider;
130
130
 
131
131
  var useChannelsStateContext = function useChannelsStateContext() {
132
- return (0, _react.useContext)(ChannelsStateContext);
132
+ var contextValue = (0, _react.useContext)(ChannelsStateContext);
133
+
134
+ if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
135
+ throw new Error("The useChannelStateContext hook was called outside the ChannelStateContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider");
136
+ }
137
+
138
+ return contextValue;
133
139
  };
134
140
 
135
141
  exports.useChannelsStateContext = useChannelsStateContext;
@@ -141,7 +147,7 @@ var withChannelsStateContext = function withChannelsStateContext(Component) {
141
147
  __self: _this,
142
148
  __source: {
143
149
  fileName: _jsxFileName,
144
- lineNumber: 203,
150
+ lineNumber: 212,
145
151
  columnNumber: 12
146
152
  }
147
153
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["ChannelsStateContext.tsx"],"names":["reducer","state","action","type","payload","cid","key","value","currentCount","subscriberCount","stateShallowCopy","Error","ChannelsStateContext","React","createContext","removeChannelState","setState","ChannelsStateProvider","children","dispatch","increaseSubscriberCount","decreaseSubscriberCount","activeChannelsRef","Object","keys","current","useChannelsStateContext","withChannelsStateContext","Component","WithChannelsStateContextComponent","props","channelsStateContext","displayName"],"mappings":"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","sourcesContent":["import React, {\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useReducer,\n useRef,\n} from 'react';\n\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { ActiveChannelsProvider } from '../activeChannelsRefContext/ActiveChannelsRefContext';\n\nimport type { ChannelContextValue } from '../channelContext/ChannelContext';\nimport type { PaginatedMessageListContextValue } from '../paginatedMessageListContext/PaginatedMessageListContext';\nimport type { ThreadContextValue } from '../threadContext/ThreadContext';\nimport type { TypingContextValue } from '../typingContext/TypingContext';\nimport { getDisplayName } from '../utils/getDisplayName';\n\nexport type ChannelState<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n members: ChannelContextValue<StreamChatGenerics>['members'];\n messages: PaginatedMessageListContextValue<StreamChatGenerics>['messages'];\n read: ChannelContextValue<StreamChatGenerics>['read'];\n subscriberCount: number;\n threadMessages: ThreadContextValue<StreamChatGenerics>['threadMessages'];\n typing: TypingContextValue<StreamChatGenerics>['typing'];\n watcherCount: ChannelContextValue<StreamChatGenerics>['watcherCount'];\n watchers: ChannelContextValue<StreamChatGenerics>['watchers'];\n};\n\ntype ChannelsState<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n [cid: string]: ChannelState<StreamChatGenerics>;\n};\n\nexport type Keys = keyof ChannelState;\n\nexport type Payload<\n Key extends Keys = Keys,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n cid: string;\n key: Key;\n value: ChannelState<StreamChatGenerics>[Key];\n};\n\ntype SetStateAction<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n payload: Payload<Keys, StreamChatGenerics>;\n type: 'SET_STATE';\n};\n\ntype IncreaseSubscriberCountAction = {\n payload: { cid: string };\n type: 'INCREASE_SUBSCRIBER_COUNT';\n};\ntype DecreaseSubscriberCountAction = {\n payload: { cid: string };\n type: 'DECREASE_SUBSCRIBER_COUNT';\n};\n\ntype Action<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =\n | SetStateAction<StreamChatGenerics>\n | IncreaseSubscriberCountAction\n | DecreaseSubscriberCountAction;\n\nexport type ChannelsStateContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n decreaseSubscriberCount: (value: { cid: string }) => void;\n increaseSubscriberCount: (value: { cid: string }) => void;\n setState: (value: Payload<Keys, StreamChatGenerics>) => void;\n state: ChannelsState<StreamChatGenerics>;\n};\n\ntype Reducer<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = (\n state: ChannelsState<StreamChatGenerics>,\n action: Action<StreamChatGenerics>,\n) => ChannelsState<StreamChatGenerics>;\n\nfunction reducer(state: ChannelsState, action: Action) {\n switch (action.type) {\n case 'SET_STATE':\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n [action.payload.key]: action.payload.value,\n },\n };\n\n case 'INCREASE_SUBSCRIBER_COUNT': {\n const currentCount = state[action.payload.cid]?.subscriberCount ?? 0;\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n subscriberCount: currentCount + 1,\n },\n };\n }\n\n case 'DECREASE_SUBSCRIBER_COUNT': {\n const currentCount = state[action.payload.cid]?.subscriberCount ?? 0;\n\n // If there last subscribed Channel component unsubscribes, we clear the channel state.\n if (currentCount <= 1) {\n const stateShallowCopy = {\n ...state,\n };\n\n delete stateShallowCopy[action.payload.cid];\n\n return stateShallowCopy;\n }\n\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n subscriberCount: currentCount - 1,\n },\n };\n }\n default:\n throw new Error();\n }\n}\n\nconst ChannelsStateContext = React.createContext({\n removeChannelState: () => {\n // do nothing.\n },\n setState: () => {\n // do nothing.\n },\n state: {},\n} as unknown as ChannelsStateContextValue);\n\nexport const ChannelsStateProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n}: {\n children: ReactNode;\n}) => {\n const [state, dispatch] = useReducer(reducer as unknown as Reducer<StreamChatGenerics>, {});\n\n const setState = useCallback((payload: Payload<Keys, StreamChatGenerics>) => {\n dispatch({ payload, type: 'SET_STATE' });\n }, []);\n\n const increaseSubscriberCount = useCallback((payload: { cid: string }) => {\n dispatch({ payload, type: 'INCREASE_SUBSCRIBER_COUNT' });\n }, []);\n\n const decreaseSubscriberCount = useCallback((payload: { cid: string }) => {\n dispatch({ payload, type: 'DECREASE_SUBSCRIBER_COUNT' });\n }, []);\n\n const value = useMemo(\n () => ({\n decreaseSubscriberCount,\n increaseSubscriberCount,\n setState,\n state,\n }),\n [state],\n );\n\n const activeChannelsRef = useRef(Object.keys(state));\n\n useEffect(() => {\n activeChannelsRef.current = Object.keys(state);\n }, [state]);\n\n return (\n <ChannelsStateContext.Provider value={value as unknown as ChannelsStateContextValue}>\n <ActiveChannelsProvider value={activeChannelsRef}>{children}</ActiveChannelsProvider>\n </ChannelsStateContext.Provider>\n );\n};\n\nexport const useChannelsStateContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => useContext(ChannelsStateContext) as unknown as ChannelsStateContextValue<StreamChatGenerics>;\n\nexport const withChannelsStateContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelsStateContextValue<StreamChatGenerics>>> => {\n const WithChannelsStateContextComponent = (\n props: Omit<P, keyof ChannelsStateContextValue<StreamChatGenerics>>,\n ) => {\n const channelsStateContext = useChannelsStateContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelsStateContext} />;\n };\n WithChannelsStateContextComponent.displayName = `WithChannelsStateContext${getDisplayName(\n Component,\n )}`;\n return WithChannelsStateContextComponent;\n};\n"]}
1
+ {"version":3,"sources":["ChannelsStateContext.tsx"],"names":["reducer","state","action","type","payload","cid","key","value","currentCount","subscriberCount","stateShallowCopy","Error","ChannelsStateContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","ChannelsStateProvider","children","dispatch","setState","increaseSubscriberCount","decreaseSubscriberCount","activeChannelsRef","Object","keys","current","useChannelsStateContext","contextValue","withChannelsStateContext","Component","WithChannelsStateContextComponent","props","channelsStateContext","displayName"],"mappings":"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","sourcesContent":["import React, {\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useReducer,\n useRef,\n} from 'react';\n\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { ActiveChannelsProvider } from '../activeChannelsRefContext/ActiveChannelsRefContext';\n\nimport type { ChannelContextValue } from '../channelContext/ChannelContext';\nimport type { PaginatedMessageListContextValue } from '../paginatedMessageListContext/PaginatedMessageListContext';\nimport type { ThreadContextValue } from '../threadContext/ThreadContext';\nimport type { TypingContextValue } from '../typingContext/TypingContext';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type ChannelState<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n members: ChannelContextValue<StreamChatGenerics>['members'];\n messages: PaginatedMessageListContextValue<StreamChatGenerics>['messages'];\n read: ChannelContextValue<StreamChatGenerics>['read'];\n subscriberCount: number;\n threadMessages: ThreadContextValue<StreamChatGenerics>['threadMessages'];\n typing: TypingContextValue<StreamChatGenerics>['typing'];\n watcherCount: ChannelContextValue<StreamChatGenerics>['watcherCount'];\n watchers: ChannelContextValue<StreamChatGenerics>['watchers'];\n};\n\ntype ChannelsState<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n [cid: string]: ChannelState<StreamChatGenerics>;\n};\n\nexport type Keys = keyof ChannelState;\n\nexport type Payload<\n Key extends Keys = Keys,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n cid: string;\n key: Key;\n value: ChannelState<StreamChatGenerics>[Key];\n};\n\ntype SetStateAction<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n payload: Payload<Keys, StreamChatGenerics>;\n type: 'SET_STATE';\n};\n\ntype IncreaseSubscriberCountAction = {\n payload: { cid: string };\n type: 'INCREASE_SUBSCRIBER_COUNT';\n};\ntype DecreaseSubscriberCountAction = {\n payload: { cid: string };\n type: 'DECREASE_SUBSCRIBER_COUNT';\n};\n\ntype Action<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =\n | SetStateAction<StreamChatGenerics>\n | IncreaseSubscriberCountAction\n | DecreaseSubscriberCountAction;\n\nexport type ChannelsStateContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n decreaseSubscriberCount: (value: { cid: string }) => void;\n increaseSubscriberCount: (value: { cid: string }) => void;\n setState: (value: Payload<Keys, StreamChatGenerics>) => void;\n state: ChannelsState<StreamChatGenerics>;\n};\n\ntype Reducer<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = (\n state: ChannelsState<StreamChatGenerics>,\n action: Action<StreamChatGenerics>,\n) => ChannelsState<StreamChatGenerics>;\n\nfunction reducer(state: ChannelsState, action: Action) {\n switch (action.type) {\n case 'SET_STATE':\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n [action.payload.key]: action.payload.value,\n },\n };\n\n case 'INCREASE_SUBSCRIBER_COUNT': {\n const currentCount = state[action.payload.cid]?.subscriberCount ?? 0;\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n subscriberCount: currentCount + 1,\n },\n };\n }\n\n case 'DECREASE_SUBSCRIBER_COUNT': {\n const currentCount = state[action.payload.cid]?.subscriberCount ?? 0;\n\n // If there last subscribed Channel component unsubscribes, we clear the channel state.\n if (currentCount <= 1) {\n const stateShallowCopy = {\n ...state,\n };\n\n delete stateShallowCopy[action.payload.cid];\n\n return stateShallowCopy;\n }\n\n return {\n ...state,\n [action.payload.cid]: {\n ...(state[action.payload.cid] || {}),\n subscriberCount: currentCount - 1,\n },\n };\n }\n default:\n throw new Error();\n }\n}\n\nconst ChannelsStateContext = React.createContext(\n DEFAULT_BASE_CONTEXT_VALUE as ChannelsStateContextValue,\n);\n\nexport const ChannelsStateProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n}: {\n children: ReactNode;\n}) => {\n const [state, dispatch] = useReducer(reducer as unknown as Reducer<StreamChatGenerics>, {});\n\n const setState = useCallback((payload: Payload<Keys, StreamChatGenerics>) => {\n dispatch({ payload, type: 'SET_STATE' });\n }, []);\n\n const increaseSubscriberCount = useCallback((payload: { cid: string }) => {\n dispatch({ payload, type: 'INCREASE_SUBSCRIBER_COUNT' });\n }, []);\n\n const decreaseSubscriberCount = useCallback((payload: { cid: string }) => {\n dispatch({ payload, type: 'DECREASE_SUBSCRIBER_COUNT' });\n }, []);\n\n const value = useMemo(\n () => ({\n decreaseSubscriberCount,\n increaseSubscriberCount,\n setState,\n state,\n }),\n [state],\n );\n\n const activeChannelsRef = useRef(Object.keys(state));\n\n useEffect(() => {\n activeChannelsRef.current = Object.keys(state);\n }, [state]);\n\n return (\n <ChannelsStateContext.Provider value={value as unknown as ChannelsStateContextValue}>\n <ActiveChannelsProvider value={activeChannelsRef}>{children}</ActiveChannelsProvider>\n </ChannelsStateContext.Provider>\n );\n};\n\nexport const useChannelsStateContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => {\n const contextValue = useContext(\n ChannelsStateContext,\n ) as unknown as ChannelsStateContextValue<StreamChatGenerics>;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useChannelStateContext hook was called outside the ChannelStateContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,\n );\n }\n\n return contextValue;\n};\n\nexport const withChannelsStateContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChannelsStateContextValue<StreamChatGenerics>>> => {\n const WithChannelsStateContextComponent = (\n props: Omit<P, keyof ChannelsStateContextValue<StreamChatGenerics>>,\n ) => {\n const channelsStateContext = useChannelsStateContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...channelsStateContext} />;\n };\n WithChannelsStateContextComponent.displayName = `WithChannelsStateContext${getDisplayName(\n Component,\n )}`;\n return WithChannelsStateContextComponent;\n};\n"]}
@@ -11,8 +11,12 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
11
11
 
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
 
14
+ var _defaultBaseContextValue = require("../utils/defaultBaseContextValue");
15
+
14
16
  var _getDisplayName = require("../utils/getDisplayName");
15
17
 
18
+ var _isTestEnvironment = require("../utils/isTestEnvironment");
19
+
16
20
  var _this = this,
17
21
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/contexts/chatContext/ChatContext.tsx";
18
22
 
@@ -20,7 +24,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
20
24
 
21
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
26
 
23
- var ChatContext = _react["default"].createContext({});
27
+ var ChatContext = _react["default"].createContext(_defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE);
24
28
 
25
29
  exports.ChatContext = ChatContext;
26
30
 
@@ -32,7 +36,7 @@ var ChatProvider = function ChatProvider(_ref) {
32
36
  __self: _this,
33
37
  __source: {
34
38
  fileName: _jsxFileName,
35
- lineNumber: 71,
39
+ lineNumber: 74,
36
40
  columnNumber: 3
37
41
  }
38
42
  }, children);
@@ -41,7 +45,13 @@ var ChatProvider = function ChatProvider(_ref) {
41
45
  exports.ChatProvider = ChatProvider;
42
46
 
43
47
  var useChatContext = function useChatContext() {
44
- return (0, _react.useContext)(ChatContext);
48
+ var contextValue = (0, _react.useContext)(ChatContext);
49
+
50
+ if (contextValue === _defaultBaseContextValue.DEFAULT_BASE_CONTEXT_VALUE && !(0, _isTestEnvironment.isTestEnvironment)()) {
51
+ throw new Error("The useChatContext hook was called outside the ChatContext Provider. Make sure you have configured Chat component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#chat");
52
+ }
53
+
54
+ return contextValue;
45
55
  };
46
56
 
47
57
  exports.useChatContext = useChatContext;
@@ -53,7 +63,7 @@ var withChatContext = function withChatContext(Component) {
53
63
  __self: _this,
54
64
  __source: {
55
65
  fileName: _jsxFileName,
56
- lineNumber: 94,
66
+ lineNumber: 107,
57
67
  columnNumber: 12
58
68
  }
59
69
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["ChatContext.tsx"],"names":["ChatContext","React","createContext","ChatProvider","children","value","useChatContext","withChatContext","Component","WithChatContextComponent","props","chatContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAKA;;;;;;;;;AAuDO,IAAMA,WAAW,GAAGC,kBAAMC,aAAN,CAAoB,EAApB,CAApB;;;;AAEA,IAAMC,YAAY,GAAG,SAAfA,YAAe;AAAA,MAG1BC,QAH0B,QAG1BA,QAH0B;AAAA,MAI1BC,KAJ0B,QAI1BA,KAJ0B;AAAA,SAQ1B,gCAAC,WAAD,CAAa,QAAb;AAAsB,IAAA,KAAK,EAAEA,KAA7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KACGD,QADH,CAR0B;AAAA,CAArB;;;;AAaA,IAAME,cAAc,GAAG,SAAjBA,cAAiB;AAAA,SAEvB,uBAAWN,WAAX,CAFuB;AAAA,CAAvB;;;;AASA,IAAMO,eAAe,GAAG,SAAlBA,eAAkB,CAI7BC,SAJ6B,EAKqC;AAClE,MAAMC,wBAAwB,GAAG,SAA3BA,wBAA2B,CAACC,KAAD,EAAgE;AAC/F,QAAMC,WAAW,GAAGL,cAAc,EAAlC;AAEA,WAAO,gCAAC,SAAD,gCAAgBI,KAAhB,EAAiCC,WAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAJD;;AAKAF,EAAAA,wBAAwB,CAACG,WAAzB,uBAAyD,oCAAeJ,SAAf,CAAzD;AACA,SAAOC,wBAAP;AACD,CAbM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { AppSettingsAPIResponse, Channel, Mute, StreamChat } from 'stream-chat';\n\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { getDisplayName } from '../utils/getDisplayName';\n\nexport type ChatContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * Object of application settings returned from Stream.\n * */\n appSettings: AppSettingsAPIResponse<StreamChatGenerics> | null;\n /**\n * The StreamChat client object\n *\n * ```\n * import { StreamChat } from 'stream-chat';\n * import { Chat } from 'stream-chat-react-native';\n *\n * const client = StreamChat.getInstance('api_key);\n * await client.connectUser('user_id', 'userToken');\n *\n * <Chat client={client}>\n * </Chat>\n * ```\n *\n * @overrideType StreamChat\n * */\n client: StreamChat<StreamChatGenerics>;\n connectionRecovering: boolean;\n isOnline: boolean;\n mutedUsers: Mute<StreamChatGenerics>[];\n /**\n * @param newChannel Channel to set as active.\n *\n * @overrideType Function\n */\n setActiveChannel: (newChannel?: Channel<StreamChatGenerics>) => void;\n /**\n * Instance of channel object from stream-chat package.\n *\n * Please check the docs around how to create or query channel - https://getstream.io/chat/docs/javascript/creating_channels/?language=javascript\n *\n * ```\n * import { StreamChat, Channel } from 'stream-chat';\n * import { Chat, Channel} from 'stream-chat-react-native';\n *\n * const client = StreamChat.getInstance('api_key');\n * await client.connectUser('user_id', 'user_token');\n * const channel = client.channel('messaging', 'channel_id');\n * await channel.watch();\n * ```\n *\n * @overrideType Channel\n */\n channel?: Channel<StreamChatGenerics>;\n};\n\nexport const ChatContext = React.createContext({} as ChatContextValue);\n\nexport const ChatProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value: ChatContextValue<StreamChatGenerics>;\n}>) => (\n <ChatContext.Provider value={value as unknown as ChatContextValue}>\n {children}\n </ChatContext.Provider>\n);\n\nexport const useChatContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => useContext(ChatContext) as unknown as ChatContextValue<StreamChatGenerics>;\n\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChatContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChatContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChatContextValue<StreamChatGenerics>>> => {\n const WithChatContextComponent = (props: Omit<P, keyof ChatContextValue<StreamChatGenerics>>) => {\n const chatContext = useChatContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...chatContext} />;\n };\n WithChatContextComponent.displayName = `WithChatContext${getDisplayName(Component)}`;\n return WithChatContextComponent;\n};\n"]}
1
+ {"version":3,"sources":["ChatContext.tsx"],"names":["ChatContext","React","createContext","DEFAULT_BASE_CONTEXT_VALUE","ChatProvider","children","value","useChatContext","contextValue","Error","withChatContext","Component","WithChatContextComponent","props","chatContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAKA;;AAEA;;AACA;;;;;;;;;AAuDO,IAAMA,WAAW,GAAGC,kBAAMC,aAAN,CAAoBC,mDAApB,CAApB;;;;AAEA,IAAMC,YAAY,GAAG,SAAfA,YAAe;AAAA,MAG1BC,QAH0B,QAG1BA,QAH0B;AAAA,MAI1BC,KAJ0B,QAI1BA,KAJ0B;AAAA,SAQ1B,gCAAC,WAAD,CAAa,QAAb;AAAsB,IAAA,KAAK,EAAEA,KAA7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KACGD,QADH,CAR0B;AAAA,CAArB;;;;AAaA,IAAME,cAAc,GAAG,SAAjBA,cAAiB,GAEvB;AACL,MAAMC,YAAY,GAAG,uBAAWR,WAAX,CAArB;;AAEA,MAAIQ,YAAY,KAAKL,mDAAjB,IAA+C,CAAC,2CAApD,EAAyE;AACvE,UAAM,IAAIM,KAAJ,+MAAN;AAGD;;AAED,SAAOD,YAAP;AACD,CAZM;;;;AAmBA,IAAME,eAAe,GAAG,SAAlBA,eAAkB,CAI7BC,SAJ6B,EAKqC;AAClE,MAAMC,wBAAwB,GAAG,SAA3BA,wBAA2B,CAACC,KAAD,EAAgE;AAC/F,QAAMC,WAAW,GAAGP,cAAc,EAAlC;AAEA,WAAO,gCAAC,SAAD,gCAAgBM,KAAhB,EAAiCC,WAAjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAJD;;AAKAF,EAAAA,wBAAwB,CAACG,WAAzB,uBAAyD,oCAAeJ,SAAf,CAAzD;AACA,SAAOC,wBAAP;AACD,CAbM","sourcesContent":["import React, { PropsWithChildren, useContext } from 'react';\n\nimport type { AppSettingsAPIResponse, Channel, Mute, StreamChat } from 'stream-chat';\n\nimport type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';\nimport { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';\n\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport type ChatContextValue<\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n> = {\n /**\n * Object of application settings returned from Stream.\n * */\n appSettings: AppSettingsAPIResponse<StreamChatGenerics> | null;\n /**\n * The StreamChat client object\n *\n * ```\n * import { StreamChat } from 'stream-chat';\n * import { Chat } from 'stream-chat-react-native';\n *\n * const client = StreamChat.getInstance('api_key);\n * await client.connectUser('user_id', 'userToken');\n *\n * <Chat client={client}>\n * </Chat>\n * ```\n *\n * @overrideType StreamChat\n * */\n client: StreamChat<StreamChatGenerics>;\n connectionRecovering: boolean;\n isOnline: boolean;\n mutedUsers: Mute<StreamChatGenerics>[];\n /**\n * @param newChannel Channel to set as active.\n *\n * @overrideType Function\n */\n setActiveChannel: (newChannel?: Channel<StreamChatGenerics>) => void;\n /**\n * Instance of channel object from stream-chat package.\n *\n * Please check the docs around how to create or query channel - https://getstream.io/chat/docs/javascript/creating_channels/?language=javascript\n *\n * ```\n * import { StreamChat, Channel } from 'stream-chat';\n * import { Chat, Channel} from 'stream-chat-react-native';\n *\n * const client = StreamChat.getInstance('api_key');\n * await client.connectUser('user_id', 'user_token');\n * const channel = client.channel('messaging', 'channel_id');\n * await channel.watch();\n * ```\n *\n * @overrideType Channel\n */\n channel?: Channel<StreamChatGenerics>;\n};\n\nexport const ChatContext = React.createContext(DEFAULT_BASE_CONTEXT_VALUE as ChatContextValue);\n\nexport const ChatProvider = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>({\n children,\n value,\n}: PropsWithChildren<{\n value: ChatContextValue<StreamChatGenerics>;\n}>) => (\n <ChatContext.Provider value={value as unknown as ChatContextValue}>\n {children}\n </ChatContext.Provider>\n);\n\nexport const useChatContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>() => {\n const contextValue = useContext(ChatContext) as unknown as ChatContextValue<StreamChatGenerics>;\n\n if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {\n throw new Error(\n `The useChatContext hook was called outside the ChatContext Provider. Make sure you have configured Chat component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#chat`,\n );\n }\n\n return contextValue;\n};\n\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChatContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChatContext = <\n P extends UnknownType,\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<P>,\n): React.FC<Omit<P, keyof ChatContextValue<StreamChatGenerics>>> => {\n const WithChatContextComponent = (props: Omit<P, keyof ChatContextValue<StreamChatGenerics>>) => {\n const chatContext = useChatContext<StreamChatGenerics>();\n\n return <Component {...(props as P)} {...chatContext} />;\n };\n WithChatContextComponent.displayName = `WithChatContext${getDisplayName(Component)}`;\n return WithChatContextComponent;\n};\n"]}