@dynamicforms/vue-forms 0.17.0 → 0.18.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,13 +1,16 @@
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
9
11
  * `null`, so a caller can tell a run a handler ended from one that reached no handler at all - and the setters
10
- * that ask a `*Changing*` handler read it as a refusal and write nothing.
12
+ * that ask a `*Changing*` handler read it as a refusal and write nothing. The answer carries it directly where the
13
+ * chain ran synchronously, and as what the answered promise resolves to where a handler in it was asynchronous.
11
14
  */
12
15
  export declare class AbortEventHandlingException extends Error {
13
16
  }
@@ -45,7 +48,8 @@ export declare class Action<T extends ActionValue = ActionValue, X extends objec
45
48
  *
46
49
  * The answer is a promise whatever the handler returns, so a handler that throws rejects it rather than throwing
47
50
  * out of this call: a caller that does not await the answer and does not attach a catch handler leaves that
48
- * rejection unhandled.
51
+ * rejection unhandled. An `AbortEventHandlingException` is the one exception that does not reject: the answer
52
+ * resolves with it, in a synchronous chain as in an asynchronous one.
49
53
  */
50
54
  execute(params?: any): Promise<any>;
51
55
  }
@@ -103,10 +107,24 @@ export declare class ActionsMap {
103
107
  bindTo(owner: FieldBase): void;
104
108
  /** True where no eager action of `identifier` stands after `index`, which makes `index` the group's entry. */
105
109
  private static outermostEager;
110
+ /**
111
+ * True where `value` is a promise, which is what a walk through an asynchronous handler answers with. The test is
112
+ * the type rather than a `then` member: a handler may answer with a value object that carries one, and calling
113
+ * `then` on such an object replaces the answer with whatever that call returns.
114
+ */
115
+ private static isPromise;
116
+ /**
117
+ * Answers an abort with itself on the asynchronous path as well. Where a handler in the chain is asynchronous, the
118
+ * walk answers with a promise and the abort raised under it arrives as that promise's rejection; this turns it back
119
+ * into the value the caller receives, so a promise the trigger answers with resolves to the exception instead of
120
+ * rejecting with it. Anything else keeps rejecting.
121
+ */
122
+ private static answerAbort;
106
123
  /**
107
124
  * Enters a group at its outermost action. An abort ends the run and is answered with rather than raised: the
108
- * exception is what the caller receives, so a run a handler ended is told apart from one that reached no handler
109
- * and from one whose handler answered null.
125
+ * exception is what the caller receives - directly where the chain ran synchronously, as what the answered promise
126
+ * resolves to where it did not - so a run a handler ended is told apart from one that reached no handler and from
127
+ * one whose handler answered null.
110
128
  */
111
129
  private run;
112
130
  /**
@@ -139,11 +157,13 @@ export declare interface ActionValue {
139
157
  declare type AllowedValues<T> = T[] | Ref<T[]> | (() => T[]);
140
158
 
141
159
  /**
142
- * 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.
143
163
  * @param mdErrorString markdown source to optionally be stripped
144
- * @return MdString or string
164
+ * @return MdString or string, or a ComputedRef of either where `mdErrorString` is itself a Ref
145
165
  */
146
- 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;
147
167
 
148
168
  export declare type ClassType = string | string[] | Record<string, boolean>;
149
169
 
@@ -984,6 +1004,9 @@ declare namespace Form {
984
1004
  NullableList,
985
1005
  Validators,
986
1006
  buildErrorMessage,
1007
+ translatedMessage,
1008
+ strings,
1009
+ translateStrings,
987
1010
  isSimpleComponentDef,
988
1011
  isCallableFunction,
989
1012
  MdString,
@@ -1483,6 +1506,19 @@ export declare class Statement {
1483
1506
  collectFields(): Set<FieldBase>;
1484
1507
  }
1485
1508
 
1509
+ export declare const strings: {
1510
+ Required: string;
1511
+ MinValue: string;
1512
+ MaxValue: string;
1513
+ ValueInRange: string;
1514
+ MinLength: string;
1515
+ MaxLength: string;
1516
+ LengthInRange: string;
1517
+ Pattern: string;
1518
+ InAllowedValues: string;
1519
+ ValidationFailed: string;
1520
+ };
1521
+
1486
1522
  declare class Transaction {
1487
1523
  private readonly participants;
1488
1524
  /** what a rollback has to put back beyond the state slots, newest last */
@@ -1593,6 +1629,22 @@ export declare interface TransactionControl {
1593
1629
  rollback(): never;
1594
1630
  }
1595
1631
 
1632
+ /** A built-in validator's default message, translated and reactive to a later `translateStrings` call. */
1633
+ export declare function translatedMessage(key: keyof typeof strings): ComputedRef<string | MdString>;
1634
+
1635
+ export declare const translateStrings: (cb: TranslateStringsCallback< {
1636
+ Required: string;
1637
+ MinValue: string;
1638
+ MaxValue: string;
1639
+ ValueInRange: string;
1640
+ MinLength: string;
1641
+ MaxLength: string;
1642
+ LengthInRange: string;
1643
+ Pattern: string;
1644
+ InAllowedValues: string;
1645
+ ValidationFailed: string;
1646
+ }>) => void;
1647
+
1596
1648
  declare const TxAnnounceValue: unique symbol;
1597
1649
 
1598
1650
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dynamicforms/vue-forms",
3
3
  "private": false,
4
- "version": "0.17.0",
4
+ "version": "0.18.0",
5
5
  "type": "module",
6
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
7
  "author": "Jure Erzno\u017enik",
@@ -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,10 +86,9 @@
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"