-
-
Notifications
You must be signed in to change notification settings - Fork 631
feat(ember-form): add Ember adapter (@tanstack/ember-form) #2156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
NullVoxPopuli-ai-agent
wants to merge
8
commits into
TanStack:main
Choose a base branch
from
NullVoxPopuli-ai-agent:ember-form-adapter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
32c6566
feat(ember-form): add Ember adapter
NullVoxPopuli 2dbfabb
feat(ember-form): closure-bound this.form.Field
NullVoxPopuli 6c06223
feat(ember-form): address review — trackedObject, reactive args, docs
NullVoxPopuli 3887537
feat(ember-form): bump ember-source to 7.1.0-alpha.5, strip `on`/`fn`…
NullVoxPopuli 7335723
chore(ember-form): address review notes + self-cleanup pass
NullVoxPopuli 8f0a3e2
feat(ember-form)!: refactor createForm into a component factory
NullVoxPopuli f43d0b7
docs(ember-form): adopt tanstackForm / f block-param convention
NullVoxPopuli 0da50ff
chore(ember-form): align with NullVoxPopuli/ember-primitives conventions
NullVoxPopuli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # EditorConfig helps developers define and maintain consistent | ||
| # coding styles between different editors and IDEs | ||
| # editorconfig.org | ||
|
|
||
| root = true | ||
|
|
||
| [*] | ||
| end_of_line = lf | ||
| charset = utf-8 | ||
| trim_trailing_whitespace = true | ||
| insert_final_newline = true | ||
| indent_style = space | ||
| indent_size = 2 | ||
|
|
||
| [*.hbs] | ||
| insert_final_newline = false | ||
|
|
||
| [*.{diff,md}] | ||
| trim_trailing_whitespace = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # This file is committed to git and should not contain any secrets. | ||
| # | ||
| # Vite recommends using .env.local or .env.[mode].local if you need to manage secrets | ||
| # SEE: https://vite.dev/guide/env-and-mode.html#env-files for more information. | ||
|
|
||
|
|
||
| # Default NODE_ENV with vite build --mode=test is production | ||
| NODE_ENV=development |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # compiled output | ||
| dist/ | ||
| dist-tests/ | ||
| declarations/ | ||
|
|
||
| # from scenarios | ||
| tmp/ | ||
| config/optional-features.json | ||
| ember-cli-build.cjs | ||
|
|
||
| # npm/pnpm/yarn pack output | ||
| *.tgz | ||
|
|
||
| # deps & caches | ||
| node_modules/ | ||
| .eslintcache | ||
| .prettiercache | ||
|
|
||
| # potentially containing secrets | ||
| *.local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # How To Contribute | ||
|
|
||
| ## Installation | ||
|
|
||
| - `git clone <repository-url>` | ||
| - `cd ember-form` | ||
| - `pnpm install` | ||
|
|
||
| ## Linting | ||
|
|
||
| - `pnpm lint` | ||
| - `pnpm lint:fix` | ||
|
|
||
| ## Building the addon | ||
|
|
||
| - `pnpm build` | ||
|
|
||
| ## Running tests | ||
|
|
||
| - `pnpm test` – Runs the test suite on the current Ember version | ||
| - `pnpm test:watch` – Runs the test suite in "watch mode" | ||
|
|
||
| ## Running the test application | ||
|
|
||
| - `pnpm start` | ||
| - Visit the test application at [http://localhost:4200](http://localhost:4200). | ||
|
|
||
| For more information on using ember-cli, visit [https://cli.emberjs.com/release/](https://cli.emberjs.com/release/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright (c) 2026 | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| # @tanstack/ember-form | ||
|
|
||
| Powerful, type-safe forms for Ember, built on `@tanstack/form-core`. | ||
|
|
||
| ## Compatibility | ||
|
|
||
| - Ember.js v6.0 or above (gjs/gts only) | ||
| - `@glimmer/component` v2 | ||
|
NullVoxPopuli-ai-agent marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Installation | ||
|
|
||
| ```sh | ||
| pnpm add @tanstack/ember-form | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```gjs | ||
| import Component from '@glimmer/component'; | ||
| import { fn, hash } from '@ember/helper'; | ||
| import { on } from '@ember/modifier'; | ||
| import { createForm, Field, Subscribe } from '@tanstack/ember-form'; | ||
|
|
||
| const handleInput = (field, event) => { | ||
| field.handleChange(event.target.value); | ||
| }; | ||
|
|
||
| const tooShort = ({ value }) => (value.length < 3 ? 'Too short' : undefined); | ||
|
|
||
| export default class SignupForm extends Component { | ||
| form = createForm(this, { | ||
| defaultValues: { firstName: '', lastName: '' }, | ||
| onSubmit: async ({ value }) => { | ||
| console.log('submit', value); | ||
| }, | ||
| }); | ||
|
|
||
| submit = (event) => { | ||
| event.preventDefault(); | ||
| this.form.handleSubmit(); | ||
| }; | ||
|
|
||
| pickSubmit = (state) => ({ | ||
| cantSubmit: !state.canSubmit, | ||
| isSubmitting: state.isSubmitting, | ||
| }); | ||
|
|
||
| <template> | ||
| <form {{on "submit" this.submit}}> | ||
| <this.form.Field | ||
| @name="firstName" | ||
| @validators={{hash onChange=tooShort}} | ||
| as |field| | ||
| > | ||
| <label> | ||
| First name | ||
| <input | ||
| value={{field.state.value}} | ||
| {{on "input" (fn handleInput field)}} | ||
| /> | ||
| </label> | ||
| {{#each field.state.meta.errors as |error|}} | ||
| <em>{{error}}</em> | ||
| {{/each}} | ||
| </this.form.Field> | ||
|
|
||
| <Subscribe @form={{this.form}} @selector={{this.pickSubmit}} as |slice|> | ||
| <button type="submit" disabled={{slice.cantSubmit}}> | ||
| {{if slice.isSubmitting "Submitting…" "Submit"}} | ||
| </button> | ||
| </Subscribe> | ||
| </form> | ||
| </template> | ||
| } | ||
| ``` | ||
|
|
||
| `<this.form.Field>` is closure-bound shorthand for `<Field @form={{this.form}}>`. Use whichever is more convenient. | ||
|
|
||
| ### API | ||
|
|
||
| - `createForm(parent, options)` — Returns a `FormApi` extended with `useStore(selector?)` and a closure-bound `Field`. `parent` should be `this` from a `@glimmer/component` (or any destroyable owner). The form is mounted immediately and unmounted when `parent` is destroyed. | ||
| - `<Field @form @name [@validators] [@defaultValue] [@asyncDebounceMs] [@listeners] [@mode]>` — Yields a `FieldApi` whose `state` is autotracked. Reads of `field.state.*` in templates rerender on store changes. | ||
| - `<this.form.Field @name [...]>` — closure-bound variant of `<Field>` returned from `createForm`. Equivalent to passing `@form={{this.form}}` explicitly. | ||
| - `<Subscribe @form [@selector]>` — Yields the result of `selector(form.store.state)` (or the full state when omitted), reactive across changes. | ||
| - `form.useStore(selector?)` — Returns `{ current }` where `current` is autotracked. Useful outside of templates (e.g. in `@cached` getters). | ||
|
|
||
| Everything else is re-exported from `@tanstack/form-core` (validators, types, helpers). | ||
|
|
||
| ## License | ||
|
|
||
| This project is licensed under the [MIT License](LICENSE.md). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| 'use strict'; | ||
|
|
||
| const { addonV1Shim } = require('@embroider/addon-shim'); | ||
| module.exports = addonV1Shim(__dirname); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * This babel.config is not used for publishing. | ||
| * It's only for the local editing experience | ||
| * (and linting) | ||
| */ | ||
| const { buildMacros } = require('@embroider/macros/babel'); | ||
|
|
||
| const { | ||
| babelCompatSupport, | ||
| templateCompatSupport, | ||
| } = require('@embroider/compat/babel'); | ||
|
|
||
| const macros = buildMacros(); | ||
|
|
||
| // For scenario testing | ||
| const isCompat = Boolean(process.env.ENABLE_COMPAT_BUILD); | ||
|
|
||
| module.exports = { | ||
| plugins: [ | ||
| [ | ||
| '@babel/plugin-transform-typescript', | ||
| { | ||
| allExtensions: true, | ||
| onlyRemoveTypeImports: true, | ||
| allowDeclareFields: true, | ||
| }, | ||
| ], | ||
| [ | ||
| 'babel-plugin-ember-template-compilation', | ||
| { | ||
| transforms: [ | ||
| ...(isCompat ? templateCompatSupport() : macros.templateMacros), | ||
| ], | ||
| }, | ||
| ], | ||
| [ | ||
| 'module:decorator-transforms', | ||
| { | ||
| runtime: { | ||
| import: require.resolve('decorator-transforms/runtime-esm'), | ||
| }, | ||
| }, | ||
| ], | ||
| ...(isCompat ? babelCompatSupport() : macros.babelMacros), | ||
| ], | ||
|
|
||
| generatorOpts: { | ||
| compact: false, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * This babel.config is only used for publishing. | ||
| * | ||
| * For local dev experience, see the babel.config | ||
| */ | ||
| module.exports = { | ||
| plugins: [ | ||
| [ | ||
| '@babel/plugin-transform-typescript', | ||
| { | ||
| allExtensions: true, | ||
| onlyRemoveTypeImports: true, | ||
| allowDeclareFields: true, | ||
| }, | ||
| ], | ||
| [ | ||
| 'babel-plugin-ember-template-compilation', | ||
| { | ||
| targetFormat: 'hbs', | ||
| transforms: [], | ||
| }, | ||
| ], | ||
| [ | ||
| 'module:decorator-transforms', | ||
| { | ||
| runtime: { | ||
| import: 'decorator-transforms/runtime-esm', | ||
| }, | ||
| }, | ||
| ], | ||
| ], | ||
|
|
||
| generatorOpts: { | ||
| compact: false, | ||
| }, | ||
| }; |
|
NullVoxPopuli-ai-agent marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "schemaVersion": "1.0.0", | ||
| "projectName": "ember-form", | ||
| "packages": [ | ||
| { | ||
| "name": "@ember/addon-blueprint", | ||
| "version": "0.17.1", | ||
| "blueprints": [ | ||
| { | ||
| "name": "@ember/addon-blueprint", | ||
| "isBaseBlueprint": true, | ||
| "options": [ | ||
| "--ci-provider=github", | ||
| "--pnpm" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import EmberApp from 'ember-strict-application-resolver'; | ||
| import EmberRouter from '@ember/routing/router'; | ||
| import PageTitleService from 'ember-page-title/services/page-title'; | ||
|
|
||
| class Router extends EmberRouter { | ||
| location = 'history'; | ||
| rootURL = '/'; | ||
| } | ||
|
|
||
| export class App extends EmberApp { | ||
| /** | ||
| * Any services or anything from the addon that needs to be in the app-tree registry | ||
| * will need to be manually specified here. | ||
| * | ||
| * Techniques to avoid needing this: | ||
| * - private services | ||
| * - require the consuming app import and configure themselves | ||
| * (which is what we're emulating here) | ||
| */ | ||
| modules = { | ||
| './router': Router, | ||
| './services/page-title': PageTitleService, | ||
| /** | ||
| * NOTE: this glob will import everything matching the glob, | ||
| * and includes non-services in the services directory. | ||
| */ | ||
| ...import.meta.glob('./services/**/*', { eager: true }), | ||
| /** | ||
| * These imports are not magic, but we do require that all entries in the | ||
| * modules object match a ./[type]/[name] pattern. | ||
| * | ||
| * See: https://rfcs.emberjs.com/id/1132-default-strict-resolver | ||
| */ | ||
| ...import.meta.glob('./templates/**/*', { eager: true }), | ||
| }; | ||
| } | ||
|
|
||
| Router.map(function () {}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * See: https://vite.dev/guide/features.html#css | ||
| * for features beyond normal CSS that are available to you. | ||
| * | ||
| * This CSS is meant for the demo-app only, and will not be included in the published assets for this library. | ||
| */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.