@dynamicforms/vue-forms 3.0.0-alpha.2 → 3.0.0-alpha.4

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.
package/dist/index.d.ts CHANGED
@@ -551,6 +551,14 @@ export declare interface DevtoolsOptions {
551
551
  /** Which elements the devtools list: every root element except the hidden ones, or only the described ones. */
552
552
  export declare type DevtoolsRegistration = 'opt-out' | 'opt-in';
553
553
 
554
+ /**
555
+ * Returns the element at `path` below `root`, or `undefined` if the path does not exist. A string path is split on
556
+ * `.`; `''` and `[]` return `root`. A step below a `Group` is a member name, below a `List` a non-negative integer
557
+ * (a number, or digits without leading zeros). A path that continues below an element that is neither a `Group` nor
558
+ * a `List` does not exist.
559
+ */
560
+ export declare function elementAt(root: FieldBase, path: string | readonly (string | number)[]): FieldBase | undefined;
561
+
554
562
  /**
555
563
  * The mutable state of one element, held in a separate object, not in the element's own properties.
556
564
  *
@@ -655,15 +663,24 @@ export declare class EnabledChangingAction extends FieldActionBase {
655
663
  execute(field: FieldBase, supr: FieldActionExecute, newValue: boolean, oldValue: boolean): boolean;
656
664
  }
657
665
 
666
+ /**
667
+ * The namespace of the error codes this library declares. A code the library raises is `${ERROR_NAMESPACE}.<code>`,
668
+ * such as `vue-forms.required`.
669
+ */
670
+ export declare const ERROR_NAMESPACE = "vue-forms";
671
+
658
672
  /**
659
673
  * The content of an error: what failed, the values it failed with, an English sentence describing it, and its
660
674
  * origin. An error the application builds from a server's response has the same content, so a renderer converts
661
675
  * validator and server errors to text with one function.
662
676
  */
663
677
  export declare interface ErrorDescription {
664
- /** Machine-readable identifier of what failed, in snake_case. */
678
+ /**
679
+ * Machine-readable identifier of what failed: `<namespace>.<code>`, such as `vue-forms.min_value`. The namespace
680
+ * names the package that declared the code.
681
+ */
665
682
  readonly code: string;
666
- /** The values of the failure, such as `minValue` for `min_value`. */
683
+ /** The values of the failure, such as `minValue` for `vue-forms.min_value`. */
667
684
  readonly params: Readonly<Record<string, unknown>>;
668
685
  /** The failure in English, plain text, with `params` substituted. */
669
686
  readonly detail: string;
@@ -1473,6 +1490,7 @@ declare namespace Form {
1473
1490
  visibilityValues,
1474
1491
  defaultVisibility,
1475
1492
  isVisibility,
1493
+ elementAt,
1476
1494
  configureDevtools,
1477
1495
  describeState,
1478
1496
  DevtoolsOptions,
@@ -1543,6 +1561,7 @@ declare namespace Form {
1543
1561
  ListItemInput,
1544
1562
  List,
1545
1563
  NullableList,
1564
+ ERROR_NAMESPACE,
1546
1565
  ErrorPolicies,
1547
1566
  ErrorPolicy,
1548
1567
  ErrorPolicyRule,
@@ -2396,8 +2415,8 @@ export declare class ValidationError implements ErrorDescription {
2396
2415
  readonly detail: string;
2397
2416
  private readonly statedOrigin?;
2398
2417
  /**
2399
- * @param code Machine-readable identifier of what failed, in snake_case.
2400
- * @param params The values of the failure, such as `minValue` for `min_value`.
2418
+ * @param code Machine-readable identifier of what failed, `<namespace>.<code>`. Stored as given.
2419
+ * @param params The values of the failure, such as `minValue` for `vue-forms.min_value`.
2401
2420
  * @param detail The failure in English, plain text. Stored as given.
2402
2421
  * @param statedOrigin The origin of the error, if its author sets it; see `origin`.
2403
2422
  */
@@ -2421,11 +2440,14 @@ export declare class ValidationError implements ErrorDescription {
2421
2440
  * renderer has a text for that code.
2422
2441
  */
2423
2442
  declare type ValidationErrorOptions = {
2424
- /** The error's `code`. Defaults to the validator's own, such as `required`. */
2443
+ /**
2444
+ * The error's `code`, used as given. Defaults to the validator's own, such as `vue-forms.required`. The
2445
+ * application prefixes its own codes with a namespace of its own.
2446
+ */
2425
2447
  code?: string;
2426
2448
  detail?: never;
2427
2449
  } | {
2428
- /** The error's `code`. */
2450
+ /** The error's `code`, used as given. */
2429
2451
  code: string;
2430
2452
  /** The error's English `detail`, plain text. `{name}` placeholders are replaced with the error's `params`. */
2431
2453
  detail?: string;
@@ -2492,7 +2514,8 @@ declare class Validator<T = any> extends ValueChangedAction {
2492
2514
  protected newBindingState(): ValidatorBindingState;
2493
2515
  /**
2494
2516
  * Returns the error a built-in validator reports: `code` and `detail` from `options` if set, the validator's own
2495
- * otherwise, with `params` substituted into the detail.
2517
+ * otherwise, with `params` substituted into the detail. Both codes are used as given: a built-in validator passes
2518
+ * its own code as `vue-forms.<code>`, and a subclass of the application passes a code in a namespace of its own.
2496
2519
  */
2497
2520
  protected errorFor(options: ValidationErrorOptions | undefined, code: string, detail: string, params: Record<string, unknown>): ValidationError;
2498
2521
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dynamicforms/vue-forms",
3
3
  "private": false,
4
- "version": "3.0.0-alpha.2",
4
+ "version": "3.0.0-alpha.4",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "Reactive forms and application state for Vue.js: validation, rules between fields, transactions and lists. UI-agnostic and TypeScript-first.",
@@ -28,8 +28,7 @@
28
28
  "build": "vite build",
29
29
  "prepack": "npm run build",
30
30
  "test": "vitest run --coverage",
31
- "lint": "eslint src --fix && vue-tsc --noEmit",
32
- "lint:ci": "eslint src && vue-tsc --noEmit",
31
+ "lint": "node scripts/lint.mjs",
33
32
  "docs:dev": "npm run docs:dev -w docs",
34
33
  "docs:build": "npm run docs:build -w docs",
35
34
  "docs:preview": "npm run docs:preview -w docs"
@@ -87,6 +86,7 @@
87
86
  "eslint-plugin-unicorn": "^73.0.0",
88
87
  "eslint-plugin-vue": "^10.10.0",
89
88
  "jsdom": "^26.0.0",
89
+ "markdownlint-cli2": "^0.18.1",
90
90
  "prettier": "^3.9.6",
91
91
  "rollup-plugin-visualizer": "^5.14.0",
92
92
  "typescript": "^5",
package/readme.md CHANGED
@@ -60,7 +60,8 @@ npm install @dynamicforms/vue-forms
60
60
  ```
61
61
 
62
62
  The package is ESM-only and requires Node 22 or newer. A CommonJS consumer reaches it through `require()` of an ES
63
- module, which Node supports without a flag from 22.12; on 22.0–22.11 it needs `--experimental-require-module`. Type definitions ship with the build. The package ships no components and no styles.
63
+ module, which Node supports without a flag from 22.12; on 22.0–22.11 it needs `--experimental-require-module`. Type
64
+ definitions ship with the build. The package ships no components and no styles.
64
65
 
65
66
  ## Basic Usage Example
66
67
 
@@ -185,7 +186,7 @@ import { Field, Group, Validators } from '@dynamicforms/vue-forms';
185
186
  const validatedForm = new Group({
186
187
  // Required field
187
188
  username: new Field({
188
- validators: [new Validators.Required({ code: 'username_required', detail: 'Username is required' })]
189
+ validators: [new Validators.Required({ code: 'app.username_required', detail: 'Username is required' })]
189
190
  }),
190
191
 
191
192
  // Email validation with pattern
@@ -193,7 +194,7 @@ const validatedForm = new Group({
193
194
  validators: [
194
195
  new Validators.Pattern(
195
196
  /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
196
- { code: 'invalid_email', detail: 'Please enter a valid email address' }
197
+ { code: 'app.invalid_email', detail: 'Please enter a valid email address' }
197
198
  )
198
199
  ]
199
200
  }),
@@ -202,7 +203,7 @@ const validatedForm = new Group({
202
203
  age: new Field({
203
204
  value: 25,
204
205
  validators: [
205
- new Validators.ValueInRange(18, 100, { code: 'age_range', detail: 'Age must be between {minValue} and {maxValue}' })
206
+ new Validators.ValueInRange(18, 100, { code: 'app.age_range', detail: 'Age must be between {minValue} and {maxValue}' })
206
207
  ]
207
208
  }),
208
209
 
@@ -216,7 +217,7 @@ const validatedForm = new Group({
216
217
  // Text length validation
217
218
  bio: new Field({
218
219
  validators: [
219
- new Validators.LengthInRange(10, 200, { code: 'bio_length', detail: 'Bio must be between 10 and 200 characters' })
220
+ new Validators.LengthInRange(10, 200, { code: 'app.bio_length', detail: 'Bio must be between 10 and 200 characters' })
220
221
  ]
221
222
  })
222
223
  });
@@ -227,10 +228,12 @@ invalid immediately. `field.touched` determines when the UI shows the errors. `R
227
228
  measuring it, so a value of only spaces counts as empty; `new Validators.Required({ trim: false })` keeps spaces as
228
229
  part of the value.
229
230
 
230
- An error is data: a `code` (`required`, `pattern`, `min_length`, …), the `params` it failed with, and an English
231
- `detail`. The library does not render it. The application, or a UI library such as `@dynamicforms/vuetify-inputs`,
232
- converts it into text, translated by its code. A validator's last argument, `{ code, detail }`, replaces the
233
- validator's default code and English detail.
231
+ An error is data: a `code` (`vue-forms.required`, `vue-forms.pattern`, `vue-forms.min_length`, …), the `params` it
232
+ failed with, and an English `detail`. A code is `<namespace>.<code>`; the library's namespace is `vue-forms`,
233
+ exported as `ERROR_NAMESPACE`. The library does not render an error. The application, or a UI library such as
234
+ `@dynamicforms/vuetify-inputs`, converts it into text, translated by its code. A validator's last argument,
235
+ `{ code, detail }`, replaces the validator's default code and English detail; the library uses that code as given,
236
+ and the application prefixes its own codes with a namespace of its own.
234
237
 
235
238
  A validation function may return a `Promise`; `field.validating` is `true` while it runs, and only the newest run
236
239
  determines the result. [Asynchronous validation](https://docs.velis.si/dynamicforms/vue-forms/api/validators#asynchronous-validation)