import type { CoreEngine } from '../../../../app/engine.js'; import type { FacetValueState } from '../../../../features/facets/facet-api/value.js'; import type { FacetSortCriterion } from '../../../../features/facets/facet-set/interfaces/request.js'; import { type Controller } from '../../../controller/headless-controller.js'; import { type FacetOptions } from './headless-core-facet-options.js'; export type { FacetOptions, FacetValueState }; interface CoreFacetProps { /** * The options for the core `Facet` controller. * */ options: FacetOptions; } /** * The `Facet` controller allows you to create a search interface component that the end user * can use to refine a query by selecting filters based on item metadata (that is, field values). * If you have enabled a [Dynamic Navigation Experience (DNE)](https://docs.coveo.com/en/m2na0333/) * model, the `Facet` controller automatically reorders facet values according to the user query. * * Examples: * - [facet.fn.tsx](https://github.com/coveo/ui-kit/blob/main/samples/headless/search-react/src/components/facet/facet.fn.tsx) * - [facet-search.tsx](https://github.com/coveo/ui-kit/blob/main/samples/headless/search-react/src/components/facet/facet-search.tsx) * - [facet.class.tsx](https://github.com/coveo/ui-kit/blob/main/samples/headless/search-react/src/components/facet/facet.class.tsx) * * @group Controllers * @category Facet */ export interface Facet extends CoreFacet { /** * Provides methods to search the facet's values. */ facetSearch: FacetSearch; /** * The state of the `Facet` controller. */ state: FacetState; } /** * The `Facet` headless controller offers a high-level interface for designing a common facet UI controller. * * @group Controllers * @category Facet */ export interface CoreFacet extends Controller { /** * Toggles the specified facet value. * * @param selection - The facet value to toggle. */ toggleSelect(selection: FacetValue): void; /** * Toggles exclusion of the specified facet value. * * @param selection - The facet value to toggle exclusion. */ toggleExclude(selection: FacetValue): void; /** * Toggles the specified facet value, deselecting others. * * @param selection - The facet value to toggle. */ toggleSingleSelect(selection: FacetValue): void; /** * Excludes the specified facet value, deselecting others. * * @param selection - The facet value to toggle exclusion. */ toggleSingleExclude(selection: FacetValue): void; /** * Checks whether the specified facet value is selected. * * @param value - The facet value to check. * @returns Whether the specified facet value is selected. */ isValueSelected(value: FacetValue): boolean; /** * Checks whether the specified facet value is excluded. * * @param value - The facet value to check. * @returns Whether the specified facet value is excluded. */ isValueExcluded(value: FacetValue): boolean; /** * Deselects all facet values. * */ deselectAll(): void; /** * Sorts the facet values according to the specified criterion. * * @param criterion - The criterion to use for sorting values. */ sortBy(criterion: FacetSortCriterion): void; /** * Checks whether the facet values are sorted according to the specified criterion. * * @param criterion - The criterion to compare. * @returns Whether the facet values are sorted according to the specified criterion. */ isSortedBy(criterion: FacetSortCriterion): boolean; /** * Increases the number of values displayed in the facet to the next multiple of the originally configured value. */ showMoreValues(): void; /** * Sets the number of values displayed in the facet to the originally configured value. * */ showLessValues(): void; /** * Enables the facet. I.e., undoes the effects of `disable`. */ enable(): void; /** * Disables the facet. I.e., prevents it from filtering results. */ disable(): void; /** * The state of the `Facet` controller. * */ state: CoreFacetState; } /** * A scoped and simplified part of the headless state that is relevant to the `Facet` controller. * * @group Controllers * @category Facet */ export interface FacetState extends CoreFacetState { /** The state of the facet's searchbox. */ facetSearch: FacetSearchState; } /** * A scoped and simplified part of the headless state that is relevant to the `Facet` controller. * * @group Controllers * @category Facet */ export interface CoreFacetState { /** The facet ID. */ facetId: string; /** The values of the facet. */ values: FacetValue[]; /** The active sortCriterion of the facet. */ sortCriterion: FacetSortCriterion; /** `true` if a search is in progress and `false` otherwise. */ isLoading: boolean; /** `true` if there is at least one non-idle value and `false` otherwise. */ hasActiveValues: boolean; /** `true` if there are more values to display and `false` otherwise. */ canShowMoreValues: boolean; /** `true` if fewer values can be displayed and `false` otherwise. */ canShowLessValues: boolean; /** Whether the facet is enabled and its values are used to filter search results. */ enabled: boolean; /** The tabs on which the facet should be enabled or disabled. */ tabs?: { included?: string[]; excluded?: string[]; }; /** * The name to display if this field is used by the Facet Generator in your interface. * See [Change Facet Generator options](https://docs.coveo.com/en/n9sd0159#change-facet-generator-options). */ label?: string; } export interface FacetSearch { /** * Updates the facet search query. * * @param text - The query to search. * */ updateText(text: string): void; /** * Shows more facet search results. * */ showMoreResults(): void; /** * Performs a facet search. * */ search(): void; /** * Selects a facet search result. * * @param value - The search result to select. * */ select(value: SpecificFacetSearchResult): void; /** * Excludes a facet search result. * * @param value - The search result to exclude. * */ exclude(value: SpecificFacetSearchResult): void; /** * Selects a search result while deselecting facet values. * * @param value - The search result to select. * */ singleSelect(value: SpecificFacetSearchResult): void; /** * Excludes a search result while including facet values. * * @param value - The search result to exclude. * */ singleExclude(value: SpecificFacetSearchResult): void; /** * Resets the query and empties the values. * */ clear(): void; /** * Updates the facet value captions. * @param captions - A dictionary that maps index field values to facet value display names. */ updateCaptions(captions: Record): void; } export interface FacetSearchState { /** * The facet search results. * */ values: SpecificFacetSearchResult[]; /** * `true` if the facet search is in progress and `false` otherwise. * */ isLoading: boolean; /** * Whether more values are available. * */ moreValuesAvailable: boolean; /** The current query in the facet search box. */ query: string; } export interface SpecificFacetSearchResult { /** * The custom facet value display name, as specified in the `captions` argument of the facet request. */ displayValue: string; /** * The original facet value, as retrieved from the field in the index. */ rawValue: string; /** * An estimate of the number of result items matching both the current query and * the filter expression that would get generated if the facet value were selected. */ count: number; } export interface FacetValue { /** * Whether a facet value is filtering results (`selected`) or not (`idle`). * */ state: FacetValueState; /** * The number of results that have the facet value. * */ numberOfResults: number; /** * The facet value. * */ value: string; } /** * Creates a `Facet` controller instance. * * @param engine - The headless engine. * @param props - The configurable `Facet` properties. * @param optionsSchema - The facet options schema to use when validating options upon facet initialization. * @returns A `Facet` controller instance. * * @group Controllers * @category Facet * */ export declare function buildCoreFacet(engine: CoreEngine, props: CoreFacetProps, optionsSchema?: import("@coveo/bueno").Schema>): CoreFacet;