@rubixstudios/payload-typesense 1.7.0 → 1.8.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 +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 +13 -12
- 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
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@ A Typesense search plugin for Payload CMS, maintained by [Rubix Studios](https:/
|
|
|
5
5
|
[](https://www.npmjs.com/package/@rubixstudios/payload-typesense)
|
|
6
6
|
[](https://github.com/rubix-studios-pty-ltd/payload-typesense/actions/workflows/release.yml)
|
|
7
7
|
|
|
8
|
+

|
|
9
|
+
|
|
8
10
|
## Installation
|
|
9
11
|
|
|
10
12
|
```sh
|
|
@@ -48,11 +50,15 @@ export default buildConfig({
|
|
|
48
50
|
|
|
49
51
|
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
52
|
|
|
51
|
-
### React search
|
|
53
|
+
### React search components
|
|
54
|
+
|
|
55
|
+
`HeadlessSearchInput` and `HeadlessSearchDialog` provide configurable search interfaces with keyboard navigation, loading states, result callbacks, and custom rendering support.
|
|
56
|
+
|
|
57
|
+
Both components support the same configuration options. Use `HeadlessSearchInput` for an inline search interface or `HeadlessSearchDialog` for a dialog-based search experience.
|
|
52
58
|
|
|
53
|
-
|
|
59
|
+
#### Search input
|
|
54
60
|
|
|
55
|
-
```
|
|
61
|
+
```typescript
|
|
56
62
|
'use client'
|
|
57
63
|
|
|
58
64
|
import { HeadlessSearchInput } from '@rubixstudios/payload-typesense'
|
|
@@ -71,9 +77,32 @@ export function GlobalSearch() {
|
|
|
71
77
|
}
|
|
72
78
|
```
|
|
73
79
|
|
|
74
|
-
Search
|
|
80
|
+
#### Search dialog
|
|
75
81
|
|
|
76
|
-
```
|
|
82
|
+
```typescript
|
|
83
|
+
'use client'
|
|
84
|
+
|
|
85
|
+
import { HeadlessSearchDialog } from '@rubixstudios/payload-typesense'
|
|
86
|
+
|
|
87
|
+
export function GlobalSearch() {
|
|
88
|
+
return (
|
|
89
|
+
<HeadlessSearchDialog
|
|
90
|
+
baseUrl="http://localhost:3000"
|
|
91
|
+
theme="modern"
|
|
92
|
+
placeholder="Search everything..."
|
|
93
|
+
onResultClick={(result) => {
|
|
94
|
+
console.log('Selected document:', result.document)
|
|
95
|
+
}}
|
|
96
|
+
/>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### Collection filtering
|
|
102
|
+
|
|
103
|
+
Both components search all enabled collections by default. Use the `collections` prop to restrict results to specific collections.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
77
106
|
<HeadlessSearchInput
|
|
78
107
|
baseUrl="http://localhost:3000"
|
|
79
108
|
collections={['posts', 'products']}
|
|
@@ -81,7 +110,17 @@ Search all enabled collections by default, or use the `collections` prop to rest
|
|
|
81
110
|
/>
|
|
82
111
|
```
|
|
83
112
|
|
|
84
|
-
|
|
113
|
+
The same configuration applies to `HeadlessSearchDialog`.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
<HeadlessSearchDialog
|
|
117
|
+
baseUrl="http://localhost:3000"
|
|
118
|
+
collections={['posts', 'products']}
|
|
119
|
+
placeholder="Search posts and products..."
|
|
120
|
+
/>
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Vector search can also be requested using the `vector` prop on either component when embedding support is configured.
|
|
85
124
|
|
|
86
125
|
## Features
|
|
87
126
|
|
|
@@ -95,15 +134,15 @@ The included React component provides modern and dark themes, responsive styling
|
|
|
95
134
|
|
|
96
135
|
Search endpoints are registered under Payload's `/api` path by default.
|
|
97
136
|
|
|
98
|
-
| Method | Endpoint
|
|
99
|
-
|
|
100
|
-
| GET
|
|
101
|
-
| GET
|
|
102
|
-
| POST
|
|
103
|
-
| GET
|
|
104
|
-
| GET
|
|
105
|
-
| GET
|
|
106
|
-
| GET
|
|
137
|
+
| Method | Endpoint | Purpose |
|
|
138
|
+
| ------ | ---------------------------------- | --------------------------- |
|
|
139
|
+
| GET | `/api/search` | Search across collections |
|
|
140
|
+
| GET | `/api/search/{collection}` | Search a collection |
|
|
141
|
+
| POST | `/api/search/{collection}` | Advanced search |
|
|
142
|
+
| GET | `/api/search/{collection}/suggest` | Search suggestions |
|
|
143
|
+
| GET | `/api/search/collections` | Available collections |
|
|
144
|
+
| GET | `/api/search/health` | Health status |
|
|
145
|
+
| GET | `/api/search/health/detailed` | Detailed health information |
|
|
107
146
|
|
|
108
147
|
Requests support pagination and the relevant Typesense search parameters. Vector search is available through the `vector=true` query parameter when enabled.
|
|
109
148
|
|
|
@@ -131,7 +170,7 @@ To request vector search from the React component, pass `vector={true}`.
|
|
|
131
170
|
|
|
132
171
|
Two themes are included, `modern` (default) and `dark`. Both can be customised using theme configuration options for colours, spacing, typography, shadows, and animations.
|
|
133
172
|
|
|
134
|
-
```
|
|
173
|
+
```typescript
|
|
135
174
|
const customTheme = {
|
|
136
175
|
theme: 'modern',
|
|
137
176
|
colors: {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type ThemeConfig, type ThemeContextValue } from './themes/types.js';
|
|
3
|
-
interface
|
|
3
|
+
interface ProviderProps {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
config: ThemeConfig;
|
|
6
6
|
}
|
|
7
|
-
export declare function ThemeProvider({ children, config }:
|
|
7
|
+
export declare function ThemeProvider({ children, config }: ProviderProps): import("react").JSX.Element;
|
|
8
8
|
export declare function useTheme(): ThemeContextValue;
|
|
9
|
+
export declare function useComponentTheme(theme?: string | ThemeConfig): ThemeContextValue;
|
|
9
10
|
export {};
|
|
10
11
|
//# sourceMappingURL=ThemeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,aAAa;IACrB,QAAQ,EAAE,SAAS,CAAA;IACnB,MAAM,EAAE,WAAW,CAAA;CACpB;AAID,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,aAAa,+BAIhE;AAED,wBAAgB,QAAQ,IAAI,iBAAiB,CAQ5C;AAED,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,iBAAiB,CAKjF"}
|
|
@@ -17,3 +17,11 @@ export function useTheme() {
|
|
|
17
17
|
}
|
|
18
18
|
return context;
|
|
19
19
|
}
|
|
20
|
+
export function useComponentTheme(theme) {
|
|
21
|
+
const context = use(ThemeContext);
|
|
22
|
+
return useThemeConfig(typeof theme === 'string' ? {
|
|
23
|
+
theme
|
|
24
|
+
} : theme ?? context?.config ?? {
|
|
25
|
+
theme: 'modern'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -3,4 +3,5 @@ export { CollectionIcon } from './collectionIcon.js';
|
|
|
3
3
|
export { ErrorIcon } from './errorIcon.js';
|
|
4
4
|
export { NoResultsIcon } from './noResultsIcon.js';
|
|
5
5
|
export { SearchIcon } from './searchIcon.js';
|
|
6
|
+
export { XIcon } from './xIcon.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/icons/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/icons/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export declare const NoResultsIcon: ({ color }: {
|
|
2
2
|
color?: string;
|
|
3
|
-
};
|
|
4
|
-
export declare const NoResultsIcon: ({ color }: Props) => import("react").JSX.Element;
|
|
5
|
-
export {};
|
|
3
|
+
}) => import("react").JSX.Element;
|
|
6
4
|
//# sourceMappingURL=noResultsIcon.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noResultsIcon.d.ts","sourceRoot":"","sources":["../../../src/components/icons/noResultsIcon.tsx"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"noResultsIcon.d.ts","sourceRoot":"","sources":["../../../src/components/icons/noResultsIcon.tsx"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,cAAgC;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,gCAoB3E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchIcon.d.ts","sourceRoot":"","sources":["../../../src/components/icons/searchIcon.tsx"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"searchIcon.d.ts","sourceRoot":"","sources":["../../../src/components/icons/searchIcon.tsx"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,cAAgC;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,gCAaxE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xIcon.d.ts","sourceRoot":"","sources":["../../../src/components/icons/xIcon.tsx"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,mCAajB,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export const XIcon = ()=>/*#__PURE__*/ _jsx("svg", {
|
|
3
|
+
"aria-hidden": "true",
|
|
4
|
+
fill: "none",
|
|
5
|
+
stroke: "currentColor",
|
|
6
|
+
strokeLinecap: "round",
|
|
7
|
+
strokeLinejoin: "round",
|
|
8
|
+
strokeWidth: "2",
|
|
9
|
+
style: {
|
|
10
|
+
height: '16px',
|
|
11
|
+
width: '16px'
|
|
12
|
+
},
|
|
13
|
+
viewBox: "0 0 24 24",
|
|
14
|
+
children: /*#__PURE__*/ _jsx("path", {
|
|
15
|
+
d: "M18 6 6 18M6 6l12 12"
|
|
16
|
+
})
|
|
17
|
+
});
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
export type {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export type { SearchDialogContentProps, SearchDialogProps, } from '../lib/search-dialog.js';
|
|
2
|
+
export type { SearchInputProps } from '../lib/search-input.js';
|
|
3
|
+
export type { SearchPaginationProps } from '../lib/search-pagination.js';
|
|
4
|
+
export type { BaseSearchInputProps, HealthCheckResponse, SearchMode, SearchResponse, SearchResult, SearchResultProps, TypesenseSearchConfig, TypoTolerance, } from '../types.js';
|
|
5
|
+
export { ClockIcon, CollectionIcon, ErrorIcon, NoResultsIcon, SearchIcon, XIcon, } from './icons/index.js';
|
|
6
|
+
export { Highlight, RenderedContent, RenderedDialog, RenderedHeader, RenderedNoResults, RenderedResult, RenderedResultError, } from './render/index.js';
|
|
7
|
+
export { default as HeadlessSearchDialog } from './search/HeadlessDialog.js';
|
|
8
|
+
export { default as HeadlessSearchInput } from './search/HeadlessInput.js';
|
|
9
|
+
export { SearchStyles } from './search/SearchStyles.js';
|
|
6
10
|
export { ThemeProvider, useTheme } from './ThemeProvider.js';
|
|
7
11
|
export * from './themes/index.js';
|
|
8
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,yBAAyB,CAAA;AAChC,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AACxE,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GACd,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,SAAS,EACT,cAAc,EACd,SAAS,EACT,aAAa,EACb,UAAU,EACV,KAAK,GACN,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,SAAS,EACT,eAAe,EACf,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,mBAAmB,GACpB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAC5E,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC5D,cAAc,mBAAmB,CAAA"}
|
package/dist/components/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { ClockIcon, CollectionIcon, ErrorIcon, NoResultsIcon, SearchIcon, XIcon } from './icons/index.js';
|
|
2
|
+
export { Highlight, RenderedContent, RenderedDialog, RenderedHeader, RenderedNoResults, RenderedResult, RenderedResultError } from './render/index.js';
|
|
3
|
+
export { default as HeadlessSearchDialog } from './search/HeadlessDialog.js';
|
|
4
|
+
export { default as HeadlessSearchInput } from './search/HeadlessInput.js';
|
|
5
|
+
export { SearchStyles } from './search/SearchStyles.js';
|
|
4
6
|
export { ThemeProvider, useTheme } from './ThemeProvider.js';
|
|
5
7
|
export * from './themes/index.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { type RefObject } from 'react';
|
|
2
|
+
import { type useSearch } from '../../hooks/useSearch.js';
|
|
3
|
+
import { type SearchDialogProps } from '../../lib/search-dialog.js';
|
|
4
|
+
import { type SearchPaginationProps } from '../../lib/search-pagination.js';
|
|
5
|
+
import { type SearchResult } from '../../types.js';
|
|
6
|
+
import { type ThemeContextValue } from '../themes/index.js';
|
|
7
|
+
type Props<T> = Pick<SearchDialogProps<T>, 'renderInput' | 'showLoading' | 'renderLoading' | 'loadingClassName' | 'inputWrapperClassName' | 'resultsContainerClassName' | 'resultsClassName' | 'renderError' | 'errorClassName' | 'showResultCount' | 'renderResultsHeader' | 'resultsHeaderClassName' | 'resultsListClassName' | 'renderResult' | 'onResultHover' | 'renderDate' | 'resultItemClassName' | 'renderNoResults' | 'noResultsClassName' | 'renderEmpty' | 'showPagination' | 'renderPagination' | 'paginationClassName' | 'paginationButtonClassName' | 'previousPageLabel' | 'nextPageLabel'> & {
|
|
8
|
+
query: string;
|
|
9
|
+
page: number;
|
|
10
|
+
results: ReturnType<typeof useSearch<T>>['results'];
|
|
11
|
+
error: ReturnType<typeof useSearch<T>>['error'];
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
isOpen: boolean;
|
|
14
|
+
resultsId: string;
|
|
15
|
+
inputProps: Parameters<NonNullable<SearchDialogProps<T>['renderInput']>>[0];
|
|
16
|
+
inputRef: RefObject<HTMLInputElement | null>;
|
|
17
|
+
resultsRef: RefObject<HTMLDivElement | null>;
|
|
18
|
+
pagination: SearchPaginationProps;
|
|
19
|
+
totalPages: number;
|
|
20
|
+
changePage: (page: number) => void;
|
|
21
|
+
clickResult: (result: SearchResult<T>) => void;
|
|
22
|
+
themeConfig: ThemeContextValue;
|
|
23
|
+
};
|
|
24
|
+
export declare function RenderedContent<T = Record<string, unknown>>({ renderInput, showLoading, renderLoading, loadingClassName, inputWrapperClassName, resultsContainerClassName, resultsClassName, renderError, errorClassName, showResultCount, renderResultsHeader, resultsHeaderClassName, resultsListClassName, renderResult, onResultHover, renderDate, resultItemClassName, renderNoResults, noResultsClassName, renderEmpty, showPagination, renderPagination, paginationClassName, paginationButtonClassName, previousPageLabel, nextPageLabel, query, page, results, error, isLoading, isOpen, resultsId, inputProps, inputRef, resultsRef, pagination, totalPages, changePage, clickResult, themeConfig, }: Props<T>): React.JSX.Element;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=Content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Content.d.ts","sourceRoot":"","sources":["../../../src/components/render/Content.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAY,KAAK,SAAS,EAAqB,MAAM,OAAO,CAAA;AAE1E,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAC3E,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAM3D,KAAK,KAAK,CAAC,CAAC,IAAI,IAAI,CAClB,iBAAiB,CAAC,CAAC,CAAC,EAClB,aAAa,GACb,aAAa,GACb,eAAe,GACf,kBAAkB,GAClB,uBAAuB,GACvB,2BAA2B,GAC3B,kBAAkB,GAClB,aAAa,GACb,gBAAgB,GAChB,iBAAiB,GACjB,qBAAqB,GACrB,wBAAwB,GACxB,sBAAsB,GACtB,cAAc,GACd,eAAe,GACf,YAAY,GACZ,qBAAqB,GACrB,iBAAiB,GACjB,oBAAoB,GACpB,aAAa,GACb,gBAAgB,GAChB,kBAAkB,GAClB,qBAAqB,GACrB,2BAA2B,GAC3B,mBAAmB,GACnB,eAAe,CAClB,GAAG;IACF,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACnD,KAAK,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IAC/C,SAAS,EAAE,OAAO,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,UAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3E,QAAQ,EAAE,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAA;IAC5C,UAAU,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IAC5C,UAAU,EAAE,qBAAqB,CAAA;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,WAAW,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IAC9C,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED,wBAAgB,eAAe,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC3D,WAAW,EACX,WAAkB,EAClB,aAAa,EACb,gBAAqB,EACrB,qBAA0B,EAC1B,yBAA8B,EAC9B,gBAAqB,EACrB,WAAW,EACX,cAAmB,EACnB,eAAsB,EACtB,mBAAmB,EACnB,sBAA2B,EAC3B,oBAAyB,EACzB,YAAY,EACZ,aAAa,EACb,UAAiB,EACjB,mBAAwB,EACxB,eAAe,EACf,kBAAuB,EACvB,WAAW,EACX,cAAqB,EACrB,gBAAgB,EAChB,mBAAwB,EACxB,yBAA8B,EAC9B,iBAA8B,EAC9B,aAAsB,EACtB,KAAK,EACL,IAAI,EACJ,OAAO,EACP,KAAK,EACL,SAAS,EACT,MAAM,EACN,SAAS,EACT,UAAU,EACV,QAAQ,EACR,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,GACZ,EAAE,KAAK,CAAC,CAAC,CAAC,qBA6JV"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import React, { Fragment, useEffect, useRef } from 'react';
|
|
3
|
+
import { handleKeyboard } from '../../utils/keyboard.js';
|
|
4
|
+
import { RenderedHeader } from './Header.js';
|
|
5
|
+
import { RenderedNoResults } from './NoResults.js';
|
|
6
|
+
import { RenderedResultError } from './ResultError.js';
|
|
7
|
+
import { RenderedResult } from './Results.js';
|
|
8
|
+
export function RenderedContent({ renderInput, showLoading = true, renderLoading, loadingClassName = '', inputWrapperClassName = '', resultsContainerClassName = '', resultsClassName = '', renderError, errorClassName = '', showResultCount = true, renderResultsHeader, resultsHeaderClassName = '', resultsListClassName = '', renderResult, onResultHover, renderDate = true, resultItemClassName = '', renderNoResults, noResultsClassName = '', renderEmpty, showPagination = true, renderPagination, paginationClassName = '', paginationButtonClassName = '', previousPageLabel = 'Previous', nextPageLabel = 'Next', query, page, results, error, isLoading, isOpen, resultsId, inputProps, inputRef, resultsRef, pagination, totalPages, changePage, clickResult, themeConfig }) {
|
|
9
|
+
const classes = themeConfig.classes;
|
|
10
|
+
const last = useRef(null);
|
|
11
|
+
useEffect(()=>{
|
|
12
|
+
if (!isLoading) {
|
|
13
|
+
last.current = !error && results ? {
|
|
14
|
+
query,
|
|
15
|
+
page,
|
|
16
|
+
results,
|
|
17
|
+
totalPages
|
|
18
|
+
} : null;
|
|
19
|
+
}
|
|
20
|
+
}, [
|
|
21
|
+
error,
|
|
22
|
+
isLoading,
|
|
23
|
+
page,
|
|
24
|
+
query,
|
|
25
|
+
results,
|
|
26
|
+
totalPages
|
|
27
|
+
]);
|
|
28
|
+
const cached = isLoading && last.current?.query === query ? last.current : null;
|
|
29
|
+
const visible = isLoading ? cached?.results : results;
|
|
30
|
+
const visiblePage = cached?.page ?? page;
|
|
31
|
+
const pages = cached?.totalPages ?? totalPages;
|
|
32
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
33
|
+
children: [
|
|
34
|
+
/*#__PURE__*/ _jsx("div", {
|
|
35
|
+
className: `${classes.inputContainer} ${inputWrapperClassName}`,
|
|
36
|
+
children: renderInput ? renderInput(inputProps) : /*#__PURE__*/ _jsx("input", {
|
|
37
|
+
...inputProps,
|
|
38
|
+
autoComplete: "off",
|
|
39
|
+
type: "search"
|
|
40
|
+
})
|
|
41
|
+
}),
|
|
42
|
+
showLoading && isLoading && !visible && (renderLoading ? renderLoading() : /*#__PURE__*/ _jsxs("div", {
|
|
43
|
+
className: `${classes.loading} ${loadingClassName}`,
|
|
44
|
+
role: "status",
|
|
45
|
+
children: [
|
|
46
|
+
/*#__PURE__*/ _jsx("div", {
|
|
47
|
+
"aria-hidden": "true",
|
|
48
|
+
className: classes.loadingSpinner
|
|
49
|
+
}),
|
|
50
|
+
"Searching..."
|
|
51
|
+
]
|
|
52
|
+
})),
|
|
53
|
+
/*#__PURE__*/ _jsx("div", {
|
|
54
|
+
"aria-busy": isLoading,
|
|
55
|
+
className: `${classes.dialogResults} ${resultsContainerClassName}`,
|
|
56
|
+
id: resultsId,
|
|
57
|
+
onKeyDown: (event)=>{
|
|
58
|
+
if (!isLoading && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) handleKeyboard(event, {
|
|
59
|
+
inputRef,
|
|
60
|
+
isOpen,
|
|
61
|
+
results,
|
|
62
|
+
resultsRef
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
ref: resultsRef,
|
|
66
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
67
|
+
className: `${classes.results} ${resultsClassName}`,
|
|
68
|
+
style: isLoading && visible ? {
|
|
69
|
+
opacity: 0.65,
|
|
70
|
+
pointerEvents: 'none'
|
|
71
|
+
} : undefined,
|
|
72
|
+
children: [
|
|
73
|
+
error && (renderError ? renderError(error) : /*#__PURE__*/ _jsx(RenderedResultError, {
|
|
74
|
+
error: error,
|
|
75
|
+
errorClassName: errorClassName,
|
|
76
|
+
themeConfig: themeConfig
|
|
77
|
+
})),
|
|
78
|
+
!error && visible && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
79
|
+
children: [
|
|
80
|
+
showResultCount && (renderResultsHeader ? renderResultsHeader(visible.found) : /*#__PURE__*/ _jsx(RenderedHeader, {
|
|
81
|
+
found: visible.found,
|
|
82
|
+
resultsHeaderClassName: resultsHeaderClassName,
|
|
83
|
+
themeConfig: themeConfig
|
|
84
|
+
})),
|
|
85
|
+
visible.hits.length > 0 ? /*#__PURE__*/ _jsx("div", {
|
|
86
|
+
className: `${classes.resultsList} ${resultsListClassName}`,
|
|
87
|
+
children: visible.hits.map((result, index)=>/*#__PURE__*/ _jsx(Fragment, {
|
|
88
|
+
children: renderResult ? renderResult(result, index, {
|
|
89
|
+
onClick: clickResult,
|
|
90
|
+
onHover: onResultHover
|
|
91
|
+
}) : /*#__PURE__*/ _jsx(RenderedResult, {
|
|
92
|
+
index: index,
|
|
93
|
+
onResultClick: clickResult,
|
|
94
|
+
onResultHover: onResultHover,
|
|
95
|
+
renderDate: renderDate,
|
|
96
|
+
result: result,
|
|
97
|
+
resultItemClassName: resultItemClassName,
|
|
98
|
+
themeConfig: themeConfig
|
|
99
|
+
})
|
|
100
|
+
}, `${result.collection ?? ''}:${result.document?.id ?? result.id ?? index}`))
|
|
101
|
+
}) : renderNoResults ? renderNoResults(query) : /*#__PURE__*/ _jsx(RenderedNoResults, {
|
|
102
|
+
noResultsClassName: noResultsClassName,
|
|
103
|
+
query: query,
|
|
104
|
+
themeConfig: themeConfig
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
}),
|
|
108
|
+
!visible && !error && !isLoading && renderEmpty?.()
|
|
109
|
+
]
|
|
110
|
+
})
|
|
111
|
+
}),
|
|
112
|
+
showPagination && visible && pages > 1 && (renderPagination ? renderPagination(pagination) : /*#__PURE__*/ _jsxs("nav", {
|
|
113
|
+
"aria-label": "Search result pages",
|
|
114
|
+
className: `${classes.pagination} ${paginationClassName}`,
|
|
115
|
+
children: [
|
|
116
|
+
/*#__PURE__*/ _jsx("button", {
|
|
117
|
+
className: `${classes.paginationButton} ${paginationButtonClassName}`,
|
|
118
|
+
disabled: isLoading || !pagination.hasPreviousPage,
|
|
119
|
+
onClick: ()=>changePage(page - 1),
|
|
120
|
+
type: "button",
|
|
121
|
+
children: previousPageLabel
|
|
122
|
+
}),
|
|
123
|
+
/*#__PURE__*/ _jsxs("span", {
|
|
124
|
+
className: classes.paginationStatus,
|
|
125
|
+
role: "status",
|
|
126
|
+
children: [
|
|
127
|
+
"Page ",
|
|
128
|
+
visiblePage,
|
|
129
|
+
" of ",
|
|
130
|
+
pages
|
|
131
|
+
]
|
|
132
|
+
}),
|
|
133
|
+
/*#__PURE__*/ _jsx("button", {
|
|
134
|
+
className: `${classes.paginationButton} ${paginationButtonClassName}`,
|
|
135
|
+
disabled: isLoading || !pagination.hasNextPage,
|
|
136
|
+
onClick: ()=>changePage(page + 1),
|
|
137
|
+
type: "button",
|
|
138
|
+
children: nextPageLabel
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
}))
|
|
142
|
+
]
|
|
143
|
+
});
|
|
144
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { type ReactNode, type RefObject } from 'react';
|
|
2
|
+
import { type useSearch } from '../../hooks/useSearch.js';
|
|
3
|
+
import { type SearchDialogProps } from '../../lib/search-dialog.js';
|
|
4
|
+
import { type ThemeContextValue } from '../themes/index.js';
|
|
5
|
+
type Props<T> = Pick<SearchDialogProps<T>, 'dialogProps' | 'dialogLabel' | 'title' | 'dialogClassName' | 'closeOnBackdropClick' | 'renderDialogHeader' | 'dialogHeaderClassName' | 'closeButtonClassName' | 'closeLabel' | 'dialogContentClassName' | 'renderDialogContent'> & {
|
|
6
|
+
dialogId: string;
|
|
7
|
+
dialogRef: RefObject<HTMLDialogElement | null>;
|
|
8
|
+
close: () => void;
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
query: string;
|
|
12
|
+
page: number;
|
|
13
|
+
results: ReturnType<typeof useSearch<T>>['results'];
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
error: ReturnType<typeof useSearch<T>>['error'];
|
|
16
|
+
themeConfig: ThemeContextValue;
|
|
17
|
+
};
|
|
18
|
+
export declare function RenderedDialog<T = Record<string, unknown>>({ dialogProps, dialogLabel, title, dialogClassName, closeOnBackdropClick, dialogContentClassName, renderDialogContent, dialogId, dialogRef, close, isOpen, children, query, page, results, isLoading, error, themeConfig, }: Props<T>): React.JSX.Element;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=Dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../../src/components/render/Dialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAE7D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAEnE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,KAAK,KAAK,CAAC,CAAC,IAAI,IAAI,CAClB,iBAAiB,CAAC,CAAC,CAAC,EAClB,aAAa,GACb,aAAa,GACb,OAAO,GACP,iBAAiB,GACjB,sBAAsB,GACtB,oBAAoB,GACpB,uBAAuB,GACvB,sBAAsB,GACtB,YAAY,GACZ,wBAAwB,GACxB,qBAAqB,CACxB,GAAG;IACF,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAA;IAC9C,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,SAAS,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACnD,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IAC/C,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED,wBAAgB,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC1D,WAAW,EACX,WAAW,EACX,KAAgB,EAChB,eAAoB,EACpB,oBAA2B,EAC3B,sBAA2B,EAC3B,mBAAmB,EACnB,QAAQ,EACR,SAAS,EACT,KAAK,EACL,MAAM,EACN,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,OAAO,EACP,SAAS,EACT,KAAK,EACL,WAAW,GACZ,EAAE,KAAK,CAAC,CAAC,CAAC,qBAsDV"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export function RenderedDialog({ dialogProps, dialogLabel, title = 'Search', dialogClassName = '', closeOnBackdropClick = true, dialogContentClassName = '', renderDialogContent, dialogId, dialogRef, close, isOpen, children, query, page, results, isLoading, error, themeConfig }) {
|
|
4
|
+
const classes = themeConfig.classes;
|
|
5
|
+
return(// biome-ignore lint/a11y/useKeyWithClickEvents: Escape handles keyboard dismissal.
|
|
6
|
+
/*#__PURE__*/ _jsx("dialog", {
|
|
7
|
+
...dialogProps,
|
|
8
|
+
"aria-label": dialogProps?.['aria-label'] ?? dialogLabel ?? (typeof title === 'string' ? title : 'Search'),
|
|
9
|
+
className: `${classes.dialog} ${dialogClassName} ${dialogProps?.className ?? ''}`,
|
|
10
|
+
id: dialogId,
|
|
11
|
+
onCancel: (event)=>{
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
close();
|
|
14
|
+
},
|
|
15
|
+
onClick: (event)=>{
|
|
16
|
+
if (!closeOnBackdropClick || event.target !== event.currentTarget) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
20
|
+
if (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom) {
|
|
21
|
+
close();
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
onClose: ()=>{
|
|
25
|
+
if (isOpen && !dialogRef.current?.open) {
|
|
26
|
+
close();
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
ref: dialogRef,
|
|
30
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
31
|
+
className: `${classes.dialogContent} ${dialogContentClassName}`,
|
|
32
|
+
children: renderDialogContent ? renderDialogContent({
|
|
33
|
+
children,
|
|
34
|
+
close,
|
|
35
|
+
query,
|
|
36
|
+
page,
|
|
37
|
+
results,
|
|
38
|
+
isLoading,
|
|
39
|
+
error
|
|
40
|
+
}) : children
|
|
41
|
+
})
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type ThemeContextValue } from '../themes/
|
|
2
|
+
import { type ThemeContextValue } from '../themes/index.js';
|
|
3
3
|
type Props = {
|
|
4
4
|
found: number;
|
|
5
5
|
resultsHeaderClassName?: string;
|
|
6
6
|
themeConfig: ThemeContextValue;
|
|
7
7
|
};
|
|
8
|
-
export declare
|
|
8
|
+
export declare function RenderedHeader({ found, resultsHeaderClassName, themeConfig }: Props): React.JSX.Element;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=Header.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../../../src/components/render/Header.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,CAAA;IACb,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED,
|
|
1
|
+
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../../../src/components/render/Header.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,CAAA;IACb,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,sBAA2B,EAAE,WAAW,EAAE,EAAE,KAAK,qBAUxF"}
|
|
@@ -1,43 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { SearchIcon } from '../icons/index.js';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
alignItems: 'center',
|
|
21
|
-
display: 'flex',
|
|
22
|
-
gap: '8px'
|
|
23
|
-
},
|
|
24
|
-
children: [
|
|
25
|
-
/*#__PURE__*/ _jsx(SearchIcon, {
|
|
26
|
-
color: themeConfig.theme.colors.metaText
|
|
27
|
-
}),
|
|
28
|
-
/*#__PURE__*/ _jsxs("span", {
|
|
29
|
-
style: {
|
|
30
|
-
color: themeConfig.theme.colors.headerText,
|
|
31
|
-
fontSize: themeConfig.theme.typography.fontSizeSm,
|
|
32
|
-
fontWeight: themeConfig.theme.typography.fontWeightMedium
|
|
33
|
-
},
|
|
34
|
-
children: [
|
|
35
|
-
found,
|
|
36
|
-
" result",
|
|
37
|
-
found !== 1 ? 's' : '',
|
|
38
|
-
" found"
|
|
39
|
-
]
|
|
40
|
-
})
|
|
41
|
-
]
|
|
42
|
-
})
|
|
4
|
+
export function RenderedHeader({ found, resultsHeaderClassName = '', themeConfig }) {
|
|
5
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
6
|
+
className: `${themeConfig.classes.resultsHeader} ${resultsHeaderClassName}`,
|
|
7
|
+
children: [
|
|
8
|
+
/*#__PURE__*/ _jsx(SearchIcon, {
|
|
9
|
+
color: themeConfig.theme.colors.metaText
|
|
10
|
+
}),
|
|
11
|
+
/*#__PURE__*/ _jsxs("span", {
|
|
12
|
+
children: [
|
|
13
|
+
found,
|
|
14
|
+
" result",
|
|
15
|
+
found !== 1 ? 's' : '',
|
|
16
|
+
" found"
|
|
17
|
+
]
|
|
18
|
+
})
|
|
19
|
+
]
|
|
43
20
|
});
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Highlight.d.ts","sourceRoot":"","sources":["../../../src/components/render/Highlight.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAIvC,eAAO,MAAM,SAAS,YAAa,MAAM,aAAa,MAAM,iCAsB3D,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { Fragment } from 'react';
|
|
3
|
+
import { decodeEntities } from '../utils/index.js';
|
|
4
|
+
export const Highlight = (snippet, className)=>{
|
|
5
|
+
let highlighted = false;
|
|
6
|
+
return snippet.split(/(<mark>|<\/mark>)/g).map((part, index)=>{
|
|
7
|
+
if (part === '<mark>') {
|
|
8
|
+
highlighted = true;
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (part === '</mark>') {
|
|
12
|
+
highlighted = false;
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return highlighted ? /*#__PURE__*/ _jsx("mark", {
|
|
16
|
+
className: className,
|
|
17
|
+
children: decodeEntities(part)
|
|
18
|
+
}, index) : /*#__PURE__*/ _jsx(Fragment, {
|
|
19
|
+
children: decodeEntities(part)
|
|
20
|
+
}, index);
|
|
21
|
+
});
|
|
22
|
+
};
|