stream-chat 9.45.0 → 9.45.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.browser.js +17 -6
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +17 -6
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +17 -6
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/search/BaseSearchSource.d.ts +2 -0
- package/dist/types/search/types.d.ts +4 -0
- package/package.json +2 -2
- package/src/search/BaseSearchSource.ts +17 -4
- package/src/search/types.ts +4 -0
|
@@ -36,6 +36,8 @@ export interface SearchSourceSync<T = any> extends ISearchSource<T> {
|
|
|
36
36
|
declare abstract class BaseSearchSourceBase<T> implements ISearchSource<T> {
|
|
37
37
|
state: StateStore<SearchSourceState<T>>;
|
|
38
38
|
pageSize: number;
|
|
39
|
+
protected allowEmptySearchString: boolean;
|
|
40
|
+
protected resetOnNewSearchQuery: boolean;
|
|
39
41
|
abstract readonly type: SearchSourceType;
|
|
40
42
|
protected constructor(options?: SearchSourceOptions);
|
|
41
43
|
get lastQueryError(): Error | undefined;
|
|
@@ -12,6 +12,10 @@ export type SearchSourceOptions = {
|
|
|
12
12
|
/** The number of milliseconds to debounce the search query. The default interval is 300ms. */
|
|
13
13
|
debounceMs?: number;
|
|
14
14
|
pageSize?: number;
|
|
15
|
+
/** When true, the source can execute queries with an empty search string. Defaults to false. */
|
|
16
|
+
allowEmptySearchString?: boolean;
|
|
17
|
+
/** When true, previously loaded items are cleared at the start of a new search query. Defaults to true. */
|
|
18
|
+
resetOnNewSearchQuery?: boolean;
|
|
15
19
|
};
|
|
16
20
|
export type SearchSourceType = 'channels' | 'users' | 'messages' | (string & {});
|
|
17
21
|
export type QueryReturnValue<T> = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat",
|
|
3
|
-
"version": "9.45.
|
|
3
|
+
"version": "9.45.2",
|
|
4
4
|
"description": "JS SDK for the Stream Chat API",
|
|
5
5
|
"homepage": "https://getstream.io/chat/",
|
|
6
6
|
"author": {
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"test-coverage": "vitest run --coverage",
|
|
104
104
|
"fix-staged": "lint-staged --config .lintstagedrc.fix.json --concurrent 1",
|
|
105
105
|
"semantic-release": "semantic-release",
|
|
106
|
-
"postinstall": "husky",
|
|
106
|
+
"postinstall": "node -e \"require('fs').existsSync('scripts/install-husky.mjs') && import('./scripts/install-husky.mjs')\"",
|
|
107
107
|
"prepare": "yarn run build"
|
|
108
108
|
},
|
|
109
109
|
"engines": {
|
|
@@ -57,16 +57,25 @@ export interface SearchSourceSync<T = any> extends ISearchSource<T> {
|
|
|
57
57
|
const DEFAULT_SEARCH_SOURCE_OPTIONS: Required<SearchSourceOptions> = {
|
|
58
58
|
debounceMs: 300,
|
|
59
59
|
pageSize: 10,
|
|
60
|
+
allowEmptySearchString: false,
|
|
61
|
+
resetOnNewSearchQuery: true,
|
|
60
62
|
} as const;
|
|
61
63
|
|
|
62
64
|
abstract class BaseSearchSourceBase<T> implements ISearchSource<T> {
|
|
63
65
|
state: StateStore<SearchSourceState<T>>;
|
|
64
66
|
pageSize: number;
|
|
67
|
+
protected allowEmptySearchString: boolean;
|
|
68
|
+
protected resetOnNewSearchQuery: boolean;
|
|
65
69
|
abstract readonly type: SearchSourceType;
|
|
66
70
|
|
|
67
71
|
protected constructor(options?: SearchSourceOptions) {
|
|
68
|
-
const { pageSize } = {
|
|
72
|
+
const { pageSize, allowEmptySearchString, resetOnNewSearchQuery } = {
|
|
73
|
+
...DEFAULT_SEARCH_SOURCE_OPTIONS,
|
|
74
|
+
...options,
|
|
75
|
+
};
|
|
69
76
|
this.pageSize = pageSize;
|
|
77
|
+
this.allowEmptySearchString = allowEmptySearchString;
|
|
78
|
+
this.resetOnNewSearchQuery = resetOnNewSearchQuery;
|
|
70
79
|
this.state = new StateStore<SearchSourceState<T>>(this.initialState);
|
|
71
80
|
}
|
|
72
81
|
|
|
@@ -136,15 +145,19 @@ abstract class BaseSearchSourceBase<T> implements ISearchSource<T> {
|
|
|
136
145
|
this.isActive &&
|
|
137
146
|
!this.isLoading &&
|
|
138
147
|
(this.hasNext || hasNewSearchQuery) &&
|
|
139
|
-
searchString
|
|
148
|
+
(this.allowEmptySearchString || searchString)
|
|
140
149
|
);
|
|
141
150
|
};
|
|
142
151
|
|
|
143
152
|
protected getStateBeforeFirstQuery(newSearchString: string): SearchSourceState<T> {
|
|
153
|
+
const initialState = this.initialState;
|
|
154
|
+
const oldItems = this.items;
|
|
155
|
+
const items = this.resetOnNewSearchQuery ? initialState.items : oldItems;
|
|
144
156
|
return {
|
|
145
|
-
...
|
|
157
|
+
...initialState,
|
|
158
|
+
items,
|
|
146
159
|
isActive: this.isActive,
|
|
147
|
-
isLoading: true,
|
|
160
|
+
isLoading: this.resetOnNewSearchQuery ? true : !oldItems,
|
|
148
161
|
searchQuery: newSearchString,
|
|
149
162
|
};
|
|
150
163
|
}
|
package/src/search/types.ts
CHANGED
|
@@ -14,6 +14,10 @@ export type SearchSourceOptions = {
|
|
|
14
14
|
/** The number of milliseconds to debounce the search query. The default interval is 300ms. */
|
|
15
15
|
debounceMs?: number;
|
|
16
16
|
pageSize?: number;
|
|
17
|
+
/** When true, the source can execute queries with an empty search string. Defaults to false. */
|
|
18
|
+
allowEmptySearchString?: boolean;
|
|
19
|
+
/** When true, previously loaded items are cleared at the start of a new search query. Defaults to true. */
|
|
20
|
+
resetOnNewSearchQuery?: boolean;
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
export type SearchSourceType = 'channels' | 'users' | 'messages' | (string & {});
|