@rubixstudios/payload-typesense 1.7.0 → 1.8.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.
- package/README.md +55 -16
- package/dist/components/ThemeProvider.d.ts +3 -2
- package/dist/components/ThemeProvider.d.ts.map +1 -1
- package/dist/components/ThemeProvider.js +8 -0
- package/dist/components/icons/index.d.ts +1 -0
- package/dist/components/icons/index.d.ts.map +1 -1
- package/dist/components/icons/index.js +1 -0
- package/dist/components/icons/noResultsIcon.d.ts +2 -4
- package/dist/components/icons/noResultsIcon.d.ts.map +1 -1
- package/dist/components/icons/searchIcon.d.ts +2 -4
- package/dist/components/icons/searchIcon.d.ts.map +1 -1
- package/dist/components/icons/xIcon.d.ts +2 -0
- package/dist/components/icons/xIcon.d.ts.map +1 -0
- package/dist/components/icons/xIcon.js +17 -0
- package/dist/components/index.d.ts +9 -5
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +5 -3
- package/dist/components/render/Content.d.ts +26 -0
- package/dist/components/render/Content.d.ts.map +1 -0
- package/dist/components/render/Content.js +144 -0
- package/dist/components/render/Dialog.d.ts +20 -0
- package/dist/components/render/Dialog.d.ts.map +1 -0
- package/dist/components/render/Dialog.js +43 -0
- package/dist/components/render/Header.d.ts +2 -2
- package/dist/components/render/Header.d.ts.map +1 -1
- package/dist/components/render/Header.js +17 -39
- package/dist/components/render/Highlight.d.ts +3 -0
- package/dist/components/render/Highlight.d.ts.map +1 -0
- package/dist/components/render/Highlight.js +22 -0
- package/dist/components/render/NoResults.d.ts +2 -2
- package/dist/components/render/NoResults.d.ts.map +1 -1
- package/dist/components/render/NoResults.js +18 -39
- package/dist/components/render/ResultError.d.ts +2 -2
- package/dist/components/render/ResultError.d.ts.map +1 -1
- package/dist/components/render/ResultError.js +7 -32
- package/dist/components/render/Results.d.ts +7 -6
- package/dist/components/render/Results.d.ts.map +1 -1
- package/dist/components/render/Results.js +34 -109
- package/dist/components/render/index.d.ts +7 -4
- package/dist/components/render/index.d.ts.map +1 -1
- package/dist/components/render/index.js +7 -4
- package/dist/components/search/HeadlessDialog.d.ts +5 -0
- package/dist/components/search/HeadlessDialog.d.ts.map +1 -0
- package/dist/components/search/HeadlessDialog.js +254 -0
- package/dist/components/search/HeadlessInput.d.ts +5 -0
- package/dist/components/search/HeadlessInput.d.ts.map +1 -0
- package/dist/components/search/HeadlessInput.js +193 -0
- package/dist/components/search/SearchStyles.d.ts +8 -0
- package/dist/components/search/SearchStyles.d.ts.map +1 -0
- package/dist/components/search/SearchStyles.js +9 -0
- package/dist/components/themes/constant.d.ts +3 -0
- package/dist/components/themes/constant.d.ts.map +1 -0
- package/dist/components/themes/constant.js +75 -0
- package/dist/components/themes/hooks.d.ts +4 -4
- package/dist/components/themes/hooks.d.ts.map +1 -1
- package/dist/components/themes/hooks.js +15 -26
- package/dist/components/themes/index.d.ts +1 -0
- package/dist/components/themes/index.d.ts.map +1 -1
- package/dist/components/themes/index.js +1 -0
- package/dist/components/themes/themes.d.ts.map +1 -1
- package/dist/components/themes/themes.js +50 -7
- package/dist/components/themes/types.d.ts +62 -2
- package/dist/components/themes/types.d.ts.map +1 -1
- package/dist/components/themes/utils.d.ts +11 -4
- package/dist/components/themes/utils.d.ts.map +1 -1
- package/dist/components/themes/utils.js +450 -315
- package/dist/components/utils/decodeEntities.d.ts +2 -0
- package/dist/components/utils/decodeEntities.d.ts.map +1 -0
- package/dist/components/utils/decodeEntities.js +23 -0
- package/dist/components/utils/index.d.ts +4 -0
- package/dist/components/utils/index.d.ts.map +1 -0
- package/dist/components/utils/index.js +3 -0
- package/dist/components/utils/toKebab.d.ts +2 -0
- package/dist/components/utils/toKebab.d.ts.map +1 -0
- package/dist/components/utils/toKebab.js +3 -0
- package/dist/components/utils/toText.d.ts +2 -0
- package/dist/components/utils/toText.d.ts.map +1 -0
- package/dist/components/utils/toText.js +3 -0
- package/dist/endpoints/handler/createAdvancedSearch.d.ts.map +1 -1
- package/dist/endpoints/handler/createAdvancedSearch.js +63 -5
- package/dist/endpoints/handler/createSearch.d.ts.map +1 -1
- package/dist/endpoints/handler/createSearch.js +73 -106
- package/dist/endpoints/handler/createSuggest.d.ts.map +1 -1
- package/dist/endpoints/handler/createSuggest.js +27 -25
- package/dist/endpoints/search.d.ts +1 -1
- package/dist/endpoints/search.d.ts.map +1 -1
- package/dist/endpoints/search.js +1 -1
- package/dist/hooks/useSearch.d.ts +8 -5
- package/dist/hooks/useSearch.d.ts.map +1 -1
- package/dist/hooks/useSearch.js +53 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +5 -2
- package/dist/lib/initialization.d.ts +1 -1
- package/dist/lib/initialization.d.ts.map +1 -1
- package/dist/lib/initialization.js +8 -8
- package/dist/lib/schema-mapper.d.ts +1 -1
- package/dist/lib/schema-mapper.d.ts.map +1 -1
- package/dist/lib/schema-mapper.js +16 -8
- package/dist/lib/search-dialog.d.ts +169 -0
- package/dist/lib/search-dialog.d.ts.map +1 -0
- package/dist/lib/search-dialog.js +4 -0
- package/dist/lib/{headlessSearch.d.ts → search-input.d.ts} +6 -3
- package/dist/lib/search-input.d.ts.map +1 -0
- package/dist/lib/search-pagination.d.ts +38 -0
- package/dist/lib/search-pagination.d.ts.map +1 -0
- package/dist/lib/search-pagination.js +4 -0
- package/dist/lib/search.d.ts +25 -0
- package/dist/lib/search.d.ts.map +1 -0
- package/dist/lib/search.js +59 -0
- package/dist/lib/validation.d.ts +36 -10
- package/dist/lib/validation.d.ts.map +1 -1
- package/dist/lib/validation.js +54 -18
- package/dist/types.d.ts +42 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/ensureCollection.d.ts +1 -1
- package/dist/utils/ensureCollection.d.ts.map +1 -1
- package/dist/utils/ensureCollection.js +58 -22
- package/dist/utils/getCollectionInfo.d.ts.map +1 -1
- package/dist/utils/getCollections.d.ts +2 -2
- package/dist/utils/getCollections.d.ts.map +1 -1
- package/dist/utils/getCollections.js +32 -20
- package/dist/utils/keyboard.js +6 -6
- package/dist/utils/sortResults.d.ts +2 -2
- package/dist/utils/sortResults.d.ts.map +1 -1
- package/dist/utils/sortResults.js +90 -60
- package/dist/utils/testConnection.d.ts +1 -1
- package/dist/utils/testConnection.d.ts.map +1 -1
- package/dist/utils/testConnection.js +2 -2
- package/dist/utils/vectorSearch.d.ts +2 -6
- package/dist/utils/vectorSearch.d.ts.map +1 -1
- package/dist/utils/vectorSearch.js +20 -10
- package/package.json +15 -14
- package/dist/components/HeadlessSearchInput.d.ts +0 -5
- package/dist/components/HeadlessSearchInput.d.ts.map +0 -1
- package/dist/components/HeadlessSearchInput.js +0 -237
- package/dist/lib/headlessSearch.d.ts.map +0 -1
- /package/dist/lib/{headlessSearch.js → search-input.js} +0 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import React, { useCallback, useEffect, useId, useRef, useState } from 'react';
|
|
4
|
+
import { useDebounce } from '../../hooks/useDebounce.js';
|
|
5
|
+
import { useSearch } from '../../hooks/useSearch.js';
|
|
6
|
+
import { handleKeyboard } from '../../utils/keyboard.js';
|
|
7
|
+
import { SearchIcon } from '../icons/index.js';
|
|
8
|
+
import { RenderedContent, RenderedDialog } from '../render/index.js';
|
|
9
|
+
import { useComponentTheme } from '../ThemeProvider.js';
|
|
10
|
+
import { SearchStyles } from './SearchStyles.js';
|
|
11
|
+
export function HeadlessSearchDialog(props) {
|
|
12
|
+
const { baseUrl, collections, debounceMs = 300, minQueryLength = 2, perPage = 10, searchMode, numTypos, vector, onResults, onSearch, onError, onLoading, onResultClick, theme, open: controlledOpen, defaultOpen = false, onOpenChange, initialQuery = '', triggerLabel, closeOnResultClick = true, clearOnClose = false, onPageChange, renderTrigger, placeholder = 'Search...', className = '', triggerClassName = '', inputClassName = '', triggerProps } = props;
|
|
13
|
+
const scope = useId();
|
|
14
|
+
const themeConfig = useComponentTheme(theme);
|
|
15
|
+
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
16
|
+
const [query, setQuery] = useState(initialQuery);
|
|
17
|
+
const [page, setPage] = useState(1);
|
|
18
|
+
const dialogRef = useRef(null);
|
|
19
|
+
const triggerRef = useRef(null);
|
|
20
|
+
const inputRef = useRef(null);
|
|
21
|
+
const resultsRef = useRef(null);
|
|
22
|
+
const openerRef = useRef(null);
|
|
23
|
+
const isOpen = controlledOpen ?? internalOpen;
|
|
24
|
+
const wasOpenRef = useRef(isOpen);
|
|
25
|
+
const dialogId = props.dialogProps?.id ?? `${scope}-dialog`;
|
|
26
|
+
const resultsId = `${scope}-results`;
|
|
27
|
+
const classes = themeConfig.classes;
|
|
28
|
+
const debouncedQuery = useDebounce(query, debounceMs);
|
|
29
|
+
const { results, error, isLoading, search, reset } = useSearch({
|
|
30
|
+
baseUrl,
|
|
31
|
+
collections,
|
|
32
|
+
enabled: isOpen,
|
|
33
|
+
minQueryLength,
|
|
34
|
+
perPage,
|
|
35
|
+
searchMode,
|
|
36
|
+
numTypos,
|
|
37
|
+
vector,
|
|
38
|
+
onResults,
|
|
39
|
+
onSearch
|
|
40
|
+
});
|
|
41
|
+
const changeOpen = useCallback((next)=>{
|
|
42
|
+
if (controlledOpen === undefined) {
|
|
43
|
+
setInternalOpen(next);
|
|
44
|
+
}
|
|
45
|
+
onOpenChange?.(next);
|
|
46
|
+
}, [
|
|
47
|
+
controlledOpen,
|
|
48
|
+
onOpenChange
|
|
49
|
+
]);
|
|
50
|
+
const close = useCallback(()=>changeOpen(false), [
|
|
51
|
+
changeOpen
|
|
52
|
+
]);
|
|
53
|
+
useEffect(()=>{
|
|
54
|
+
if (!isOpen) return;
|
|
55
|
+
const root = document.documentElement;
|
|
56
|
+
const previousOverflow = root.style.overflow;
|
|
57
|
+
root.style.overflow = 'hidden';
|
|
58
|
+
return ()=>{
|
|
59
|
+
root.style.overflow = previousOverflow;
|
|
60
|
+
};
|
|
61
|
+
}, [
|
|
62
|
+
isOpen
|
|
63
|
+
]);
|
|
64
|
+
useEffect(()=>{
|
|
65
|
+
const dialog = dialogRef.current;
|
|
66
|
+
if (!dialog) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (isOpen && !dialog.open) {
|
|
70
|
+
openerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : triggerRef.current;
|
|
71
|
+
dialog.showModal();
|
|
72
|
+
inputRef.current?.focus();
|
|
73
|
+
} else if (!isOpen && dialog.open) {
|
|
74
|
+
dialog.close();
|
|
75
|
+
openerRef.current?.focus();
|
|
76
|
+
}
|
|
77
|
+
if (!isOpen && wasOpenRef.current && clearOnClose) {
|
|
78
|
+
setQuery('');
|
|
79
|
+
setPage(1);
|
|
80
|
+
}
|
|
81
|
+
wasOpenRef.current = isOpen;
|
|
82
|
+
}, [
|
|
83
|
+
isOpen,
|
|
84
|
+
clearOnClose
|
|
85
|
+
]);
|
|
86
|
+
useEffect(()=>{
|
|
87
|
+
const dialog = dialogRef.current;
|
|
88
|
+
return ()=>{
|
|
89
|
+
if (dialog?.open) {
|
|
90
|
+
dialog.close();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}, []);
|
|
94
|
+
useEffect(()=>{
|
|
95
|
+
if (isOpen && query === debouncedQuery) {
|
|
96
|
+
void search(debouncedQuery, page);
|
|
97
|
+
}
|
|
98
|
+
}, [
|
|
99
|
+
isOpen,
|
|
100
|
+
query,
|
|
101
|
+
debouncedQuery,
|
|
102
|
+
page,
|
|
103
|
+
search
|
|
104
|
+
]);
|
|
105
|
+
useEffect(()=>{
|
|
106
|
+
if (error) {
|
|
107
|
+
onError?.(error);
|
|
108
|
+
}
|
|
109
|
+
}, [
|
|
110
|
+
error,
|
|
111
|
+
onError
|
|
112
|
+
]);
|
|
113
|
+
useEffect(()=>{
|
|
114
|
+
onLoading?.(isLoading);
|
|
115
|
+
}, [
|
|
116
|
+
isLoading,
|
|
117
|
+
onLoading
|
|
118
|
+
]);
|
|
119
|
+
const collectionKey = collections?.join(',');
|
|
120
|
+
useEffect(()=>{
|
|
121
|
+
setPage(1);
|
|
122
|
+
}, [
|
|
123
|
+
baseUrl,
|
|
124
|
+
collectionKey,
|
|
125
|
+
perPage,
|
|
126
|
+
searchMode,
|
|
127
|
+
numTypos,
|
|
128
|
+
vector
|
|
129
|
+
]);
|
|
130
|
+
const totalPages = results ? Math.ceil(results.found / perPage) : 0;
|
|
131
|
+
useEffect(()=>{
|
|
132
|
+
if (results && !isLoading && page > Math.max(1, totalPages)) {
|
|
133
|
+
setPage(Math.max(1, totalPages));
|
|
134
|
+
}
|
|
135
|
+
}, [
|
|
136
|
+
results,
|
|
137
|
+
isLoading,
|
|
138
|
+
page,
|
|
139
|
+
totalPages
|
|
140
|
+
]);
|
|
141
|
+
const clickResult = (result)=>{
|
|
142
|
+
onResultClick?.(result);
|
|
143
|
+
if (closeOnResultClick) {
|
|
144
|
+
close();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const changePage = (next)=>{
|
|
148
|
+
if (isLoading || !Number.isInteger(next) || next < 1 || next > totalPages || next === page) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
setPage(next);
|
|
152
|
+
onPageChange?.(next);
|
|
153
|
+
if (resultsRef.current) {
|
|
154
|
+
resultsRef.current.scrollTop = 0;
|
|
155
|
+
}
|
|
156
|
+
inputRef.current?.focus();
|
|
157
|
+
};
|
|
158
|
+
const inputProps = {
|
|
159
|
+
'aria-label': 'Search input',
|
|
160
|
+
'aria-controls': resultsId,
|
|
161
|
+
'aria-busy': isLoading,
|
|
162
|
+
className: `${classes.input} ${inputClassName}`,
|
|
163
|
+
ref: inputRef,
|
|
164
|
+
value: query,
|
|
165
|
+
placeholder,
|
|
166
|
+
onChange: (event)=>{
|
|
167
|
+
reset();
|
|
168
|
+
setQuery(event.target.value);
|
|
169
|
+
setPage(1);
|
|
170
|
+
},
|
|
171
|
+
onFocus: ()=>{},
|
|
172
|
+
onBlur: (_event)=>{},
|
|
173
|
+
onKeyDown: (event)=>{
|
|
174
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
175
|
+
handleKeyboard(event, {
|
|
176
|
+
inputRef,
|
|
177
|
+
isOpen,
|
|
178
|
+
results,
|
|
179
|
+
resultsRef
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const buttonProps = {
|
|
185
|
+
...triggerProps,
|
|
186
|
+
type: 'button',
|
|
187
|
+
ref: triggerRef,
|
|
188
|
+
'aria-label': triggerProps?.['aria-label'] ?? (typeof triggerLabel === 'string' ? triggerLabel : 'Search'),
|
|
189
|
+
'aria-haspopup': 'dialog',
|
|
190
|
+
'aria-expanded': isOpen,
|
|
191
|
+
'aria-controls': dialogId,
|
|
192
|
+
className: `${classes.trigger} ${triggerClassName} ${triggerProps?.className ?? ''}`,
|
|
193
|
+
onClick: (event)=>{
|
|
194
|
+
triggerProps?.onClick?.(event);
|
|
195
|
+
if (!event.defaultPrevented) changeOpen(true);
|
|
196
|
+
},
|
|
197
|
+
children: triggerLabel ?? /*#__PURE__*/ _jsx(SearchIcon, {})
|
|
198
|
+
};
|
|
199
|
+
const pagination = {
|
|
200
|
+
page,
|
|
201
|
+
perPage,
|
|
202
|
+
found: results?.found ?? 0,
|
|
203
|
+
totalPages,
|
|
204
|
+
isLoading,
|
|
205
|
+
hasPreviousPage: page > 1,
|
|
206
|
+
hasNextPage: page < totalPages,
|
|
207
|
+
onPageChange: changePage
|
|
208
|
+
};
|
|
209
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
210
|
+
className: `${classes.dialogRoot} ${className}`,
|
|
211
|
+
"data-search-theme": scope,
|
|
212
|
+
children: [
|
|
213
|
+
/*#__PURE__*/ _jsx(SearchStyles, {
|
|
214
|
+
scope: scope,
|
|
215
|
+
themeConfig: themeConfig
|
|
216
|
+
}),
|
|
217
|
+
renderTrigger ? renderTrigger(buttonProps) : /*#__PURE__*/ _jsx("button", {
|
|
218
|
+
...buttonProps
|
|
219
|
+
}),
|
|
220
|
+
/*#__PURE__*/ _jsx(RenderedDialog, {
|
|
221
|
+
...props,
|
|
222
|
+
close: close,
|
|
223
|
+
dialogId: dialogId,
|
|
224
|
+
dialogRef: dialogRef,
|
|
225
|
+
error: error,
|
|
226
|
+
isLoading: isLoading,
|
|
227
|
+
isOpen: isOpen,
|
|
228
|
+
page: page,
|
|
229
|
+
query: query,
|
|
230
|
+
results: results,
|
|
231
|
+
themeConfig: themeConfig,
|
|
232
|
+
children: /*#__PURE__*/ _jsx(RenderedContent, {
|
|
233
|
+
...props,
|
|
234
|
+
changePage: changePage,
|
|
235
|
+
clickResult: clickResult,
|
|
236
|
+
error: error,
|
|
237
|
+
inputProps: inputProps,
|
|
238
|
+
inputRef: inputRef,
|
|
239
|
+
isLoading: isLoading,
|
|
240
|
+
isOpen: isOpen,
|
|
241
|
+
page: page,
|
|
242
|
+
pagination: pagination,
|
|
243
|
+
query: query,
|
|
244
|
+
results: results,
|
|
245
|
+
resultsId: resultsId,
|
|
246
|
+
resultsRef: resultsRef,
|
|
247
|
+
themeConfig: themeConfig,
|
|
248
|
+
totalPages: totalPages
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
]
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
export default HeadlessSearchDialog;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { type SearchInputProps } from '../../lib/search-input.js';
|
|
3
|
+
export declare function HeadlessSearchInput<T = Record<string, unknown>>(props: SearchInputProps<T>): ReactElement;
|
|
4
|
+
export default HeadlessSearchInput;
|
|
5
|
+
//# sourceMappingURL=HeadlessInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeadlessInput.d.ts","sourceRoot":"","sources":["../../../src/components/search/HeadlessInput.tsx"],"names":[],"mappings":"AAEA,OAAc,EAKZ,KAAK,YAAY,EAKlB,MAAM,OAAO,CAAA;AAId,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAYjE,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,GACzB,YAAY,CAwPd;eAEc,mBAAmB"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import React, { Fragment, useEffect, useId, useRef, useState } from 'react';
|
|
4
|
+
import { useDebounce } from '../../hooks/useDebounce.js';
|
|
5
|
+
import { useSearch } from '../../hooks/useSearch.js';
|
|
6
|
+
import { handleKeyboard } from '../../utils/keyboard.js';
|
|
7
|
+
import { RenderedHeader, RenderedNoResults, RenderedResult, RenderedResultError } from '../render/index.js';
|
|
8
|
+
import { useComponentTheme } from '../ThemeProvider.js';
|
|
9
|
+
import { SearchStyles } from './SearchStyles.js';
|
|
10
|
+
export function HeadlessSearchInput(props) {
|
|
11
|
+
const { baseUrl, className = '', collections, debounceMs = 300, enableSuggestions = true, errorClassName = '', inputClassName = '', inputWrapperClassName = '', loadingClassName = '', minQueryLength = 2, noResultsClassName = '', onError, onLoading, onResultClick, onResults, onSearch, perPage = 10, placeholder = 'Search...', onResultHover, renderDate = true, renderError, renderInput, renderLoading, renderNoResults, renderResult, renderResultsHeader, resultItemClassName = '', resultsClassName = '', resultsContainerClassName = '', resultsHeaderClassName = '', resultsListClassName = '', showLoading = true, showResultCount = true, theme, vector = false, searchMode, numTypos } = props;
|
|
12
|
+
const scope = useId();
|
|
13
|
+
const themeConfig = useComponentTheme(theme);
|
|
14
|
+
const [query, setQuery] = useState('');
|
|
15
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
16
|
+
const inputRef = useRef(null);
|
|
17
|
+
const resultsRef = useRef(null);
|
|
18
|
+
const rootRef = useRef(null);
|
|
19
|
+
const resultsId = `${scope}-results`;
|
|
20
|
+
const classes = themeConfig.classes;
|
|
21
|
+
const debouncedQuery = useDebounce(query, debounceMs);
|
|
22
|
+
const { error, isLoading, results, search, reset } = useSearch({
|
|
23
|
+
baseUrl,
|
|
24
|
+
collections,
|
|
25
|
+
minQueryLength,
|
|
26
|
+
onResults,
|
|
27
|
+
onSearch,
|
|
28
|
+
perPage,
|
|
29
|
+
vector,
|
|
30
|
+
searchMode,
|
|
31
|
+
numTypos
|
|
32
|
+
});
|
|
33
|
+
useEffect(()=>{
|
|
34
|
+
if (query === debouncedQuery) {
|
|
35
|
+
void search(debouncedQuery);
|
|
36
|
+
}
|
|
37
|
+
}, [
|
|
38
|
+
query,
|
|
39
|
+
debouncedQuery,
|
|
40
|
+
search
|
|
41
|
+
]);
|
|
42
|
+
useEffect(()=>{
|
|
43
|
+
if (error) {
|
|
44
|
+
onError?.(error);
|
|
45
|
+
}
|
|
46
|
+
}, [
|
|
47
|
+
error,
|
|
48
|
+
onError
|
|
49
|
+
]);
|
|
50
|
+
useEffect(()=>{
|
|
51
|
+
onLoading?.(isLoading);
|
|
52
|
+
}, [
|
|
53
|
+
isLoading,
|
|
54
|
+
onLoading
|
|
55
|
+
]);
|
|
56
|
+
useEffect(()=>{
|
|
57
|
+
if (!isOpen) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const outside = (event)=>{
|
|
61
|
+
if (event.target instanceof Node && !rootRef.current?.contains(event.target)) {
|
|
62
|
+
setIsOpen(false);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
document.addEventListener('pointerdown', outside);
|
|
66
|
+
return ()=>document.removeEventListener('pointerdown', outside);
|
|
67
|
+
}, [
|
|
68
|
+
isOpen
|
|
69
|
+
]);
|
|
70
|
+
const clickResult = (result)=>{
|
|
71
|
+
onResultClick?.(result);
|
|
72
|
+
setIsOpen(false);
|
|
73
|
+
setQuery('');
|
|
74
|
+
reset();
|
|
75
|
+
};
|
|
76
|
+
const keyDown = (event)=>{
|
|
77
|
+
if (event.key === 'Escape') {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
setIsOpen(false);
|
|
80
|
+
inputRef.current?.focus();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
handleKeyboard(event, {
|
|
84
|
+
inputRef,
|
|
85
|
+
isOpen,
|
|
86
|
+
results,
|
|
87
|
+
resultsRef
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
const inputProps = {
|
|
91
|
+
'aria-label': 'Search input',
|
|
92
|
+
'aria-controls': isOpen ? resultsId : undefined,
|
|
93
|
+
'aria-busy': isLoading,
|
|
94
|
+
className: `${classes.input} ${inputClassName}`,
|
|
95
|
+
ref: inputRef,
|
|
96
|
+
value: query,
|
|
97
|
+
placeholder,
|
|
98
|
+
onChange: (event)=>{
|
|
99
|
+
reset();
|
|
100
|
+
setQuery(event.target.value);
|
|
101
|
+
setIsOpen(enableSuggestions && event.target.value.trim().length >= minQueryLength);
|
|
102
|
+
},
|
|
103
|
+
onFocus: ()=>{
|
|
104
|
+
if (enableSuggestions && query.trim().length >= minQueryLength) {
|
|
105
|
+
setIsOpen(true);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
onBlur: (_event)=>{},
|
|
109
|
+
onKeyDown: keyDown
|
|
110
|
+
};
|
|
111
|
+
return(// biome-ignore lint/a11y/noStaticElementInteractions: Closes when lost focus.
|
|
112
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
113
|
+
className: `${classes.container} ${className}`,
|
|
114
|
+
"data-search-theme": scope,
|
|
115
|
+
onBlur: (event)=>{
|
|
116
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setIsOpen(false);
|
|
117
|
+
},
|
|
118
|
+
ref: rootRef,
|
|
119
|
+
children: [
|
|
120
|
+
/*#__PURE__*/ _jsx(SearchStyles, {
|
|
121
|
+
scope: scope,
|
|
122
|
+
themeConfig: themeConfig
|
|
123
|
+
}),
|
|
124
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
125
|
+
className: `${classes.inputContainer} ${inputWrapperClassName}`,
|
|
126
|
+
children: [
|
|
127
|
+
renderInput ? renderInput(inputProps) : /*#__PURE__*/ _jsx("input", {
|
|
128
|
+
...inputProps,
|
|
129
|
+
autoComplete: "off",
|
|
130
|
+
type: "search"
|
|
131
|
+
}),
|
|
132
|
+
isLoading && showLoading && (renderLoading ? renderLoading() : /*#__PURE__*/ _jsx("div", {
|
|
133
|
+
"aria-label": "Searching",
|
|
134
|
+
className: `${classes.loadingIndicator} ${loadingClassName}`,
|
|
135
|
+
role: "status",
|
|
136
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
137
|
+
"aria-hidden": "true",
|
|
138
|
+
className: classes.loadingSpinner
|
|
139
|
+
})
|
|
140
|
+
}))
|
|
141
|
+
]
|
|
142
|
+
}),
|
|
143
|
+
enableSuggestions && isOpen && (results || error) && // biome-ignore lint/a11y/noStaticElementInteractions: Handles keyboard navigation.
|
|
144
|
+
/*#__PURE__*/ _jsx("div", {
|
|
145
|
+
className: `${classes.resultsContainer} ${resultsContainerClassName}`,
|
|
146
|
+
id: resultsId,
|
|
147
|
+
onKeyDown: keyDown,
|
|
148
|
+
ref: resultsRef,
|
|
149
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
150
|
+
className: `${classes.results} ${resultsClassName}`,
|
|
151
|
+
children: [
|
|
152
|
+
error && (renderError ? renderError(error) : /*#__PURE__*/ _jsx(RenderedResultError, {
|
|
153
|
+
error: error,
|
|
154
|
+
errorClassName: errorClassName,
|
|
155
|
+
themeConfig: themeConfig
|
|
156
|
+
})),
|
|
157
|
+
!error && results && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
158
|
+
children: [
|
|
159
|
+
showResultCount && (renderResultsHeader ? renderResultsHeader(results.found) : /*#__PURE__*/ _jsx(RenderedHeader, {
|
|
160
|
+
found: results.found,
|
|
161
|
+
resultsHeaderClassName: resultsHeaderClassName,
|
|
162
|
+
themeConfig: themeConfig
|
|
163
|
+
})),
|
|
164
|
+
results.hits.length ? /*#__PURE__*/ _jsx("div", {
|
|
165
|
+
className: `${classes.resultsList} ${resultsListClassName}`,
|
|
166
|
+
children: results.hits.map((result, index)=>/*#__PURE__*/ _jsx(Fragment, {
|
|
167
|
+
children: renderResult ? renderResult(result, index, {
|
|
168
|
+
onClick: clickResult,
|
|
169
|
+
onHover: onResultHover
|
|
170
|
+
}) : /*#__PURE__*/ _jsx(RenderedResult, {
|
|
171
|
+
index: index,
|
|
172
|
+
onResultClick: clickResult,
|
|
173
|
+
onResultHover: onResultHover,
|
|
174
|
+
renderDate: renderDate,
|
|
175
|
+
result: result,
|
|
176
|
+
resultItemClassName: resultItemClassName,
|
|
177
|
+
themeConfig: themeConfig
|
|
178
|
+
})
|
|
179
|
+
}, `${result.collection ?? ''}:${result.document?.id ?? result.id ?? index}`))
|
|
180
|
+
}) : renderNoResults ? renderNoResults(query) : /*#__PURE__*/ _jsx(RenderedNoResults, {
|
|
181
|
+
noResultsClassName: noResultsClassName,
|
|
182
|
+
query: query,
|
|
183
|
+
themeConfig: themeConfig
|
|
184
|
+
})
|
|
185
|
+
]
|
|
186
|
+
})
|
|
187
|
+
]
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
]
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
export default HeadlessSearchInput;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ThemeContextValue } from '../themes/types.js';
|
|
2
|
+
type Props = {
|
|
3
|
+
themeConfig: ThemeContextValue;
|
|
4
|
+
scope: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function SearchStyles({ themeConfig, scope }: Props): import("react").JSX.Element | null;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=SearchStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchStyles.d.ts","sourceRoot":"","sources":["../../../src/components/search/SearchStyles.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAG3D,KAAK,KAAK,GAAG;IACX,WAAW,EAAE,iBAAiB,CAAA;IAC9B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,wBAAgB,YAAY,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,KAAK,sCAMzD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { generateStyles } from '../themes/utils.js';
|
|
3
|
+
export function SearchStyles({ themeConfig, scope }) {
|
|
4
|
+
if (themeConfig.config.unstyled) return null;
|
|
5
|
+
const themeStyles = generateStyles(themeConfig.theme, themeConfig.config, scope);
|
|
6
|
+
return /*#__PURE__*/ _jsx("style", {
|
|
7
|
+
children: themeStyles
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const unitless: Set<string>;
|
|
2
|
+
export declare const parts: readonly ["container", "inputContainer", "input", "inputDisabled", "inputFocus", "resultsContainer", "results", "resultsHeader", "resultsList", "resultItem", "resultItemActive", "resultItemFocus", "resultItemHover", "resultDescription", "resultHighlight", "resultMeta", "resultTitle", "collectionBadge", "scoreBadge", "error", "loading", "loadingSpinner", "noResults", "facetContainer", "facetItem", "facetItemActive", "focusable", "hidden", "visible", "dialogRoot", "dialog", "dialogBackdrop", "dialogHeader", "dialogTitle", "dialogContent", "dialogResults", "trigger", "pagination", "paginationButton", "paginationStatus", "resultLayout", "resultIcon", "resultBody", "resultMetaItem", "noResultsTitle", "noResultsDescription", "loadingIndicator"];
|
|
3
|
+
//# sourceMappingURL=constant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../src/components/themes/constant.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,aAyBnB,CAAA;AAEF,eAAO,MAAM,KAAK,8uBAgDuB,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export const unitless = new Set([
|
|
2
|
+
'opacity',
|
|
3
|
+
'zIndex',
|
|
4
|
+
'fontWeight',
|
|
5
|
+
'lineHeight',
|
|
6
|
+
'flex',
|
|
7
|
+
'flexGrow',
|
|
8
|
+
'flexShrink',
|
|
9
|
+
'order',
|
|
10
|
+
'WebkitLineClamp',
|
|
11
|
+
'aspectRatio',
|
|
12
|
+
'columnCount',
|
|
13
|
+
'columns',
|
|
14
|
+
'gridArea',
|
|
15
|
+
'gridRow',
|
|
16
|
+
'gridColumn',
|
|
17
|
+
'gridRowStart',
|
|
18
|
+
'gridRowEnd',
|
|
19
|
+
'gridColumnStart',
|
|
20
|
+
'gridColumnEnd',
|
|
21
|
+
'animationIterationCount',
|
|
22
|
+
'scale',
|
|
23
|
+
'fillOpacity',
|
|
24
|
+
'strokeOpacity',
|
|
25
|
+
'strokeWidth'
|
|
26
|
+
]);
|
|
27
|
+
export const parts = [
|
|
28
|
+
'container',
|
|
29
|
+
'inputContainer',
|
|
30
|
+
'input',
|
|
31
|
+
'inputDisabled',
|
|
32
|
+
'inputFocus',
|
|
33
|
+
'resultsContainer',
|
|
34
|
+
'results',
|
|
35
|
+
'resultsHeader',
|
|
36
|
+
'resultsList',
|
|
37
|
+
'resultItem',
|
|
38
|
+
'resultItemActive',
|
|
39
|
+
'resultItemFocus',
|
|
40
|
+
'resultItemHover',
|
|
41
|
+
'resultDescription',
|
|
42
|
+
'resultHighlight',
|
|
43
|
+
'resultMeta',
|
|
44
|
+
'resultTitle',
|
|
45
|
+
'collectionBadge',
|
|
46
|
+
'scoreBadge',
|
|
47
|
+
'error',
|
|
48
|
+
'loading',
|
|
49
|
+
'loadingSpinner',
|
|
50
|
+
'noResults',
|
|
51
|
+
'facetContainer',
|
|
52
|
+
'facetItem',
|
|
53
|
+
'facetItemActive',
|
|
54
|
+
'focusable',
|
|
55
|
+
'hidden',
|
|
56
|
+
'visible',
|
|
57
|
+
'dialogRoot',
|
|
58
|
+
'dialog',
|
|
59
|
+
'dialogBackdrop',
|
|
60
|
+
'dialogHeader',
|
|
61
|
+
'dialogTitle',
|
|
62
|
+
'dialogContent',
|
|
63
|
+
'dialogResults',
|
|
64
|
+
'trigger',
|
|
65
|
+
'pagination',
|
|
66
|
+
'paginationButton',
|
|
67
|
+
'paginationStatus',
|
|
68
|
+
'resultLayout',
|
|
69
|
+
'resultIcon',
|
|
70
|
+
'resultBody',
|
|
71
|
+
'resultMetaItem',
|
|
72
|
+
'noResultsTitle',
|
|
73
|
+
'noResultsDescription',
|
|
74
|
+
'loadingIndicator'
|
|
75
|
+
];
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type Theme, type ThemeConfig, type ThemeContextValue } from './types.js';
|
|
2
|
-
import {
|
|
1
|
+
import { type Theme, type ThemeConfig, type ThemeContextValue, type ThemeVariant } from './types.js';
|
|
2
|
+
import { generateClasses } from './utils.js';
|
|
3
3
|
export declare function useThemeConfig(config: ThemeConfig): ThemeContextValue;
|
|
4
4
|
export declare function useThemeStyles(config: ThemeConfig): Record<string, string>;
|
|
5
5
|
export declare function useResponsiveTheme(baseConfig: ThemeConfig, isMobile: boolean): ThemeConfig;
|
|
6
6
|
export declare function useThemeToggle(lightConfig: ThemeConfig, darkConfig: ThemeConfig, isDark: boolean): ThemeConfig;
|
|
7
|
-
export declare function useThemeClasses(config: ThemeConfig): ReturnType<typeof
|
|
7
|
+
export declare function useThemeClasses(config: ThemeConfig): ReturnType<typeof generateClasses>;
|
|
8
8
|
export declare function useThemeColors(config: ThemeConfig): Theme['colors'];
|
|
9
9
|
export declare function useThemeSpacing(config: ThemeConfig): Theme['spacing'];
|
|
10
10
|
export declare function useThemeTypography(config: ThemeConfig): Theme['typography'];
|
|
11
|
-
export declare function useSystemTheme():
|
|
11
|
+
export declare function useSystemTheme(): ThemeVariant;
|
|
12
12
|
export declare function useAutoTheme(lightTheme: string, darkTheme: string): string;
|
|
13
13
|
export declare function useCustomTheme(baseThemeName: string, overrides: Partial<ThemeConfig>): ThemeConfig;
|
|
14
14
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/components/themes/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/components/themes/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AACpG,OAAO,EAEL,eAAe,EAQhB,MAAM,YAAY,CAAA;AAEnB,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,iBAAiB,CAoBrE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAM1E;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,GAAG,WAAW,CAwB1F;AAED,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,WAAW,EACvB,MAAM,EAAE,OAAO,GACd,WAAW,CAEb;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAMvF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,CAMnE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,CAMrE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,CAM3E;AAED,wBAAgB,cAAc,IAAI,YAAY,CAE7C;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAI1E;AAED,wBAAgB,cAAc,CAC5B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,GAC9B,WAAW,CAQb"}
|