Skip to content

feat!: lifecycle events, revert, skipFilled, headless controller; remove autoInit - #3

Open
JDeffner wants to merge 2 commits into
mainfrom
core/events-controller
Open

JDeffner wants to merge 2 commits into
mainfrom
core/events-controller

Conversation

@JDeffner

@JDeffner JDeffner commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Adds the pieces a UI layer (element, React hook) needs on top of the fill flow.

Added

  • aff:start, aff:field-filled, aff:done, aff:error as bubbling CustomEvents on the form, with an HTMLElementEventMap augmentation so event.detail is typed (fillField dispatches on the field it wrote).
  • FillResult.filled[].previous and FillResult.missingRequired (required fields still empty, over all fields of the form).
  • revertFill(result, keys?) restores those values exactly, including empty strings, unchecked radio groups and multi-selects.
  • FillOptions.skipFilled drops non-empty fields from the prompt, the schema and the fill.
  • AIFormFill.applyExtraction(data, fields, opts?), the apply half of fillForm, for the review path.
  • createFormFill(options), a headless controller: fill, extract, applyExtracted, cancel, undo, subscribe, getSnapshot, destroy, over an idle/working/done/error snapshot compatible with useSyncExternalStore.
  • readFieldValue(element).

Breaking: autoInit/AutoInitOptions are removed; use createFormFill({ form, source, trigger }). README, CHANGELOG, docs/ARCHITECTURE.md and the Basic/Voice demos are updated.

Note for review: API Extractor drops declare global when it rolls declarations up, so pnpm build now appends the augmentation with scripts/append-event-types.js (vite.config.js was off limits).

pnpm lint, format:check, typecheck, test (164) and build pass; dist/ is rebuilt.

🤖 Generated with Claude Code

JDeffner and others added 2 commits September 4, 2026 23:37
Add the APIs a UI layer needs on top of the fill flow, and drop autoInit.

- lib/core/events.ts: aff:start, aff:field-filled, aff:done, aff:error as
  bubbling CustomEvents, plus an HTMLElementEventMap augmentation so
  event.detail is typed for consumers.
- FillResult: every filled entry carries `previous`, and the result carries
  `missingRequired` over all fields of the form.
- lib/form/revert.ts: revertFill(result, keys?) restores those values
  exactly, through the same native setters and input/change events.
- FillOptions.skipFilled excludes non-empty fields from the prompt, the
  schema and the fill.
- AIFormFill.applyExtraction(data, fields, opts?) is the apply half of
  fillForm, so a review step gets the same result and events.
- lib/core/controller.ts: createFormFill() resolves form, source and trigger
  from elements or selectors and exposes fill/extract/applyExtracted/cancel/
  undo/subscribe/getSnapshot/destroy over an idle-working-done-error state.
- readFieldValue(element) reads a field in the shape the library writes it.

BREAKING CHANGE: autoInit and AutoInitOptions are removed. Use
createFormFill({ form, source, trigger }), which takes elements or selectors
and has real teardown.

API Extractor drops `declare global` when it rolls declarations up, so
`pnpm build` appends the augmentation with scripts/append-event-types.js.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @JDeffner, your pull request is larger than the review limit of 150,000 diff characters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant