This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1 @@
export declare type MaybePromise<TResolution> = Promise<TResolution> | TResolution;

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,4 @@
export declare type UserAgent = {
segment: string;
version?: string;
};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,15 @@
import { AutocompleteNavigator } from './AutocompleteNavigator';
import { AutocompletePropGetters } from './AutocompletePropGetters';
import { AutocompleteSetters } from './AutocompleteSetters';
export declare type BaseItem = Record<string, unknown>;
export interface AutocompleteScopeApi<TItem extends BaseItem> extends AutocompleteSetters<TItem> {
/**
* Triggers a search to refresh the state.
*/
refresh(): Promise<void>;
/**
* Functions to navigate to a URL.
*/
navigator: AutocompleteNavigator<TItem>;
}
export declare type AutocompleteApi<TItem extends BaseItem, TEvent = Event, TMouseEvent = MouseEvent, TKeyboardEvent = KeyboardEvent> = AutocompleteScopeApi<TItem> & AutocompletePropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>;

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,10 @@
import { BaseItem } from './AutocompleteApi';
import { InternalAutocompleteSource } from './AutocompleteSource';
export interface AutocompleteCollection<TItem extends BaseItem> {
source: InternalAutocompleteSource<TItem>;
items: TItem[];
}
export interface AutocompleteCollectionItemsArray<TItem extends BaseItem> {
source: InternalAutocompleteSource<TItem>;
items: TItem[][];
}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,3 @@
export interface AutocompleteContext {
[key: string]: unknown;
}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,13 @@
export declare type AutocompleteEnvironment = Window | {
[prop: string]: unknown;
addEventListener: Window['addEventListener'];
removeEventListener: Window['removeEventListener'];
setTimeout: Window['setTimeout'];
clearTimeout: Window['clearTimeout'];
document: Window['document'];
location: {
assign: Location['assign'];
};
open: Window['open'];
navigator?: Partial<Window['navigator']>;
};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,28 @@
import { BaseItem } from './AutocompleteApi';
import { AutocompleteState } from './AutocompleteState';
export interface AutocompleteNavigator<TItem extends BaseItem> {
/**
* Called when a URL should be open in the current page.
*/
navigate(params: {
itemUrl: string;
item: TItem;
state: AutocompleteState<TItem>;
}): void;
/**
* Called when a URL should be open in a new tab.
*/
navigateNewTab(params: {
itemUrl: string;
item: TItem;
state: AutocompleteState<TItem>;
}): void;
/**
* Called when a URL should be open in a new window.
*/
navigateNewWindow(params: {
itemUrl: string;
item: TItem;
state: AutocompleteState<TItem>;
}): void;
}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,185 @@
import type { MaybePromise } from '../MaybePromise';
import { AutocompleteScopeApi, BaseItem } from './AutocompleteApi';
import { AutocompleteEnvironment } from './AutocompleteEnvironment';
import { AutocompleteNavigator } from './AutocompleteNavigator';
import { AutocompletePlugin } from './AutocompletePlugin';
import { Reshape } from './AutocompleteReshape';
import { AutocompleteSource, InternalAutocompleteSource } from './AutocompleteSource';
import { AutocompleteState } from './AutocompleteState';
export interface OnSubmitParams<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> {
state: AutocompleteState<TItem>;
event: any;
}
export declare type OnResetParams<TItem extends BaseItem> = OnSubmitParams<TItem>;
export interface OnInputParams<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> {
query: string;
state: AutocompleteState<TItem>;
}
export declare type GetSourcesParams<TItem extends BaseItem> = OnInputParams<TItem>;
export declare type GetSources<TItem extends BaseItem> = (params: GetSourcesParams<TItem>) => MaybePromise<Array<AutocompleteSource<TItem> | boolean | undefined>>;
export declare type InternalGetSources<TItem extends BaseItem> = (params: GetSourcesParams<TItem>) => Promise<Array<InternalAutocompleteSource<TItem>>>;
interface OnStateChangeProps<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> {
/**
* The current Autocomplete state.
*/
state: AutocompleteState<TItem>;
/**
* The previous Autocomplete state.
*/
prevState: AutocompleteState<TItem>;
}
export interface AutocompleteOptions<TItem extends BaseItem> {
/**
* A flag to activate the debug mode.
*
* This is useful while developing because it keeps the panel open even when the blur event occurs. **Make sure to disable it in production.**
*
* See [**Debugging**](https://www.algolia.com/doc/ui-libraries/autocomplete/guides/debugging/) for more information.
*
* @default false
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-debug
*/
debug?: boolean;
/**
* An ID for the autocomplete to create accessible attributes.
*
* It is incremented by default when creating a new Autocomplete instance.
*
* @default "autocomplete-0"
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-id
*/
id?: string;
/**
* The function called when the internal state changes.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-onstatechange
*/
onStateChange?(props: OnStateChangeProps<TItem>): void;
/**
* The placeholder text to show in the search input when there's no query.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-placeholder
*/
placeholder?: string;
/**
* Whether to focus the search input or not when the page is loaded.
*
* @default false
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-autofocus
*/
autoFocus?: boolean;
/**
* The default item index to pre-select.
*
* We recommend using `0` when the autocomplete is used to open links, instead of triggering a search in an application.
*
* @default null
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-defaultactiveitemid
*/
defaultActiveItemId?: number | null;
/**
* Whether to open the panel on focus when there's no query.
*
* @default false
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-openonfocus
*/
openOnFocus?: boolean;
/**
* How many milliseconds must elapse before considering the autocomplete experience [stalled](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/state/#param-status).
*
* @default 300
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-stallthreshold
*/
stallThreshold?: number;
/**
* The initial state to apply when autocomplete is created.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-initialstate
*/
initialState?: Partial<AutocompleteState<TItem>>;
/**
* The [sources](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/) to get the suggestions from.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-getsources
*/
getSources?: GetSources<TItem>;
/**
* The environment in which your application is running.
*
* This is useful if you're using autocomplete in a different context than `window`.
*
* @default window
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-environment
*/
environment?: AutocompleteEnvironment;
/**
* An implementation of Autocomplete's Navigator API to redirect the user when opening a link.
*
* Learn more on the [**Navigator API**](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/keyboard-navigation/) documentation.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-navigator
*/
navigator?: Partial<AutocompleteNavigator<TItem>>;
/**
* The function called to determine whether the panel should open or not.
*
* By default, the panel opens when there are items in the state.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-shouldpanelopen
*/
shouldPanelOpen?(params: {
state: AutocompleteState<TItem>;
}): boolean;
/**
* The function called when submitting the Autocomplete form.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-onsubmit
*/
onSubmit?(params: OnSubmitParams<TItem>): void;
/**
* The function called when resetting the Autocomplete form.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-onreset
*/
onReset?(params: OnResetParams<TItem>): void;
/**
* The plugins that encapsulate and distribute custom Autocomplete behaviors.
*
* See [**Plugins**](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/plugins/) for more information.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-plugins
*/
plugins?: Array<AutocompletePlugin<any, any>>;
/**
* The function called to reshape the sources after they're resolved.
*
* This is useful to transform sources before rendering them. You can group sources by attribute, remove duplicates, create shared limits between sources, etc.
*
* See [**Reshaping sources**](https://www.algolia.com/doc/ui-libraries/autocomplete/guides/reshaping-sources/) for more information.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-reshape
*/
reshape?: Reshape<TItem>;
}
export interface InternalAutocompleteOptions<TItem extends BaseItem> extends AutocompleteOptions<TItem> {
debug: boolean;
id: string;
onStateChange(props: OnStateChangeProps<TItem>): void;
placeholder: string;
autoFocus: boolean;
defaultActiveItemId: number | null;
openOnFocus: boolean;
stallThreshold: number;
initialState: AutocompleteState<TItem>;
getSources: InternalGetSources<TItem>;
environment: AutocompleteEnvironment;
navigator: AutocompleteNavigator<TItem>;
plugins: Array<AutocompletePlugin<any, any>>;
shouldPanelOpen(params: {
state: AutocompleteState<TItem>;
}): boolean;
onSubmit(params: OnSubmitParams<TItem>): void;
onReset(params: OnResetParams<TItem>): void;
reshape: Reshape<TItem>;
}
export {};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,43 @@
import { AutocompleteScopeApi, BaseItem } from './AutocompleteApi';
import { AutocompleteOptions } from './AutocompleteOptions';
import { PluginReshape } from './AutocompleteReshape';
import { OnSelectParams, OnActiveParams, OnResolveParams } from './AutocompleteSource';
declare type PluginSubscriber<TParams> = (params: TParams) => void;
export interface PluginSubscribeParams<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> {
onSelect(fn: PluginSubscriber<OnSelectParams<TItem>>): void;
onActive(fn: PluginSubscriber<OnActiveParams<TItem>>): void;
onResolve(fn: PluginSubscriber<OnResolveParams<TItem>>): void;
}
export declare type AutocompletePlugin<TItem extends BaseItem, TData = unknown> = Partial<Pick<AutocompleteOptions<any>, 'onStateChange' | 'onSubmit' | 'onReset'> & Pick<AutocompleteOptions<TItem>, 'getSources'>> & {
/**
* The function called when Autocomplete starts.
*
* It lets you subscribe to lifecycle hooks and interact with the instance's state and context.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/plugins/#param-subscribe
*/
subscribe?(params: PluginSubscribeParams<any>): void;
/**
* An extra plugin object to expose properties and functions as APIs.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/plugins/#param-data
*/
data?: TData;
/**
* A name to identify the plugin.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/plugins/#param-name
*/
name?: string;
/**
* A function to reshape the sources.
*
* It gets called before the user's reshape function.
*/
reshape?: PluginReshape<TItem>;
/**
* @internal
*/
__autocomplete_pluginOptions?: Record<string, any>;
};
export {};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,100 @@
import { BaseItem } from './AutocompleteApi';
import { InternalAutocompleteSource } from './AutocompleteSource';
export interface AutocompletePropGetters<TItem extends BaseItem, TEvent = Event, TMouseEvent = MouseEvent, TKeyboardEvent = KeyboardEvent> {
getEnvironmentProps: GetEnvironmentProps;
getRootProps: GetRootProps;
getFormProps: GetFormProps<TEvent>;
getLabelProps: GetLabelProps;
getInputProps: GetInputProps<TEvent, TMouseEvent, TKeyboardEvent>;
getPanelProps: GetPanelProps<TMouseEvent>;
getListProps: GetListProps;
getItemProps: GetItemProps<TItem, TMouseEvent>;
}
export declare type GetEnvironmentProps = (props: {
[key: string]: unknown;
formElement: HTMLElement;
inputElement: HTMLInputElement;
panelElement: HTMLElement;
}) => {
onTouchStart(event: TouchEvent): void;
onTouchMove(event: TouchEvent): void;
onMouseDown(event: MouseEvent): void;
};
export declare type GetRootProps = (props?: {
[key: string]: unknown;
}) => {
role: 'combobox';
'aria-expanded': boolean;
'aria-haspopup': boolean | 'dialog' | 'menu' | 'true' | 'false' | 'grid' | 'listbox' | 'tree' | undefined;
'aria-owns': string | undefined;
'aria-labelledby': string;
};
export declare type GetFormProps<TEvent = Event> = (props: {
[key: string]: unknown;
inputElement: HTMLInputElement | null;
}) => {
action: '';
noValidate: true;
role: 'search';
onSubmit(event: TEvent): void;
onReset(event: TEvent): void;
};
export declare type GetLabelProps = (props?: {
[key: string]: unknown;
sourceIndex?: number;
}) => {
htmlFor: string;
id: string;
};
export declare type GetInputProps<TEvent, TMouseEvent, TKeyboardEvent> = (props: {
[key: string]: unknown;
inputElement: HTMLInputElement | null;
maxLength?: number;
}) => {
id: string;
value: string;
autoFocus: boolean;
placeholder: string;
autoComplete: 'on' | 'off';
autoCorrect: 'on' | 'off';
autoCapitalize: 'on' | 'off';
enterKeyHint: 'go' | 'search';
spellCheck: 'false';
maxLength: number;
type: 'search';
'aria-autocomplete': 'none' | 'inline' | 'list' | 'both';
'aria-activedescendant': string | undefined;
'aria-controls': string | undefined;
'aria-labelledby': string;
onChange(event: TEvent): void;
onKeyDown(event: TKeyboardEvent): void;
onFocus(event: TEvent): void;
onBlur(): void;
onClick(event: TMouseEvent): void;
};
export declare type GetPanelProps<TMouseEvent> = (props?: {
[key: string]: unknown;
}) => {
onMouseDown(event: TMouseEvent): void;
onMouseLeave(): void;
};
export declare type GetListProps = (props?: {
[key: string]: unknown;
sourceIndex?: number;
}) => {
role: 'listbox';
'aria-labelledby': string;
id: string;
};
export declare type GetItemProps<TItem extends BaseItem, TMouseEvent = MouseEvent> = (props: {
[key: string]: unknown;
item: TItem;
source: InternalAutocompleteSource<TItem>;
}) => {
id: string;
role: 'option';
'aria-selected': boolean;
onMouseMove(event: TMouseEvent): void;
onMouseDown(event: TMouseEvent): void;
onClick(event: TMouseEvent): void;
};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,25 @@
import { BaseItem } from './AutocompleteApi';
import { AutocompleteSource } from './AutocompleteSource';
import { AutocompleteState } from './AutocompleteState';
export declare type AutocompleteReshapeSource<TItem extends BaseItem> = AutocompleteSource<TItem> & {
getItems(): TItem[];
};
export declare type AutocompleteReshapeSourcesBySourceId<TItem extends BaseItem> = Record<string, AutocompleteReshapeSource<TItem>>;
export declare type ReshapeParams<TItem extends BaseItem, TState extends AutocompleteState<TItem> = AutocompleteState<TItem>> = {
/**
* The resolved sources provided by [`getSources`](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-getsources)
*/
sources: Array<AutocompleteReshapeSource<TItem>>;
/**
* The resolved sources grouped by [`sourceId`](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-sourceid)s
*/
sourcesBySourceId: AutocompleteReshapeSourcesBySourceId<TItem>;
/**
* The current Autocomplete state.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/state
*/
state: TState;
};
export declare type Reshape<TItem extends BaseItem, TState extends AutocompleteState<TItem> = AutocompleteState<TItem>> = (params: ReshapeParams<TItem, TState>) => Array<AutocompleteReshapeSource<TItem>>;
export declare type PluginReshape<TItem extends BaseItem, TState extends AutocompleteState<TItem> = AutocompleteState<TItem>> = (params: Omit<ReshapeParams<TItem, TState>, 'sources'>) => Omit<ReshapeParams<TItem, TState>, 'sources'>;

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,46 @@
import { BaseItem } from './AutocompleteApi';
import { AutocompleteCollection, AutocompleteCollectionItemsArray } from './AutocompleteCollection';
import { AutocompleteState } from './AutocompleteState';
export declare type StateUpdater<TState> = (value: TState) => void;
export interface AutocompleteSetters<TItem extends BaseItem> {
/**
* Sets the highlighted item index.
*
* Pass `null` to unselect items.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/state/#param-setactiveitemid
*/
setActiveItemId: StateUpdater<AutocompleteState<TItem>['activeItemId']>;
/**
* Sets the query.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/state/#param-setquery
*/
setQuery: StateUpdater<AutocompleteState<TItem>['query']>;
/**
* Sets the collections.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/state/#param-setcollections
*/
setCollections: StateUpdater<Array<AutocompleteCollection<TItem> | AutocompleteCollectionItemsArray<TItem>>>;
/**
* Sets whether the panel is open or not.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/state/#param-setisopen
*/
setIsOpen: StateUpdater<AutocompleteState<TItem>['isOpen']>;
/**
* Sets the status of the autocomplete.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/state/#param-setisopen
*/
setStatus: StateUpdater<AutocompleteState<TItem>['status']>;
/**
* Sets the context passed to lifecycle hooks.
*
* See more in [**Context**](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/context/).
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/state/#param-setcontext
*/
setContext: StateUpdater<AutocompleteState<TItem>['context']>;
}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,76 @@
import type { FacetHit, Hit } from '@algolia/client-search';
import type { MaybePromise } from '../MaybePromise';
import type { SearchForFacetValuesResponse, SearchResponse } from '../preset-algolia/algoliasearch';
import type { RequesterDescription } from '../preset-algolia/createRequester';
import { AutocompleteScopeApi, BaseItem } from './AutocompleteApi';
import { GetSourcesParams } from './AutocompleteOptions';
import { AutocompleteState } from './AutocompleteState';
export interface OnSelectParams<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> {
state: AutocompleteState<TItem>;
event: any;
item: TItem;
itemInputValue: ReturnType<InternalAutocompleteSource<TItem>['getItemInputValue']>;
itemUrl: ReturnType<InternalAutocompleteSource<TItem>['getItemUrl']>;
source: InternalAutocompleteSource<TItem>;
}
export declare type OnActiveParams<TItem extends BaseItem> = OnSelectParams<TItem>;
export declare type OnResolveParams<TItem extends BaseItem> = {
source: AutocompleteSource<TItem>;
results: SearchForFacetValuesResponse | SearchResponse<TItem> | TItem[] | TItem[][];
items: FacetHit[][] | FacetHit[] | Array<Hit<TItem>> | Array<SearchForFacetValuesResponse | SearchResponse<TItem> | TItem[] | TItem[][]>;
state: AutocompleteState<TItem>;
};
declare type DefaultIndicator = {
/**
* Optional key on a function to indicate it's the default value of this function.
*/
__default?: boolean;
};
export interface AutocompleteSource<TItem extends BaseItem> {
/**
* Unique identifier for the source.
*/
sourceId: string;
/**
* The function called to get the value of an item.
*
* The value is used to fill the search box.
*/
getItemInputValue?: DefaultIndicator & (({ item, state, }: {
item: TItem;
state: AutocompleteState<TItem>;
}) => string);
/**
* The function called to get the URL of the item.
*
* The value is used to add [keyboard accessibility](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/keyboard-navigation/) features to let users open items in the current tab, a new tab, or a new window.
*/
getItemUrl?: DefaultIndicator & (({ item, state, }: {
item: TItem;
state: AutocompleteState<TItem>;
}) => string | undefined);
/**
* The function called when the input changes.
*
* You can use this function to filter the items based on the query.
*/
getItems(params: GetSourcesParams<TItem>): MaybePromise<TItem[] | TItem[][] | RequesterDescription<TItem>>;
/**
* The function called whenever an item is selected.
*/
onSelect?: DefaultIndicator & ((params: OnSelectParams<TItem>) => void);
/**
* The function called whenever an item is active.
*
* You can trigger different behaviors if the item is active depending on the triggering event using the `event` parameter.
*/
onActive?: DefaultIndicator & ((params: OnActiveParams<TItem>) => void);
/**
* The function called whenever a source resolves.
*/
onResolve?: DefaultIndicator & ((params: OnResolveParams<TItem>) => void);
}
export declare type InternalAutocompleteSource<TItem extends BaseItem> = {
[KParam in keyof AutocompleteSource<TItem>]-?: AutocompleteSource<TItem>[KParam];
};
export {};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,12 @@
import { BaseItem } from './AutocompleteApi';
import { AutocompleteCollection } from './AutocompleteCollection';
import { AutocompleteContext } from './AutocompleteContext';
export interface AutocompleteState<TItem extends BaseItem> {
activeItemId: number | null;
query: string;
completion: string | null;
collections: Array<AutocompleteCollection<TItem>>;
isOpen: boolean;
status: 'idle' | 'loading' | 'stalled' | 'error';
context: AutocompleteContext;
}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,11 @@
export * from './AutocompleteApi';
export * from './AutocompleteCollection';
export * from './AutocompleteContext';
export * from './AutocompleteEnvironment';
export * from './AutocompleteOptions';
export * from './AutocompleteSource';
export * from './AutocompletePropGetters';
export * from './AutocompletePlugin';
export * from './AutocompleteReshape';
export * from './AutocompleteSetters';
export * from './AutocompleteState';

