SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Interface EditCommitApi<V>

    The edit/commit state machine shared by every value-controlled field — the part of a field that has nothing to do with what it edits: the two baselines, the dirty flag, the live vs commit channels, and the done-key policy.

    The rules it owns, once, for every field:

    • Two baselines. committedText is the last ACCEPTED value; baselineText is the text when the current session started. They differ because the live-change model applies every intermediate change — "the value before" can then only mean before-the-session, not before-the-last-change.
    • Escape is two-level. Session open + TOUCHED → cancel (revert to the baseline, onDone with reason: 'cancel'). Idle + dirty → a plain revert to the committed text, no commit channel. An UNTOUCHED session → the key is NOT captured, so a host dialog still closes on it. "Touched", not "changed": an edit that lands back on the starting text is still one to Escape out of.
    • Enter belongs to whoever owns the commit. changeOn: 'done' captures it (the field is the commit point); 'live' lets it bubble to the host's default button, finishing any open session first.
    • Tab commits then advances — un-captured, so the natural tab order still runs. Invalid text CANCELS instead of committing, so focus never advances carrying an error.
    • Invalid never commits on any accept path; blur commits only when dirty; and a done key plus the blur it causes are ONE gesture, delivered once (the one-shot guard).
    • The input owns its text keys. Delete / caret motion / the native chords are consumed (EditCommitApi.handleTextKeys) so they never reach the app's command dispatch.

    Hosts keep their own concerns — a formula field's reference bus and grammar, a plain field's validation — and wire them in through UseEditCommitOptions.parse and EditCommitSession.

    interface EditCommitApi<V> {
        baselineTextRef: RefObject<string>;
        committedTextRef: RefObject<string>;
        dirty: boolean;
        dirtyRef: RefObject<boolean>;
        error: string | null;
        errorRef: RefObject<string | null>;
        lastValidRef: RefObject<V | null>;
        text: string;
        textRef: RefObject<string>;
        touchedRef: RefObject<boolean>;
        beginSession(): void;
        cancel(): void;
        commit(): void;
        consumeBlurGuard(): boolean;
        handleDoneKeys(e: KeyboardEvent): boolean;
        handleTextKeys(e: KeyboardEvent): boolean;
        liveChange(next: string): void;
        notifyDone(args: EditDoneArgs): void;
        resetBlurGuard(): void;
        resetCommitted(next: string, value?: V | null): void;
        revertToBaseline(): void;
        revertToCommitted(): void;
        setError(next: string | null): void;
        setText(next: string): void;
    }

    Type Parameters

    • V
    Index
    baselineTextRef: RefObject<string>

    The text as of the current session's start — what a cancel reverts to.

    committedTextRef: RefObject<string>

    The last COMMITTED text — what an idle revert returns to.

    dirty: boolean

    true when the text differs from the committed value's text.

    dirtyRef: RefObject<boolean>

    dirty, synchronously.

    error: string | null

    Parse/validation error for the current text (a message key; null when valid).

    errorRef: RefObject<string | null>

    error, synchronously (the commit gate runs inside event handlers).

    lastValidRef: RefObject<V | null>

    The last successfully parsed value — what the commit channel delivers.

    text: string

    The live display text.

    textRef: RefObject<string>

    text readable synchronously (the handlers run outside render).

    touchedRef: RefObject<boolean>

    Whether the user has EDITED since the session started — what Escape claims the key on. Distinct from dirty (text ≠ committed) and from "text ≠ baseline": a round-trip back to the starting text leaves this true.

    • A session is starting: the CURRENT text becomes the cancel baseline.

      Returns void

    • Explicit cancel (a dialog's Cancel, the adornment ✗) — always fires the commit channel.

      Returns void

    • Explicit accept (a dialog's OK, the adornment ✓).

      Returns void

    • Read + clear the one-shot guard: true means a done key already delivered this gesture's commit and the blur that follows it must not deliver a second one.

      Returns boolean

    • The shared done-key policy — Escape / Enter / Tab, per changeOn (see the module doc). Returns true when the key was the field's to handle, so the host can stop there.

      Parameters

      • e: KeyboardEvent

      Returns boolean

    • The keys a focused input owns NATIVELY — consume them so the app's command dispatch never sees them. Returns true when the key was consumed; call AFTER handleDoneKeys.

      Parameters

      • e: KeyboardEvent

      Returns boolean

    • Parse next → error state + last valid value, emitting on the live channel per changeOn.

      Parameters

      • next: string

      Returns void

    • Deliver the COMMIT channel once for a finished edit. An accept while the text is INVALID is swallowed (the stale last-valid value must not escape; the error stays shown to fix or Escape); a cancel always fires. A delivered accept re-bases the committed text, so the field reads clean and a follow-up blur cannot re-deliver the same accept.

      Parameters

      Returns void

    • Any new key resets the one-shot blur guard — call at the TOP of the host's key handler.

      Returns void

    • Adopt next as the committed text (an outside value change): clean, unerrored, revert target.

      Parameters

      • next: string
      • Optionalvalue: V | null

      Returns void

    • Restore the session-start text (a cancel) and re-parse it.

      Returns void

    • Restore the committed text (the idle, field-level Escape) and re-parse it.

      Returns void

    • Set the error state directly (e.g. clearing it alongside a revert).

      Parameters

      • next: string | null

      Returns void

    • Set the display text (and re-derive dirty). Does NOT parse — pair with liveChange.

      Parameters

      • next: string

      Returns void