/** A caret position (`start === end`) or a directed/undirected selection range. */
export interface TextFieldSelection {
start: number;
end: number;
}
/** The mutable buffer exposed inside an {@link WebTextFieldState.edit} block. */
export interface TextFieldEditBuffer {
text: string;
selection: TextFieldSelection;
}
/** A listener notified after every committed mutation. */
export type TextFieldStateListener = () => void;
/**
* Observable, transactional text-field state container.
*
* Mirrors Compose `TextFieldState`: the only way to mutate text + selection
* together is the atomic {@link edit} transaction, so a single notification is
* dispatched per logical change (text and caret never observed mid-update).
*/
export declare class WebTextFieldState {
private _text;
private _selection;
private readonly _listeners;
constructor(initialText?: string, initialSelection?: TextFieldSelection);
/** Current text value. */
get text(): string;
/** Current selection/caret, always clamped to `[0, text.length]`. */
get selection(): TextFieldSelection;
/**
* Stable identity snapshot for `useSyncExternalStore`. Returns the raw text;
* because edits are transactional, text identity changes iff a commit
* happened, which is the correct "did the store change" signal for the value.
*/
getSnapshot(): string;
/**
* Move the caret / set the selection without changing text. Out-of-range
* indices are clamped. Notifies subscribers only when the range changes.
*/
setSelection(start: number, end?: number): void;
/**
* Replace the whole text value, re-clamping the existing selection against
* the new length. Prefer {@link edit} when you also need to move the caret.
*/
setText(text: string): void;
/**
* Atomic transaction over text + selection. The block receives a mutable
* buffer initialised from the current state; mutations are validated and
* committed together, dispatching a single notification. If the block throws,
* nothing is committed (the state is left untouched).
*
* @example
* state.edit((buffer) => {
* buffer.text = buffer.text.toUpperCase();
* buffer.selection = { start: buffer.text.length, end: buffer.text.length };
* });
*/
edit(block: (buffer: TextFieldEditBuffer) => void): void;
/**
* Convenience editor: replace the current selection (or insert at the caret)
* with `replacement`, then place the caret right after the inserted text.
*/
replaceSelection(replacement: string): void;
/**
* Subscribe to commits. Returns an unsubscribe function. Shaped for direct
* use as the first argument of `useSyncExternalStore`.
*/
subscribe(listener: TextFieldStateListener): () => void;
private notify;
}
/**
* Hook recreating Compose's `rememberTextFieldState()`.
*
* The {@link WebTextFieldState} instance is created exactly once (lazy
* `useState` initialiser) and stays stable across re-renders. The component
* re-renders only when the committed text changes, via `useSyncExternalStore` —
* chosen over a manual `useEffect` + `forceUpdate` because it is the React 19
* tearing-safe primitive: it reads the snapshot synchronously during render
* (so concurrent renders never observe a stale value) and avoids the
* double-render that a "subscribe in effect then setState" approach incurs on
* mount. The `getServerSnapshot` argument makes it SSR/hydration-safe.
*
* Because selection lives on the same instance, callers that need caret-driven
* re-renders can subscribe to it themselves; the default snapshot intentionally
* tracks text only, so moving the caret does not re-render the whole subtree.
*
* @param initialValue Initial text; caret is placed at the end of it.
* @returns The stable, observable state container.
*/
export declare function useTextFieldState(initialValue?: string): WebTextFieldState;
/**
* A structural view of a focusable text-entry element exposing the standard
* selection API. Both a raw ``/`