View File

@@ -0,0 +1,11 @@
export * from './AutocompleteApi';
export * from './AutocompleteCollection';
export * from './AutocompleteContext';
export * from './AutocompleteEnvironment';
export * from './AutocompleteOptions';
export * from './AutocompleteSource';
export * from './AutocompletePropGetters';
export * from './AutocompletePlugin';
export * from './AutocompleteReshape';
export * from './AutocompleteSetters';
export * from './AutocompleteState';

View File

@@ -0,0 +1,3 @@
export declare function createRef<TValue>(initialValue: TValue): {
current: TValue;
};

View File

@@ -0,0 +1,5 @@
export function createRef(initialValue) {
return {
current: initialValue
};
}

View File

@@ -0,0 +1 @@
export declare function debounce<TParams>(fn: (...params: TParams[]) => void, time: number): (...args: TParams[]) => void;

View File

@@ -0,0 +1,14 @@
export function debounce(fn, time) {
var timerId = undefined;
return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (timerId) {
clearTimeout(timerId);
}
timerId = setTimeout(function () {
return fn.apply(void 0, args);
}, time);
};
}

View File

@@ -0,0 +1,5 @@
/**
* Decycles objects with circular references.
* This is used to print cyclic structures in development environment only.
*/
export declare function decycle(obj: any, seen?: Set<unknown>): any;

