@rubixstudios/payload-typesense 1.6.13 → 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.
Files changed (123) hide show
  1. package/README.md +76 -120
  2. package/dist/components/HeadlessSearchInput.d.ts.map +1 -1
  3. package/dist/components/HeadlessSearchInput.js +173 -140
  4. package/dist/components/ThemeProvider.d.ts +2 -2
  5. package/dist/components/ThemeProvider.d.ts.map +1 -1
  6. package/dist/components/ThemeProvider.js +7 -5
  7. package/dist/components/icons/clockIcon.d.ts +2 -0
  8. package/dist/components/icons/clockIcon.d.ts.map +1 -0
  9. package/dist/components/icons/clockIcon.js +16 -0
  10. package/dist/components/icons/collectionIcon.d.ts +2 -0
  11. package/dist/components/icons/collectionIcon.d.ts.map +1 -0
  12. package/dist/components/icons/collectionIcon.js +16 -0
  13. package/dist/components/icons/errorIcon.d.ts +2 -0
  14. package/dist/components/icons/errorIcon.d.ts.map +1 -0
  15. package/dist/components/icons/errorIcon.js +16 -0
  16. package/dist/components/icons/index.d.ts +6 -0
  17. package/dist/components/icons/index.d.ts.map +1 -0
  18. package/dist/components/icons/index.js +5 -0
  19. package/dist/components/icons/noResultsIcon.d.ts +6 -0
  20. package/dist/components/icons/noResultsIcon.d.ts.map +1 -0
  21. package/dist/components/icons/noResultsIcon.js +19 -0
  22. package/dist/components/icons/searchIcon.d.ts +6 -0
  23. package/dist/components/icons/searchIcon.d.ts.map +1 -0
  24. package/dist/components/icons/searchIcon.js +16 -0
  25. package/dist/components/index.d.ts +2 -1
  26. package/dist/components/index.d.ts.map +1 -1
  27. package/dist/components/index.js +2 -1
  28. package/dist/components/render/Header.d.ts +3 -3
  29. package/dist/components/render/Header.d.ts.map +1 -1
  30. package/dist/components/render/Header.js +29 -26
  31. package/dist/components/render/NoResults.d.ts +3 -3
  32. package/dist/components/render/NoResults.d.ts.map +1 -1
  33. package/dist/components/render/NoResults.js +34 -37
  34. package/dist/components/render/ResultError.d.ts +3 -3
  35. package/dist/components/render/ResultError.d.ts.map +1 -1
  36. package/dist/components/render/ResultError.js +27 -26
  37. package/dist/components/render/Results.d.ts +4 -4
  38. package/dist/components/render/Results.d.ts.map +1 -1
  39. package/dist/components/render/Results.js +140 -136
  40. package/dist/components/themes/hooks.d.ts +2 -40
  41. package/dist/components/themes/hooks.d.ts.map +1 -1
  42. package/dist/components/themes/hooks.js +33 -82
  43. package/dist/components/themes/themes.d.ts.map +1 -1
  44. package/dist/components/themes/themes.js +16 -20
  45. package/dist/components/themes/types.d.ts.map +1 -1
  46. package/dist/components/themes/utils.d.ts +2 -14
  47. package/dist/components/themes/utils.d.ts.map +1 -1
  48. package/dist/components/themes/utils.js +24 -37
  49. package/dist/endpoints/handler/createAdvancedSearch.d.ts +1 -1
  50. package/dist/endpoints/handler/createAdvancedSearch.d.ts.map +1 -1
  51. package/dist/endpoints/handler/createAdvancedSearch.js +72 -8
  52. package/dist/endpoints/handler/createCollections.d.ts +1 -1
  53. package/dist/endpoints/handler/createCollections.d.ts.map +1 -1
  54. package/dist/endpoints/handler/createCollections.js +8 -8
  55. package/dist/endpoints/handler/createSearch.d.ts +1 -1
  56. package/dist/endpoints/handler/createSearch.d.ts.map +1 -1
  57. package/dist/endpoints/handler/createSearch.js +38 -30
  58. package/dist/endpoints/handler/createSuggest.d.ts +1 -1
  59. package/dist/endpoints/handler/createSuggest.d.ts.map +1 -1
  60. package/dist/endpoints/handler/createSuggest.js +26 -11
  61. package/dist/endpoints/health.d.ts +2 -2
  62. package/dist/endpoints/health.d.ts.map +1 -1
  63. package/dist/endpoints/health.js +58 -52
  64. package/dist/endpoints/search.d.ts +2 -9
  65. package/dist/endpoints/search.d.ts.map +1 -1
  66. package/dist/endpoints/search.js +17 -16
  67. package/dist/{utils → hooks}/useDebounce.d.ts.map +1 -1
  68. package/dist/{utils → hooks}/useDebounce.js +2 -2
  69. package/dist/{utils → hooks}/useSearch.d.ts.map +1 -1
  70. package/dist/hooks/useSearch.js +93 -0
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +38 -32
  73. package/dist/lib/cache.d.ts.map +1 -1
  74. package/dist/lib/cache.js +54 -25
  75. package/dist/lib/client.d.ts +1 -1
  76. package/dist/lib/client.d.ts.map +1 -1
  77. package/dist/lib/client.js +35 -31
  78. package/dist/lib/headlessSearch.d.ts +24 -20
  79. package/dist/lib/headlessSearch.d.ts.map +1 -1
  80. package/dist/lib/hooks.d.ts +3 -11
  81. package/dist/lib/hooks.d.ts.map +1 -1
  82. package/dist/lib/hooks.js +12 -45
  83. package/dist/lib/initialization.d.ts +1 -1
  84. package/dist/lib/initialization.d.ts.map +1 -1
  85. package/dist/lib/initialization.js +51 -49
  86. package/dist/lib/schema-mapper.d.ts +3 -6
  87. package/dist/lib/schema-mapper.d.ts.map +1 -1
  88. package/dist/lib/schema-mapper.js +82 -84
  89. package/dist/lib/validation.d.ts +26 -34
  90. package/dist/lib/validation.d.ts.map +1 -1
  91. package/dist/lib/validation.js +48 -58
  92. package/dist/types.d.ts +154 -127
  93. package/dist/types.d.ts.map +1 -1
  94. package/dist/types.js +1 -1
  95. package/dist/utils/buildError.d.ts +1 -1
  96. package/dist/utils/buildError.d.ts.map +1 -1
  97. package/dist/utils/buildError.js +2 -2
  98. package/dist/utils/ensureCollection.d.ts +2 -2
  99. package/dist/utils/ensureCollection.d.ts.map +1 -1
  100. package/dist/utils/ensureCollection.js +103 -23
  101. package/dist/utils/extractText.d.ts.map +1 -1
  102. package/dist/utils/extractText.js +11 -8
  103. package/dist/utils/getCacheStats.d.ts.map +1 -1
  104. package/dist/utils/getCacheStats.js +1 -8
  105. package/dist/utils/getCollectionInfo.js +1 -1
  106. package/dist/utils/{getAllCollections.d.ts → getCollections.d.ts} +2 -2
  107. package/dist/utils/getCollections.d.ts.map +1 -0
  108. package/dist/utils/getCollections.js +140 -0
  109. package/dist/utils/keyboard.d.ts +4 -4
  110. package/dist/utils/keyboard.d.ts.map +1 -1
  111. package/dist/utils/keyboard.js +20 -22
  112. package/dist/utils/sortResults.d.ts +3 -0
  113. package/dist/utils/sortResults.d.ts.map +1 -0
  114. package/dist/utils/sortResults.js +73 -0
  115. package/dist/utils/vectorSearch.d.ts +3 -2
  116. package/dist/utils/vectorSearch.d.ts.map +1 -1
  117. package/dist/utils/vectorSearch.js +9 -7
  118. package/package.json +9 -9
  119. package/dist/utils/getAllCollections.d.ts.map +0 -1
  120. package/dist/utils/getAllCollections.js +0 -103
  121. package/dist/utils/useSearch.js +0 -66
  122. /package/dist/{utils → hooks}/useDebounce.d.ts +0 -0
  123. /package/dist/{utils → hooks}/useSearch.d.ts +0 -0
