@stream-io/feeds-client 0.1.9 → 0.1.10

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 (38) hide show
  1. package/@react-bindings/hooks/search-state-hooks/index.ts +3 -0
  2. package/@react-bindings/index.ts +5 -0
  3. package/CHANGELOG.md +7 -0
  4. package/dist/@react-bindings/contexts/StreamSearchContext.d.ts +12 -0
  5. package/dist/@react-bindings/contexts/StreamSearchResultsContext.d.ts +12 -0
  6. package/dist/@react-bindings/hooks/search-state-hooks/index.d.ts +3 -0
  7. package/dist/@react-bindings/hooks/search-state-hooks/useSearchQuery.d.ts +4 -0
  8. package/dist/@react-bindings/hooks/search-state-hooks/useSearchResult.d.ts +8 -0
  9. package/dist/@react-bindings/hooks/search-state-hooks/useSearchSources.d.ts +4 -0
  10. package/dist/@react-bindings/index.d.ts +5 -0
  11. package/dist/@react-bindings/wrappers/StreamSearch.d.ts +12 -0
  12. package/dist/@react-bindings/wrappers/StreamSearchResults.d.ts +12 -0
  13. package/dist/index-react-bindings.browser.cjs +85 -16
  14. package/dist/index-react-bindings.browser.cjs.map +1 -1
  15. package/dist/index-react-bindings.browser.js +77 -17
  16. package/dist/index-react-bindings.browser.js.map +1 -1
  17. package/dist/index-react-bindings.node.cjs +85 -16
  18. package/dist/index-react-bindings.node.cjs.map +1 -1
  19. package/dist/index-react-bindings.node.js +77 -17
  20. package/dist/index-react-bindings.node.js.map +1 -1
  21. package/dist/index.browser.cjs +26 -125
  22. package/dist/index.browser.cjs.map +1 -1
  23. package/dist/index.browser.js +26 -125
  24. package/dist/index.browser.js.map +1 -1
  25. package/dist/index.node.cjs +26 -125
  26. package/dist/index.node.cjs.map +1 -1
  27. package/dist/index.node.js +26 -125
  28. package/dist/index.node.js.map +1 -1
  29. package/dist/src/common/BaseSearchSource.d.ts +3 -1
  30. package/dist/src/common/FeedSearchSource.d.ts +5 -1
  31. package/dist/src/common/SearchController.d.ts +2 -0
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +1 -1
  34. package/src/common/ActivitySearchSource.ts +5 -15
  35. package/src/common/BaseSearchSource.ts +9 -9
  36. package/src/common/FeedSearchSource.ts +20 -65
  37. package/src/common/SearchController.ts +2 -0
  38. package/src/common/UserSearchSource.ts +9 -61
