@dynamicforms/vue-forms 0.17.1 → 1.0.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.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { ComponentOptionsMixin } from 'vue';
2
2
  import { ComponentProvideOptions } from 'vue';
3
+ import { ComputedRef } from 'vue';
3
4
  import { DefineComponent } from 'vue';
4
5
  import { PublicProps } from 'vue';
5
6
  import { Ref } from 'vue';
7
+ import { TranslateStringsCallback } from '@dynamicforms/translatable';
6
8
 
7
9
  /**
8
10
  * Thrown from a handler to end the run it is in. What the trigger answers with is the exception itself rather than
@@ -155,11 +157,13 @@ export declare interface ActionValue {
155
157
  declare type AllowedValues<T> = T[] | Ref<T[]> | (() => T[]);
156
158
 
157
159
  /**
158
- * Depending on the useMarkdownInValidators setting, return either markdown or a plain string error message
160
+ * Depending on the useMarkdownInValidators setting, return either markdown or a plain string error message. A
161
+ * Ref is stripped/wrapped on read rather than once here, so a translated template re-applies the same choice
162
+ * as its text changes.
159
163
  * @param mdErrorString markdown source to optionally be stripped
160
- * @return MdString or string
164
+ * @return MdString or string, or a ComputedRef of either where `mdErrorString` is itself a Ref
161
165
  */
162
- export declare function buildErrorMessage(mdErrorString: string): string | MdString;
166
+ export declare function buildErrorMessage<T extends string | Ref<string>>(mdErrorString: T): T extends Ref<string> ? ComputedRef<string | MdString> : string | MdString;
163
167
 
164
168
  export declare type ClassType = string | string[] | Record<string, boolean>;
165
169
 