package/README.md CHANGED
@@ -1,11 +1,9 @@
1
- # PayloadCMS + Typesense Plugin
1
+ # Payload CMS + Typesense
2
2
 
3
- Rubix Studios' Typesense integration for Payload CMS is built for production search workflows, with a lightweight, modular structure and optional support for advanced capabilities such as vector querying.
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
  [![npm version](https://img.shields.io/npm/v/@rubixstudios/payload-typesense.svg)](https://www.npmjs.com/package/@rubixstudios/payload-typesense)
8
- ![Release](https://github.com/rubix-studios-pty-ltd/payload-typesense/actions/workflows/release.yml/badge.svg)
6
+ [![Release](https://github.com/rubix-studios-pty-ltd/payload-typesense/actions/workflows/release.yml/badge.svg)](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/config'
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: 'xyz',
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, // Overrides the default sync limit of 1000
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 GlobalSearchPage() {
60
+ export function GlobalSearch() {
62
61
  return (
63
62
  <HeadlessSearchInput
64
63
  baseUrl="http://localhost:3000"
65
- theme="modern" // Available themes: "modern" | "dark"
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
- export function CollectionSearch() {
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
- export function VectorSearch() {
88
- return (
89
- <HeadlessSearchInput
90
- baseUrl="http://localhost:3000"
91
- vector={true} // Vector search enabled
92
- collections={['posts', 'products']}
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
- - **Performance**
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
- ## Themes
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 plugin includes a powerful theme system with 2 pre-built themes and unlimited customization:
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
- ### Pre-built
94
+ ## API endpoints
142
95
 
143
- ```tsx
144
- // Modern theme (default)
145
- <HeadlessSearchInput theme="modern" />
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
- // Dark theme
148
- <HeadlessSearchInput theme="dark" />
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
- ### Custom
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 theme={customTheme} />
150
+ <HeadlessSearchInput
151
+ baseUrl="http://localhost:3000"
152
+ theme={customTheme}
153
+ />
170
154
  ```
171
155
 
172
- ### Theme Features
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 support or inquiries:
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
- ## Author
162
+ ## License
206
163
 
207
- Rubix Studios
208
- [https://rubixstudios.com.au](https://rubixstudios.com.au)
164
+ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
209
165
 
210
- ## Acknowledgments
166
+ ## Credits
211
167
 
212
- - [FrontTribe](https://github.com/FrontTribe/typesense-search)
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,KAAsC,MAAM,OAAO,CAAA;AAE1D,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,0BAA0B,CAAA;AAaxE,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,KAAK,EAAE,wBAAwB,CAAC,CAAC,CAAC,GACjC,KAAK,CAAC,YAAY,CAgTpB;eAEc,mBAAmB"}
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,12 +1,13 @@
1
1
  'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
3
  import React, { useEffect, useRef, useState } from 'react';
4
+ import { useDebounce } from '../hooks/useDebounce.js';
5
+ import { useSearch } from '../hooks/useSearch.js';
3
6
  import { handleKeyboard } from '../utils/keyboard.js';
4
- import { useDebounce } from '../utils/useDebounce.js';
5
- import { useSearch } from '../utils/useSearch.js';
6
7
  import { RenderedHeader, RenderedNoResults, RenderedResult, RenderedResultError } from './render/index.js';
7
8
  import { useThemeConfig } from './themes/hooks.js';
8
9
  export function HeadlessSearchInput(props) {
9
- const { baseUrl, className = '', collections, debounceMs = 300, enableSuggestions: _enableSuggestions = true, errorClassName = '', inputClassName = '', inputWrapperClassName = '', minQueryLength = 2, noResultsClassName = '', onResultClick, onResults, onSearch, perPage = 10, placeholder = 'Search...', renderDate = true, renderError, renderInput, renderNoResults, renderResult, renderResultsHeader, resultItemClassName = '', resultsClassName = '', resultsContainerClassName = '', resultsHeaderClassName = '', resultsListClassName = '', showLoading = true, showResultCount = true, theme = 'modern', vector = false } = props;
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;
10
11
  const [query, setQuery] = useState('');
11
12
  const [isOpen, setIsOpen] = useState(false);
12
13
  const inputRef = useRef(null);
@@ -26,21 +27,18 @@ export function HeadlessSearchInput(props) {
26
27
  vector
27
28
  });
28
29
  useEffect(()=>{
29
- if (debouncedQuery.length >= minQueryLength) {
30
- void search(debouncedQuery);
31
- }
30
+ void search(debouncedQuery);
32
31
  }, [
33
32
  debouncedQuery,
34
- minQueryLength,
35
33
  search
36
34
  ]);
37
- const handleInputChange = (e)=>{
38
- const value = e.target.value;
35
+ const handleInputChange = (event)=>{
36
+ const value = event.target.value;
39
37
  setQuery(value);
40
- setIsOpen(value.length >= minQueryLength);
38
+ setIsOpen(enableSuggestions && value.length >= minQueryLength);
41
39
  };
42
40
  const handleInputFocus = ()=>{
43
- if (query.length >= minQueryLength) {
41
+ if (enableSuggestions && query.length >= minQueryLength) {
44
42
  setIsOpen(true);
45
43
  }
46
44
  };
@@ -56,6 +54,9 @@ export function HeadlessSearchInput(props) {
56
54
  setIsOpen(false);
57
55
  setQuery('');
58
56
  };
57
+ const handleResultHover = (result)=>{
58
+ onResultHover?.(result);
59
+ };
59
60
  const handleKeyDown = (e)=>{
60
61
  handleKeyboard(e, {
61
62
  inputRef,
@@ -64,141 +65,173 @@ export function HeadlessSearchInput(props) {
64
65
  resultsRef
65
66
  });
66
67
  };
67
- return /*#__PURE__*/ React.createElement("div", {
68
+ return /*#__PURE__*/ _jsxs("div", {
68
69
  className: className,
69
70
  style: {
70
71
  margin: '0 auto',
71
72
  maxWidth: '600px',
72
73
  position: 'relative',
73
74
  width: '100%'
74
- }
75
- }, /*#__PURE__*/ React.createElement("div", {
76
- className: inputWrapperClassName,
77
- style: {
78
- position: 'relative',
79
- width: '100%'
80
- }
81
- }, renderInput ? renderInput({
82
- className: inputClassName,
83
- onBlur: handleInputBlur,
84
- onChange: handleInputChange,
85
- onFocus: handleInputFocus,
86
- onKeyDown: handleKeyDown,
87
- placeholder,
88
- ref: inputRef,
89
- value: query
90
- }) : /*#__PURE__*/ React.createElement("input", {
91
- "aria-label": "Search input",
92
- autoComplete: "off",
93
- className: inputClassName,
94
- onBlur: (e)=>{
95
- e.target.style.borderColor = themeConfig.theme.colors.inputBorder;
96
- e.target.style.boxShadow = 'none';
97
- handleInputBlur(e);
98
- },
99
- onChange: handleInputChange,
100
- onFocus: (e)=>{
101
- e.target.style.borderColor = themeConfig.theme.colors.inputBorderFocus;
102
- e.target.style.boxShadow = themeConfig.config.enableShadows !== false ? `0 0 0 3px ${themeConfig.theme.colors.inputBorderFocus}20` : 'none';
103
- handleInputFocus();
104
- },
105
- onKeyDown: handleKeyDown,
106
- placeholder: placeholder,
107
- ref: inputRef,
108
- style: {
109
- backgroundColor: themeConfig.theme.colors.inputBackground,
110
- border: `2px solid ${themeConfig.theme.colors.inputBorder}`,
111
- borderRadius: themeConfig.config.enableRoundedCorners !== false ? themeConfig.theme.spacing.inputBorderRadius : '0',
112
- boxShadow: 'none',
113
- color: themeConfig.theme.colors.inputText,
114
- fontFamily: themeConfig.theme.typography.fontFamily,
115
- fontSize: themeConfig.theme.spacing.inputFontSize,
116
- fontWeight: themeConfig.theme.typography.fontWeightNormal,
117
- lineHeight: themeConfig.theme.typography.lineHeightNormal,
118
- outline: 'none',
119
- padding: themeConfig.theme.spacing.inputPadding,
120
- transition: themeConfig.config.enableAnimations !== false ? `all ${themeConfig.theme.animations.transitionNormal} ${themeConfig.theme.animations.easeInOut}` : 'none',
121
- width: '100%'
122
75
  },
123
- title: "Search input",
124
- type: "text",
125
- value: query
126
- }), isLoading && showLoading && /*#__PURE__*/ React.createElement("div", {
127
- style: {
128
- position: 'absolute',
129
- right: '12px',
130
- top: '50%',
131
- transform: 'translateY(-50%)'
132
- }
133
- }, /*#__PURE__*/ React.createElement("style", null, `
134
- @keyframes spin {
135
- 0% { transform: rotate(0deg); }
136
- 100% { transform: rotate(360deg); }
137
- }
138
- `), /*#__PURE__*/ React.createElement("div", {
139
- "data-testid": "loading-spinner",
140
- style: {
141
- animation: `spin 1s linear infinite`,
142
- border: `2px solid ${themeConfig.theme.colors.inputBorder}`,
143
- borderRadius: '50%',
144
- borderTop: `2px solid ${themeConfig.theme.colors.inputBorderFocus}`,
145
- height: '16px',
146
- width: '16px'
147
- }
148
- }))), isOpen && results && /*#__PURE__*/ React.createElement("div", {
149
- className: resultsContainerClassName,
150
- ref: resultsRef,
151
- style: {
152
- backgroundColor: themeConfig.theme.colors.resultsBackground,
153
- border: `1px solid ${themeConfig.theme.colors.resultsBorder}`,
154
- borderRadius: themeConfig.config.enableRoundedCorners !== false ? themeConfig.theme.spacing.resultsBorderRadius : '0',
155
- boxShadow: themeConfig.config.enableShadows !== false ? themeConfig.theme.shadows.shadowLg : 'none',
156
- boxSizing: 'border-box',
157
- display: 'flex',
158
- left: '0',
159
- marginTop: '10px',
160
- maxHeight: themeConfig.theme.spacing.resultsMaxHeight,
161
- overflow: 'hidden',
162
- padding: '4px',
163
- position: 'absolute',
164
- right: '0',
165
- top: '100%',
166
- zIndex: 1000,
167
- ...themeConfig.config.enableAnimations !== false && {
168
- animation: `slideDown ${themeConfig.theme.animations.animationNormal} ${themeConfig.theme.animations.easeOut}`
169
- }
170
- }
171
- }, /*#__PURE__*/ React.createElement("div", {
172
- className: `relative ${resultsClassName}`,
173
- style: {
174
- minHeight: 0,
175
- overflowY: 'auto'
176
- }
177
- }, error && (renderError ? renderError(error) : /*#__PURE__*/ React.createElement(RenderedResultError, {
178
- error: error,
179
- errorClassName: errorClassName,
180
- themeConfig: themeConfig
181
- })), !error && results && /*#__PURE__*/ React.createElement(React.Fragment, null, showResultCount && (renderResultsHeader ? renderResultsHeader(results.found) : /*#__PURE__*/ React.createElement(RenderedHeader, {
182
- found: results.found,
183
- resultsHeaderClassName: resultsHeaderClassName,
184
- themeConfig: themeConfig
185
- })), results.hits.length > 0 ? /*#__PURE__*/ React.createElement("div", {
186
- className: resultsListClassName
187
- }, results.hits.map((result, index)=>renderResult ? renderResult(result, index, {
188
- onClick: handleResultClick
189
- }) : /*#__PURE__*/ React.createElement(RenderedResult, {
190
- index: index,
191
- key: result.document?.id || result.id || index,
192
- onResultClick: handleResultClick,
193
- renderDate: renderDate,
194
- result: result,
195
- resultItemClassName: resultItemClassName,
196
- resultsContainerClassName: resultsContainerClassName,
197
- themeConfig: themeConfig
198
- }))) : renderNoResults ? renderNoResults(query) : /*#__PURE__*/ React.createElement(RenderedNoResults, {
199
- noResultsClassName: noResultsClassName,
200
- query: query,
201
- themeConfig: themeConfig
202
- })))));
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
+ });
203
236
  }
204
237
  export default HeadlessSearchInput;
@@ -1,10 +1,10 @@
1
- import React, { type ReactNode } from 'react';
1
+ import { type ReactNode } from 'react';
2
2
  import { type ThemeConfig, type ThemeContextValue } from './themes/types.js';
3
3
  interface ThemeProviderProps {
4
4
  children: ReactNode;
5
5
  config: ThemeConfig;
6
6
  }
7
- export declare function ThemeProvider({ children, config }: ThemeProviderProps): React.JSX.Element;
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
@@ -1 +1 @@
1
- {"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../src/components/ThemeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAiB,KAAK,SAAS,EAAO,MAAM,OAAO,CAAA;AAGjE,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAE5E,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAA;IACnB,MAAM,EAAE,WAAW,CAAA;CACpB;AAID,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,kBAAkB,qBAIrE;AAED,wBAAgB,QAAQ,IAAI,iBAAiB,CAM5C"}
1
+ {"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../src/components/ThemeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,SAAS,EAAO,MAAM,OAAO,CAAA;AAG1D,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAE5E,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAA;IACnB,MAAM,EAAE,WAAW,CAAA;CACpB;AAID,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,kBAAkB,+BAIrE;AAED,wBAAgB,QAAQ,IAAI,iBAAiB,CAQ5C"}