View File

@@ -0,0 +1,32 @@
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
/**
* Decycles objects with circular references.
* This is used to print cyclic structures in development environment only.
*/
export function decycle(obj) {
var seen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set();
if (!(process.env.NODE_ENV !== 'production') || !obj || _typeof(obj) !== 'object') {
return obj;
}
if (seen.has(obj)) {
return '[Circular]';
}
var newSeen = seen.add(obj);
if (Array.isArray(obj)) {
return obj.map(function (x) {
return decycle(x, newSeen);
});
}
return Object.fromEntries(Object.entries(obj).map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return [key, decycle(value, newSeen)];
}));
}

View File

@@ -0,0 +1 @@
export declare function flatten<TType>(values: Array<TType | TType[]>): TType[];

View File

@@ -0,0 +1,5 @@
export function flatten(values) {
return values.reduce(function (a, b) {
return a.concat(b);
}, []);
}

View File

@@ -0,0 +1 @@
export declare function generateAutocompleteId(): string;

View File

@@ -0,0 +1,4 @@
var autocompleteId = 0;
export function generateAutocompleteId() {
return "autocomplete-".concat(autocompleteId++);
}

View File

@@ -0,0 +1 @@
export declare function getAttributeValueByPath<TRecord>(record: TRecord, path: string[]): any;

