@samline/forms 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -7
  3. package/dist/browser/global.d.ts +10 -16
  4. package/dist/browser/global.global.js +319 -49
  5. package/dist/browser/global.global.js.map +1 -1
  6. package/dist/browser/index.cjs +1309 -0
  7. package/dist/browser/index.cjs.map +1 -0
  8. package/dist/browser/index.d.cts +14 -0
  9. package/dist/browser/index.d.ts +14 -0
  10. package/dist/browser/index.js +23 -0
  11. package/dist/browser/index.js.map +1 -0
  12. package/dist/chunk-L4GRKSQ5.js +1270 -0
  13. package/dist/chunk-L4GRKSQ5.js.map +1 -0
  14. package/dist/index.cjs +134 -23
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +4 -158
  17. package/dist/index.d.ts +4 -158
  18. package/dist/index.js +7 -1148
  19. package/dist/index.js.map +1 -1
  20. package/dist/registry-BpqJetAt.d.cts +148 -0
  21. package/dist/registry-BpqJetAt.d.ts +148 -0
  22. package/docs/api/append.md +96 -0
  23. package/docs/api/auto-submit.md +91 -0
  24. package/docs/api/clear-errors.md +69 -0
  25. package/docs/api/destroy.md +65 -0
  26. package/docs/api/disable-auto-submit.md +65 -0
  27. package/docs/api/element.md +78 -0
  28. package/docs/api/form.md +154 -0
  29. package/docs/api/format.md +270 -0
  30. package/docs/api/get-data.md +90 -0
  31. package/docs/api/get-field.md +87 -0
  32. package/docs/api/get-state.md +95 -0
  33. package/docs/api/get-value.md +114 -0
  34. package/docs/api/index.md +54 -0
  35. package/docs/api/observe.md +126 -0
  36. package/docs/api/on-submit.md +90 -0
  37. package/docs/api/parse-form-data.md +94 -0
  38. package/docs/api/prefill.md +89 -0
  39. package/docs/api/regex.md +155 -0
  40. package/docs/api/reset.md +60 -0
  41. package/docs/api/revalidate.md +50 -0
  42. package/docs/api/set-errors.md +97 -0
  43. package/docs/api/set-value.md +120 -0
  44. package/docs/api/subscribe.md +91 -0
  45. package/docs/api/unwatch.md +74 -0
  46. package/docs/api/validate-field-value.md +108 -0
  47. package/docs/api/validate-values.md +100 -0
  48. package/docs/api/validate.md +100 -0
  49. package/docs/api/watch.md +117 -0
  50. package/docs/browser.md +156 -0
  51. package/docs/css-styling.md +187 -0
  52. package/docs/getting-started.md +217 -0
  53. package/docs/options.md +259 -0
  54. package/docs/recipes.md +477 -0
  55. package/docs/typescript.md +576 -0
  56. package/docs/vanilla.md +12 -0
  57. package/package.json +58 -14
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Samuel Olvera (samline)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Forms
2
2
 
3
- > A small, framework-free form controller for vanilla JS and direct browser usage.
3
+ > A TypeScript-first, framework-free controller for native HTML forms.
4
4
 
5
- > It binds to an `HTMLFormElement`, keeps field state in sync with the DOM, runs validation, lets you react to changes via watchers or subscribers, and ships a serialized payload for `fetch` flows.
5
+ > Add validation, reactive field state, accessible error handling, serialization, auto-submit, and optional input formatting without adopting a UI framework.
6
6
 
7
7
  ---
8
8
 
@@ -42,10 +42,10 @@ Requires Node 20+ when bundling. Runtime target is ES2020.
42
42
  Use the browser build when you do not have a bundler and need to run the package directly in HTML, Shopify, WordPress, or any traditional template.
43
43
 
44
44
  ```html
45
- <script src="https://unpkg.com/@samline/forms@2.4.0/dist/browser/global.global.js"></script>
45
+ <script src="https://unpkg.com/@samline/forms@2.6.0/dist/browser/global.global.js"></script>
46
46
  ```
47
47
 
48
- > Pin the version in production. Replace `2.4.0` with the version you ship.
48
+ > Pin the version in production. Replace `2.6.0` with the version you ship.
49
49
 
50
50
  The browser bundle exposes a single global: `window.Forms`.
51
51
 
