@rubixstudios/payload-typesense 1.6.12 → 1.7.0
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 +76 -120
- package/dist/components/HeadlessSearchInput.d.ts.map +1 -1
- package/dist/components/HeadlessSearchInput.js +174 -142
- package/dist/components/ThemeProvider.d.ts +3 -3
- package/dist/components/ThemeProvider.d.ts.map +1 -1
- package/dist/components/ThemeProvider.js +6 -5
- package/dist/components/icons/clockIcon.d.ts +2 -0
- package/dist/components/icons/clockIcon.d.ts.map +1 -0
- package/dist/components/icons/clockIcon.js +16 -0
- package/dist/components/icons/collectionIcon.d.ts +2 -0
- package/dist/components/icons/collectionIcon.d.ts.map +1 -0
- package/dist/components/icons/collectionIcon.js +16 -0
- package/dist/components/icons/errorIcon.d.ts +2 -0
- package/dist/components/icons/errorIcon.d.ts.map +1 -0
- package/dist/components/icons/errorIcon.js +16 -0
- package/dist/components/icons/index.d.ts +6 -0
- package/dist/components/icons/index.d.ts.map +1 -0
- package/dist/components/icons/index.js +5 -0
- package/dist/components/icons/noResultsIcon.d.ts +6 -0
- package/dist/components/icons/noResultsIcon.d.ts.map +1 -0
- package/dist/components/icons/noResultsIcon.js +19 -0
- package/dist/components/icons/searchIcon.d.ts +6 -0
- package/dist/components/icons/searchIcon.d.ts.map +1 -0
- package/dist/components/icons/searchIcon.js +16 -0
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -1
- package/dist/components/render/Header.d.ts +3 -3
- package/dist/components/render/Header.d.ts.map +1 -1
- package/dist/components/render/Header.js +29 -26
- package/dist/components/render/NoResults.d.ts +3 -3
- package/dist/components/render/NoResults.d.ts.map +1 -1
- package/dist/components/render/NoResults.js +34 -37
- package/dist/components/render/ResultError.d.ts +3 -3
- package/dist/components/render/ResultError.d.ts.map +1 -1
- package/dist/components/render/ResultError.js +27 -26
- package/dist/components/render/Results.d.ts +4 -4
- package/dist/components/render/Results.d.ts.map +1 -1
- package/dist/components/render/Results.js +140 -136
- package/dist/components/themes/hooks.d.ts +2 -40
- package/dist/components/themes/hooks.d.ts.map +1 -1
- package/dist/components/themes/hooks.js +33 -82
- package/dist/components/themes/themes.d.ts.map +1 -1
- package/dist/components/themes/themes.js +16 -20
- package/dist/components/themes/types.d.ts.map +1 -1
- package/dist/components/themes/utils.d.ts +2 -14
- package/dist/components/themes/utils.d.ts.map +1 -1
- package/dist/components/themes/utils.js +24 -37
- package/dist/endpoints/handler/createAdvancedSearch.d.ts +1 -1
- package/dist/endpoints/handler/createAdvancedSearch.d.ts.map +1 -1
- package/dist/endpoints/handler/createAdvancedSearch.js +72 -8
- package/dist/endpoints/handler/createCollections.d.ts +1 -1
- package/dist/endpoints/handler/createCollections.d.ts.map +1 -1
- package/dist/endpoints/handler/createCollections.js +8 -8
- package/dist/endpoints/handler/createSearch.d.ts +1 -1
- package/dist/endpoints/handler/createSearch.d.ts.map +1 -1
- package/dist/endpoints/handler/createSearch.js +45 -44
- package/dist/endpoints/handler/createSuggest.d.ts +1 -1
- package/dist/endpoints/handler/createSuggest.d.ts.map +1 -1
- package/dist/endpoints/handler/createSuggest.js +26 -11
- package/dist/endpoints/health.d.ts +2 -2
- package/dist/endpoints/health.d.ts.map +1 -1
- package/dist/endpoints/health.js +58 -52
- package/dist/endpoints/search.d.ts +2 -9
- package/dist/endpoints/search.d.ts.map +1 -1
- package/dist/endpoints/search.js +17 -16
- package/dist/{utils → hooks}/useDebounce.d.ts.map +1 -1
- package/dist/{utils → hooks}/useDebounce.js +2 -2
- package/dist/{utils → hooks}/useSearch.d.ts.map +1 -1
- package/dist/hooks/useSearch.js +93 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -32
- package/dist/lib/cache.d.ts.map +1 -1
- package/dist/lib/cache.js +54 -25
- package/dist/lib/client.d.ts +1 -1
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/client.js +35 -31
- package/dist/lib/headlessSearch.d.ts +24 -20
- package/dist/lib/headlessSearch.d.ts.map +1 -1
- package/dist/lib/hooks.d.ts +3 -11
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +12 -45
- package/dist/lib/initialization.d.ts +1 -1
- package/dist/lib/initialization.d.ts.map +1 -1
- package/dist/lib/initialization.js +51 -49
- package/dist/lib/schema-mapper.d.ts +3 -6
- package/dist/lib/schema-mapper.d.ts.map +1 -1
- package/dist/lib/schema-mapper.js +82 -84
- package/dist/lib/validation.d.ts +26 -34
- package/dist/lib/validation.d.ts.map +1 -1
- package/dist/lib/validation.js +48 -58
- package/dist/types.d.ts +154 -127
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/buildError.d.ts +1 -1
- package/dist/utils/buildError.d.ts.map +1 -1
- package/dist/utils/buildError.js +2 -2
- package/dist/utils/ensureCollection.d.ts +2 -2
- package/dist/utils/ensureCollection.d.ts.map +1 -1
- package/dist/utils/ensureCollection.js +103 -23
- package/dist/utils/extractText.d.ts.map +1 -1
- package/dist/utils/extractText.js +11 -8
- package/dist/utils/getCacheStats.d.ts.map +1 -1
- package/dist/utils/getCacheStats.js +1 -8
- package/dist/utils/getCollectionInfo.d.ts.map +1 -1
- package/dist/utils/getCollectionInfo.js +1 -1
- package/dist/utils/{getAllCollections.d.ts → getCollections.d.ts} +2 -2
- package/dist/utils/getCollections.d.ts.map +1 -0
- package/dist/utils/getCollections.js +140 -0
- package/dist/utils/keyboard.d.ts +4 -4
- package/dist/utils/keyboard.d.ts.map +1 -1
- package/dist/utils/keyboard.js +20 -22
- package/dist/utils/sortResults.d.ts +3 -0
- package/dist/utils/sortResults.d.ts.map +1 -0
- package/dist/utils/sortResults.js +73 -0
- package/dist/utils/testConnection.d.ts.map +1 -1
- package/dist/utils/vectorSearch.d.ts +3 -2
- package/dist/utils/vectorSearch.d.ts.map +1 -1
- package/dist/utils/vectorSearch.js +9 -7
- package/package.json +14 -14
- package/dist/utils/getAllCollections.d.ts.map +0 -1
- package/dist/utils/getAllCollections.js +0 -103
- package/dist/utils/useSearch.js +0 -66
- /package/dist/{utils → hooks}/useDebounce.d.ts +0 -0
- /package/dist/{utils → hooks}/useSearch.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Payload CMS + Typesense
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
The plugin is actively maintained by Rubix Studios.
|
|
3
|
+
A Typesense search plugin for Payload CMS, maintained by [Rubix Studios](https://rubixstudios.com.au). It provides automatic document synchronisation, configurable search endpoints, optional vector search, and a React search component with customisable themes.
|
|
6
4
|
|
|
7
5
|
[](https://www.npmjs.com/package/@rubixstudios/payload-typesense)
|
|
8
|
-

|
|
6
|
+
[](https://github.com/rubix-studios-pty-ltd/payload-typesense/actions/workflows/release.yml)
|
|
9
7
|
|
|
10
8
|
## Installation
|
|
11
9
|
|
|
@@ -13,16 +11,18 @@ The plugin is actively maintained by Rubix Studios.
|
|
|
13
11
|
pnpm add @rubixstudios/payload-typesense
|
|
14
12
|
```
|
|
15
13
|
|
|
14
|
+
Add the plugin to your Payload configuration and specify the collections you want indexed.
|
|
15
|
+
|
|
16
16
|
```typescript
|
|
17
17
|
// payload.config.ts
|
|
18
|
-
import { buildConfig } from 'payload
|
|
18
|
+
import { buildConfig } from 'payload'
|
|
19
19
|
import { typesenseSearch } from '@rubixstudios/payload-typesense'
|
|
20
20
|
|
|
21
21
|
export default buildConfig({
|
|
22
22
|
plugins: [
|
|
23
23
|
typesenseSearch({
|
|
24
24
|
typesense: {
|
|
25
|
-
apiKey:
|
|
25
|
+
apiKey: process.env.TYPESENSE_API_KEY!,
|
|
26
26
|
nodes: [
|
|
27
27
|
{
|
|
28
28
|
host: 'localhost',
|
|
@@ -38,31 +38,30 @@ export default buildConfig({
|
|
|
38
38
|
facetFields: ['category', 'status'],
|
|
39
39
|
displayName: 'Blog Posts',
|
|
40
40
|
icon: '📝',
|
|
41
|
-
syncLimit: 500,
|
|
41
|
+
syncLimit: 500,
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
|
-
// This feature is experimental
|
|
45
|
-
vectorSearch: {
|
|
46
|
-
enabled: true, // Enables vector-based semantic search
|
|
47
|
-
embedFrom: ['title', 'content'], // Omit to fall back to collection searchFields
|
|
48
|
-
embeddingModel: 'azure/text-embedding-ada-002',
|
|
49
|
-
modelConfig: {
|
|
50
|
-
api_key: 'your-api-key',
|
|
51
|
-
url: 'https://modelendpoint.com/openai',
|
|
52
|
-
},
|
|
53
44
|
}),
|
|
54
45
|
],
|
|
55
46
|
})
|
|
56
47
|
```
|
|
57
48
|
|
|
49
|
+
The plugin initialises enabled collections in Typesense and synchronises existing documents during startup. Subsequent document changes and deletions are handled through Payload collection hooks when automatic synchronisation is enabled.
|
|
50
|
+
|
|
51
|
+
### React search component
|
|
52
|
+
|
|
53
|
+
`HeadlessSearchInput` provides a configurable search interface with keyboard navigation, loading states, result callbacks, and custom rendering support.
|
|
54
|
+
|
|
58
55
|
```tsx
|
|
56
|
+
'use client'
|
|
57
|
+
|
|
59
58
|
import { HeadlessSearchInput } from '@rubixstudios/payload-typesense'
|
|
60
59
|
|
|
61
|
-
export function
|
|
60
|
+
export function GlobalSearch() {
|
|
62
61
|
return (
|
|
63
62
|
<HeadlessSearchInput
|
|
64
63
|
baseUrl="http://localhost:3000"
|
|
65
|
-
theme="modern"
|
|
64
|
+
theme="modern"
|
|
66
65
|
placeholder="Search everything..."
|
|
67
66
|
onResultClick={(result) => {
|
|
68
67
|
console.log('Selected document:', result.document)
|
|
@@ -70,85 +69,67 @@ export function GlobalSearchPage() {
|
|
|
70
69
|
/>
|
|
71
70
|
)
|
|
72
71
|
}
|
|
72
|
+
```
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<HeadlessSearchInput
|
|
77
|
-
baseUrl="http://localhost:3000"
|
|
78
|
-
collections={['posts', 'products']}
|
|
79
|
-
placeholder="Search posts and products..."
|
|
80
|
-
onResultClick={(result) => {
|
|
81
|
-
console.log('Selected document:', result.document)
|
|
82
|
-
}}
|
|
83
|
-
/>
|
|
84
|
-
)
|
|
85
|
-
}
|
|
74
|
+
Search all enabled collections by default, or use the `collections` prop to restrict results.
|
|
86
75
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
placeholder="Search posts and products..."
|
|
94
|
-
onResultClick={(result) => {
|
|
95
|
-
console.log('Selected document:', result.document)
|
|
96
|
-
}}
|
|
97
|
-
/>
|
|
98
|
-
)
|
|
99
|
-
}
|
|
76
|
+
```tsx
|
|
77
|
+
<HeadlessSearchInput
|
|
78
|
+
baseUrl="http://localhost:3000"
|
|
79
|
+
collections={['posts', 'products']}
|
|
80
|
+
placeholder="Search posts and products..."
|
|
81
|
+
/>
|
|
100
82
|
```
|
|
101
83
|
|
|
84
|
+
Vector search can also be requested using the `vector` prop when embedding support is configured.
|
|
85
|
+
|
|
102
86
|
## Features
|
|
103
87
|
|
|
104
|
-
-
|
|
105
|
-
Sub-millisecond search responses with optimized request handling.
|
|
106
|
-
- **Flexible Search**
|
|
107
|
-
Single-collection, multi-collection, or universal search using one component.
|
|
108
|
-
- **Vector Search**
|
|
109
|
-
Optional semantic search using embeddings, with graceful fallback to keyword search.
|
|
110
|
-
- **Modern UI**
|
|
111
|
-
Headless, responsive implementation compatible with Tailwind CSS.
|
|
112
|
-
- **Real-Time Synchronisation**
|
|
113
|
-
Continuous indexing and sync with Payload CMS.
|
|
114
|
-
- **Efficient Caching**
|
|
115
|
-
In-memory caching with configurable TTL and race-condition safeguards.
|
|
116
|
-
- **Production Ready**
|
|
117
|
-
Robust error handling, deployment-safe defaults, and platform compatibility.
|
|
118
|
-
- **Tree-Shakable Architecture**
|
|
119
|
-
Modular design enabling smaller bundles and selective feature usage.
|
|
120
|
-
|
|
121
|
-
## Endpoints
|
|
122
|
-
|
|
123
|
-
- `GET /api/search` - Universal search across all collections
|
|
124
|
-
- `GET /api/search/{collection}` - Search specific collection
|
|
125
|
-
- `POST /api/search/{collection}` - Advanced search with filters
|
|
126
|
-
- `GET /api/search/{collection}/suggest` - Search suggestions
|
|
127
|
-
- `GET /api/search/collections` - Collection metadata
|
|
128
|
-
- `GET /api/search/health` - Health check
|
|
129
|
-
|
|
130
|
-
## Components
|
|
131
|
-
|
|
132
|
-
- **HeadlessSearchInput**: Single component supporting all search patterns:
|
|
133
|
-
- **Collections**: `collections={['posts', 'products']}` - Smart filtering with universal search
|
|
134
|
-
- **Universal Search**: No collection props - Search across all collections
|
|
135
|
-
- **Complete UI Control**: Customizable rendering with comprehensive theme system
|
|
88
|
+
The plugin supports keyword search across individual or multiple collections, with configurable searchable fields, filtering, sorting, faceting, and highlighting through Typesense. Search endpoints include in-memory caching to reduce repeated requests.
|
|
136
89
|
|
|
137
|
-
|
|
90
|
+
Document synchronisation is handled through Payload hooks, while existing documents are indexed during initialisation. Optional vector search enables embedding-based queries through supported models and Typesense configuration.
|
|
138
91
|
|
|
139
|
-
The
|
|
92
|
+
The included React component provides modern and dark themes, responsive styling, and custom rendering options without requiring a separate search UI library.
|
|
140
93
|
|
|
141
|
-
|
|
94
|
+
## API endpoints
|
|
142
95
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
96
|
+
Search endpoints are registered under Payload's `/api` path by default.
|
|
97
|
+
|
|
98
|
+
| Method | Endpoint | Purpose |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| GET | `/api/search` | Search across collections |
|
|
101
|
+
| GET | `/api/search/{collection}` | Search a collection |
|
|
102
|
+
| POST | `/api/search/{collection}` | Advanced search |
|
|
103
|
+
| GET | `/api/search/{collection}/suggest` | Search suggestions |
|
|
104
|
+
| GET | `/api/search/collections` | Available collections |
|
|
105
|
+
| GET | `/api/search/health` | Health status |
|
|
106
|
+
| GET | `/api/search/health/detailed` | Detailed health information |
|
|
107
|
+
|
|
108
|
+
Requests support pagination and the relevant Typesense search parameters. Vector search is available through the `vector=true` query parameter when enabled.
|
|
146
109
|
|
|
147
|
-
|
|
148
|
-
|
|
110
|
+
## Vector search
|
|
111
|
+
|
|
112
|
+
Vector search is optional and experimental. Configure an embedding model and the fields used to generate embeddings.
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
vectorSearch: {
|
|
116
|
+
enabled: true,
|
|
117
|
+
embedFrom: ['title', 'content'],
|
|
118
|
+
embeddingModel: 'azure/text-embedding-ada-002',
|
|
119
|
+
modelConfig: {
|
|
120
|
+
api_key: process.env.EMBEDDING_API_KEY!,
|
|
121
|
+
url: 'https://modelendpoint.com/openai',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
149
124
|
```
|
|
150
125
|
|
|
151
|
-
|
|
126
|
+
When `embedFrom` is omitted, the plugin uses the collection's configured search fields. Embedding model credentials and endpoint settings depend on the selected provider.
|
|
127
|
+
|
|
128
|
+
To request vector search from the React component, pass `vector={true}`.
|
|
129
|
+
|
|
130
|
+
## Themes
|
|
131
|
+
|
|
132
|
+
Two themes are included, `modern` (default) and `dark`. Both can be customised using theme configuration options for colours, spacing, typography, shadows, and animations.
|
|
152
133
|
|
|
153
134
|
```tsx
|
|
154
135
|
const customTheme = {
|
|
@@ -166,47 +147,22 @@ const customTheme = {
|
|
|
166
147
|
enableShadows: true,
|
|
167
148
|
}
|
|
168
149
|
|
|
169
|
-
<HeadlessSearchInput
|
|
150
|
+
<HeadlessSearchInput
|
|
151
|
+
baseUrl="http://localhost:3000"
|
|
152
|
+
theme={customTheme}
|
|
153
|
+
/>
|
|
170
154
|
```
|
|
171
155
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
- **2 Pre-built Themes**: Modern, Dark
|
|
175
|
-
- **Unlimited Customization**: Override any color, spacing, typography, or animation
|
|
176
|
-
- **Performance Options**: Disable animations/shadows for better performance
|
|
177
|
-
- **Responsive Design**: Automatic mobile optimization
|
|
178
|
-
- **CSS Variables**: Advanced styling with CSS custom properties
|
|
179
|
-
- **TypeScript Support**: Full type safety for all theme configurations
|
|
180
|
-
|
|
181
|
-
## Production
|
|
182
|
-
|
|
183
|
-
- **Race Condition Protection**: `ensureCollection` prevents startup crashes
|
|
184
|
-
- **Type Safety**: Proper Payload CMS types prevent runtime errors
|
|
185
|
-
- **Document Validation**: Filters malformed data before sync
|
|
186
|
-
- **Graceful Degradation**: Silent failures don't break Payload operations
|
|
187
|
-
|
|
188
|
-
## Developer
|
|
189
|
-
|
|
190
|
-
- **Smaller Components**: Easier to understand and maintain
|
|
191
|
-
- **Maintainable**: Single Responsibility Principle enforced
|
|
192
|
-
- **Well-Documented**: Clear separation of concerns
|
|
193
|
-
|
|
194
|
-
## License
|
|
195
|
-
|
|
196
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
156
|
+
The component also supports custom class names and rendering callbacks for more control over the search interface.
|
|
197
157
|
|
|
198
158
|
## Support
|
|
199
159
|
|
|
200
|
-
For
|
|
201
|
-
|
|
202
|
-
- LinkedIn: [rubixvi](https://www.linkedin.com/in/rubixvi/)
|
|
203
|
-
- Website: [Rubix Studios](https://rubixstudios.com.au)
|
|
160
|
+
For issues, questions, or feature requests, visit [GitHub Issues](https://github.com/rubix-studios-pty-ltd/payload-typesense/issues) or contact [Rubix Studios](https://rubixstudios.com.au).
|
|
204
161
|
|
|
205
|
-
##
|
|
162
|
+
## License
|
|
206
163
|
|
|
207
|
-
|
|
208
|
-
[https://rubixstudios.com.au](https://rubixstudios.com.au)
|
|
164
|
+
Licensed under the MIT License. See [LICENSE](LICENSE) for details.
|
|
209
165
|
|
|
210
|
-
##
|
|
166
|
+
## Credits
|
|
211
167
|
|
|
212
|
-
|
|
168
|
+
Developed and maintained by [Rubix Studios](https://rubixstudios.com.au). Based on the original [FrontTribe Typesense Search](https://github.com/FrontTribe/typesense-search) project.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeadlessSearchInput.d.ts","sourceRoot":"","sources":["../../src/components/HeadlessSearchInput.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"HeadlessSearchInput.d.ts","sourceRoot":"","sources":["../../src/components/HeadlessSearchInput.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAA;AAI1D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AAWxE,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,KAAK,EAAE,wBAAwB,CAAC,CAAC,CAAC,GACjC,KAAK,CAAC,YAAY,CAoUpB;eAEc,mBAAmB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import
|
|
3
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { useDebounce } from '../hooks/useDebounce.js';
|
|
5
|
+
import { useSearch } from '../hooks/useSearch.js';
|
|
4
6
|
import { handleKeyboard } from '../utils/keyboard.js';
|
|
5
|
-
import { useDebounce } from '../utils/useDebounce.js';
|
|
6
|
-
import { useSearch } from '../utils/useSearch.js';
|
|
7
7
|
import { RenderedHeader, RenderedNoResults, RenderedResult, RenderedResultError } from './render/index.js';
|
|
8
8
|
import { useThemeConfig } from './themes/hooks.js';
|
|
9
9
|
export function HeadlessSearchInput(props) {
|
|
10
|
-
const { baseUrl, className = '', collections, debounceMs = 300, enableSuggestions
|
|
10
|
+
const { baseUrl, className = '', collections, debounceMs = 300, enableSuggestions = true, errorClassName = '', inputClassName = '', inputWrapperClassName = '', minQueryLength = 2, noResultsClassName = '', 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 = 'modern', vector = false } = props;
|
|
11
11
|
const [query, setQuery] = useState('');
|
|
12
12
|
const [isOpen, setIsOpen] = useState(false);
|
|
13
13
|
const inputRef = useRef(null);
|
|
@@ -27,21 +27,18 @@ export function HeadlessSearchInput(props) {
|
|
|
27
27
|
vector
|
|
28
28
|
});
|
|
29
29
|
useEffect(()=>{
|
|
30
|
-
|
|
31
|
-
void search(debouncedQuery);
|
|
32
|
-
}
|
|
30
|
+
void search(debouncedQuery);
|
|
33
31
|
}, [
|
|
34
32
|
debouncedQuery,
|
|
35
|
-
minQueryLength,
|
|
36
33
|
search
|
|
37
34
|
]);
|
|
38
|
-
const handleInputChange = (
|
|
39
|
-
const value =
|
|
35
|
+
const handleInputChange = (event)=>{
|
|
36
|
+
const value = event.target.value;
|
|
40
37
|
setQuery(value);
|
|
41
|
-
setIsOpen(value.length >= minQueryLength);
|
|
38
|
+
setIsOpen(enableSuggestions && value.length >= minQueryLength);
|
|
42
39
|
};
|
|
43
40
|
const handleInputFocus = ()=>{
|
|
44
|
-
if (query.length >= minQueryLength) {
|
|
41
|
+
if (enableSuggestions && query.length >= minQueryLength) {
|
|
45
42
|
setIsOpen(true);
|
|
46
43
|
}
|
|
47
44
|
};
|
|
@@ -57,6 +54,9 @@ export function HeadlessSearchInput(props) {
|
|
|
57
54
|
setIsOpen(false);
|
|
58
55
|
setQuery('');
|
|
59
56
|
};
|
|
57
|
+
const handleResultHover = (result)=>{
|
|
58
|
+
onResultHover?.(result);
|
|
59
|
+
};
|
|
60
60
|
const handleKeyDown = (e)=>{
|
|
61
61
|
handleKeyboard(e, {
|
|
62
62
|
inputRef,
|
|
@@ -65,141 +65,173 @@ export function HeadlessSearchInput(props) {
|
|
|
65
65
|
resultsRef
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
|
-
return /*#__PURE__*/
|
|
68
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
69
69
|
className: className,
|
|
70
70
|
style: {
|
|
71
71
|
margin: '0 auto',
|
|
72
72
|
maxWidth: '600px',
|
|
73
73
|
position: 'relative',
|
|
74
74
|
width: '100%'
|
|
75
|
-
}
|
|
76
|
-
}, /*#__PURE__*/ React.createElement("div", {
|
|
77
|
-
className: inputWrapperClassName,
|
|
78
|
-
style: {
|
|
79
|
-
position: 'relative',
|
|
80
|
-
width: '100%'
|
|
81
|
-
}
|
|
82
|
-
}, renderInput ? renderInput({
|
|
83
|
-
className: inputClassName,
|
|
84
|
-
onBlur: handleInputBlur,
|
|
85
|
-
onChange: handleInputChange,
|
|
86
|
-
onFocus: handleInputFocus,
|
|
87
|
-
onKeyDown: handleKeyDown,
|
|
88
|
-
placeholder,
|
|
89
|
-
ref: inputRef,
|
|
90
|
-
value: query
|
|
91
|
-
}) : /*#__PURE__*/ React.createElement("input", {
|
|
92
|
-
"aria-label": "Search input",
|
|
93
|
-
autoComplete: "off",
|
|
94
|
-
className: inputClassName,
|
|
95
|
-
onBlur: (e)=>{
|
|
96
|
-
e.target.style.borderColor = themeConfig.theme.colors.inputBorder;
|
|
97
|
-
e.target.style.boxShadow = 'none';
|
|
98
|
-
handleInputBlur(e);
|
|
99
|
-
},
|
|
100
|
-
onChange: handleInputChange,
|
|
101
|
-
onFocus: (e)=>{
|
|
102
|
-
e.target.style.borderColor = themeConfig.theme.colors.inputBorderFocus;
|
|
103
|
-
e.target.style.boxShadow = themeConfig.config.enableShadows !== false ? `0 0 0 3px ${themeConfig.theme.colors.inputBorderFocus}20` : 'none';
|
|
104
|
-
handleInputFocus();
|
|
105
|
-
},
|
|
106
|
-
onKeyDown: handleKeyDown,
|
|
107
|
-
placeholder: placeholder,
|
|
108
|
-
ref: inputRef,
|
|
109
|
-
style: {
|
|
110
|
-
backgroundColor: themeConfig.theme.colors.inputBackground,
|
|
111
|
-
border: `2px solid ${themeConfig.theme.colors.inputBorder}`,
|
|
112
|
-
borderRadius: themeConfig.config.enableRoundedCorners !== false ? themeConfig.theme.spacing.inputBorderRadius : '0',
|
|
113
|
-
boxShadow: 'none',
|
|
114
|
-
color: themeConfig.theme.colors.inputText,
|
|
115
|
-
fontFamily: themeConfig.theme.typography.fontFamily,
|
|
116
|
-
fontSize: themeConfig.theme.spacing.inputFontSize,
|
|
117
|
-
fontWeight: themeConfig.theme.typography.fontWeightNormal,
|
|
118
|
-
lineHeight: themeConfig.theme.typography.lineHeightNormal,
|
|
119
|
-
outline: 'none',
|
|
120
|
-
padding: themeConfig.theme.spacing.inputPadding,
|
|
121
|
-
transition: themeConfig.config.enableAnimations !== false ? `all ${themeConfig.theme.animations.transitionNormal} ${themeConfig.theme.animations.easeInOut}` : 'none',
|
|
122
|
-
width: '100%'
|
|
123
75
|
},
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
76
|
+
children: [
|
|
77
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
78
|
+
className: inputWrapperClassName,
|
|
79
|
+
style: {
|
|
80
|
+
position: 'relative',
|
|
81
|
+
width: '100%'
|
|
82
|
+
},
|
|
83
|
+
children: [
|
|
84
|
+
renderInput ? renderInput({
|
|
85
|
+
className: inputClassName,
|
|
86
|
+
onBlur: handleInputBlur,
|
|
87
|
+
onChange: handleInputChange,
|
|
88
|
+
onFocus: handleInputFocus,
|
|
89
|
+
onKeyDown: handleKeyDown,
|
|
90
|
+
placeholder,
|
|
91
|
+
ref: inputRef,
|
|
92
|
+
value: query
|
|
93
|
+
}) : /*#__PURE__*/ _jsx("input", {
|
|
94
|
+
"aria-label": "Search input",
|
|
95
|
+
autoComplete: "off",
|
|
96
|
+
className: inputClassName,
|
|
97
|
+
onBlur: (e)=>{
|
|
98
|
+
e.target.style.borderColor = themeConfig.theme.colors.inputBorder;
|
|
99
|
+
e.target.style.boxShadow = 'none';
|
|
100
|
+
handleInputBlur(e);
|
|
101
|
+
},
|
|
102
|
+
onChange: handleInputChange,
|
|
103
|
+
onFocus: (e)=>{
|
|
104
|
+
e.target.style.borderColor = themeConfig.theme.colors.inputBorderFocus;
|
|
105
|
+
e.target.style.boxShadow = themeConfig.config.enableShadows !== false ? `0 0 0 3px ${themeConfig.theme.colors.inputBorderFocus}20` : 'none';
|
|
106
|
+
handleInputFocus();
|
|
107
|
+
},
|
|
108
|
+
onKeyDown: handleKeyDown,
|
|
109
|
+
placeholder: placeholder,
|
|
110
|
+
ref: inputRef,
|
|
111
|
+
style: {
|
|
112
|
+
backgroundColor: themeConfig.theme.colors.inputBackground,
|
|
113
|
+
border: `2px solid ${themeConfig.theme.colors.inputBorder}`,
|
|
114
|
+
borderRadius: themeConfig.config.enableRoundedCorners !== false ? themeConfig.theme.spacing.inputBorderRadius : '0',
|
|
115
|
+
boxShadow: 'none',
|
|
116
|
+
color: themeConfig.theme.colors.inputText,
|
|
117
|
+
fontFamily: themeConfig.theme.typography.fontFamily,
|
|
118
|
+
fontSize: themeConfig.theme.spacing.inputFontSize,
|
|
119
|
+
fontWeight: themeConfig.theme.typography.fontWeightNormal,
|
|
120
|
+
lineHeight: themeConfig.theme.typography.lineHeightNormal,
|
|
121
|
+
outline: 'none',
|
|
122
|
+
padding: themeConfig.theme.spacing.inputPadding,
|
|
123
|
+
transition: themeConfig.config.enableAnimations !== false ? `all ${themeConfig.theme.animations.transitionNormal} ${themeConfig.theme.animations.easeInOut}` : 'none',
|
|
124
|
+
width: '100%'
|
|
125
|
+
},
|
|
126
|
+
title: "Search input",
|
|
127
|
+
type: "text",
|
|
128
|
+
value: query
|
|
129
|
+
}),
|
|
130
|
+
isLoading && showLoading && (renderLoading ? renderLoading() : /*#__PURE__*/ _jsxs("div", {
|
|
131
|
+
style: {
|
|
132
|
+
position: 'absolute',
|
|
133
|
+
right: '12px',
|
|
134
|
+
top: '50%',
|
|
135
|
+
transform: 'translateY(-50%)'
|
|
136
|
+
},
|
|
137
|
+
children: [
|
|
138
|
+
/*#__PURE__*/ _jsx("style", {
|
|
139
|
+
children: `
|
|
140
|
+
@keyframes spin {
|
|
141
|
+
0% { transform: rotate(0deg); }
|
|
142
|
+
100% { transform: rotate(360deg); }
|
|
143
|
+
}
|
|
144
|
+
`
|
|
145
|
+
}),
|
|
146
|
+
/*#__PURE__*/ _jsx("div", {
|
|
147
|
+
"data-testid": "loading-spinner",
|
|
148
|
+
style: {
|
|
149
|
+
animation: 'spin 1s linear infinite',
|
|
150
|
+
border: `2px solid ${themeConfig.theme.colors.inputBorder}`,
|
|
151
|
+
borderRadius: '50%',
|
|
152
|
+
borderTop: `2px solid ${themeConfig.theme.colors.inputBorderFocus}`,
|
|
153
|
+
height: '16px',
|
|
154
|
+
width: '16px'
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
]
|
|
158
|
+
}))
|
|
159
|
+
]
|
|
160
|
+
}),
|
|
161
|
+
enableSuggestions && isOpen && (results || error) && // biome-ignore lint/a11y/noStaticElementInteractions: Handle keyboard navigation
|
|
162
|
+
/*#__PURE__*/ _jsx("div", {
|
|
163
|
+
className: resultsContainerClassName,
|
|
164
|
+
onKeyDown: (event)=>{
|
|
165
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
166
|
+
handleKeyDown(event);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
ref: resultsRef,
|
|
170
|
+
style: {
|
|
171
|
+
backgroundColor: themeConfig.theme.colors.resultsBackground,
|
|
172
|
+
border: `1px solid ${themeConfig.theme.colors.resultsBorder}`,
|
|
173
|
+
borderRadius: themeConfig.config.enableRoundedCorners !== false ? themeConfig.theme.spacing.resultsBorderRadius : '0',
|
|
174
|
+
boxShadow: themeConfig.config.enableShadows !== false ? themeConfig.theme.shadows.shadowLg : 'none',
|
|
175
|
+
boxSizing: 'border-box',
|
|
176
|
+
display: 'flex',
|
|
177
|
+
left: '0',
|
|
178
|
+
marginTop: '10px',
|
|
179
|
+
maxHeight: themeConfig.theme.spacing.resultsMaxHeight,
|
|
180
|
+
overflow: 'hidden',
|
|
181
|
+
padding: '4px',
|
|
182
|
+
position: 'absolute',
|
|
183
|
+
right: '0',
|
|
184
|
+
top: '100%',
|
|
185
|
+
zIndex: 1000,
|
|
186
|
+
...themeConfig.config.enableAnimations !== false && {
|
|
187
|
+
animation: `slideDown ${themeConfig.theme.animations.animationNormal} ${themeConfig.theme.animations.easeOut}`
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
191
|
+
className: `relative ${resultsClassName}`,
|
|
192
|
+
style: {
|
|
193
|
+
minHeight: 0,
|
|
194
|
+
overflowY: 'auto'
|
|
195
|
+
},
|
|
196
|
+
children: [
|
|
197
|
+
error && (renderError ? renderError(error) : /*#__PURE__*/ _jsx(RenderedResultError, {
|
|
198
|
+
error: error,
|
|
199
|
+
errorClassName: errorClassName,
|
|
200
|
+
themeConfig: themeConfig
|
|
201
|
+
})),
|
|
202
|
+
!error && results && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
203
|
+
children: [
|
|
204
|
+
showResultCount && (renderResultsHeader ? renderResultsHeader(results.found) : /*#__PURE__*/ _jsx(RenderedHeader, {
|
|
205
|
+
found: results.found,
|
|
206
|
+
resultsHeaderClassName: resultsHeaderClassName,
|
|
207
|
+
themeConfig: themeConfig
|
|
208
|
+
})),
|
|
209
|
+
results.hits.length > 0 ? /*#__PURE__*/ _jsx("div", {
|
|
210
|
+
className: resultsListClassName,
|
|
211
|
+
children: results.hits.map((result, index)=>renderResult ? renderResult(result, index, {
|
|
212
|
+
onClick: handleResultClick,
|
|
213
|
+
onHover: handleResultHover
|
|
214
|
+
}) : /*#__PURE__*/ _jsx(RenderedResult, {
|
|
215
|
+
index: index,
|
|
216
|
+
onResultClick: handleResultClick,
|
|
217
|
+
onResultHover: ()=>handleResultHover(result),
|
|
218
|
+
renderDate: renderDate,
|
|
219
|
+
result: result,
|
|
220
|
+
resultItemClassName: resultItemClassName,
|
|
221
|
+
resultsContainerClassName: resultsContainerClassName,
|
|
222
|
+
themeConfig: themeConfig
|
|
223
|
+
}, result.document?.id || result.id || index))
|
|
224
|
+
}) : renderNoResults ? renderNoResults(query) : /*#__PURE__*/ _jsx(RenderedNoResults, {
|
|
225
|
+
noResultsClassName: noResultsClassName,
|
|
226
|
+
query: query,
|
|
227
|
+
themeConfig: themeConfig
|
|
228
|
+
})
|
|
229
|
+
]
|
|
230
|
+
})
|
|
231
|
+
]
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
]
|
|
235
|
+
});
|
|
204
236
|
}
|
|
205
237
|
export default HeadlessSearchInput;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
2
|
import { type ThemeConfig, type ThemeContextValue } from './themes/types.js';
|
|
3
3
|
interface ThemeProviderProps {
|
|
4
|
-
children:
|
|
4
|
+
children: ReactNode;
|
|
5
5
|
config: ThemeConfig;
|
|
6
6
|
}
|
|
7
|
-
export declare function ThemeProvider({ children, config }: ThemeProviderProps):
|
|
7
|
+
export declare function ThemeProvider({ children, config }: ThemeProviderProps): import("react").JSX.Element;
|
|
8
8
|
export declare function useTheme(): ThemeContextValue;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=ThemeProvider.d.ts.map
|