View File

@@ -0,0 +1,5 @@
export function getAttributeValueByPath(record, path) {
return path.reduce(function (current, key) {
return current && current[key];
}, record);
}

View File

@@ -0,0 +1,3 @@
export declare function getItemsCount<TAutocompleteState extends {
collections: any[];
}>(state: TAutocompleteState): number;

View File

@@ -0,0 +1,8 @@
export function getItemsCount(state) {
if (state.collections.length === 0) {
return 0;
}
return state.collections.reduce(function (sum, collection) {
return sum + collection.items.length;
}, 0);
}

View File

@@ -0,0 +1,17 @@
export * from './createRef';
export * from './debounce';
export * from './decycle';
export * from './flatten';
export * from './generateAutocompleteId';
export * from './getAttributeValueByPath';
export * from './getItemsCount';
export * from './invariant';
export * from './isEqual';
export * from './MaybePromise';
export * from './noop';
export * from './safelyRunOnBrowser';
export * from './UserAgent';
export * from './userAgents';
export * from './version';
export * from './warn';
export * from './js';

View File

@@ -0,0 +1,17 @@
export * from './createRef';
export * from './debounce';
export * from './decycle';
export * from './flatten';
export * from './generateAutocompleteId';
export * from './getAttributeValueByPath';
export * from './getItemsCount';
export * from './invariant';
export * from './isEqual';
export * from './MaybePromise';
export * from './noop';
export * from './safelyRunOnBrowser';
export * from './UserAgent';
export * from './userAgents';
export * from './version';
export * from './warn';
export * from './js';

View File

@@ -0,0 +1,6 @@
/**
* Throws an error if the condition is not met in development mode.
* This is used to make development a better experience to provide guidance as
* to where the error comes from.
*/
export declare function invariant(condition: boolean, message: string | (() => string)): void;

View File