@@ -55,7 +55,7 @@ The browser bundle exposes a single global: `window.Forms`.
55
55
  <button type="submit">Send</button>
56
56
  </form>
57
57
 
58
- <script src="https://unpkg.com/@samline/forms@2.4.0/dist/browser/global.global.js"></script>
58
+ <script src="https://unpkg.com/@samline/forms@2.6.0/dist/browser/global.global.js"></script>
59
59
  <script>
60
60
  const contactForm = window.Forms.newForm({ id: 'contact-form' })
61
61
 
@@ -78,7 +78,8 @@ See [docs/browser.md](docs/browser.md) for the full browser surface.
78
78
  | Entrypoint | When to use |
79
79
  | --- | --- |
80
80
  | `@samline/forms` | Main vanilla API for bundlers, ESM, or CJS consumers. |
81
- | `@samline/forms/browser` | Pre-bundled IIFE that registers `window.Forms` for direct `<script>` usage. |
81
+ | `@samline/forms/browser` | ESM/CJS browser module with registry exports, bundled types, and `window.Forms` registration. |
82
+ | `@samline/forms/browser/global` | Pre-bundled IIFE for direct `<script>` usage; the CDN URL resolves to `dist/browser/global.global.js`. |
82
83
 
83
84
  The vanilla entrypoint also exports `browser`, the same `{ form, newForm, destroyForm, available }` surface as the IIFE but as a module-level singleton (no `globalThis` side-effect). Use it from a bundler when you want the registry helpers without the IIFE — see [docs/browser.md → Using the same shape from a bundler](docs/browser.md#using-the-same-shape-from-a-bundler).
84
85
 
@@ -177,4 +178,4 @@ Full API reference, guides, and examples are available at **[samline.github.io/f
177
178
 
178
179
  ## License
179
180
 
180
- MIT
181
+ MIT
@@ -2,23 +2,11 @@ type FormatType = 'general' | 'phone' | 'numeral' | 'date' | 'time' | 'creditCar
2
2
  interface FieldFormatConfig {
3
3
  /** One of the supported `@samline/formatter` `FormatType` values. */
4
4
  type: FormatType;
5
- /**
6
- * Canonical name of the formatted field. The value the backend
7
- * ultimately receives (the `raw` output of the formatter) is
8
- * exposed under this name; the formatter is responsible for
9
- * keeping it in sync with the visible input.
10
- */
5
+ /** Canonical field name or fields whose raw values are submitted. */
11
6
  field: string | string[];
12
7
  /**
13
- * Name of the visible input that shows the formatted value to
14
- * the user. Defaults to `${fieldName}_displayed`.
15
- *
16
- * The visible is **renamed** from `field` to `displayField` on
17
- * the first `format()` call (idempotent on re-binding). A hidden
18
- * `<input type="hidden" name="<field>">` is created next to it
19
- * to carry the raw value. Both names are first-class in the
20
- * controller's API (`getValue`, `getField`, `setValue`, `watch`,
21
- * `getData`) — see `docs/api/format.md` for the full contract.
8
+ * Name of the visible input for a single field. Array configurations
9
+ * must omit this option and derive one display name per field.
22
10
  */
23
11
  displayField?: string;
24
12
  /**
@@ -49,6 +37,8 @@ interface FieldValidationRules {
49
37
  minLength?: RuleConfig<number>;
50
38
  maxLength?: RuleConfig<number>;
51
39
  pattern?: RuleConfig<RegExp>;
40
+ /** Field name whose non-empty value must equal this field's value. */
41
+ sameAs?: RuleConfig<string>;
52
42
  validate?: FieldValidator | FieldValidator[];
53
43
  }
54
44
  type ValidationSchema = Record<string, FieldValidationRules>;
@@ -155,10 +145,14 @@ interface FormsApi {
155
145
  }
156
146
 
157
147
  declare const Forms: FormsApi;
148
+ declare const form: (target: FormTarget, options?: FormControllerOptions) => FormController;
149
+ declare const newForm: (input: NewFormInput) => FormController | undefined;
150
+ declare const destroyForm: (id: string) => void;
151
+ declare const available: FormsAvailable;
158
152
  declare global {
159
153
  interface Window {
160
154
  Forms: FormsApi;
161
155
  }
162
156
  }
163
157
 
164
- export { Forms as default };
158
+ export { available, Forms as default, destroyForm, form, newForm };