@@ -5729,10 +5729,10 @@ const useFeedsClient = () => {
5729
5729
  */
5730
5730
  const useClientConnectedUser = () => {
5731
5731
  const client = useFeedsClient();
5732
- const { user } = useStateStore(client?.state, selector$7) ?? {};
5732
+ const { user } = useStateStore(client?.state, selector$a) ?? {};
5733
5733
  return user;
5734
5734
  };
5735
- const selector$7 = (nextState) => ({
5735
+ const selector$a = (nextState) => ({
5736
5736
  user: nextState.connected_user,
5737
5737
  });
5738
5738
 
@@ -5741,10 +5741,10 @@ const selector$7 = (nextState) => ({
5741
5741
  */
5742
5742
  const useWsConnectionState = () => {
5743
5743
  const client = useFeedsClient();
5744
- const { is_healthy } = useStateStore(client?.state, selector$6) ?? {};
5744
+ const { is_healthy } = useStateStore(client?.state, selector$9) ?? {};
5745
5745
  return { is_healthy };
5746
5746
  };
5747
- const selector$6 = (nextState) => ({
5747
+ const selector$9 = (nextState) => ({
5748
5748
  is_healthy: nextState.is_ws_connection_healthy,
5749
5749
  });
5750
5750
 
@@ -5794,7 +5794,7 @@ const useStableCallback = (callback) => {
5794
5794
  const useFeedActivities = (feedFromProps) => {
5795
5795
  const feedFromContext = useFeedContext();
5796
5796
  const feed = feedFromProps ?? feedFromContext;
5797
- const data = useStateStore(feed?.state, selector$5);
5797
+ const data = useStateStore(feed?.state, selector$8);
5798
5798
  const loadNextPage = useStableCallback(async () => {
5799
5799
  if (!feed || !data?.has_next_page || data?.is_loading) {
5800
5800
  return;
@@ -5803,7 +5803,7 @@ const useFeedActivities = (feedFromProps) => {
5803
5803
  });
5804
5804
  return react.useMemo(() => ({ ...data, loadNextPage }), [data, loadNextPage]);
5805
5805
  };
5806
- const selector$5 = ({ is_loading_activities, next, activities = [] }) => ({
5806
+ const selector$8 = ({ is_loading_activities, next, activities = [] }) => ({
5807
5807
  is_loading: is_loading_activities,
5808
5808
  has_next_page: typeof next !== 'undefined',
5809
5809
  activities,
@@ -5876,13 +5876,13 @@ const FeedOwnCapability = {
5876
5876
  };
5877
5877
 
5878
5878
  const stableEmptyArray = [];
5879
- const selector$4 = (currentState) => ({
5879
+ const selector$7 = (currentState) => ({
5880
5880
  oc: currentState.own_capabilities ?? stableEmptyArray,
5881
5881
  });
5882
5882
  const useOwnCapabilities = (feedFromProps) => {
5883
5883
  const feedFromContext = useFeedContext();
5884
5884
  const feed = feedFromProps ?? feedFromContext;
5885
- const { oc = stableEmptyArray } = useStateStore(feed?.state, selector$4) ?? {};
5885
+ const { oc = stableEmptyArray } = useStateStore(feed?.state, selector$7) ?? {};
5886
5886
  return react.useMemo(() => ({
5887
5887
  can_add_activity: oc.indexOf(FeedOwnCapability.ADD_ACTIVITY) > -1,
5888
5888
  can_add_activity_reaction: oc.indexOf(FeedOwnCapability.ADD_ACTIVITY_REACTION) > -1,
@@ -5917,7 +5917,7 @@ const useOwnCapabilities = (feedFromProps) => {
5917
5917
  }), [oc]);
5918
5918
  };
5919
5919
 
5920
- const selector$3 = ({ follower_count, followers, followers_pagination, }) => ({
5920
+ const selector$6 = ({ follower_count, followers, followers_pagination, }) => ({
5921
5921
  follower_count,
5922
5922
  followers,
5923
5923
  followers_pagination,
@@ -5925,7 +5925,7 @@ const selector$3 = ({ follower_count, followers, followers_pagination, }) => ({
5925
5925
  function useFollowers(feedFromProps) {
5926
5926
  const feedFromContext = useFeedContext();
5927
5927
  const feed = feedFromProps ?? feedFromContext;
5928
- const data = useStateStore(feed?.state, selector$3);
5928
+ const data = useStateStore(feed?.state, selector$6);
5929
5929
  const loadNextPage = react.useCallback((...options) => feed?.loadNextPageFollowers(...options), [feed]);
5930
5930
  return react.useMemo(() => {
5931
5931
  if (!data) {
@@ -5940,7 +5940,7 @@ function useFollowers(feedFromProps) {
5940
5940
  }, [data, loadNextPage]);
5941
5941
  }
5942
5942
 
5943
- const selector$2 = ({ following_count, following, following_pagination, }) => ({
5943
+ const selector$5 = ({ following_count, following, following_pagination, }) => ({
5944
5944
  following_count,
5945
5945
  following,
5946
5946
  following_pagination,
@@ -5948,7 +5948,7 @@ const selector$2 = ({ following_count, following, following_pagination, }) => ({
5948
5948
  function useFollowing(feedFromProps) {
5949
5949
  const feedFromContext = useFeedContext();
5950
5950
  const feed = feedFromProps ?? feedFromContext;
5951
- const data = useStateStore(feed?.state, selector$2);
5951
+ const data = useStateStore(feed?.state, selector$5);
5952
5952
  const loadNextPage = react.useCallback((...options) => feed?.loadNextPageFollowing(...options), [feed]);
5953
5953
  return react.useMemo(() => {
5954
5954
  if (!data) {
@@ -5970,9 +5970,9 @@ function useFollowing(feedFromProps) {
5970
5970
  const useFeedMetadata = (feedFromProps) => {
5971
5971
  const feedFromContext = useFeedContext();
5972
5972
  const feed = feedFromProps ?? feedFromContext;
5973
- return useStateStore(feed?.state, selector$1);
5973
+ return useStateStore(feed?.state, selector$4);
5974
5974
  };
5975
- const selector$1 = ({ follower_count = 0, following_count = 0, created_by, created_at, updated_at, }) => ({
5975
+ const selector$4 = ({ follower_count = 0, following_count = 0, created_by, created_at, updated_at, }) => ({
5976
5976
  created_by,
5977
5977
  follower_count,
5978
5978
  following_count,
@@ -5987,12 +5987,62 @@ const selector$1 = ({ follower_count = 0, following_count = 0, created_by, creat
5987
5987
  const useOwnFollows = (feedFromProps) => {
5988
5988
  const feedFromContext = useFeedContext();
5989
5989
  const feed = feedFromProps ?? feedFromContext;
5990
- return useStateStore(feed?.state, selector);
5990
+ return useStateStore(feed?.state, selector$3);
5991
5991
  };
5992
- const selector = ({ own_follows }) => ({
5992
+ const selector$3 = ({ own_follows }) => ({
5993
5993
  own_follows,
5994
5994
  });
5995
5995
 
5996
+ const StreamSearchResultsContext = react.createContext(undefined);
5997
+ /**
5998
+ * Hook to access the nearest SearchSource instance.
5999
+ */
6000
+ const useSearchResultsContext = () => {
6001
+ return react.useContext(StreamSearchResultsContext);
6002
+ };
6003
+
6004
+ const useSearchResult = (sourceFromProps) => {
6005
+ const sourceFromContext = useSearchResultsContext();
6006
+ const source = sourceFromProps ?? sourceFromContext;
6007
+ const { items, error, isLoading, hasNext } = useStateStore(source?.state, selector$2) ?? {};
6008
+ const loadMore = useStableCallback(async () => {
6009
+ source?.search();
6010
+ });
6011
+ return react.useMemo(() => ({ items, error, isLoading, hasNext, loadMore }), [error, hasNext, isLoading, items, loadMore]);
6012
+ };
6013
+ const selector$2 = ({ items, isLoading, hasNext, lastQueryError, }) => ({
6014
+ items,
6015
+ isLoading,
6016
+ hasNext,
6017
+ error: lastQueryError,
6018
+ });
6019
+
6020
+ const StreamSearchContext = react.createContext(undefined);
6021
+ /**
6022
+ * Hook to access the nearest SearchController instance.
6023
+ */
6024
+ const useSearchContext = () => {
6025
+ return react.useContext(StreamSearchContext);
6026
+ };
6027
+
6028
+ const useSearchQuery = (controllerFromProps) => {
6029
+ const controllerFromState = useSearchContext();
6030
+ const controller = controllerFromProps ?? controllerFromState;
6031
+ return useStateStore(controller?.state, selector$1);
6032
+ };
6033
+ const selector$1 = ({ searchQuery }) => ({
6034
+ searchQuery,
6035
+ });
6036
+
6037
+ const useSearchSources = (controllerFromProps) => {
6038
+ const controllerFromState = useSearchContext();
6039
+ const controller = controllerFromProps ?? controllerFromState;
6040
+ return useStateStore(controller?.state, selector);
6041
+ };
6042
+ const selector = ({ sources }) => ({
6043
+ sources,
6044
+ });
6045
+
5996
6046
  /**
5997
6047
  * A utility hook that takes in an entity and a reaction type, and creates reaction actions
5998
6048
  * that can then be used on the UI. The entity can be either an ActivityResponse or a CommentResponse
@@ -6064,10 +6114,24 @@ const StreamFeed = ({ feed, children }) => {
6064
6114
  };
6065
6115
  StreamFeed.displayName = 'StreamFeed';
6066
6116
 
6117
+ const StreamSearch = ({ searchController, children, }) => {
6118
+ return (jsxRuntime.jsx(StreamSearchContext.Provider, { value: searchController, children: children }));
6119
+ };
6120
+ StreamSearch.displayName = 'StreamSearch';
6121
+
6122
+ const StreamSearchResults = ({ source, children, }) => {
6123
+ return (jsxRuntime.jsx(StreamSearchResultsContext.Provider, { value: source, children: children }));
6124
+ };
6125
+ StreamSearchResults.displayName = 'StreamSearchResults';
6126
+
6067
6127
  exports.StreamFeed = StreamFeed;
6068
6128
  exports.StreamFeedContext = StreamFeedContext;
6069
6129
  exports.StreamFeeds = StreamFeeds;
6070
6130
  exports.StreamFeedsContext = StreamFeedsContext;
6131
+ exports.StreamSearch = StreamSearch;
6132
+ exports.StreamSearchContext = StreamSearchContext;
6133
+ exports.StreamSearchResults = StreamSearchResults;
6134
+ exports.StreamSearchResultsContext = StreamSearchResultsContext;
6071
6135
  exports.useBookmarkActions = useBookmarkActions;
6072
6136
  exports.useClientConnectedUser = useClientConnectedUser;
6073
6137
  exports.useComments = useComments;
@@ -6081,6 +6145,11 @@ exports.useFollowing = useFollowing;
6081
6145
  exports.useOwnCapabilities = useOwnCapabilities;
6082
6146
  exports.useOwnFollows = useOwnFollows;
6083
6147
  exports.useReactionActions = useReactionActions;
6148
+ exports.useSearchContext = useSearchContext;
6149
+ exports.useSearchQuery = useSearchQuery;
6150
+ exports.useSearchResult = useSearchResult;
6151
+ exports.useSearchResultsContext = useSearchResultsContext;
6152
+ exports.useSearchSources = useSearchSources;
6084
6153
  exports.useStateStore = useStateStore;
6085
6154
  exports.useWsConnectionState = useWsConnectionState;
6086
6155
  //# sourceMappingURL=index-react-bindings.node.cjs.map