@@ -0,0 +1,13 @@
/**
* Throws an error if the condition is not met in development mode.
* This is used to make development a better experience to provide guidance as
* to where the error comes from.
*/
export function invariant(condition, message) {
if (!(process.env.NODE_ENV !== 'production')) {
return;
}
if (!condition) {
throw new Error("[Autocomplete] ".concat(typeof message === 'function' ? message() : message));
}
}

View File

@@ -0,0 +1 @@
export declare function isEqual(first: any, second: any): boolean;

View File

@@ -0,0 +1,24 @@
function isPrimitive(obj) {
return obj !== Object(obj);
}
export function isEqual(first, second) {
if (first === second) {
return true;
}
if (isPrimitive(first) || isPrimitive(second) || typeof first === 'function' || typeof second === 'function') {
return first === second;
}
if (Object.keys(first).length !== Object.keys(second).length) {
return false;
}
for (var _i = 0, _Object$keys = Object.keys(first); _i < _Object$keys.length; _i++) {
var key = _Object$keys[_i];
if (!(key in second)) {
return false;
}
if (!isEqual(first[key], second[key])) {
return false;
}
}
return true;
}

View File

@@ -0,0 +1,28 @@
export declare type AutocompleteClassNames = {
detachedCancelButton: string;
detachedFormContainer: string;
detachedContainer: string;
detachedOverlay: string;
detachedSearchButton: string;
detachedSearchButtonIcon: string;
detachedSearchButtonPlaceholder: string;
detachedSearchButtonQuery: string;
form: string;
input: string;
inputWrapper: string;
inputWrapperPrefix: string;
inputWrapperSuffix: string;
item: string;
label: string;
list: string;
loadingIndicator: string;
panel: string;
panelLayout: string;
clearButton: string;
root: string;
source: string;
sourceFooter: string;
sourceHeader: string;
sourceNoResults: string;
submitButton: string;
};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,6 @@
import { BaseItem } from '../core';
import { InternalAutocompleteSource } from './AutocompleteSource';
export interface AutocompleteCollection<TItem extends BaseItem> {
source: InternalAutocompleteSource<TItem>;
items: TItem[];
}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,23 @@
/// <reference types="react" />
import { HighlightHitParams } from './HighlightHitParams';
declare type AutocompleteHighlightComponent = <THit>({ hit, attribute, tagName, }: HighlightHitParams<THit>) => JSX.Element;
export declare type PublicAutocompleteComponents = Record<string, (props: any) => JSX.Element>;
export interface AutocompleteComponents extends PublicAutocompleteComponents {
/**
* Highlight matches in an Algolia hit.
*/
Highlight: AutocompleteHighlightComponent;
/**
* Reverse-highlight matches in an Algolia hit.
*/
ReverseHighlight: AutocompleteHighlightComponent;
/**
* Reverse-highlight and snippets matches in an Algolia hit.
*/
ReverseSnippet: AutocompleteHighlightComponent;
/**
* Highlight and snippet matches in an Algolia hit.
*/
Snippet: AutocompleteHighlightComponent;
}
export {};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,106 @@
import { AutocompleteScopeApi, AutocompleteOptions as AutocompleteCoreOptions, BaseItem, GetSourcesParams } from '../core';
import { MaybePromise } from '../MaybePromise';
import { AutocompleteClassNames } from './AutocompleteClassNames';
import { PublicAutocompleteComponents } from './AutocompleteComponents';
import { AutocompletePlugin } from './AutocompletePlugin';
import { AutocompletePropGetters } from './AutocompletePropGetters';
import { AutocompleteRender } from './AutocompleteRender';
import { AutocompleteRenderer } from './AutocompleteRenderer';
import { AutocompleteSource } from './AutocompleteSource';
import { AutocompleteState } from './AutocompleteState';
import { AutocompleteTranslations } from './AutocompleteTranslations';
export interface OnStateChangeProps<TItem extends BaseItem> extends AutocompleteScopeApi<TItem> {
/**
* The current Autocomplete state.
*/
state: AutocompleteState<TItem>;
/**
* The previous Autocomplete state.
*/
prevState: AutocompleteState<TItem>;
}
export declare type GetSources<TItem extends BaseItem> = (params: GetSourcesParams<TItem>) => MaybePromise<Array<AutocompleteSource<TItem> | boolean | undefined>>;
export interface AutocompleteOptions<TItem extends BaseItem> extends AutocompleteCoreOptions<TItem>, Partial<AutocompletePropGetters<TItem>> {
/**
* The container for the Autocomplete search box.
*
* You can either pass a [CSS selector](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors) or an [Element](https://developer.mozilla.org/docs/Web/API/HTMLElement). If there are several containers matching the selector, Autocomplete picks up the first one.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-container
*/
container: string | HTMLElement;
/**
* The container for the Autocomplete panel.
*
* You can either pass a [CSS selector](https://developer.mozilla.org/docs/Web/CSS/CSS_Selectors) or an [Element](https://developer.mozilla.org/docs/Web/API/HTMLElement). If there are several containers matching the selector, Autocomplete picks up the first one.
*
* @default document.body
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-panelcontainer
*/
panelContainer?: string | HTMLElement;
/**
* The Media Query to turn Autocomplete into a detached experience.
*
* @default "(max-width: 680px)"
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-detachedmediaquery
* @link https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
*/
detachedMediaQuery?: string;
getSources?: GetSources<TItem>;
/**
* The panel's horizontal position.
*
* @default "input-wrapper-width"
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-panelplacement
*/
panelPlacement?: 'start' | 'end' | 'full-width' | 'input-wrapper-width';
/**
* Class names to inject for each created DOM element.
*
* This is useful to style your autocomplete with external CSS frameworks.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-classnames
*/
classNames?: Partial<AutocompleteClassNames>;
/**
* The function that renders the autocomplete panel.
*
* This is useful to customize the rendering, for example, using multi-row or multi-column layouts.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-render
*/
render?: AutocompleteRender<TItem>;
/**
* The function that renders a no results section when there are no hits.
*
* This is useful to let the user know that the query returned no results.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-rendernoresults
*/
renderNoResults?: AutocompleteRender<TItem>;
initialState?: Partial<AutocompleteState<TItem>>;
onStateChange?(props: OnStateChangeProps<TItem>): void;
/**
* The virtual DOM implementation to plug to Autocomplete. It defaults to Preact.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-renderer
*/
renderer?: AutocompleteRenderer;
plugins?: Array<AutocompletePlugin<any, any>>;
/**
* Components to register in the Autocomplete rendering lifecycles.
*
* Registered components become available in [`templates`](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/templates/), [`render`](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-render), and in [`renderNoResults`](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-rendernoresults).
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-components
*/
components?: PublicAutocompleteComponents;
/**
* A mapping of translation strings.
*
* Defaults to English values.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-translations
*/
translations?: Partial<AutocompleteTranslations>;
}

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,13 @@
import { BaseItem } from '../core';
import { AutocompletePlugin as AutocompleteCorePlugin } from '../core/AutocompletePlugin';
import { AutocompleteOptions } from './AutocompleteOptions';
export declare type AutocompletePlugin<TItem extends BaseItem, TData> = Omit<AutocompleteCorePlugin<TItem, TData>, 'getSources'> & {
/**
* The [sources](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/) to get the suggestions from.
*
* When defined, theyre merged with the sources of your Autocomplete instance.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/plugins/#param-getsources
*/
getSources?: AutocompleteOptions<TItem>['getSources'];
};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,33 @@
import { BaseItem, AutocompleteApi as AutocompleteCoreApi, AutocompleteScopeApi } from '../core';
import { AutocompleteState } from './AutocompleteState';
declare type PropsGetterParams<TItem extends BaseItem, TParam> = TParam & {
state: AutocompleteState<TItem>;
} & AutocompleteScopeApi<TItem>;
export declare type AutocompletePropGetters<TItem extends BaseItem> = {
getEnvironmentProps(params: PropsGetterParams<TItem, {
props: ReturnType<AutocompleteCoreApi<TItem>['getEnvironmentProps']>;
}>): ReturnType<AutocompleteCoreApi<TItem>['getEnvironmentProps']>;
getFormProps(params: PropsGetterParams<TItem, {
props: ReturnType<AutocompleteCoreApi<TItem>['getFormProps']>;
}>): ReturnType<AutocompleteCoreApi<TItem>['getFormProps']>;
getInputProps(params: PropsGetterParams<TItem, {
props: ReturnType<AutocompleteCoreApi<TItem>['getInputProps']>;
inputElement: HTMLInputElement;
}>): ReturnType<AutocompleteCoreApi<TItem>['getInputProps']>;
getItemProps(params: PropsGetterParams<TItem, {
props: ReturnType<AutocompleteCoreApi<TItem>['getItemProps']>;
}>): ReturnType<AutocompleteCoreApi<TItem>['getItemProps']>;
getLabelProps(params: PropsGetterParams<TItem, {
props: ReturnType<AutocompleteCoreApi<TItem>['getLabelProps']>;
}>): ReturnType<AutocompleteCoreApi<TItem>['getLabelProps']>;
getListProps(params: PropsGetterParams<TItem, {
props: ReturnType<AutocompleteCoreApi<TItem>['getListProps']>;
}>): ReturnType<AutocompleteCoreApi<TItem>['getListProps']>;
getPanelProps(params: PropsGetterParams<TItem, {
props: ReturnType<AutocompleteCoreApi<TItem>['getPanelProps']>;
}>): ReturnType<AutocompleteCoreApi<TItem>['getPanelProps']>;
getRootProps(params: PropsGetterParams<TItem, {
props: ReturnType<AutocompleteCoreApi<TItem>['getRootProps']>;
}>): ReturnType<AutocompleteCoreApi<TItem>['getRootProps']>;
};
export {};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,15 @@
import { AutocompleteScopeApi, BaseItem } from '../core';
import { AutocompleteComponents } from './AutocompleteComponents';
import { HTMLTemplate, Pragma, PragmaFrag, Render, VNode } from './AutocompleteRenderer';
import { AutocompleteState } from './AutocompleteState';
export declare type AutocompleteRender<TItem extends BaseItem> = (params: AutocompleteScopeApi<TItem> & {
children: VNode;
state: AutocompleteState<TItem>;
sections: VNode[];
elements: Record<string, VNode>;
components: AutocompleteComponents;
createElement: Pragma;
Fragment: PragmaFrag;
html: HTMLTemplate;
render: Render;
}, root: HTMLElement) => void;

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,33 @@
/// <reference types="react" />
export declare type Pragma = (type: any, props: Record<string, any> | null, ...children: ComponentChildren[]) => JSX.Element;
export declare type PragmaFrag = any;
declare type ComponentChild = VNode<any> | string | number | boolean | null | undefined;
declare type ComponentChildren = ComponentChild[] | ComponentChild;
export declare type VNode<TProps = {}> = {
type: any;
key: string | number | any;
props: TProps & {
children: ComponentChildren;
};
};
export declare type Render = (vnode: ComponentChild, parent: Element | Document | ShadowRoot | DocumentFragment, replaceNode?: Element | Text | undefined) => void;
export declare type AutocompleteRenderer = {
/**
* The function to create virtual nodes.
*
* @default preact.createElement
*/
createElement: Pragma;
/**
* The component to use to create fragments.
*
* @default preact.Fragment
*/
Fragment: PragmaFrag;
/**
* The function to render children to an element.
*/
render?: Render;
};
export declare type HTMLTemplate = (strings: TemplateStringsArray, ...values: any[]) => VNode | VNode[];
export {};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,74 @@
import { AutocompleteSource as AutocompleteCoreSource, InternalAutocompleteSource as InternalAutocompleteCoreSource, BaseItem } from '../core';
import { AutocompleteComponents } from './AutocompleteComponents';
import { AutocompleteRenderer, HTMLTemplate, VNode } from './AutocompleteRenderer';
import { AutocompleteState } from './AutocompleteState';
declare type Template<TParams> = (params: TParams & AutocompleteRenderer & {
components: AutocompleteComponents;
html: HTMLTemplate;
}) => VNode | VNode[] | string;
/**
* Templates to display in the autocomplete panel.
*
* A template can either return a string, or perform DOM mutations (manipulating DOM elements with JavaScript and attaching events) without returning a string.
*/
export declare type SourceTemplates<TItem extends BaseItem> = {
/**
* A function that returns the template for each item of the source.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/templates/#param-item
*/
item: Template<{
item: TItem;
state: AutocompleteState<TItem>;
}>;
/**
* A function that returns the template for the header (before the list of items).
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/templates/#param-header
*/
header?: Template<{
state: AutocompleteState<TItem>;
source: AutocompleteSource<TItem>;
items: TItem[];
}>;
/**
* A function that returns the template for the footer (after the list of items).
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/templates/#param-footer
*/
footer?: Template<{
state: AutocompleteState<TItem>;
source: AutocompleteSource<TItem>;
items: TItem[];
}>;
/**
* A function that returns the template for when there are no items.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/templates/#param-noresults
*/
noResults?: Template<{
state: AutocompleteState<TItem>;
source: AutocompleteSource<TItem>;
}>;
};
declare type WithTemplates<TType, TItem extends BaseItem> = TType & {
/**
* A set of templates to customize how sections and their items are displayed.
*
* See [**Displaying items with Templates**](templates) for more information.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/sources/#param-templates
*/
templates: SourceTemplates<TItem>;
};
export interface AutocompleteCoreSourceWithDocs<TItem extends BaseItem> extends AutocompleteCoreSource<TItem> {
/**
* Unique identifier for the source.
*
* It is used as value for the `data-autocomplete-source-id` attribute of the source `section` container.
*/
sourceId: string;
}
export declare type AutocompleteSource<TItem extends BaseItem> = WithTemplates<AutocompleteCoreSourceWithDocs<TItem>, TItem>;
export declare type InternalAutocompleteSource<TItem extends BaseItem> = WithTemplates<InternalAutocompleteCoreSource<TItem>, TItem>;
export {};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,10 @@
import { AutocompleteState as AutocompleteCoreState, BaseItem } from '../core';
import { AutocompleteCollection } from './AutocompleteCollection';
export declare type AutocompleteState<TItem extends BaseItem> = Omit<AutocompleteCoreState<TItem>, 'collections'> & {
/**
* The collections of items.
*
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/state/#param-collections
*/
collections: Array<AutocompleteCollection<TItem>>;
};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,5 @@
export declare type AutocompleteTranslations = {
detachedCancelButtonText: string;
clearButtonTitle: string;
submitButtonTitle: string;
};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,18 @@
export declare type HighlightHitParams<THit> = {
/**
* The Algolia hit whose attribute to retrieve the highlighted parts from.
*/
hit: THit;
/**
* The attribute to retrieve the highlighted parts from.
*
* You can use the array syntax to reference nested attributes.
*/
attribute: keyof THit | string[];
/**
* The tag name to use for highlighted parts.
*
* @default "mark"
*/
tagName?: string;
};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,12 @@
export * from './AutocompleteClassNames';
export * from './AutocompleteCollection';
export * from './AutocompleteComponents';
export * from './AutocompleteOptions';
export * from './AutocompletePlugin';
export * from './AutocompletePropGetters';
export * from './AutocompleteRender';
export * from './AutocompleteRenderer';
export * from './AutocompleteSource';
export * from './AutocompleteState';
export * from './AutocompleteTranslations';
export * from './HighlightHitParams';

