Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/ember-form/.editorconfig
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
8 changes: 8 additions & 0 deletions packages/ember-form/.env.development
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
20 changes: 20 additions & 0 deletions packages/ember-form/.gitignore
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
28 changes: 28 additions & 0 deletions packages/ember-form/CONTRIBUTING.md
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/).
9 changes: 9 additions & 0 deletions packages/ember-form/LICENSE.md
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.
89 changes: 89 additions & 0 deletions packages/ember-form/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# @tanstack/ember-form

Powerful, type-safe forms for Ember, built on `@tanstack/form-core`.

## Compatibility

- Ember.js v6.0 or above (gjs/gts only)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this should really be ember-source 6.8+

ember.js isn't a package (that's relevant anyway)

- `@glimmer/component` v2
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

we don't need to specify this, because package manager peer errors will tell the user


## 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}}>
<Field
@form={{this.form}}
@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}}
</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>
}
```

### API

- `createForm(parent, options)` — Returns a `FormApi` extended with `useStore(selector?)`. `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.
- `<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).
4 changes: 4 additions & 0 deletions packages/ember-form/addon-main.cjs
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);
50 changes: 50 additions & 0 deletions packages/ember-form/babel.config.cjs
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,
},
};
36 changes: 36 additions & 0 deletions packages/ember-form/babel.publish.config.cjs
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,
},
};
20 changes: 20 additions & 0 deletions packages/ember-form/config/ember-cli-update.json
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

let's delete this and the config folder -- for this project, keeping up with the blueprint upstream doesn't matter

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"
]
}
]
}
]
}
38 changes: 38 additions & 0 deletions packages/ember-form/demo-app/app.gts
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 () {});
6 changes: 6 additions & 0 deletions packages/ember-form/demo-app/styles.css
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.
*/
Loading