uicore-ts
Version:
UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha
110 lines (109 loc) • 5.08 kB
TypeScript
import { UIAutocompleteDropdownView } from "./UIAutocompleteDropdownView";
import { UIAutocompleteItem } from "./UIAutocompleteRowView";
import { UITextField } from "./UITextField";
import { UIViewAddControlEventTargetObject } from "./UIView";
export declare class UIAutocompleteTextField<T = string> extends UITextField {
_autocompleteItems: UIAutocompleteItem<T>[];
_selectedItem?: UIAutocompleteItem<T>;
_dropdownView: UIAutocompleteDropdownView<T>;
_isDropdownOpen: boolean;
_strictSelection: boolean;
_isValid: boolean;
_userHasNavigatedDropdown: boolean;
/**
* When YES, the filter text is split on whitespace and all words must appear
* in the item label (AND logic). When NO (default), the full filter string is
* matched as a single substring.
*/
usesMultiWordAndSearch: boolean;
static controlEvent: {
readonly PointerDown: "PointerDown";
readonly PointerMove: "PointerMove";
readonly PointerDrag: "PointerDrag";
readonly PointerLeave: "PointerLeave";
readonly PointerEnter: "PointerEnter";
readonly PointerUpInside: "PointerUpInside";
readonly PointerTap: "PointerTap";
readonly PointerUp: "PointerUp";
readonly MultipleTouches: "PointerZoom";
readonly PointerCancel: "PointerCancel";
readonly PointerHover: "PointerHover";
readonly EnterDown: "EnterDown";
readonly EnterUp: "EnterUp";
readonly SpaceDown: "SpaceDown";
readonly EscDown: "EscDown";
readonly TabDown: "TabDown";
readonly LeftArrowDown: "LeftArrowDown";
readonly RightArrowDown: "RightArrowDown";
readonly DownArrowDown: "DownArrowDown";
readonly UpArrowDown: "UpArrowDown";
readonly Focus: "Focus";
readonly Blur: "Blur";
} & {
TextChange: string;
ValidationChange: string;
} & {
SelectionDidChange: string;
};
get controlEventTargetAccumulator(): UIViewAddControlEventTargetObject<typeof UIAutocompleteTextField>;
constructor(elementID?: string);
/** Override in subclass to provide a custom dropdown view. */
newDropdownView(): UIAutocompleteDropdownView<T>;
get selectedItem(): T | undefined;
get strictSelection(): boolean;
set strictSelection(strict: boolean);
commitSelection(item: UIAutocompleteItem<T>): void;
/** Convenience: set string suggestions. Each string becomes { label: s, value: s }. */
set autocompleteStrings(strings: string[]);
get autocompleteStrings(): string[];
set autocompleteData(items: UIAutocompleteItem<T>[]);
get autocompleteData(): UIAutocompleteItem<T>[];
/**
* Splits the given lowercase-trimmed filter text into individual words when
* usesMultiWordAndSearch is YES, or returns it as a single-element array otherwise.
* Returns an empty array when the input is empty.
*/
_filterWordsFromText(filterText: string): string[];
/**
* Returns true when the given label (already lowercased) satisfies all filter
* words — i.e. every word appears somewhere in the label.
*/
_labelMatchesFilterWords(label: string, filterWords: string[]): boolean;
/**
* Returns true when the character immediately before `position` in `label`
* is a word separator (or the position is at the start of the string).
* Used to give a bonus to matches that start at a word boundary.
*/
_isWordBoundary(label: string, position: number): boolean;
/**
* Scores a label against the filter words. Lower score = better match.
*
* Scoring factors (in priority order):
* 1. Non-sequential penalty — words must appear in typed order to avoid
* a large penalty that pushes them below all sequential matches.
* 2. Per-word boundary score — for each filter word, a mid-word match
* scores worse than a word-boundary match. The sum across all words
* determines the boundary tier.
* 3. Position of the first matched word — within the same boundary tier,
* earlier appearances rank higher.
* 4. Total label length — shorter labels are more specific (tiebreaker).
*
* Example: query "põ pu"
* "Põhjavee puhastusvahendid" → "põ" at boundary(0), "pu" at boundary(9) → low boundary score
* "põrandapuhastusvahendid" → "põ" at boundary(0), "pu" mid-word(7) → higher boundary score
* → "Põhjavee puhastusvahendid" ranks first.
*/
_scoreLabel(label: string, filterWords: string[]): number;
updateFilteredItems(): void;
openDropdown(): void;
closeDropdown(): void;
/** Whether the current text is valid given the strictSelection setting. */
get isValid(): boolean;
/**
* Hook for subclasses to apply custom visual styling based on validation state.
* Called after dropdown closes and after selection changes.
*/
updateValidationVisuals(): void;
wasRemovedFromViewTree(): void;
layoutSubviews(): void;
}