View File

@@ -0,0 +1,12 @@
export * from './AutocompleteClassNames';
export * from './AutocompleteCollection';
export * from './AutocompleteComponents';
export * from './AutocompleteOptions';
export * from './AutocompletePlugin';
export * from './AutocompletePropGetters';
export * from './AutocompleteRender';
export * from './AutocompleteRenderer';
export * from './AutocompleteSource';
export * from './AutocompleteState';
export * from './AutocompleteTranslations';
export * from './HighlightHitParams';

View File

@@ -0,0 +1 @@
export declare const noop: () => void;

View File

@@ -0,0 +1 @@
export var noop = function noop() {};

View File

@@ -0,0 +1,54 @@
import * as ClientSearch from '@algolia/client-search';
import type * as AlgoliaSearch from 'algoliasearch/lite';
declare type AnyToUnknown<TSubject> = (any extends TSubject ? true : false) extends true ? unknown : TSubject;
declare type SearchClientShape = {
search: unknown;
};
declare type ClientLiteV5 = AnyToUnknown<
/** @ts-ignore */
ReturnType<typeof AlgoliaSearch.liteClient>>;
declare type ClientSearchV5 = AnyToUnknown<
/** @ts-ignore */
ReturnType<typeof ClientSearch.searchClient>>;
declare type ClientV5 = ClientLiteV5 extends SearchClientShape ? ClientLiteV5 : ClientSearchV5 extends SearchClientShape ? ClientSearchV5 : unknown;
declare type PickForClient<TMapping extends {
v4: unknown;
v5: unknown;
}> = ClientV5 extends SearchClientShape ? TMapping['v5'] : TMapping['v4'];
export declare type SearchClient = PickForClient<{
/** @ts-ignore */
v4: AlgoliaSearch.SearchClient;
/** @ts-ignore */
v5: ClientV5;
}>;
export declare type MultipleQueriesQuery = PickForClient<{
/** @ts-ignore */
v4: ClientSearch.MultipleQueriesQuery;
/** @ts-ignore */
v5: AlgoliaSearch.LegacySearchMethodProps[number];
}>;
export declare type SearchForFacetValuesResponse = PickForClient<{
/** @ts-ignore */
v4: ClientSearch.SearchForFacetValuesResponse;
/** @ts-ignore */
v5: AlgoliaSearch.SearchForFacetValuesResponse;
}>;
export declare type SearchResponse<THit> = PickForClient<{
/** @ts-ignore */
v4: ClientSearch.SearchResponse<THit>;
/** @ts-ignore */
v5: AlgoliaSearch.SearchResponse<THit>;
}>;
export declare type HighlightResult<THit> = PickForClient<{
/** @ts-ignore */
v4: ClientSearch.HighlightResult<THit>;
/** @ts-ignore */
v5: AlgoliaSearch.HighlightResult;
}>;
export declare type SnippetResult<THit> = PickForClient<{
/** @ts-ignore */
v4: ClientSearch.SnippetResult<THit>;
/** @ts-ignore */
v5: AlgoliaSearch.SnippetResult;
}>;
export {};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,89 @@
import { UserAgent } from '../UserAgent';
import { MultipleQueriesQuery, SearchClient, SearchForFacetValuesResponse, SearchResponse } from './algoliasearch';
export interface SearchParams {
/**
* The initialized Algolia search client.
*/
searchClient: SearchClient;
/**
* A list of queries to execute.
*/
queries: MultipleQueriesQuery[];
/**
* A list of user agents to add to the search client.
*
* This is useful to track usage of an integration.
*/
userAgents?: UserAgent[];
}
export declare type Fetcher = <TRecord>({ searchClient, queries, userAgents, }: SearchParams) => Promise<Array<SearchForFacetValuesResponse | SearchResponse<TRecord>>>;
declare type FacetHit = {
label: string;
count: number;
_highlightResult: {
label: {
value: string;
};
};
};
export declare type FetcherParams = Pick<Parameters<Fetcher>[0], 'searchClient' | 'queries'>;
export declare type RequesterParams<THit> = {
transformResponse(response: TransformResponseParams<THit>): TransformedRequesterResponse<THit>;
};
declare type TransformResponseParams<THit> = {
results: Array<SearchResponse<THit> | SearchForFacetValuesResponse>;
hits: Array<SearchResponse<THit>['hits']>;
facetHits: FacetHit[][];
};
export declare type TransformedRequesterResponse<THit> = Array<SearchResponse<THit>['hits']> | SearchResponse<THit>['hits'] | FacetHit[][] | FacetHit[];
export declare type TransformResponse<THit> = (response: TransformResponseParams<THit>) => TransformedRequesterResponse<THit>;
declare type FetcherParamsQuery<THit> = {
query: MultipleQueriesQuery;
sourceId: string;
transformResponse: TransformResponse<THit>;
};
export declare type ExecuteParams<THit> = {
searchClient: SearchClient;
requests: Array<FetcherParamsQuery<THit>>;
};
export declare type Execute<THit> = (params: ExecuteParams<THit>) => Promise<ExecuteResponse<THit>>;
export declare type ExecuteResponse<THit> = Array<{
items: SearchResponse<THit> | SearchForFacetValuesResponse;
sourceId: string;
transformResponse: TransformResponse<THit>;
}>;
export declare type RequestParams<THit> = FetcherParams & {
/**
* The function to transform the Algolia response before passing it to the Autocomplete state. You have access to the full Algolia results, as well as the pre-computed hits and facet hits.
*
* This is useful to manipulate the hits, or store data from the results in the [context](https://www.algolia.com/doc/ui-libraries/autocomplete/core-concepts/context/).
*/
transformResponse?: TransformResponse<THit>;
};
export declare type RequesterDescription<THit> = {
/**
* The search client used for this request. Multiple queries with the same client are batched (if `requesterId` is also the same).
*/
searchClient: SearchClient;
/**
* Identifies requesters to confirm their queries should be batched.
* This ensures that requesters with the same client but different
* post-processing functions don't get batched.
* When falsy, batching is disabled.
* For example, the Algolia requesters use "algolia".
*/
requesterId?: string;
/**
* The search parameters used for this query.
*/
queries: MultipleQueriesQuery[];
/**
* Transforms the response of this search before returning it to the caller.
*/
transformResponse: TransformResponse<THit>;
/**
* Post-processing function for multi-queries.
*/
execute: Execute<THit>;
};
export {};