@@ -658,6 +662,10 @@ export declare abstract class FieldBase<T = any, X extends object = Extras> {
658
662
  * List of errors. The array handed out is the one the element holds, and a validator writes into it in place,
659
663
  * so a transaction that is open takes the element into its record here: a rollback that put back everything
660
664
  * except the errors would leave a state the form never held.
665
+ *
666
+ * The array and its members are Vue proxies, not the raw instances a validator returned - `field.errors[0] ===
667
+ * myError` is `false` for the very error that produced it. Unwrapping here would lose the tracked read a
668
+ * template needs to re-render when a message behind a `Ref` changes; `toRaw()` compares identity instead.
661
669
  */
662
670
  get errors(): ValidationError[];
663
671
  set errors(newValue: ValidationError[]);
@@ -821,6 +829,8 @@ export declare abstract class FieldBase<T = any, X extends object = Extras> {
821
829
  /**
822
830
  * Records a child's new verdict in this element's tally. The child reports it as it settles, and the commit
823
831
  * settles the deepest element first, so the tally a container reads when its own turn comes is finished.
832
+ * The delta is applied here rather than recomputed by walking the members at commit, which would cost
833
+ * `O(members)` per container and turn a list fill back into the quadratic walk this tally exists to avoid.
824
834
  */
825
835
  protected childValidityChanged(nowValid: boolean): void;
826
836
  /**
@@ -1000,6 +1010,9 @@ declare namespace Form {
1000
1010
  NullableList,
1001
1011
  Validators,
1002
1012
  buildErrorMessage,
1013
+ translatedMessage,
1014
+ strings,
1015
+ translateStrings,
1003
1016
  isSimpleComponentDef,
1004
1017
  isCallableFunction,
1005
1018
  MdString,
@@ -1499,6 +1512,19 @@ export declare class Statement {
1499
1512
  collectFields(): Set<FieldBase>;
1500
1513
  }
1501
1514
 
1515
+ export declare const strings: {
1516
+ Required: string;
1517
+ MinValue: string;
1518
+ MaxValue: string;
1519
+ ValueInRange: string;
1520
+ MinLength: string;
1521
+ MaxLength: string;
1522
+ LengthInRange: string;
1523
+ Pattern: string;
1524
+ InAllowedValues: string;
1525
+ ValidationFailed: string;
1526
+ };
1527
+
1502
1528
  declare class Transaction {
1503
1529
  private readonly participants;
1504
1530
  /** what a rollback has to put back beyond the state slots, newest last */
@@ -1609,6 +1635,22 @@ export declare interface TransactionControl {
1609
1635
  rollback(): never;
1610
1636
  }
1611
1637
 
1638
+ /** A built-in validator's default message, translated and reactive to a later `translateStrings` call. */
1639
+ export declare function translatedMessage(key: keyof typeof strings): ComputedRef<string | MdString>;
1640
+
1641
+ export declare const translateStrings: (cb: TranslateStringsCallback< {
1642
+ Required: string;
1643
+ MinValue: string;
1644
+ MaxValue: string;
1645
+ ValueInRange: string;
1646
+ MinLength: string;
1647
+ MaxLength: string;
1648
+ LengthInRange: string;
1649
+ Pattern: string;
1650
+ InAllowedValues: string;
1651
+ ValidationFailed: string;
1652
+ }>) => void;
1653
+
1612
1654
  declare const TxAnnounceValue: unique symbol;
1613
1655
 
1614
1656
  /**
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@dynamicforms/vue-forms",
3
3
  "private": false,
4
- "version": "0.17.1",
4
+ "version": "1.0.0",
5
5
  "type": "module",
6
- "description": "A lightweight Vue.js library for form state management with built-in validation, conditional logic, nested structures, and a rich event system. UI-agnostic and TypeScript-first.",
7
- "author": "Jure Erzno\u017enik",
6
+ "description": "A Vue.js library for form state management with built-in validation, conditional logic, nested structures, and a rich event system. UI-agnostic and TypeScript-first.",
7
+ "author": "Jure Erznožnik",
8
8
  "files": [
9
9
  "dist/*"
10
10
  ],
@@ -55,6 +55,7 @@
55
55
  "node": ">=22"
56
56
  },
57
57
  "dependencies": {
58
+ "@dynamicforms/translatable": "^0.1.0",
58
59
  "lodash-es": "^4.17.21"
59
60
  },
60
61
  "peerDependencies": {
@@ -68,7 +69,7 @@
68
69
  "@typescript-eslint/eslint-plugin": "^8.67.0",
69
70
  "@typescript-eslint/parser": "^8.67.0",
70
71
  "@vitejs/plugin-vue": "^6",
71
- "@vitest/coverage-v8": "^3",
72
+ "@vitest/coverage-v8": "^4",
72
73
  "@vue/test-utils": "^2.2.4",
73
74
  "@vue/tsconfig": "^0.7.0",
74
75
  "baseline-browser-mapping": "^2.8.31",
@@ -85,12 +86,15 @@
85
86
  "prettier": "^3.9.6",
86
87
  "rollup-plugin-visualizer": "^5.14.0",
87
88
  "typescript": "^5",
88
- "vite": "^7",
89
+ "vite": "^8",
89
90
  "vite-plugin-dts": "^4",
90
- "vite-plugin-eslint": "^1.8.1",
91
- "vitest": "^3",
91
+ "vitest": "^4",
92
92
  "vue-eslint-parser": "^10.4.1",
93
93
  "vue-markdown-render": "^2.3.0",
94
94
  "vue-tsc": "^2"
95
+ },
96
+ "allowScripts": {
97
+ "@parcel/watcher@2.5.6": true,
98
+ "unrs-resolver@1.12.2": true
95
99
  }
96
100
  }
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @dynamicforms/vue-forms
2
2
 
3
- A lightweight, reactive data entry forms library for Vue.js that handles form state management without dictating your
3
+ A reactive data entry forms library for Vue.js that handles form state management without dictating your
4
4
  UI components.
5
5
 
6
6
  ## Introduction
@@ -18,7 +18,6 @@ mechanism applies at every level of a nested form.
18
18
  - **Fields that react to each other**: Conditional visibility, enablement and values are declared as statements over other fields, and an action pipeline lets a handler intercept, transform or abort an event.
19
19
  - **Reactive & Type-Safe**: Every member of a field, group or list is a tracked read, and a group's value type is inferred from the fields it holds, nested structures included.
20
20
  - **Structural serialization**: A group's value is the shape of its fields, and `Group.createFromFormData()` turns a plain object back into a form.
21
- - **Lightweight**: `vue` (^3.5.2) is the only peer dependency and `lodash-es` the only runtime one.
22
21
 
23
22
  ## Features
24
23
 
@@ -42,7 +41,6 @@ mechanism applies at every level of a nested form.
42
41
  as a second type argument, checked by the compiler and read through `extra`
43
42
  - **Display modes**: control field visibility with different display modes (Full, Hidden, Invisible, Suppress)
44
43
  - **TypeScript support**: full type definitions, and a group's value type inferred from the fields it holds
45
- - **Lightweight**: `vue` (^3.5.2) is the only peer dependency and `lodash-es` the only runtime one
46
44
 
47
45
  ## Installation
48
46