@uniformdev/search 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react.d.mts +112 -3
- package/dist/react.d.ts +112 -3
- package/dist/react.js +354 -23
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +355 -18
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { FC, ReactNode } from 'react';
|
|
3
|
-
import { d as Pagination, S as SearchHit, a as Facets, P as PageSize,
|
|
2
|
+
import { FC, ReactNode, InputHTMLAttributes, HTMLAttributes } from 'react';
|
|
3
|
+
import { d as Pagination, S as SearchHit, a as Facets, P as PageSize, h as SearchParams, C as CollectionResult, F as FacetBy, g as SearchItemConfig } from './client-DOew5kqb.mjs';
|
|
4
4
|
|
|
5
5
|
interface SearchProviderProps {
|
|
6
6
|
children: ReactNode;
|
|
@@ -39,6 +39,18 @@ interface UseSearchReturn {
|
|
|
39
39
|
* (App Router slots) instead of it being passed to the provider. */
|
|
40
40
|
registerOrderBy: (id: string, orderBy: unknown) => void;
|
|
41
41
|
unregisterOrderBy: (id: string) => void;
|
|
42
|
+
/** The search function the provider drives (typo-tolerance wrapper included). Exposed
|
|
43
|
+
* so in-engine components (e.g. an autocomplete box) issue the SAME request shape. */
|
|
44
|
+
performSearch: (params: SearchParams) => Promise<CollectionResult>;
|
|
45
|
+
/** Fields the query string is matched against (as configured on the engine). */
|
|
46
|
+
queryBy?: string[];
|
|
47
|
+
/** Locale the search is scoped to (per-locale collection). */
|
|
48
|
+
locale?: string;
|
|
49
|
+
/** Always-applied base `filter_by` string (from the engine's base filters). */
|
|
50
|
+
baseFilterString?: string;
|
|
51
|
+
/** The active facet selections as a `performSearch` `filters` object — mirrors the
|
|
52
|
+
* main results request so an autocomplete can reproduce the current filtered context. */
|
|
53
|
+
currentFilters: Record<string, unknown>;
|
|
42
54
|
filterOptions: FacetBy[];
|
|
43
55
|
setFilterOptions: (filters: FacetBy[]) => void;
|
|
44
56
|
/** Additive registration of a single facet option (keyed by fieldKey). Used by facet
|
|
@@ -56,6 +68,103 @@ declare const SearchProvider: FC<SearchProviderProps>;
|
|
|
56
68
|
|
|
57
69
|
declare function useSearch(): UseSearchReturn;
|
|
58
70
|
|
|
71
|
+
interface UseAutocompleteOptions {
|
|
72
|
+
/**
|
|
73
|
+
* The search function (same signature used by `SearchProvider`). Typically
|
|
74
|
+
* `createSearchClient(...).performSearch`.
|
|
75
|
+
*/
|
|
76
|
+
performSearch: (params: SearchParams) => Promise<CollectionResult>;
|
|
77
|
+
/** Fields to query against (mirrors `SearchProvider`'s `queryBy`). */
|
|
78
|
+
queryBy?: string[];
|
|
79
|
+
/** A base Typesense `filter_by` string applied to every request. */
|
|
80
|
+
baseFilterBy?: string;
|
|
81
|
+
/** Active facet selections (same `filters` object `SearchProvider` sends), so the
|
|
82
|
+
* autocomplete request mirrors the main results' filtered context. */
|
|
83
|
+
filters?: Record<string, unknown>;
|
|
84
|
+
/** Locale to scope the search to (per-locale collection). */
|
|
85
|
+
locale?: string;
|
|
86
|
+
/** Max number of suggestions to fetch/show. Default: 6. */
|
|
87
|
+
perPage?: number;
|
|
88
|
+
/** Minimum number of characters before a request is made. Default: 1. */
|
|
89
|
+
minQueryLength?: number;
|
|
90
|
+
/** Debounce, in ms, between the last keystroke and the request. Default: 150. */
|
|
91
|
+
debounceMs?: number;
|
|
92
|
+
/** Open the panel as soon as the input is focused (if there is anything to show). Default: false. */
|
|
93
|
+
openOnFocus?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Called when a suggestion is chosen (Enter on the active item, or a click). Use this to
|
|
96
|
+
* navigate to the item's page.
|
|
97
|
+
*/
|
|
98
|
+
onSelect?: (item: SearchHit) => void;
|
|
99
|
+
/**
|
|
100
|
+
* Called when the raw query is submitted (Enter with no active suggestion). Use this to send
|
|
101
|
+
* the user to a full search-results page.
|
|
102
|
+
*/
|
|
103
|
+
onSubmit?: (query: string) => void;
|
|
104
|
+
maxTypos?: number;
|
|
105
|
+
minLengthFor1Typo?: number;
|
|
106
|
+
minLengthFor2Typos?: number;
|
|
107
|
+
typoFallbackThreshold?: number;
|
|
108
|
+
prioritizeExactMatch?: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface AutocompleteInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
111
|
+
role: 'combobox';
|
|
112
|
+
'aria-autocomplete': 'list';
|
|
113
|
+
'aria-expanded': boolean;
|
|
114
|
+
'aria-controls': string;
|
|
115
|
+
'aria-activedescendant'?: string;
|
|
116
|
+
autoComplete: 'off';
|
|
117
|
+
}
|
|
118
|
+
interface AutocompleteListboxProps extends HTMLAttributes<HTMLElement> {
|
|
119
|
+
role: 'listbox';
|
|
120
|
+
id: string;
|
|
121
|
+
}
|
|
122
|
+
interface AutocompleteItemProps extends HTMLAttributes<HTMLElement> {
|
|
123
|
+
role: 'option';
|
|
124
|
+
id: string;
|
|
125
|
+
'aria-selected': boolean;
|
|
126
|
+
}
|
|
127
|
+
interface UseAutocompleteReturn {
|
|
128
|
+
/** Current input value. */
|
|
129
|
+
query: string;
|
|
130
|
+
/** Set the input value programmatically (does not trigger `onSubmit`). */
|
|
131
|
+
setQuery: (value: string) => void;
|
|
132
|
+
/** The current suggestions (top hits for the query). */
|
|
133
|
+
suggestions: SearchHit[];
|
|
134
|
+
/** True while a request is in flight. */
|
|
135
|
+
isLoading: boolean;
|
|
136
|
+
/** Whether the suggestions panel should be shown. */
|
|
137
|
+
isOpen: boolean;
|
|
138
|
+
/** Index of the keyboard-active suggestion, or -1 when none is active. */
|
|
139
|
+
activeIndex: number;
|
|
140
|
+
/** The keyboard-active suggestion, or null. */
|
|
141
|
+
activeItem: SearchHit | null;
|
|
142
|
+
/** Open the panel (if there is anything to show). */
|
|
143
|
+
open: () => void;
|
|
144
|
+
/** Close the panel and clear the active item. */
|
|
145
|
+
close: () => void;
|
|
146
|
+
/** Clear the query, suggestions, and close the panel. */
|
|
147
|
+
clear: () => void;
|
|
148
|
+
/** Select a suggestion (fires `onSelect` and closes the panel). */
|
|
149
|
+
selectItem: (item: SearchHit) => void;
|
|
150
|
+
/** Props for a `<label>` associated with the input. */
|
|
151
|
+
getLabelProps: () => {
|
|
152
|
+
id: string;
|
|
153
|
+
htmlFor: string;
|
|
154
|
+
};
|
|
155
|
+
/** Props for the `<input>` (combobox). Pass-through props are merged, yours win. */
|
|
156
|
+
getInputProps: (userProps?: InputHTMLAttributes<HTMLInputElement>) => AutocompleteInputProps;
|
|
157
|
+
/** Props for the suggestions container (listbox). */
|
|
158
|
+
getListboxProps: (userProps?: HTMLAttributes<HTMLElement>) => AutocompleteListboxProps;
|
|
159
|
+
/** Props for a single suggestion (option). */
|
|
160
|
+
getItemProps: (params: {
|
|
161
|
+
item: SearchHit;
|
|
162
|
+
index: number;
|
|
163
|
+
userProps?: HTMLAttributes<HTMLElement>;
|
|
164
|
+
}) => AutocompleteItemProps;
|
|
165
|
+
}
|
|
166
|
+
declare function useAutocomplete(options: UseAutocompleteOptions): UseAutocompleteReturn;
|
|
167
|
+
|
|
59
168
|
declare const DOTS = "...";
|
|
60
169
|
interface UsePaginationParams {
|
|
61
170
|
currentPage: number;
|
|
@@ -101,4 +210,4 @@ interface UrlResolverOptions {
|
|
|
101
210
|
}
|
|
102
211
|
declare function createDefaultUrlResolver(configs: SearchItemConfig[], options?: UrlResolverOptions): UrlResolver;
|
|
103
212
|
|
|
104
|
-
export { DOTS, SearchContext, SearchItemDefaultUrlResolverProvider, SearchItemUrlResolverProvider, SearchProvider, type SearchProviderProps, type UrlResolver, type UseSearchPaginationReturn, type UseSearchReturn, createDefaultUrlResolver, usePagination, useSearch, useSearchPagination, useUrlResolver };
|
|
213
|
+
export { type AutocompleteInputProps, type AutocompleteItemProps, type AutocompleteListboxProps, DOTS, SearchContext, SearchItemDefaultUrlResolverProvider, SearchItemUrlResolverProvider, SearchProvider, type SearchProviderProps, type UrlResolver, type UseAutocompleteOptions, type UseAutocompleteReturn, type UseSearchPaginationReturn, type UseSearchReturn, createDefaultUrlResolver, useAutocomplete, usePagination, useSearch, useSearchPagination, useUrlResolver };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { FC, ReactNode } from 'react';
|
|
3
|
-
import { d as Pagination, S as SearchHit, a as Facets, P as PageSize,
|
|
2
|
+
import { FC, ReactNode, InputHTMLAttributes, HTMLAttributes } from 'react';
|
|
3
|
+
import { d as Pagination, S as SearchHit, a as Facets, P as PageSize, h as SearchParams, C as CollectionResult, F as FacetBy, g as SearchItemConfig } from './client-DOew5kqb.js';
|
|
4
4
|
|
|
5
5
|
interface SearchProviderProps {
|
|
6
6
|
children: ReactNode;
|
|
@@ -39,6 +39,18 @@ interface UseSearchReturn {
|
|
|
39
39
|
* (App Router slots) instead of it being passed to the provider. */
|
|
40
40
|
registerOrderBy: (id: string, orderBy: unknown) => void;
|
|
41
41
|
unregisterOrderBy: (id: string) => void;
|
|
42
|
+
/** The search function the provider drives (typo-tolerance wrapper included). Exposed
|
|
43
|
+
* so in-engine components (e.g. an autocomplete box) issue the SAME request shape. */
|
|
44
|
+
performSearch: (params: SearchParams) => Promise<CollectionResult>;
|
|
45
|
+
/** Fields the query string is matched against (as configured on the engine). */
|
|
46
|
+
queryBy?: string[];
|
|
47
|
+
/** Locale the search is scoped to (per-locale collection). */
|
|
48
|
+
locale?: string;
|
|
49
|
+
/** Always-applied base `filter_by` string (from the engine's base filters). */
|
|
50
|
+
baseFilterString?: string;
|
|
51
|
+
/** The active facet selections as a `performSearch` `filters` object — mirrors the
|
|
52
|
+
* main results request so an autocomplete can reproduce the current filtered context. */
|
|
53
|
+
currentFilters: Record<string, unknown>;
|
|
42
54
|
filterOptions: FacetBy[];
|
|
43
55
|
setFilterOptions: (filters: FacetBy[]) => void;
|
|
44
56
|
/** Additive registration of a single facet option (keyed by fieldKey). Used by facet
|
|
@@ -56,6 +68,103 @@ declare const SearchProvider: FC<SearchProviderProps>;
|
|
|
56
68
|
|
|
57
69
|
declare function useSearch(): UseSearchReturn;
|
|
58
70
|
|
|
71
|
+
interface UseAutocompleteOptions {
|
|
72
|
+
/**
|
|
73
|
+
* The search function (same signature used by `SearchProvider`). Typically
|
|
74
|
+
* `createSearchClient(...).performSearch`.
|
|
75
|
+
*/
|
|
76
|
+
performSearch: (params: SearchParams) => Promise<CollectionResult>;
|
|
77
|
+
/** Fields to query against (mirrors `SearchProvider`'s `queryBy`). */
|
|
78
|
+
queryBy?: string[];
|
|
79
|
+
/** A base Typesense `filter_by` string applied to every request. */
|
|
80
|
+
baseFilterBy?: string;
|
|
81
|
+
/** Active facet selections (same `filters` object `SearchProvider` sends), so the
|
|
82
|
+
* autocomplete request mirrors the main results' filtered context. */
|
|
83
|
+
filters?: Record<string, unknown>;
|
|
84
|
+
/** Locale to scope the search to (per-locale collection). */
|
|
85
|
+
locale?: string;
|
|
86
|
+
/** Max number of suggestions to fetch/show. Default: 6. */
|
|
87
|
+
perPage?: number;
|
|
88
|
+
/** Minimum number of characters before a request is made. Default: 1. */
|
|
89
|
+
minQueryLength?: number;
|
|
90
|
+
/** Debounce, in ms, between the last keystroke and the request. Default: 150. */
|
|
91
|
+
debounceMs?: number;
|
|
92
|
+
/** Open the panel as soon as the input is focused (if there is anything to show). Default: false. */
|
|
93
|
+
openOnFocus?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Called when a suggestion is chosen (Enter on the active item, or a click). Use this to
|
|
96
|
+
* navigate to the item's page.
|
|
97
|
+
*/
|
|
98
|
+
onSelect?: (item: SearchHit) => void;
|
|
99
|
+
/**
|
|
100
|
+
* Called when the raw query is submitted (Enter with no active suggestion). Use this to send
|
|
101
|
+
* the user to a full search-results page.
|
|
102
|
+
*/
|
|
103
|
+
onSubmit?: (query: string) => void;
|
|
104
|
+
maxTypos?: number;
|
|
105
|
+
minLengthFor1Typo?: number;
|
|
106
|
+
minLengthFor2Typos?: number;
|
|
107
|
+
typoFallbackThreshold?: number;
|
|
108
|
+
prioritizeExactMatch?: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface AutocompleteInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
111
|
+
role: 'combobox';
|
|
112
|
+
'aria-autocomplete': 'list';
|
|
113
|
+
'aria-expanded': boolean;
|
|
114
|
+
'aria-controls': string;
|
|
115
|
+
'aria-activedescendant'?: string;
|
|
116
|
+
autoComplete: 'off';
|
|
117
|
+
}
|
|
118
|
+
interface AutocompleteListboxProps extends HTMLAttributes<HTMLElement> {
|
|
119
|
+
role: 'listbox';
|
|
120
|
+
id: string;
|
|
121
|
+
}
|
|
122
|
+
interface AutocompleteItemProps extends HTMLAttributes<HTMLElement> {
|
|
123
|
+
role: 'option';
|
|
124
|
+
id: string;
|
|
125
|
+
'aria-selected': boolean;
|
|
126
|
+
}
|
|
127
|
+
interface UseAutocompleteReturn {
|
|
128
|
+
/** Current input value. */
|
|
129
|
+
query: string;
|
|
130
|
+
/** Set the input value programmatically (does not trigger `onSubmit`). */
|
|
131
|
+
setQuery: (value: string) => void;
|
|
132
|
+
/** The current suggestions (top hits for the query). */
|
|
133
|
+
suggestions: SearchHit[];
|
|
134
|
+
/** True while a request is in flight. */
|
|
135
|
+
isLoading: boolean;
|
|
136
|
+
/** Whether the suggestions panel should be shown. */
|
|
137
|
+
isOpen: boolean;
|
|
138
|
+
/** Index of the keyboard-active suggestion, or -1 when none is active. */
|
|
139
|
+
activeIndex: number;
|
|
140
|
+
/** The keyboard-active suggestion, or null. */
|
|
141
|
+
activeItem: SearchHit | null;
|
|
142
|
+
/** Open the panel (if there is anything to show). */
|
|
143
|
+
open: () => void;
|
|
144
|
+
/** Close the panel and clear the active item. */
|
|
145
|
+
close: () => void;
|
|
146
|
+
/** Clear the query, suggestions, and close the panel. */
|
|
147
|
+
clear: () => void;
|
|
148
|
+
/** Select a suggestion (fires `onSelect` and closes the panel). */
|
|
149
|
+
selectItem: (item: SearchHit) => void;
|
|
150
|
+
/** Props for a `<label>` associated with the input. */
|
|
151
|
+
getLabelProps: () => {
|
|
152
|
+
id: string;
|
|
153
|
+
htmlFor: string;
|
|
154
|
+
};
|
|
155
|
+
/** Props for the `<input>` (combobox). Pass-through props are merged, yours win. */
|
|
156
|
+
getInputProps: (userProps?: InputHTMLAttributes<HTMLInputElement>) => AutocompleteInputProps;
|
|
157
|
+
/** Props for the suggestions container (listbox). */
|
|
158
|
+
getListboxProps: (userProps?: HTMLAttributes<HTMLElement>) => AutocompleteListboxProps;
|
|
159
|
+
/** Props for a single suggestion (option). */
|
|
160
|
+
getItemProps: (params: {
|
|
161
|
+
item: SearchHit;
|
|
162
|
+
index: number;
|
|
163
|
+
userProps?: HTMLAttributes<HTMLElement>;
|
|
164
|
+
}) => AutocompleteItemProps;
|
|
165
|
+
}
|
|
166
|
+
declare function useAutocomplete(options: UseAutocompleteOptions): UseAutocompleteReturn;
|
|
167
|
+
|
|
59
168
|
declare const DOTS = "...";
|
|
60
169
|
interface UsePaginationParams {
|
|
61
170
|
currentPage: number;
|
|
@@ -101,4 +210,4 @@ interface UrlResolverOptions {
|
|
|
101
210
|
}
|
|
102
211
|
declare function createDefaultUrlResolver(configs: SearchItemConfig[], options?: UrlResolverOptions): UrlResolver;
|
|
103
212
|
|
|
104
|
-
export { DOTS, SearchContext, SearchItemDefaultUrlResolverProvider, SearchItemUrlResolverProvider, SearchProvider, type SearchProviderProps, type UrlResolver, type UseSearchPaginationReturn, type UseSearchReturn, createDefaultUrlResolver, usePagination, useSearch, useSearchPagination, useUrlResolver };
|
|
213
|
+
export { type AutocompleteInputProps, type AutocompleteItemProps, type AutocompleteListboxProps, DOTS, SearchContext, SearchItemDefaultUrlResolverProvider, SearchItemUrlResolverProvider, SearchProvider, type SearchProviderProps, type UrlResolver, type UseAutocompleteOptions, type UseAutocompleteReturn, type UseSearchPaginationReturn, type UseSearchReturn, createDefaultUrlResolver, useAutocomplete, usePagination, useSearch, useSearchPagination, useUrlResolver };
|