View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,8 @@
declare type BrowserCallback<TReturn> = (params: {
window: typeof window;
}) => TReturn;
/**
* Safely runs code meant for browser environments only.
*/
export declare function safelyRunOnBrowser<TReturn>(callback: BrowserCallback<TReturn>): TReturn | undefined;
export {};

View File

@@ -0,0 +1,11 @@
/**
* Safely runs code meant for browser environments only.
*/
export function safelyRunOnBrowser(callback) {
if (typeof window !== 'undefined') {
return callback({
window: window
});
}
return undefined;
}

View File

@@ -0,0 +1,4 @@
export declare const userAgents: {
segment: string;
version: string;
}[];

View File

@@ -0,0 +1,5 @@
import { version } from './version';
export var userAgents = [{
segment: 'autocomplete-core',
version: version
}];

View File

@@ -0,0 +1 @@
export declare const version = "1.9.3";

View File

@@ -0,0 +1 @@
export var version = '1.9.3';

View File

@@ -0,0 +1,8 @@
export declare const warnCache: {
current: {};
};
/**
* Logs a warning if the condition is not met.
* This is used to log issues in development environment only.
*/
export declare function warn(condition: boolean, message: string): void;

View File

@@ -0,0 +1,24 @@
export var warnCache = {
current: {}
};
/**
* Logs a warning if the condition is not met.
* This is used to log issues in development environment only.
*/
export function warn(condition, message) {
if (!(process.env.NODE_ENV !== 'production')) {
return;
}
if (condition) {
return;
}
var sanitizedMessage = message.trim();
var hasAlreadyPrinted = warnCache.current[sanitizedMessage];
if (!hasAlreadyPrinted) {
warnCache.current[sanitizedMessage] = true;
// eslint-disable-next-line no-console
console.warn("[Autocomplete] ".concat(sanitizedMessage));
}
}

