import type { Extension } from '@codemirror/state'; import { EditorView } from '@codemirror/view'; import { type RefObject } from 'react'; import type { MessageTarget } from '../../forms/validation/message-routing.js'; import { type ValidationState, type ValidationTrigger } from '../../forms/validation/types.js'; import type { InlineDiagnostic } from '../code-editor/inline-diagnostic.js'; /** * Options for {@link useEditorValidation}. */ type UseEditorValidationOptions = { /** * Ref to the live `EditorView` instance. */ viewRef: RefObject; /** * Consumer-supplied diagnostics, used when they override the built-in linter. */ diagnosticsRef: RefObject; /** * Whether consumer diagnostics are in use, which makes validation synchronous. */ isDiagnosticsEnabledRef: RefObject; /** * The `id` prop forwarded from the host component, used for form association. */ id?: string; /** * The `name` attribute for form submission. */ name?: string; /** * Whether the field is required; triggers a `valueMissing` error when empty. */ required?: boolean; /** * Associates the control with a `
` by its id. */ form?: string; /** * Controls where Strato validation messages are routed. */ messageTarget?: MessageTarget | MessageTarget[]; /** * Callback fired when the editor's validation state changes. */ onValidityChange?: (state: ValidationState) => void; /** * Reveals an error immediately, bypassing the blur gate. */ markTouched?: () => void; /** * The current consumer-supplied `diagnostics` prop value; re-emits validation * when it changes (synchronous path only). */ diagnostics?: InlineDiagnostic[]; /** * The current editor `value` prop; re-emits validation when it changes * (synchronous path only). */ value?: string; }; /** * Result of {@link useEditorValidation}. */ type UseEditorValidationResult = { /** CodeMirror extension driving the validation state machine. */ validationListener: Extension; /** * Validates on demand, awaiting any outstanding lint run first. `reveal` * surfaces a resulting error even while focus is inside. */ validate: (trigger: ValidationTrigger, reveal?: boolean) => Promise; /** Reports a blur that CodeMirror's own focus tracking did not observe. */ notifyBlur: () => void; }; /** * Drives the editor's validation lifecycle: tracks async lint runs, emits * `ValidationState` transitions, and registers the editor with an enclosing * `Form` so it participates in submission and message routing. * * @internal */ export declare function useEditorValidation({ viewRef, diagnosticsRef, isDiagnosticsEnabledRef, id, name, required, form, messageTarget, onValidityChange, markTouched, diagnostics, value, }: UseEditorValidationOptions): UseEditorValidationResult; export {}; //# sourceMappingURL=useEditorValidation.d.ts.map