@dynamicforms/vue-forms 0.6.0 → 0.11.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.cts CHANGED
@@ -7,13 +7,41 @@ import { Ref } from 'vue';
7
7
  export declare class AbortEventHandlingException extends Error {
8
8
  }
9
9
 
10
- export declare class Action<T extends ActionValue = ActionValue> extends Field<T> {
11
- protected init(params?: Partial<IFieldConstructorParams<T>>): void;
10
+ export declare class Action<T extends ActionValue = ActionValue, X extends object = {}> extends Field<T, X> {
11
+ protected init(params?: IFieldParams<T, X>): void;
12
+ /**
13
+ * A copy of the value this action holds, carrying one member rewritten. A member handed undefined is dropped
14
+ * from the copy rather than written into it: an own key holding undefined is invisible to a reader and to
15
+ * JSON, but lodash isEqual compares own-key sets, so writing one would leave the action permanently changed
16
+ * against a baseline that never carried the key.
17
+ */
18
+ private valueWith;
12
19
  get icon(): string | undefined;
13
20
  set icon(newValue: string | undefined);
14
21
  get label(): string | undefined;
22
+ /**
23
+ * The two setters hand the value setter a new object rather than writing into the one the action holds, so each
24
+ * is an ordinary value change: the handlers fire, isChanged answers over it, and a disabled action refuses it.
25
+ * The new object is built only for a member that differs from the one held - the value setter compares by
26
+ * identity and every copy is a new object, so without the comparison here a write of the value already held
27
+ * would announce a change and invalidate the value cache of every container above.
28
+ */
15
29
  set label(newValue: string | undefined);
16
- execute(params: any): void;
30
+ /** the counter behind `busy`, allocated for this action the first time it is asked for */
31
+ private get busyRuns();
32
+ /** true from the moment execute() is called until the handler it ran has settled, however it settles */
33
+ get busy(): boolean;
34
+ /**
35
+ * Runs the ExecuteAction chain registered on this action and answers what the chain returned. `busy` stands for
36
+ * the length of the run: the chain is entered synchronously, and the flag is cleared once the value it produced
37
+ * has settled - a handler that returns a promise holds it for as long as that promise takes, and one that
38
+ * rejects clears it as it rejects.
39
+ *
40
+ * The answer is a promise whatever the handler returns, so a handler that throws rejects it rather than throwing
41
+ * out of this call: a caller that does not await the answer and does not attach a catch handler leaves that
42
+ * rejection unhandled.
43
+ */
44
+ execute(params?: any): Promise<any>;
17
45
  }
18
46
 
19
47
  declare type ActionExecutor = (field: FieldBase, supr: FieldActionExecute, ...params: any[]) => any;
@@ -22,11 +50,37 @@ export declare class ActionsMap extends Map<symbol, FieldActionExecute> {
22
50
  private readonly eagerActions;
23
51
  private readonly registeredActions;
24
52
  register(action: FieldActionBase): void;
53
+ /**
54
+ * True when triggering this action would run something: a handler registered under the identifier, or - on the
55
+ * value change identifier, which trigger() answers with an eager pass as well - any eager action at all. A
56
+ * caller that has to build the parameters before it can trigger asks this first and skips building them when
57
+ * there is nothing to receive them.
58
+ */
59
+ willTrigger(identifier: symbol): boolean;
25
60
  trigger<T extends FieldActionBase>(ActionClass: (abstract new (...args: any[]) => T) & {
26
61
  classIdentifier: symbol;
27
62
  }, field: FieldBase, ...params: any[]): any;
63
+ /**
64
+ * Runs the chain registered under one identifier and nothing else. A caller that has already run the eager
65
+ * pass - a transaction runs it at the write, so that the validators have decided before it commits - reaches
66
+ * the handlers through here, so the eager actions are not run a second time at the announcement.
67
+ */
68
+ triggerChain(identifier: symbol, field: FieldBase, ...params: any[]): any;
28
69
  triggerEager(field: FieldBase, ...params: any[]): any;
70
+ /** the validators registered in this map, in registration order */
71
+ get validators(): Validator[];
29
72
  clone(): ActionsMap;
73
+ /**
74
+ * Tells every action in this map that it serves `owner`. A copied map holds the instances the original holds, so
75
+ * the element that took the copy on is announced to them here, the way registering an action announces the
76
+ * element it was registered on.
77
+ */
78
+ bindTo(owner: FieldBase): void;
79
+ /**
80
+ * A copy of this map carrying everything but the validators. It only leaves them out: releasing what a
81
+ * validator installed elsewhere is the caller's to do, and only once the transaction that dropped them has
82
+ * committed, because a rollback puts this map back with its validators in it.
83
+ */
30
84
  cloneWithoutValidators(): ActionsMap;
31
85
  }
32
86
 
@@ -47,13 +101,55 @@ export declare type ClassType = string | string[] | Record<string, boolean>;
47
101
  export declare type ClassTypes = ClassType | ClassType[];
48
102
 
49
103
  declare class CompareTo<T = any> extends Validator {
50
- private otherField;
51
104
  private isValidComparison;
52
- private unregistered;
53
- constructor(otherField: FieldBase, isValidComparison: (myValue: T, otherValue: T) => boolean, message: RenderContentRef);
54
- unregister(): void;
105
+ private readonly otherField;
106
+ /**
107
+ * The fields this validator is registered on. Registration reaches one element at a time - the rows of a list
108
+ * take the validator on one by one, as they are built from the item template that carries it - so this is what
109
+ * says which of the fields a declaration stands for actually carry the rule, and a field that never took it on
110
+ * is left alone by a change of the compared field.
111
+ */
112
+ private readonly registrations;
113
+ /**
114
+ * The fields this validator has installed its listener on. A binding of such a field carries the listener too -
115
+ * a binding takes on the actions of the field it was bound from - so the field it was bound from is what is
116
+ * asked about as well, and a list of a thousand rows installs one listener rather than a thousand.
117
+ */
118
+ private readonly listening;
119
+ /**
120
+ * What the fields this validator was registered on were declared as. One entry stands for every binding of such a
121
+ * field, so a change of a compared field finds the fields of the record that change happened in without a list
122
+ * of a thousand rows being held here.
123
+ */
124
+ private readonly declarations;
125
+ constructor(otherField: CompareToTarget, isValidComparison: (myValue: T, otherValue: T) => boolean, message: RenderContentRef);
126
+ /** The field `field` is compared against, within the record `field` belongs to. */
127
+ private resolve;
128
+ /**
129
+ * Makes a change of `other` re-run this comparison. The listener re-runs it over the fields of the record the
130
+ * change happened in rather than over the field that installed it, so the listener a row inherits with the field
131
+ * it was bound from serves that row; and it re-runs this one validator, not the chain around it.
132
+ */
133
+ private listenOn;
134
+ boundToBinding(binding: FieldBase): void;
135
+ private comparisonState;
136
+ protected newBindingState(): CompareToBindingState<T>;
137
+ unregisterFrom(binding: FieldBase): void;
55
138
  }
56
139
 
140
+ /** What the validator remembers about one field it validates. */
141
+ declare interface CompareToBindingState<T> extends ValidatorBindingState {
142
+ oldValue: T;
143
+ }
144
+
145
+ /**
146
+ * How the field to compare against is named. A field names it directly, a string names it by the name its
147
+ * container holds it under, and a callback works it out from the field being validated. All three answer for the
148
+ * record the validation is running over: handed the field of a `List`'s item template, a row compares against that
149
+ * row's field.
150
+ */
151
+ declare type CompareToTarget = FieldBase | string | ((field: FieldBase) => FieldBase | null | undefined);
152
+
57
153
  export declare class ConditionalEnabledAction extends ConditionalStatementAction {
58
154
  constructor(statement: Statement);
59
155
  }
@@ -61,12 +157,43 @@ export declare class ConditionalEnabledAction extends ConditionalStatementAction
61
157
  declare type ConditionalExecutorFn = (field: FieldBase, currentResult: boolean, previousResult: boolean | undefined) => void;
62
158
 
63
159
  export declare class ConditionalStatementAction extends ValueChangedAction {
64
- private lastResult;
65
- private readonly boundFields;
160
+ private readonly statement;
161
+ private readonly conditionalExecutor;
162
+ /**
163
+ * What the elements this action was registered on were declared as. It holds declarations rather than the
164
+ * elements themselves, so one entry stands for every row of a list, and the element a result is applied to is
165
+ * the one that declaration names within the record the change happened in.
166
+ */
167
+ private readonly declarations;
168
+ /**
169
+ * The elements this action was registered on. Registration reaches one element at a time - the rows of a list
170
+ * take the action on one by one, as they are built from the item template that carries it - so this is what
171
+ * says which of the elements a declaration stands for the action actually drives.
172
+ */
173
+ private readonly registrations;
66
174
  constructor(statement: Statement, executorFn: ConditionalExecutorFn);
67
175
  static get classIdentifier(): symbol;
68
176
  get eager(): boolean;
69
- boundToField(field: FieldBase): void;
177
+ boundToBinding(binding: FieldBase): void;
178
+ /**
179
+ * The elements of `scope` this action controls: what each declaration it serves names within that record, and of
180
+ * those the ones that took the action on. A row of a list that never took it on is not one this action drives.
181
+ */
182
+ private targetsIn;
183
+ /**
184
+ * Re-evaluates the statement over one record and applies the result where it changed. The result is recorded
185
+ * before the executor runs, because an executor that writes a value re-enters through that value's eager pass
186
+ * and what it has to find there is the result being applied. It answers whether the record held anything for
187
+ * this action to drive, which is how a caller learns that the record is not assembled yet.
188
+ */
189
+ private applyIn;
190
+ /**
191
+ * Re-evaluates the records a change of `source` speaks for. A field of the record the targets live in speaks for
192
+ * that record alone, which is what keeps one row of a list from answering for another; a field above them - a
193
+ * form field every row reads - speaks for every record below it, and for the record the action was declared in
194
+ * where the change reaches none.
195
+ */
196
+ private applyFrom;
70
197
  }
71
198
 
72
199
  export declare class ConditionalValueAction<T> extends ConditionalStatementAction {
@@ -77,6 +204,15 @@ export declare class ConditionalVisibilityAction extends ConditionalStatementAct
77
204
  constructor(statement: Statement);
78
205
  }
79
206
 
207
+ /**
208
+ * What a container holds beyond the common slots: the object the value getter last built, together with the
209
+ * version of the tree it was built from.
210
+ */
211
+ declare interface ContainerSlots<T = any> extends ElementSlots<T> {
212
+ cachedValue: T;
213
+ cachedValueVersion: number;
214
+ }
215
+
80
216
  /**
81
217
  * DisplayMode enum provides an enumeration for supported ways of rendering a particular object in the DOM
82
218
  */
@@ -93,7 +229,64 @@ export declare namespace DisplayMode {
93
229
  export function isDefined(mode: number | string): boolean;
94
230
  }
95
231
 
96
- export declare const EmptyField: Field<string>;
232
+ /**
233
+ * The mutable state of one element, held in an object of its own beside the element rather than in the element's
234
+ * own properties.
235
+ *
236
+ * An element reaches it through two views of that one object, both in private class fields of `FieldBase`:
237
+ * `this.state` is `reactive(slots)` and `this.raw` is the object itself. A slot read through `state` inside a
238
+ * render effect or a computed subscribes that effect to the slot, and a write to the slot re-runs it. The
239
+ * bookkeeping an element does for itself goes through `raw`, which neither records a read nor announces a write.
240
+ * The value cache of a container goes through `raw` in particular: its getter writes the cache while it runs, and
241
+ * a tracked write there costs the reading effect one extra evaluation, and one extra render on mount, for a value
242
+ * it has already built.
243
+ *
244
+ * Being private class fields is what puts the two views out of reach of everything outside `FieldBase`: a private
245
+ * field is absent from `Object.keys`, `JSON.stringify`, `Object.getOwnPropertySymbols` and lodash `getAllKeys` by
246
+ * construction, and needs no per-instance property definition to be. Both `JSON.stringify` and lodash `isEqual`
247
+ * walk their way down a structure over own keys, enumerable symbols included, and the `parent` slot is in the
248
+ * state: reachable, it would take either walker back into the container the element came from.
249
+ *
250
+ * What they do reach on an element is `_actions` once something is registered, `_fields` on a `Group` and
251
+ * `_itemTemplate` on a `List`. All three lead downwards only.
252
+ */
253
+ declare interface ElementSlots<T = any> {
254
+ /** the value the element was given at construction; isChanged compares against it */
255
+ originalValue: T;
256
+ /** the value the last ValueChangedAction reported; the next transaction measures its net change against it */
257
+ announcedValue: T;
258
+ errors: ValidationError[];
259
+ visibility: DisplayMode;
260
+ enabled: boolean;
261
+ /** counts the writes that changed the value of the element or of anything below it */
262
+ valueVersion: number;
263
+ /** how many asynchronous validation runs are in flight on this element */
264
+ validatingCount: number;
265
+ /** the container that holds this element, absent while none does; takeChild writes it, releaseChild clears it */
266
+ parent: FieldBase | undefined;
267
+ /** the name the containing Group holds this element under; a List row carries none */
268
+ fieldName: string | undefined;
269
+ /** generation of the validators attached to the element; clearValidators() raises it */
270
+ validationEpoch: number;
271
+ /**
272
+ * The extended properties the element carries, typed by the element's own X parameter. A write replaces the
273
+ * object rather than writing into it, so an effect that read the slot re-runs on the write, and the object a
274
+ * transaction captured is the one a rollback puts back.
275
+ */
276
+ extra: object;
277
+ /**
278
+ * The element this one was bound from, absent on an element that was declared rather than bound. It is what lets
279
+ * an action shared by every binding work out which binding of a second element it means: `declaration` is the
280
+ * canonical one, so a binding of a binding names the element the whole family was declared as.
281
+ */
282
+ declaration: FieldBase | undefined;
283
+ /** the verdict the last commit announced, which is what a change of validity is measured against */
284
+ valid: boolean;
285
+ /** number of direct children whose last announced verdict was invalid */
286
+ invalidChildren: number;
287
+ }
288
+
289
+ export declare const EmptyField: Field<string, {}>;
97
290
 
98
291
  export declare class EnabledChangedAction extends FieldActionBase {
99
292
  constructor(executorFn: (field: FieldBase, supr: FieldActionExecute, newValue: boolean, oldValue: boolean) => void);
@@ -113,10 +306,13 @@ export declare class ExecuteAction extends FieldActionBase {
113
306
  execute(field: FieldBase, supr: FieldActionExecute, params: any): any;
114
307
  }
115
308
 
116
- export declare class Field<T = any> extends FieldBase<T> {
117
- protected _value: T;
118
- protected _touched: boolean;
119
- constructor(params?: Partial<IFieldConstructorParams<T>>);
309
+ export declare class Field<T = any, X extends object = {}> extends FieldBase<T, X> {
310
+ protected get state(): FieldSlots<T>;
311
+ protected get raw(): FieldSlots<T>;
312
+ /** the value slot itself, without the notifications the value setter carries around a write */
313
+ protected get _value(): T;
314
+ protected set _value(newValue: T);
315
+ constructor(params?: IFieldParams<T, X>);
120
316
  /**
121
317
  * Applies the constructor parameters. It is a hook so that a subclass needing different parameter handling
122
318
  * overrides one method instead of redeclaring the constructor - Action does exactly that.
@@ -126,69 +322,366 @@ export declare class Field<T = any> extends FieldBase<T> {
126
322
  * subclass initializes read as undefined inside it, and anything it writes to such a member is overwritten
127
323
  * the moment the initializer runs.
128
324
  */
129
- protected init(params?: Partial<IFieldConstructorParams<T>>): void;
325
+ protected init(params?: IFieldParams<T, X>): void;
130
326
  get value(): T;
131
327
  set value(newValue: T);
132
328
  get touched(): boolean;
133
329
  set touched(touched: boolean);
134
- clone(overrides?: Partial<IFieldConstructorParams<T>>): this;
330
+ bind(data?: T, overrides?: IBindParams<T, X>): this;
135
331
  }
136
332
 
137
333
  export declare abstract class FieldActionBase {
138
334
  static get classIdentifier(): symbol;
139
335
  get classIdentifier(): symbol;
140
336
  private readonly executorFn;
337
+ /**
338
+ * What this action remembers about one of the elements it serves. An action instance is shared - a `List` row
339
+ * carries the instances the item template carries - so anything an action holds about the element it last ran
340
+ * over belongs to that element rather than to the action: a verdict, a sequence number, a listener it installed.
341
+ * The keys are weak, so what an action remembers about a row is released with the row.
342
+ */
343
+ private readonly states;
141
344
  constructor(executorFn: ActionExecutor);
345
+ /**
346
+ * This action's state for `key`, created by `init` the first time it is asked for. The key is the element the
347
+ * action is running over, or the record that element belongs to where what is remembered is a fact about the
348
+ * whole record.
349
+ */
350
+ protected state<S>(key: object, init: () => S): S;
142
351
  execute(field: FieldBase, supr: FieldActionExecute, ...params: any[]): any;
143
352
  get eager(): boolean;
144
- boundToField(field: FieldBase): void;
145
- unregister(): void;
353
+ /**
354
+ * Announces that this action now serves `binding`. It runs once per element the action is registered on, the
355
+ * copies of that element included: a copy takes on the instances it was copied from and each is told about the
356
+ * copy as it does.
357
+ */
358
+ boundToBinding(binding: FieldBase): void;
359
+ /**
360
+ * Announces that `binding` no longer holds this action. It names one element rather than the action as a whole,
361
+ * because the instance goes on serving every other element it was registered on.
362
+ */
363
+ unregisterFrom(binding: FieldBase): void;
146
364
  }
147
365
 
148
366
  export declare type FieldActionExecute<T = any> = (field: FieldBase<T>, ...params: any[]) => any;
149
367
 
150
- export declare abstract class FieldBase<T = any> {
368
+ export declare abstract class FieldBase<T = any, X extends object = {}> {
369
+ #private;
151
370
  /**
152
- * A field is a Vue reactive proxy from construction onwards: the base constructor returns the proxy, and a
153
- * derived class's `this` is whatever super() returned, so every subclass constructor, field initializer and
154
- * method sees the proxy. Consequence: plain `field.property = value` is tracked, with no wrapper in between.
371
+ * Vue's getTargetType answers INVALID for an object that carries __v_skip, so reactive() hands an element back
372
+ * unwrapped and no element is ever behind a proxy of its own. isReactive() reads the second flag, and it stays
373
+ * true because what carries an element's reactivity - its state - is a reactive object.
374
+ *
375
+ * Two consequences for a consumer, both silent. watch(field, cb) with a bare element as the source registers
376
+ * no dependency, because the deep traversal Vue starts for a reactive source stops on __v_skip; the supported
377
+ * form is watch(() => field.value, cb). And readonly(field) hands the element straight back, so the value it
378
+ * returns is the element itself and a write through it reaches the field; what a caller hands out instead is
379
+ * the value, which is frozen, or a computed over it.
155
380
  */
156
- constructor();
381
+ get __v_skip(): boolean;
382
+ get __v_isReactive(): boolean;
383
+ constructor(slots: ElementSlots<T>);
384
+ /** the tracked view of this element's state; a subclass narrows the return type to its own slots */
385
+ protected get state(): ElementSlots<T>;
386
+ /** the untracked view of this element's state; a subclass narrows the return type to its own slots */
387
+ protected get raw(): ElementSlots<T>;
157
388
  abstract get value(): T;
158
389
  abstract set value(newValue: T);
159
390
  abstract get touched(): boolean;
160
391
  abstract set touched(touched: boolean);
161
- abstract clone(overrides?: Partial<IFieldConstructorParams<T>>): FieldBase<T>;
162
- originalValue: T;
163
- private validatingCount;
392
+ /**
393
+ * A new element of this one's class over `data`: same class, same registered actions, same extended properties,
394
+ * and the change history starting over. It is how a declaration is put to work over a record - every row a
395
+ * `List` builds is its item template bound to that row's data - and the element it is called on is what the new
396
+ * one answers `declaration` with.
397
+ *
398
+ * `data` of `undefined` is no data supplied and the new element carries what this one holds; an explicit `null`
399
+ * is data and clears. `overrides` states the rest: `originalValue` is read by key presence, `enabled` and
400
+ * `visibility` fall back to this element's, and extended properties it names are written over the ones carried
401
+ * over. The new element is detached - no `parent`, no `fieldName` - so it is free to be taken by a container.
402
+ */
403
+ abstract bind(data?: T, overrides?: IBindParams<T, X>): FieldBase<T, X>;
404
+ /**
405
+ * Exchanges the data this element holds for `data`, in place. The element is the same instance afterwards - its
406
+ * identity, its actions, its extended properties and its place in whatever container holds it all stand - and it
407
+ * ends up in the state `bind(data)` would have produced: the values are written, the change history starts over
408
+ * and the validators run. It is what recycles one element across records, which is what a virtualised renderer
409
+ * does with the rows it keeps.
410
+ *
411
+ * The element makes no statement of its own about the exchange: no `ValueChangedAction` fires for it, the way
412
+ * none fires for an element that was just built. Its members do announce theirs, and a verdict that moves is
413
+ * announced as always - a rebound element that is invalid says so to the container holding it. A change an
414
+ * open transaction is already owed an announcement for stands: the commit reports the pair measured from
415
+ * where the element was when the transaction opened.
416
+ *
417
+ * The data is measured against the element's `declaration`, so a key a record leaves out is taken from the
418
+ * declaration rather than left as the previous record had it.
419
+ */
420
+ rebind(data: T): this;
421
+ /** contains original field value as was provided at creation */
422
+ get originalValue(): T;
423
+ set originalValue(newValue: T);
424
+ /**
425
+ * The extended properties this element carries: what a consumer attached to it beyond the members the class
426
+ * declares, such as the label, hint or css class a UI layer binds to the input it renders the element with.
427
+ * The read is tracked, so a template rendering off `field.extra.label` re-renders when the property is written.
428
+ *
429
+ * Every property is optional here, whatever `X` states: a parameter object need not carry one and
430
+ * setExtendedValues writes as few as a caller likes, so a property `X` declares as required is present only
431
+ * once something has written it.
432
+ *
433
+ * The object is frozen and setExtendedValues is the way to change it: it is the object a transaction captured,
434
+ * and one written in place would leave a rollback with nothing to put back.
435
+ */
436
+ get extra(): Readonly<Partial<X>>;
437
+ /**
438
+ * Writes extended properties. The values given are merged over the ones the element carries, so a write of one
439
+ * property leaves the others standing, and the merged set replaces the object the element held.
440
+ */
441
+ setExtendedValues(values: Partial<X>): void;
442
+ /**
443
+ * The extended properties a parameter object carries: every key the element does not answer for itself. A key
444
+ * the element answers for at the time the parameters are applied - `value`, `enabled`, an accessor a subclass
445
+ * adds - is the element's own; a key that only Object.prototype answers for is nobody's declaration and counts
446
+ * as extended, and `validators` and `actions` are neither, since they state what to register on the element.
447
+ *
448
+ * A member a subclass declares as a class field is not among the keys the element answers for: class fields are
449
+ * defined on the instance after the base constructor returns, and the parameters are applied inside it. A
450
+ * subclass that wants a parameter of its own name assigned to it declares that member as an accessor.
451
+ */
452
+ protected extendedOf(params: object): Partial<X>;
453
+ /**
454
+ * Applies a parameter object: the members the element answers for are assigned to the element and the rest
455
+ * become its extended properties. Assigning a getter-only member throws a TypeError, which is what a caller
456
+ * naming `valid` or `parent` past the type system gets.
457
+ */
458
+ protected assignParams(params: object): void;
459
+ /**
460
+ * Takes this element into the record of the open transaction, where one is open. A write of a single slot that
461
+ * announces nothing calls it instead of opening a transaction of its own: on its own such a write is already
462
+ * atomic, and inside a transaction it has to be part of what a rollback puts back.
463
+ */
464
+ protected touchState(): void;
465
+ /**
466
+ * Records the whole of this element's mutable state, so that a rolled-back transaction can put it back exactly
467
+ * as it found it. The errors array is copied because a validator writes into the array it is handed rather than
468
+ * replacing it, and a subclass copies whatever else it holds by reference the same way.
469
+ *
470
+ * What is not in the snapshot is the action map, which no write touches: an operation that replaces it hands
471
+ * the transaction its own undo instead, so this stays the one shape every element captures.
472
+ */
473
+ protected [TxCapture](): TxSnapshot;
474
+ /**
475
+ * Puts a captured state back. It writes through the tracked view, so an effect that ran on the state the
476
+ * transaction produced runs again on the state it is being returned to, and only for the slots that differ.
477
+ *
478
+ * validatingCount is the one slot the element keeps: it counts runs that are in flight, and a rollback cannot
479
+ * un-start one. Put back, the count would no longer match the endValidating calls still to come.
480
+ */
481
+ protected [TxRestore](snapshot: TxSnapshot): void;
164
482
  /** true while at least one asynchronous validator is still running for this field */
165
483
  get validating(): boolean;
166
484
  /** announces the start of one asynchronous validation run; validators pair it with endValidating */
167
485
  beginValidating(): void;
168
486
  /** announces the end of one asynchronous validation run */
169
487
  endValidating(): void;
170
- protected _valid: boolean;
171
- errors: ValidationError[];
172
- parent?: Group;
173
- fieldName?: string;
174
- protected actions: ActionsMap;
175
- private _visibility;
488
+ /**
489
+ * List of errors. The array handed out is the one the element holds, and a validator writes into it in place,
490
+ * so a transaction that is open takes the element into its record here: a rollback that put back everything
491
+ * except the errors would leave a state the form never held.
492
+ */
493
+ get errors(): ValidationError[];
494
+ set errors(newValue: ValidationError[]);
495
+ /**
496
+ * The container that holds this element: the Group it is a member of, or the List whose row it is, and
497
+ * undefined while no container holds it. The container writes it; everyone else reads it. The read is tracked,
498
+ * so an effect rendering off the link - `v-if="field.parent"` - re-runs when a container takes the element or
499
+ * releases it.
500
+ */
501
+ get parent(): Group | undefined;
502
+ /** when member of a Group, fieldName specifies the name of this field. Written by the group, read-only after */
503
+ get fieldName(): string | undefined;
504
+ /**
505
+ * The element this one was declared as: itself for an element built from parameters, and the element it was
506
+ * bound from for a binding - transitively, so a binding of a binding names the same one. Every row a `List`
507
+ * builds from an item template is a binding of it, so a row's member and the template's member it stands for
508
+ * answer with the same element, and an action registered on the template can tell the two apart.
509
+ */
510
+ get declaration(): FieldBase;
511
+ /** The elements this one holds: a Group's members, a List's rows, none for a leaf. */
512
+ protected get members(): FieldBase[];
513
+ /**
514
+ * Every element in this element's subtree, this element included, that was declared as `declaration`. It answers
515
+ * the question a shared action asks when the record it changed in is not the record its targets live in - a form
516
+ * field that every row of a list reacts to - and it costs the subtree, so it is the path taken only when the
517
+ * cheaper one, resolving within a single record, does not apply.
518
+ */
519
+ bindingsOf(declaration: FieldBase): FieldBase[];
520
+ /** set while an eager pass over this element is waiting for the record the element belongs to */
521
+ protected _recordPending?: boolean;
522
+ /**
523
+ * States that an eager pass over this element reached an element it needs and did not find it, because the
524
+ * record this element belongs to was not assembled at the time: a `List` row is built member by member and its
525
+ * members are bound before any of them holds the row, so a validator comparing two of them runs before the
526
+ * row exists. The container that finishes the record runs the pass again, and a pass that still reaches
527
+ * nothing says so again, so the next container above answers for it.
528
+ */
529
+ markRecordIncomplete(): void;
530
+ /**
531
+ * Runs the eager passes outstanding in `element`'s subtree, now that the record it belongs to is assembled. A
532
+ * container calls it where it has just made a record complete: a Group that has written its members, and a
533
+ * List that has taken a row, which is what gives the row's fields the form above it.
534
+ */
535
+ protected completeRecords(element?: FieldBase): void;
536
+ /** Runs this element's eager actions over the value it holds and re-forms the verdict they reach. */
537
+ private rerunEagerActions;
538
+ /**
539
+ * The map this element registers its actions in, absent while it has registered none. Code that only triggers
540
+ * reads this slot rather than `actions`, so an element with nothing registered stays free of a map: `actions`
541
+ * allocates one for whoever asks, and a trigger over an empty map does nothing anyway.
542
+ */
543
+ protected _actions?: ActionsMap;
544
+ protected get actions(): ActionsMap;
545
+ protected set actions(newValue: ActionsMap);
546
+ /**
547
+ * Counts the writes that have changed the value of this element or of anything below it. A container reads it
548
+ * before answering from its value cache, and the read is an ordinary tracked one, so an effect that took a
549
+ * cached value still re-runs when a descendant is written.
550
+ */
551
+ protected get valueVersion(): number;
552
+ /**
553
+ * Marks the value of this element and of every ancestor as superseded. It walks the parent chain, so it costs
554
+ * the nesting depth: an ancestor rebuilds its value the next time one is asked of it, instead of being walked
555
+ * here for a reader that may never come. The walk also brings each element into the open transaction, so a
556
+ * rollback puts the versions back and no reader is left holding a cache the tree no longer supports.
557
+ */
558
+ protected bumpValueVersion(): void;
559
+ /**
560
+ * States that this element's value changed and that every container above it therefore holds a different value
561
+ * too. Nothing is announced here: the transaction works out at commit which of the elements enrolled actually
562
+ * ends up holding a different value, and announces those once each.
563
+ *
564
+ * `force` states that the caller already knows this element's value changed - one item more or fewer is a
565
+ * different list whatever the items compare as - so the commit announces it without composing a comparison.
566
+ */
567
+ protected propagateValueChanged(force?: boolean): void;
568
+ /**
569
+ * Re-reads the value that the next ValueChangedAction will report as the one it replaces. A leaf records what
570
+ * it announced at every announcement, so its copy is always current and there is nothing to re-read; a
571
+ * container that skipped composing a value nobody was listening for overrides this.
572
+ */
573
+ protected refreshPreviousValue(): void;
574
+ /**
575
+ * The verdict validate() records and announces: this element's own errors plus the tally of children that
576
+ * reported themselves invalid, so a container forms it without walking its members. `valid` is the read path
577
+ * and answers over the live errors arrays instead; the two differ only for an error written into a member
578
+ * without a validate() call, which is the documented cost of pushing errors by hand.
579
+ */
580
+ protected get countedValid(): boolean;
581
+ /**
582
+ * Makes this element the container of `child`: it installs the back-reference, records the name a Group holds
583
+ * the child under, and takes the child into the invalid tally. An element belongs to one container at a time,
584
+ * so a child that already carries the link is refused; releaseChild() takes the link away again, and an element
585
+ * released that way can be handed on. The child's state is unreachable from outside FieldBase, so a container
586
+ * writes the two slots through here rather than on the child.
587
+ */
588
+ protected takeChild(child: FieldBase, fieldName?: string): void;
589
+ /** Takes a child into this element's invalid tally; a container calls it once the child's parent link exists. */
590
+ protected adoptChild(child: FieldBase): void;
591
+ /**
592
+ * Drops a child out of this element's invalid tally and takes its back-reference away. An element keeps no link
593
+ * to a container that no longer holds it: it would go on moving that container's tally, and the link is what
594
+ * stands in the way of the element being taken by another container.
595
+ */
596
+ protected releaseChild(child: FieldBase): void;
597
+ /**
598
+ * Brings this element to the state a fresh binding of `source` carrying `value` would be in: `value` is written
599
+ * where the caller supplied one and `source`'s own value where it did not, the change history - originalValue,
600
+ * touched - starts over and the errors are dropped and re-established by the validators. A container that reuses
601
+ * an element at a position it already holds calls it, so the element is indistinguishable from one built for
602
+ * that position.
603
+ */
604
+ protected resetTo(source: FieldBase, value: any): void;
605
+ /** Resets a member. It is what lets a container reach the reset of a child whose class it does not know. */
606
+ protected resetChild(child: FieldBase, source: FieldBase, value: any): void;
607
+ /**
608
+ * Records a child's new verdict in this element's tally. The child reports it as it settles, and the commit
609
+ * settles the deepest element first, so the tally a container reads when its own turn comes is finished.
610
+ */
611
+ protected childValidityChanged(nowValid: boolean): void;
612
+ /**
613
+ * The composed verdict a container answers `valid` with, memoised by Vue. The walk over the members is what
614
+ * makes an error pushed into one of them visible without a validate() call, and the computed keeps that walk
615
+ * from repeating while nothing it read has moved.
616
+ */
617
+ protected get validRead(): boolean;
618
+ /** What validRead computes. A leaf answers over its own errors; a container adds its members. */
619
+ protected composeValid(): boolean;
176
620
  get visibility(): DisplayMode;
177
621
  set visibility(newValue: DisplayMode);
178
- private _enabled;
179
622
  get enabled(): boolean;
180
623
  set enabled(newValue: boolean);
624
+ /**
625
+ * True for an element whose value is composed of its members'. The commit builds such a value only where
626
+ * something receives it, compares it by content rather than by identity, and runs the element's own validators
627
+ * with the announcement: a container's validators read the composed value, which exists only once the members
628
+ * have been written. A leaf's validators have run at the write instead, so its announcement carries no eager
629
+ * pass of its own.
630
+ */
631
+ protected get composesValue(): boolean;
632
+ /**
633
+ * Announces what this element's value became over the transaction. The pair carried is (value now, value at the
634
+ * last announcement), so a value that went A -> B -> A within the transaction says nothing, and the events an
635
+ * operation states rather than an element's state - an item added, an item removed - are emitted first, in the
636
+ * order the operations happened.
637
+ */
638
+ protected [TxAnnounceValue](tx: Transaction, dirty: boolean, force: boolean, structural?: TxStructuralEvent[]): void;
639
+ /**
640
+ * Forms the verdict this element ends the transaction with and announces a transition of it. The container is
641
+ * told first, so a handler reads a tally that already includes this verdict, and it is enrolled in the same
642
+ * transaction: its own verdict is composed of its members', so a member that moves without a value change - an
643
+ * asynchronous validator, an error pushed in by hand - is what makes the container re-form its own. The
644
+ * transaction settles the deepest element first, so a container is reached only once its members have decided.
645
+ */
646
+ protected [TxSettleValidity](tx: Transaction): void;
181
647
  validate(revalidate?: boolean): void;
182
648
  get valid(): boolean;
183
649
  get fullValue(): any;
184
650
  get isChanged(): boolean;
651
+ /**
652
+ * Brings a fresh element into the state a binding of `source` is in: it records what it was declared as, takes
653
+ * on the extended properties and the actions `source` carries, and runs the eager ones over the value it was
654
+ * built with. The extended properties `overrides` states are written over the ones `source` carries, and they
655
+ * are in place before the eager pass, so an action reading one sees what the binding ends up carrying. The
656
+ * actions are the very instances `source` holds - what a binding takes on is data, not behaviour - and each is
657
+ * told about this element as it is taken on, so an action serving several bindings knows all of them.
658
+ */
659
+ protected boundFrom(source: FieldBase<any, X>, newValue: any, oldValue: any, overrides?: object): void;
660
+ /**
661
+ * Registers the actions a constructor received in its parameters: registration without the eager trigger,
662
+ * because a constructor ends with a single this.actions.triggerEager(...) over the finished value, and an
663
+ * eager action registered here would otherwise also run once per registration, over a half-built field.
664
+ */
665
+ protected registerInitialActions(actions: FieldActionBase[]): void;
185
666
  registerAction(action: FieldActionBase): this;
186
667
  triggerAction<T2 extends FieldActionBase>(actionClass: (abstract new (...args: any[]) => T2) & {
187
668
  classIdentifier: symbol;
188
669
  }, ...params: any[]): any;
670
+ /**
671
+ * Generation counter of the validators attached to this field. A Validator reads it when a run starts and drops
672
+ * a result whose epoch no longer matches, so a validation still in flight when clearValidators() is called
673
+ * cannot push an error onto a field that no longer has the validator that produced it.
674
+ */
675
+ get validationEpoch(): number;
189
676
  clearValidators(): void;
190
677
  }
191
678
 
679
+ /** what a Field holds beyond the common slots: the value itself, and whether it has been touched */
680
+ declare interface FieldSlots<T = any> extends ElementSlots<T> {
681
+ value: T;
682
+ touched: boolean;
683
+ }
684
+
192
685
  export declare type FieldsToValues<T extends GenericFieldsInterface> = {
193
686
  [K in keyof T]: T[K]['value'];
194
687
  };
@@ -196,6 +689,8 @@ export declare type FieldsToValues<T extends GenericFieldsInterface> = {
196
689
  declare namespace Form {
197
690
  export {
198
691
  DisplayMode,
692
+ transaction,
693
+ TransactionControl,
199
694
  FieldActionBase,
200
695
  ActionsMap,
201
696
  EnabledChangedAction,
@@ -223,6 +718,8 @@ declare namespace Form {
223
718
  EmptyField,
224
719
  IFieldConstructorActionsList,
225
720
  IFieldConstructorParams,
721
+ IFieldParams,
722
+ IBindParams,
226
723
  AbortEventHandlingException,
227
724
  FieldActionExecute,
228
725
  FieldBase,
@@ -253,6 +750,7 @@ declare namespace Form {
253
750
  RenderableValue,
254
751
  ValidationFunctionResult,
255
752
  ValidationFunction,
753
+ ValidatorBindingState,
256
754
  Validator
257
755
  }
258
756
  }
@@ -268,25 +766,60 @@ declare interface FormsConfig {
268
766
 
269
767
  export declare type GenericFieldsInterface = Record<string, FieldBase>;
270
768
 
271
- export declare class Group<T extends GenericFieldsInterface = GenericFieldsInterface> extends FieldBase<GroupValue<T>> {
769
+ export declare class Group<T extends GenericFieldsInterface = GenericFieldsInterface, X extends object = {}> extends FieldBase<GroupValue<T>, X> {
770
+ protected get state(): ContainerSlots<GroupValue<T>>;
771
+ protected get raw(): ContainerSlots<GroupValue<T>>;
272
772
  private readonly _fields;
273
- private _value;
274
- private suppressNotifyValueChanged;
275
- constructor(fields: T, params?: Partial<IFieldConstructorParams<GroupValueInput<T>>>);
773
+ constructor(fields: T, params?: IFieldParams<GroupValueInput<T>, X>);
774
+ /**
775
+ * The copy of a built value that serves as a baseline. The value getter hands out one object per version, and
776
+ * a baseline holding that same object would report every value as its own original.
777
+ */
778
+ private static baseline;
276
779
  private addField;
277
780
  private static isValidFields;
278
781
  static createFromFormData(data: Record<string, any> | null): Group;
279
782
  field<K extends keyof T>(fieldName: K): T[K] | null;
280
783
  get fields(): T;
784
+ protected get members(): FieldBase[];
281
785
  get value(): GroupValue<T>;
786
+ /**
787
+ * Writes the members that the given value carries. The members are written one by one and the group says
788
+ * nothing in between: the transaction the assignment runs in measures the group's own value and its own verdict
789
+ * once, over the finished set, and announces each at most once.
790
+ */
791
+ private assignMembers;
282
792
  set value(newValue: GroupValueInput<T>);
793
+ /**
794
+ * Members are reset one by one rather than assigned as a whole value: the value setter writes only the keys the
795
+ * value carries, while a member the value leaves out has to end up holding what the template gives it. `source`
796
+ * supplies that per member, so a group reset from the template it was bound from matches a fresh binding of it.
797
+ */
798
+ protected resetTo(source: FieldBase, value: any): void;
283
799
  get touched(): boolean;
284
800
  set touched(touched: boolean);
285
801
  get fullValue(): Record<string, any>;
802
+ /**
803
+ * Records that a member changed its value, so that the transaction in progress works out at commit what this
804
+ * group's own value became and announces it once. A mutation method calls it itself; you rarely need to.
805
+ */
286
806
  notifyValueChanged(): void;
807
+ protected get composesValue(): boolean;
808
+ /**
809
+ * A group with nothing listening for its value does not compose one at all, so the copy it holds is from before
810
+ * the changes nobody received. A registration that adds a listener brings it up to date here, and what the
811
+ * listener is then told about is the change that follows it.
812
+ */
813
+ protected refreshPreviousValue(): void;
287
814
  get valid(): boolean;
815
+ protected composeValid(): boolean;
288
816
  validate(revalidate?: boolean): void;
289
- clone(overrides?: Partial<IFieldConstructorParams<GroupValueInput<T>>>): Group<T>;
817
+ bind(data?: GroupValueInput<T>, overrides?: IBindParams<GroupValueInput<T>, X>): Group<T, X>;
818
+ /**
819
+ * A record need not name every member: a key it leaves out is taken from the declaration, the same way a member
820
+ * the constructor is given no value for takes the one it was declared with.
821
+ */
822
+ rebind(data: GroupValueInput<T>): this;
290
823
  }
291
824
 
292
825
  /** what Group.value reads back: the full field map, or null when no field serializes */
@@ -295,17 +828,25 @@ export declare type GroupValue<T extends GenericFieldsInterface> = FieldsToValue
295
828
  /** what Group.value and the Group constructor accept: keys left out are simply not assigned */
296
829
  export declare type GroupValueInput<T extends GenericFieldsInterface> = Partial<FieldsToValues<T>> | null;
297
830
 
831
+ /**
832
+ * What bind() accepts beside the data it binds: everything a constructor takes except the value, which the data
833
+ * argument states. Of the members named here, bind() reads `originalValue`, `enabled` and `visibility`;
834
+ * `validators` and `actions` state what to register and are carried by the binding from its declaration, and the
835
+ * rest are the element's to establish.
836
+ */
837
+ export declare type IBindParams<T = any, X extends object = {}> = Partial<Omit<IFieldConstructorParams<T>, 'value'>> & Partial<NoInfer<X>>;
838
+
298
839
  export declare interface IFieldConstructorActionsList {
299
840
  actions?: FieldActionBase[];
300
841
  validators?: FieldActionBase[];
301
842
  }
302
843
 
303
844
  /**
304
- * Parameters accepted by field constructors and by clone overrides.
845
+ * Parameters accepted by field constructors and by bind overrides.
305
846
  *
306
847
  * Only writable members are listed. valid, validating, fullValue and isChanged are getter-only, so assigning
307
- * them throws a TypeError. parent and fieldName are set by the container: until a Group or List installs them
308
- * as non-configurable accessors, assigning them is silently accepted, which is why the type rejects them.
848
+ * them throws a TypeError. So are parent and fieldName: a container writes the slots behind them when it takes
849
+ * an element, and nobody else can, which is why the type rejects them.
309
850
  */
310
851
  export declare type IFieldConstructorParams<T = any> = {
311
852
  value: T;
@@ -316,6 +857,20 @@ export declare type IFieldConstructorParams<T = any> = {
316
857
  errors: ValidationError[];
317
858
  } & IFieldConstructorActionsList;
318
859
 
860
+ /**
861
+ * What an element's constructor accepts: the parameters the element answers for itself, together with the
862
+ * extended properties its X parameter declares.
863
+ *
864
+ * X is left out of inference, so an element built without a type argument carries no extended properties and a
865
+ * parameter object naming one is rejected as an excess property. A caller that wants them states them:
866
+ * `new Field<string, { label: string }>({ value: 'a', label: 'Name' })`.
867
+ *
868
+ * The two halves are made partial separately. `Partial<A & X>` is a mapped type over an intersection, which is
869
+ * what T is inferred through, and inference through it answers with one constituent of a union rather than the
870
+ * union: `new Field({ value: someStringOrNumber })` would be a Field<string>.
871
+ */
872
+ export declare type IFieldParams<T = any, X extends object = {}> = Partial<IFieldConstructorParams<T>> & Partial<NoInfer<X>>;
873
+
319
874
  declare class InAllowedValues<T = any> extends Validator {
320
875
  constructor(allowedValues: T[], message?: RenderContentRef);
321
876
  }
@@ -333,26 +888,58 @@ declare class LengthInRange<T = any> extends Validator {
333
888
  constructor(minLength: number, maxLength: number, message?: RenderContentRef);
334
889
  }
335
890
 
336
- export declare class List<T extends GenericFieldsInterface = GenericFieldsInterface> extends FieldBase<ListValue> {
337
- private _value;
891
+ export declare class List<T extends GenericFieldsInterface = GenericFieldsInterface, X extends object = {}> extends FieldBase<ListValue, X> {
892
+ protected get state(): ListSlots<T>;
893
+ protected get raw(): ListSlots<T>;
338
894
  private _itemTemplate?;
339
- private _previousValue;
340
- constructor(itemTemplate?: Group<T>, params?: Partial<IFieldConstructorParams<ListValue>>);
895
+ constructor(itemTemplate?: Group<T>, params?: IFieldParams<ListValue, X>);
896
+ /** The row array is copied as well: a rollback puts back the set the list held, not the array it went on to hold. */
897
+ protected [TxCapture](): TxSnapshot;
898
+ /**
899
+ * The copy of a built value that serves as a baseline. The value getter hands out one array per version, and a
900
+ * baseline holding that same array would report every value as its own original.
901
+ */
902
+ private static baseline;
341
903
  private processSetValueItem;
904
+ /**
905
+ * Builds the item that fills a gap left by an insert beyond the end of the list: the item template bound to its
906
+ * own values, or an empty group when the list has no template.
907
+ */
908
+ private createPaddingItem;
342
909
  private setValueInternal;
343
910
  get value(): ListValue;
344
911
  set value(newValue: Record<string, any>[]);
912
+ /**
913
+ * The rows are taken from `source` where the caller supplied no value of its own, so a list nested in a row that
914
+ * a whole-list assignment reuses ends up holding what the template gives it rather than what it held before.
915
+ */
916
+ protected resetTo(source: FieldBase, value: any): void;
345
917
  get touched(): boolean;
346
918
  set touched(touched: boolean);
347
- clone(overrides?: Partial<IFieldConstructorParams<ListValue>>): List<T>;
919
+ bind(data?: ListValue, overrides?: IBindParams<ListValue, X>): List<T, X>;
920
+ /**
921
+ * Records that a row changed its value, so that the transaction in progress works out at commit what this
922
+ * list's own value became and announces it once. The mutation methods call it themselves; you rarely need to.
923
+ */
348
924
  notifyValueChanged(): void;
925
+ protected get composesValue(): boolean;
926
+ /**
927
+ * A list with nothing listening for its value does not compose one at all, so the copy it holds is from before
928
+ * the changes nobody received. A registration that adds a listener brings it up to date here, and what the
929
+ * listener is then told about is the change that follows it.
930
+ */
931
+ protected refreshPreviousValue(): void;
349
932
  get valid(): boolean;
933
+ protected composeValid(): boolean;
350
934
  validate(revalidate?: boolean): void;
935
+ protected get members(): FieldBase[];
351
936
  get(index: number): Group<T> | undefined;
352
937
  push(item: any): number;
353
938
  pop(): Group<T> | undefined;
354
939
  remove(index: number): Group<T> | undefined;
355
940
  insert(item: any, index: number): number;
941
+ /** Drops every row this list holds out of its tally, so a row that changes its verdict later is not counted. */
942
+ private releaseRows;
356
943
  clear(): void;
357
944
  }
358
945
 
@@ -368,6 +955,11 @@ export declare class ListItemRemovedAction extends FieldActionBase {
368
955
  execute(field: FieldBase, supr: FieldActionExecute, item: any, index: number): void;
369
956
  }
370
957
 
958
+ /** what a List holds beyond the container slots: the rows themselves */
959
+ declare interface ListSlots<T extends GenericFieldsInterface = GenericFieldsInterface> extends ContainerSlots<ListValue> {
960
+ rows: Group<T>[] | null;
961
+ }
962
+
371
963
  /** what List.value reads back: one plain object per item, or null when the list is empty */
372
964
  export declare type ListValue = Record<string, any>[] | null;
373
965
 
@@ -485,9 +1077,20 @@ export declare class Statement {
485
1077
  private readonly operator;
486
1078
  private readonly operand2;
487
1079
  constructor(operand1: OperandType, operator: Operator, operand2: OperandType);
1080
+ /**
1081
+ * The value an operand contributes. A field operand names a field of the record the statement is evaluated in:
1082
+ * the same statement over a `List` reads row 3's field while row 3 is the record, and a field belonging to no
1083
+ * record of the statement's own - a form field above the list - is read where it stands. A record that does not
1084
+ * hold the field yet contributes undefined, which is what a half-built row answers with.
1085
+ */
1086
+ private static valueOf;
488
1087
  get operand1Value(): any;
489
1088
  get operand2Value(): any;
490
- evaluate(): boolean;
1089
+ /**
1090
+ * The result of the statement, over the record `scope` belongs to where one is given and over the fields the
1091
+ * statement was built from where it is not.
1092
+ */
1093
+ evaluate(scope?: FieldBase): boolean;
491
1094
  /**
492
1095
  * Recursively collects all fields used in this statement and its nested statements
493
1096
  * @returns A set of all fields used in this statement
@@ -495,6 +1098,155 @@ export declare class Statement {
495
1098
  collectFields(): Set<FieldBase>;
496
1099
  }
497
1100
 
1101
+ declare class Transaction {
1102
+ private readonly participants;
1103
+ /** work that stands only where the transaction commits; a rollback simply never does it */
1104
+ private readonly deferred;
1105
+ /** what a rollback has to put back beyond the state slots, newest last */
1106
+ private readonly undo;
1107
+ /** true once the transaction has been unwound, which is what tells a run started inside it to say nothing */
1108
+ private unwound;
1109
+ /** the depth the announcement in progress is working at, -1 while none is */
1110
+ private passDepth;
1111
+ /** set while a pass is running and an element it has already passed the depth of gets enrolled */
1112
+ private restartPass;
1113
+ /** true for a transaction that was rolled back rather than committed */
1114
+ get rolledBack(): boolean;
1115
+ private participant;
1116
+ /**
1117
+ * Records the state of an element the first time the transaction modifies it. The whole of the mutable state
1118
+ * goes into the snapshot rather than the part being written: a rollback that restored some of it would leave
1119
+ * the element in a state the form never held.
1120
+ */
1121
+ touch(element: FieldBase): void;
1122
+ /** Enrols an element as one whose value the commit has to announce. `force` skips the comparison. */
1123
+ markValueChanged(element: FieldBase, force: boolean): void;
1124
+ /** Enrols an element as one whose verdict the commit has to re-form. */
1125
+ markValidityDirty(element: FieldBase): void;
1126
+ /**
1127
+ * Queues an event that states an operation rather than a state. Added and removed items have no net over a
1128
+ * transaction, so they are neither compared nor coalesced: the commit emits them in the order they happened.
1129
+ */
1130
+ recordStructural(element: FieldBase, event: TxStructuralEvent): void;
1131
+ /** True where the commit still owes this element a value announcement. */
1132
+ willAnnounceValue(element: FieldBase): boolean;
1133
+ /**
1134
+ * Registers work the commit does once everything has been announced. It is for what a rollback could not take
1135
+ * back: releasing a listener, dropping a registration. Held until the commit, it is simply never done where the
1136
+ * transaction unwinds instead.
1137
+ */
1138
+ whenCommitted(work: () => void): void;
1139
+ /**
1140
+ * Registers what a rollback has to put back beyond the element's state slots. The snapshot covers the slots,
1141
+ * which is everything an ordinary write touches; an operation that replaces something else the element carries
1142
+ * hands its own undo in here rather than making every snapshot carry the thing.
1143
+ */
1144
+ whenRolledBack(work: () => void): void;
1145
+ /**
1146
+ * Notes that an element at or below the depth the pass in progress is working at has been enrolled. The pass
1147
+ * then gives up the rest of its batch and is started again over what is now owed, so the newcomer is reached
1148
+ * before the containers above it: an element a handler writes must still be announced before the container
1149
+ * whose composed value carries that write. The depth is only measured while a pass is running - outside one
1150
+ * there is nothing the answer would change.
1151
+ */
1152
+ private noteDepth;
1153
+ /**
1154
+ * Puts every element the transaction modified back as it found it. Nothing is announced: from an observer's
1155
+ * point of view the transaction never happened. What a rollback cannot take back are side effects - a handler
1156
+ * that called a server during the transaction already did.
1157
+ */
1158
+ rollback(): void;
1159
+ /**
1160
+ * Announces what the transaction did. Values first and verdicts after, because a container's validators run
1161
+ * with its value announcement and the verdict they reach is what the validity pass then reports. Both passes
1162
+ * run deepest first - field, then row, then list - which is the order the change travelled in.
1163
+ *
1164
+ * A handler may write while the commit runs; its writes join this transaction, so both passes repeat until
1165
+ * nothing is left dirty.
1166
+ */
1167
+ commit(): void;
1168
+ /**
1169
+ * The dirty participants a pass has to visit, one bucket per nesting depth; ties keep the order they were
1170
+ * enrolled in. A nesting depth is a small integer, so the elements go into buckets rather than through a
1171
+ * comparison sort: a whole-list assignment enrols one participant per field, and ordering those by comparison
1172
+ * would cost more than the announcement it orders.
1173
+ */
1174
+ private buckets;
1175
+ /**
1176
+ * Runs one pass over the dirty participants, deepest bucket first; the caller repeats it until it answers
1177
+ * false. The buckets are taken once, and the pass gives up as soon as a handler enrols an element at or below
1178
+ * the depth being drained: that element is not in the bucket being walked, and going on would reach the
1179
+ * containers above it first. The caller's next pass takes fresh buckets and finds it at its own depth.
1180
+ */
1181
+ private pass;
1182
+ private announceValues;
1183
+ private settleValidity;
1184
+ }
1185
+
1186
+ /**
1187
+ * Runs `fn` as one atomic change. The writes it makes land in the elements as they are made and the events they
1188
+ * produce are announced once, at the end, over the net result.
1189
+ *
1190
+ * A call made while a transaction is already open joins it: nothing is committed until the outermost call
1191
+ * returns. A throw out of `fn` rolls the whole transaction back and rethrows, and `tx.rollback()` rolls it back
1192
+ * without an error, in which case the call answers undefined.
1193
+ *
1194
+ * The handle `fn` receives is usable only for the duration of that call; calling it afterwards throws a TypeError.
1195
+ *
1196
+ * @throws TypeError immediately if `fn` returns a thenable - a transaction cannot cross an await.
1197
+ */
1198
+ export declare function transaction<R>(fn: (tx: TransactionControl) => R): R | undefined;
1199
+
1200
+ export declare interface TransactionControl {
1201
+ /**
1202
+ * Undoes everything the transaction has done and ends it, announcing nothing. It unwinds from the point of
1203
+ * the call, so nothing after it runs. There are no savepoints: a nested call rolls back the whole transaction
1204
+ * it joined, not its own part of it.
1205
+ *
1206
+ * @throws TypeError where the transaction the handle belongs to has already closed.
1207
+ */
1208
+ rollback(): never;
1209
+ }
1210
+
1211
+ declare const TxAnnounceValue: unique symbol;
1212
+
1213
+ /**
1214
+ * The protocol a transaction drives its participants through. The four members are symbol-keyed so that they
1215
+ * carry no name a consumer could reach or collide with, and they live on the prototype, so no walker over an
1216
+ * element's own keys sees them either.
1217
+ */
1218
+ declare const TxCapture: unique symbol;
1219
+
1220
+ declare const TxRestore: unique symbol;
1221
+
1222
+ declare const TxSettleValidity: unique symbol;
1223
+
1224
+ /**
1225
+ * A transaction is the unit an observer sees a change in. Every mutating operation runs inside one: where the
1226
+ * caller opens none, the operation is the transaction, so a single write is atomic without anything having to be
1227
+ * remembered at the call site.
1228
+ *
1229
+ * Writes land in the element straight away and only the announcement waits. At commit the net transitions are
1230
+ * measured against the state the elements last announced and each is announced once, so a value that goes A -> B
1231
+ * -> A within one transaction says nothing. Validators run while the transaction is open, because the verdict
1232
+ * they reach is what the commit announces; every other action fires at commit.
1233
+ *
1234
+ * A transaction may not cross an await: transaction() throws when the callback returns a thenable. Two
1235
+ * overlapping transactions therefore cannot exist, and an asynchronous validator settling later opens one of its
1236
+ * own at that moment.
1237
+ */
1238
+ /** the slots of one element as they stood when the transaction first modified it */
1239
+ declare type TxSnapshot = Record<string, any>;
1240
+
1241
+ /** a ListItemAddedAction or ListItemRemovedAction waiting for the commit that will emit it */
1242
+ declare interface TxStructuralEvent {
1243
+ actionClass: (abstract new (...args: any[]) => FieldActionBase) & {
1244
+ classIdentifier: symbol;
1245
+ };
1246
+ item: any;
1247
+ index: number;
1248
+ }
1249
+
498
1250
  /**
499
1251
  * Base validation error class with component rendering capabilities
500
1252
  */
@@ -548,20 +1300,47 @@ export declare class Validator<T = any> extends ValueChangedAction {
548
1300
  * @param validationFn Function that validates the field value and returns errors or null
549
1301
  */
550
1302
  constructor(validationFn: ValidationFunction<T>);
1303
+ /**
1304
+ * Returns the error instance this validator owns and may later withdraw: the argument itself when it carries no
1305
+ * ownership stamp or already carries this validator's, a copy of it when it belongs to another validator. The
1306
+ * stamp is not configurable, so an instance one validator owns can never be reassigned to another; the copy is
1307
+ * what makes an error instance shareable between validators, and it keeps the prototype and every own property,
1308
+ * including the non-enumerable ones, so it renders exactly like the instance it was made from.
1309
+ */
1310
+ private claim;
551
1311
  static get classIdentifier(): symbol;
552
1312
  get eager(): boolean;
1313
+ /**
1314
+ * What this validator remembers about one of the fields it validates. One instance may be registered on several
1315
+ * fields - every row of a list carries the instances the item template carries - so each field has a record of
1316
+ * its own. A subclass that remembers more widens the record by overriding `newBindingState`.
1317
+ */
1318
+ protected bindingState(field: FieldBase<any>): ValidatorBindingState;
1319
+ /**
1320
+ * The record a field starts with. `run` is the sequence number of the newest run over that field: every
1321
+ * execution takes the next one and a result is applied only while its number is still the newest, so a slow run
1322
+ * cannot overwrite the verdict of a faster one that started after it.
1323
+ */
1324
+ protected newBindingState(): ValidatorBindingState;
553
1325
  protected replacePlaceholdersFunction(text: RenderContentRef, replace: Record<string, any>): RenderContentRef;
554
1326
  protected replacePlaceholders(text: RenderContentRef, replace: Record<string, any>): RenderContentRef;
555
1327
  }
556
1328
 
1329
+ /** What a validator remembers about one field it is registered on; a subclass widens it. */
1330
+ export declare interface ValidatorBindingState {
1331
+ run: number;
1332
+ }
1333
+
557
1334
  export declare namespace Validators {
558
1335
  export {
559
1336
  CompareTo,
1337
+ CompareToTarget,
560
1338
  InAllowedValues,
561
1339
  Required_2 as Required,
562
1340
  Pattern,
563
1341
  ValidationFunctionResult,
564
1342
  ValidationFunction,
1343
+ ValidatorBindingState,
565
1344
  Validator,
566
1345
  MinValue,
567
1346
  MaxValue,