37
node_modules/@algolia/autocomplete-shared/package.json generated vendored Normal file
View File

@@ -0,0 +1,37 @@
{
"name": "@algolia/autocomplete-shared",
"description": "Shared utils for Autocomplete packages.",
"version": "1.9.3",
"license": "MIT",
"homepage": "https://github.com/algolia/autocomplete",
"repository": "algolia/autocomplete",
"author": {
"name": "Algolia, Inc.",
"url": "https://www.algolia.com"
},
"source": "src/index.ts",
"types": "dist/esm/index.d.ts",
"module": "dist/esm/index.js",
"main": "dist/esm/index.js",
"sideEffects": false,
"files": [
"dist/"
],
"scripts": {
"build:clean": "rm -rf ./dist",
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm --ignore '**/*/__tests__/'",
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm",
"build": "yarn build:clean && yarn build:esm && yarn build:types",
"on:change": "concurrently \"yarn build:esm\" \"yarn build:types\"",
"prepare": "yarn build:esm && yarn build:types",
"watch": "watch \"yarn on:change\" --ignoreDirectoryPattern \"/dist/\""
},
"devDependencies": {
"@algolia/client-search": "4.16.0",
"algoliasearch": "4.16.0"
},
"peerDependencies": {
"@algolia/client-search": ">= 4.9.1 < 6",
"algoliasearch": ">= 4.9.1 < 6"
}
}