@dynamicforms/vue-forms 0.6.1 → 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.
@@ -1,51 +1,80 @@
1
- var bt = Object.defineProperty, vt = Object.defineProperties;
2
- var yt = Object.getOwnPropertyDescriptors;
3
- var U = Object.getOwnPropertySymbols;
4
- var et = Object.prototype.hasOwnProperty, it = Object.prototype.propertyIsEnumerable;
5
- var q = (n, i, t) => i in n ? bt(n, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[i] = t, v = (n, i) => {
6
- for (var t in i || (i = {}))
7
- et.call(i, t) && q(n, t, i[t]);
8
- if (U)
9
- for (var t of U(i))
10
- it.call(i, t) && q(n, t, i[t]);
1
+ var Gt = Object.defineProperty, Yt = Object.defineProperties;
2
+ var Jt = Object.getOwnPropertyDescriptors;
3
+ var q = Object.getOwnPropertySymbols;
4
+ var mt = Object.prototype.hasOwnProperty, bt = Object.prototype.propertyIsEnumerable;
5
+ var vt = (n) => {
6
+ throw TypeError(n);
7
+ };
8
+ var K = (n, e, t) => e in n ? Gt(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, p = (n, e) => {
9
+ for (var t in e || (e = {}))
10
+ mt.call(e, t) && K(n, t, e[t]);
11
+ if (q)
12
+ for (var t of q(e))
13
+ bt.call(e, t) && K(n, t, e[t]);
11
14
  return n;
12
- }, w = (n, i) => vt(n, yt(i));
13
- var F = (n, i) => {
15
+ }, x = (n, e) => Yt(n, Jt(e));
16
+ var k = (n, e) => {
14
17
  var t = {};
15
- for (var e in n)
16
- et.call(n, e) && i.indexOf(e) < 0 && (t[e] = n[e]);
17
- if (n != null && U)
18
- for (var e of U(n))
19
- i.indexOf(e) < 0 && it.call(n, e) && (t[e] = n[e]);
18
+ for (var s in n)
19
+ mt.call(n, s) && e.indexOf(s) < 0 && (t[s] = n[s]);
20
+ if (n != null && q)
21
+ for (var s of q(n))
22
+ e.indexOf(s) < 0 && bt.call(n, s) && (t[s] = n[s]);
20
23
  return t;
21
24
  };
22
- var o = (n, i, t) => q(n, typeof i != "symbol" ? i + "" : i, t);
23
- import { isEqual as D, isBoolean as Vt, isString as A, isEmpty as Q, truncate as Ct, isArray as rt, isObject as at } from "lodash-es";
24
- import { unref as h, computed as xt, isRef as _t, reactive as Et, defineComponent as It, resolveComponent as st, openBlock as At, createBlock as St, h as j } from "vue";
25
- var T = /* @__PURE__ */ ((n) => (n[n.SUPPRESS = 1] = "SUPPRESS", n[n.HIDDEN = 5] = "HIDDEN", n[n.INVISIBLE = 8] = "INVISIBLE", n[n.FULL = 10] = "FULL", n))(T || {});
26
- const nt = 10;
25
+ var d = (n, e, t) => K(n, typeof e != "symbol" ? e + "" : e, t), Vt = (n, e, t) => e.has(n) || vt("Cannot " + t);
26
+ var l = (n, e, t) => (Vt(n, e, "read from private field"), t ? t.call(n) : e.get(n)), Z = (n, e, t) => e.has(n) ? vt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), tt = (n, e, t, s) => (Vt(n, e, "write to private field"), s ? s.call(n, t) : e.set(n, t), t);
27
+ var wt = (n, e, t) => new Promise((s, i) => {
28
+ var r = (c) => {
29
+ try {
30
+ o(t.next(c));
31
+ } catch (u) {
32
+ i(u);
33
+ }
34
+ }, a = (c) => {
35
+ try {
36
+ o(t.throw(c));
37
+ } catch (u) {
38
+ i(u);
39
+ }
40
+ }, o = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(r, a);
41
+ o((t = t.apply(n, e)).next());
42
+ });
43
+ import { isEqual as nt, isEmpty as L, isBoolean as Kt, isString as P, truncate as Zt, isArray as Tt, isObject as Ot } from "lodash-es";
44
+ import { unref as b, computed as jt, isRef as te, reactive as ee, ref as se, defineComponent as ie, resolveComponent as yt, openBlock as ne, createBlock as re, h as R } from "vue";
45
+ var F = /* @__PURE__ */ ((n) => (n[n.SUPPRESS = 1] = "SUPPRESS", n[n.HIDDEN = 5] = "HIDDEN", n[n.INVISIBLE = 8] = "INVISIBLE", n[n.FULL = 10] = "FULL", n))(F || {});
46
+ const Et = 10, xt = new Set(
47
+ Object.values(F).filter((n) => typeof n == "number")
48
+ );
27
49
  ((n) => {
28
- function i(s) {
29
- return s.toUpperCase() === "SUPPRESS" ? 1 : s.toUpperCase() === "HIDDEN" ? 5 : s.toUpperCase() === "INVISIBLE" ? 8 : nt;
50
+ function e(i) {
51
+ return i.toUpperCase() === "SUPPRESS" ? 1 : i.toUpperCase() === "HIDDEN" ? 5 : i.toUpperCase() === "INVISIBLE" ? 8 : Et;
30
52
  }
31
- n.fromString = i;
32
- function t(s) {
33
- const r = typeof s == "number" ? s : n.fromString(s);
34
- return Object.values(n).includes(r) ? r : nt;
53
+ n.fromString = e;
54
+ function t(i) {
55
+ const r = typeof i == "number" ? i : n.fromString(i);
56
+ return xt.has(r) ? r : Et;
35
57
  }
36
58
  n.fromAny = t;
37
- function e(s) {
38
- const r = typeof s == "number" ? s : n.fromString(s);
39
- return Object.values(n).includes(r);
40
- }
41
- n.isDefined = e;
42
- })(T || (T = {}));
43
- Object.freeze(T);
44
- const S = T;
45
- class m {
46
- constructor(i) {
47
- o(this, "executorFn");
48
- this.executorFn = i;
59
+ function s(i) {
60
+ const r = typeof i == "number" ? i : n.fromString(i);
61
+ return xt.has(r);
62
+ }
63
+ n.isDefined = s;
64
+ })(F || (F = {}));
65
+ Object.freeze(F);
66
+ const N = F;
67
+ class y {
68
+ constructor(e) {
69
+ d(this, "executorFn");
70
+ /**
71
+ * What this action remembers about one of the elements it serves. An action instance is shared - a `List` row
72
+ * carries the instances the item template carries - so anything an action holds about the element it last ran
73
+ * over belongs to that element rather than to the action: a verdict, a sequence number, a listener it installed.
74
+ * The keys are weak, so what an action remembers about a row is released with the row.
75
+ */
76
+ d(this, "states", /* @__PURE__ */ new WeakMap());
77
+ this.executorFn = e;
49
78
  }
50
79
  static get classIdentifier() {
51
80
  throw new Error("classIdentifier must be declared");
@@ -53,60 +82,295 @@ class m {
53
82
  get classIdentifier() {
54
83
  return this.constructor.classIdentifier;
55
84
  }
56
- execute(i, t, ...e) {
57
- return this.executorFn(i, t, ...e);
85
+ /**
86
+ * This action's state for `key`, created by `init` the first time it is asked for. The key is the element the
87
+ * action is running over, or the record that element belongs to where what is remembered is a fact about the
88
+ * whole record.
89
+ */
90
+ state(e, t) {
91
+ return this.states.has(e) || this.states.set(e, t()), this.states.get(e);
92
+ }
93
+ execute(e, t, ...s) {
94
+ return this.executorFn(e, t, ...s);
58
95
  }
59
96
  get eager() {
60
97
  return !1;
61
98
  }
99
+ /**
100
+ * Announces that this action now serves `binding`. It runs once per element the action is registered on, the
101
+ * copies of that element included: a copy takes on the instances it was copied from and each is told about the
102
+ * copy as it does.
103
+ */
62
104
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
63
- boundToField(i) {
105
+ boundToBinding(e) {
64
106
  }
65
- unregister() {
107
+ /**
108
+ * Announces that `binding` no longer holds this action. It names one element rather than the action as a whole,
109
+ * because the instance goes on serving every other element it was registered on.
110
+ */
111
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
112
+ unregisterFrom(e) {
66
113
  }
67
114
  }
68
- class W extends Error {
115
+ class rt extends Error {
69
116
  }
70
- const lt = /* @__PURE__ */ Symbol("ValueChangedAction");
71
- class y extends m {
72
- constructor(i) {
73
- super(i);
117
+ const B = /* @__PURE__ */ Symbol("ValueChangedAction");
118
+ class O extends y {
119
+ constructor(e) {
120
+ super(e);
74
121
  }
75
122
  static get classIdentifier() {
76
- return lt;
123
+ return B;
124
+ }
125
+ execute(e, t, s, i) {
126
+ return super.execute(e, t, s, i);
127
+ }
128
+ }
129
+ const z = /* @__PURE__ */ Symbol("Transaction.capture"), Pt = /* @__PURE__ */ Symbol("Transaction.restore"), Ft = /* @__PURE__ */ Symbol("Transaction.announceValue"), Nt = /* @__PURE__ */ Symbol("Transaction.settleValidity");
130
+ function Ct(n) {
131
+ let e = 0, t = n.parent;
132
+ for (; t; )
133
+ e++, t = t.parent;
134
+ return e;
135
+ }
136
+ class ae {
137
+ constructor() {
138
+ d(this, "participants", /* @__PURE__ */ new Map());
139
+ /** work that stands only where the transaction commits; a rollback simply never does it */
140
+ d(this, "deferred", []);
141
+ /** what a rollback has to put back beyond the state slots, newest last */
142
+ d(this, "undo", []);
143
+ /** true once the transaction has been unwound, which is what tells a run started inside it to say nothing */
144
+ d(this, "unwound", !1);
145
+ /** the depth the announcement in progress is working at, -1 while none is */
146
+ d(this, "passDepth", -1);
147
+ /** set while a pass is running and an element it has already passed the depth of gets enrolled */
148
+ d(this, "restartPass", !1);
149
+ }
150
+ /** true for a transaction that was rolled back rather than committed */
151
+ get rolledBack() {
152
+ return this.unwound;
153
+ }
154
+ participant(e) {
155
+ let t = this.participants.get(e);
156
+ return t || (t = { element: e, valueDirty: !1, forceValue: !1, validityDirty: !1 }, this.participants.set(e, t)), t;
157
+ }
158
+ /**
159
+ * Records the state of an element the first time the transaction modifies it. The whole of the mutable state
160
+ * goes into the snapshot rather than the part being written: a rollback that restored some of it would leave
161
+ * the element in a state the form never held.
162
+ */
163
+ touch(e) {
164
+ const t = this.participant(e);
165
+ t.snapshot || (t.snapshot = e[z]());
166
+ }
167
+ /** Enrols an element as one whose value the commit has to announce. `force` skips the comparison. */
168
+ markValueChanged(e, t) {
169
+ const s = this.participant(e);
170
+ s.valueDirty = !0, t && (s.forceValue = !0), this.noteDepth(e);
171
+ }
172
+ /** Enrols an element as one whose verdict the commit has to re-form. */
173
+ markValidityDirty(e) {
174
+ this.participant(e).validityDirty = !0, this.noteDepth(e);
175
+ }
176
+ /**
177
+ * Queues an event that states an operation rather than a state. Added and removed items have no net over a
178
+ * transaction, so they are neither compared nor coalesced: the commit emits them in the order they happened.
179
+ */
180
+ recordStructural(e, t) {
181
+ var i;
182
+ const s = this.participant(e);
183
+ ((i = s.structural) != null ? i : s.structural = []).push(t), this.noteDepth(e);
184
+ }
185
+ /** True where the commit still owes this element a value announcement. */
186
+ willAnnounceValue(e) {
187
+ var t, s;
188
+ return (s = (t = this.participants.get(e)) == null ? void 0 : t.valueDirty) != null ? s : !1;
189
+ }
190
+ /**
191
+ * Registers work the commit does once everything has been announced. It is for what a rollback could not take
192
+ * back: releasing a listener, dropping a registration. Held until the commit, it is simply never done where the
193
+ * transaction unwinds instead.
194
+ */
195
+ whenCommitted(e) {
196
+ this.deferred.push(e);
197
+ }
198
+ /**
199
+ * Registers what a rollback has to put back beyond the element's state slots. The snapshot covers the slots,
200
+ * which is everything an ordinary write touches; an operation that replaces something else the element carries
201
+ * hands its own undo in here rather than making every snapshot carry the thing.
202
+ */
203
+ whenRolledBack(e) {
204
+ this.undo.push(e);
205
+ }
206
+ /**
207
+ * Notes that an element at or below the depth the pass in progress is working at has been enrolled. The pass
208
+ * then gives up the rest of its batch and is started again over what is now owed, so the newcomer is reached
209
+ * before the containers above it: an element a handler writes must still be announced before the container
210
+ * whose composed value carries that write. The depth is only measured while a pass is running - outside one
211
+ * there is nothing the answer would change.
212
+ */
213
+ noteDepth(e) {
214
+ this.passDepth < 0 || Ct(e) >= this.passDepth && (this.restartPass = !0);
215
+ }
216
+ /**
217
+ * Puts every element the transaction modified back as it found it. Nothing is announced: from an observer's
218
+ * point of view the transaction never happened. What a rollback cannot take back are side effects - a handler
219
+ * that called a server during the transaction already did.
220
+ */
221
+ rollback() {
222
+ this.unwound = !0, [...this.participants.values()].reverse().forEach((t) => {
223
+ t.snapshot && t.element[Pt](t.snapshot);
224
+ }), this.participants.clear();
225
+ for (let t = this.undo.length - 1; t >= 0; t--) this.undo[t]();
226
+ this.undo.length = 0, this.deferred.length = 0;
227
+ }
228
+ /**
229
+ * Announces what the transaction did. Values first and verdicts after, because a container's validators run
230
+ * with its value announcement and the verdict they reach is what the validity pass then reports. Both passes
231
+ * run deepest first - field, then row, then list - which is the order the change travelled in.
232
+ *
233
+ * A handler may write while the commit runs; its writes join this transaction, so both passes repeat until
234
+ * nothing is left dirty.
235
+ */
236
+ commit() {
237
+ for (; !(!this.announceValues() && !this.settleValidity()); )
238
+ ;
239
+ this.deferred.splice(0).forEach((t) => t());
240
+ }
241
+ /**
242
+ * The dirty participants a pass has to visit, one bucket per nesting depth; ties keep the order they were
243
+ * enrolled in. A nesting depth is a small integer, so the elements go into buckets rather than through a
244
+ * comparison sort: a whole-list assignment enrols one participant per field, and ordering those by comparison
245
+ * would cost more than the announcement it orders.
246
+ */
247
+ buckets(e) {
248
+ const t = [];
249
+ return this.participants.forEach((s) => {
250
+ var r;
251
+ if (!e(s)) return;
252
+ const i = Ct(s.element);
253
+ ((r = t[i]) != null ? r : t[i] = []).push(s);
254
+ }), t;
255
+ }
256
+ /**
257
+ * Runs one pass over the dirty participants, deepest bucket first; the caller repeats it until it answers
258
+ * false. The buckets are taken once, and the pass gives up as soon as a handler enrols an element at or below
259
+ * the depth being drained: that element is not in the bucket being walked, and going on would reach the
260
+ * containers above it first. The caller's next pass takes fresh buckets and finds it at its own depth.
261
+ */
262
+ pass(e, t) {
263
+ const s = this.buckets(e);
264
+ if (!s.length) return !1;
265
+ for (let i = s.length - 1; i >= 0; i--) {
266
+ const r = s[i];
267
+ if (r) {
268
+ this.passDepth = i, this.restartPass = !1;
269
+ try {
270
+ for (let a = 0; a < r.length; a++) {
271
+ if (this.restartPass) return !0;
272
+ const o = r[a];
273
+ e(o) && t(o);
274
+ }
275
+ } finally {
276
+ this.passDepth = -1;
277
+ }
278
+ if (this.restartPass) return !0;
279
+ }
280
+ }
281
+ return !0;
77
282
  }
78
- execute(i, t, e, s) {
79
- return super.execute(i, t, e, s);
283
+ announceValues() {
284
+ return this.pass(
285
+ (e) => e.valueDirty || e.structural !== void 0,
286
+ (e) => {
287
+ const { structural: t } = e, s = e.valueDirty, i = e.forceValue;
288
+ e.structural = void 0, e.valueDirty = !1, e.forceValue = !1, e.element[Ft](this, s, i, t);
289
+ }
290
+ );
291
+ }
292
+ settleValidity() {
293
+ return this.pass(
294
+ (e) => e.validityDirty,
295
+ (e) => {
296
+ e.validityDirty = !1, e.element[Nt](this);
297
+ }
298
+ );
80
299
  }
81
300
  }
82
- const ot = { useMarkdownInValidators: !0 };
83
- function Pt() {
84
- return ot;
301
+ let _, et;
302
+ function kt() {
303
+ return _;
85
304
  }
86
- function wt(n) {
87
- Object.assign(ot, n);
305
+ class Rt {
88
306
  }
89
- const he = {
90
- install(n, i) {
91
- i && wt(i);
307
+ class oe {
308
+ constructor() {
309
+ d(this, "open", !0);
310
+ }
311
+ rollback() {
312
+ throw this.open ? new Rt() : new TypeError(
313
+ "this transaction handle is spent: the transaction that handed it out has closed. A handle is only usable inside the call that received it."
314
+ );
315
+ }
316
+ close() {
317
+ this.open = !1;
318
+ }
319
+ }
320
+ function St(n) {
321
+ if (n != null && typeof n.then == "function")
322
+ throw new TypeError(
323
+ "a transaction may not be asynchronous: the callback returned a thenable. Do the awaiting outside and open a transaction for each synchronous part."
324
+ );
325
+ }
326
+ function ot(n) {
327
+ if (_) {
328
+ const s = n(et);
329
+ return St(s), s;
330
+ }
331
+ const e = new ae(), t = new oe();
332
+ _ = e, et = t;
333
+ try {
334
+ const s = n(t);
335
+ return St(s), e.commit(), s;
336
+ } catch (s) {
337
+ if (e.rollback(), s instanceof Rt) return;
338
+ throw s;
339
+ } finally {
340
+ _ = void 0, et = void 0, t.close();
341
+ }
342
+ }
343
+ function g(n) {
344
+ return _ ? n(_) : ot(() => n(_));
345
+ }
346
+ const Dt = { useMarkdownInValidators: !0 };
347
+ function le() {
348
+ return Dt;
349
+ }
350
+ function ce(n) {
351
+ Object.assign(Dt, n);
352
+ }
353
+ const Ye = {
354
+ install(n, e) {
355
+ e && ce(e);
92
356
  }
93
357
  };
94
- class O extends String {
95
- constructor(t, e, s) {
358
+ class U extends String {
359
+ constructor(t, s, i) {
96
360
  super(t);
97
- o(this, "plugins");
98
- o(this, "options");
99
- this.plugins = s, this.options = e;
361
+ d(this, "plugins");
362
+ d(this, "options");
363
+ this.plugins = i, this.options = s;
100
364
  }
101
365
  }
102
- function X(n) {
103
- const i = h(n);
104
- return typeof i == "object" && "componentName" in i;
366
+ function lt(n) {
367
+ const e = b(n);
368
+ return typeof e == "object" && "componentName" in e;
105
369
  }
106
- function k(n) {
107
- return typeof h(n) == "function";
370
+ function H(n) {
371
+ return typeof b(n) == "function";
108
372
  }
109
- class G {
373
+ class ct {
110
374
  get componentName() {
111
375
  return "Comment";
112
376
  }
@@ -120,12 +384,12 @@ class G {
120
384
  return "";
121
385
  }
122
386
  }
123
- class Ft extends G {
124
- constructor(t, e = "") {
387
+ class ue extends ct {
388
+ constructor(t, s = "") {
125
389
  super();
126
- o(this, "text");
127
- o(this, "classes");
128
- this.text = t, this.classes = e;
390
+ d(this, "text");
391
+ d(this, "classes");
392
+ this.text = t, this.classes = s;
129
393
  }
130
394
  get componentName() {
131
395
  return "template";
@@ -137,24 +401,24 @@ class Ft extends G {
137
401
  return this.classes;
138
402
  }
139
403
  }
140
- class g extends G {
141
- constructor(t, e = "") {
404
+ class V extends ct {
405
+ constructor(t, s = "") {
142
406
  super();
143
- o(this, "classes");
144
- o(this, "text");
145
- o(this, "textType");
146
- this.classes = e, this.text = t, this.textType = xt(() => this.getTextType);
407
+ d(this, "classes");
408
+ d(this, "text");
409
+ d(this, "textType");
410
+ this.classes = s, this.text = t, this.textType = jt(() => this.getTextType);
147
411
  }
148
412
  get resolvedText() {
149
- const t = h(this.text);
150
- return k(t) ? t() : t;
413
+ const t = b(this.text);
414
+ return H(t) ? t() : t;
151
415
  }
152
416
  get getTextType() {
153
417
  const t = this.resolvedText;
154
- return t ? t instanceof O ? "md" : X(t) ? "component" : "string" : "string";
418
+ return t ? t instanceof U ? "md" : lt(t) ? "component" : "string" : "string";
155
419
  }
156
420
  get componentName() {
157
- switch (h(this.textType)) {
421
+ switch (b(this.textType)) {
158
422
  case "string":
159
423
  return "template";
160
424
  case "md":
@@ -166,7 +430,7 @@ class g extends G {
166
430
  }
167
431
  }
168
432
  get componentBindings() {
169
- switch (h(this.textType)) {
433
+ switch (b(this.textType)) {
170
434
  case "string":
171
435
  return {};
172
436
  case "md": {
@@ -180,7 +444,7 @@ class g extends G {
180
444
  }
181
445
  }
182
446
  get componentBody() {
183
- switch (h(this.textType)) {
447
+ switch (b(this.textType)) {
184
448
  case "string":
185
449
  return this.resolvedText;
186
450
  case "component":
@@ -193,52 +457,42 @@ class g extends G {
193
457
  return this.classes;
194
458
  }
195
459
  }
196
- class jt extends g {
460
+ class he extends V {
197
461
  }
198
- function b(n) {
199
- return Pt().useMarkdownInValidators ? new O(n) : n.replace(/[*_~`]/g, "").replace(/!\[(.*?)\]\(.*?\)/g, "$1").replace(/\[(.*?)\]\((.*?)\)/g, "$1").replace(/#+\s?/g, "").replace(/>\s?/g, "").replace(/(\*|-|\d+\.)\s+/g, "").replace(/`{3}[\s\S]*?`{3}/g, "").replace(/`([^`]+)`/g, "$1").replace(/\n{2,}/g, `
462
+ function E(n) {
463
+ return le().useMarkdownInValidators ? new U(n) : n.replace(/[*_~`]/g, "").replace(/!\[(.*?)\]\(.*?\)/g, "$1").replace(/\[(.*?)\]\((.*?)\)/g, "$1").replace(/#+\s?/g, "").replace(/>\s?/g, "").replace(/(\*|-|\d+\.)\s+/g, "").replace(/`{3}[\s\S]*?`{3}/g, "").replace(/`([^`]+)`/g, "$1").replace(/\n{2,}/g, `
200
464
  `);
201
465
  }
202
- const Nt = /* @__PURE__ */ Symbol("Validator"), Tt = () => b("Validation could not be completed");
203
- class f extends y {
466
+ const de = /* @__PURE__ */ Symbol("Validator"), ge = () => E("Validation could not be completed");
467
+ class v extends O {
204
468
  /**
205
469
  * Creates a new validator
206
470
  * @param validationFn Function that validates the field value and returns errors or null
207
471
  */
208
472
  constructor(t) {
209
- super((s, r, a, l) => {
210
- var B;
211
- const u = ((B = this.runs.get(s)) != null ? B : 0) + 1;
212
- this.runs.set(s, u);
213
- const d = s.validationEpoch, x = () => this.runs.get(s) === u && s.validationEpoch === d, _ = t(a, l, s) || [], P = (p) => {
214
- var K;
215
- const E = (K = p == null ? void 0 : p.map((I) => this.claim(I))) != null ? K : [];
216
- for (let I = s.errors.length - 1; I >= 0; I--) {
217
- const Z = s.errors[I];
218
- if (Z.source === this.source) {
219
- const tt = E.findIndex((mt) => D(mt, Z));
220
- tt >= 0 ? E.splice(tt, 1) : s.errors.splice(I, 1);
473
+ super((i, r, a, o) => {
474
+ const c = this.bindingState(i), u = ++c.run, C = i.validationEpoch, G = kt(), dt = () => c.run === u && i.validationEpoch === C && !(G != null && G.rolledBack), Y = t(a, o, i) || [], J = (S) => ot(() => {
475
+ var gt;
476
+ const $ = (gt = S == null ? void 0 : S.map((j) => this.claim(j))) != null ? gt : [];
477
+ for (let j = i.errors.length - 1; j >= 0; j--) {
478
+ const ft = i.errors[j];
479
+ if (ft.source === this.source) {
480
+ const pt = $.findIndex((Xt) => nt(Xt, ft));
481
+ pt >= 0 ? $.splice(pt, 1) : i.errors.splice(j, 1);
221
482
  }
222
483
  }
223
- E.length > 0 && s.errors.push(...E), s.validate();
224
- };
225
- return _ instanceof Promise ? (s.beginValidating(), _.then(
226
- (p) => {
227
- x() && P(p);
484
+ $.length > 0 && i.errors.push(...$), i.validate();
485
+ });
486
+ return Y instanceof Promise ? (i.beginValidating(), Y.then(
487
+ (S) => {
488
+ dt() && J(S);
228
489
  },
229
- (p) => {
230
- x() && (P([new g(Tt())]), console.error("Validation failed", p));
490
+ (S) => {
491
+ dt() && (J([new V(ge())]), console.error("Validation failed", S));
231
492
  }
232
- ).finally(() => s.endValidating()).catch((p) => console.error("Validation failed", p))) : P(_), r(s, a, l);
493
+ ).finally(() => i.endValidating()).catch((S) => console.error("Validation failed", S))) : J(Y), r(i, a, o);
233
494
  });
234
- o(this, "source");
235
- /**
236
- * Sequence number of the newest run of this validator, per field. Every execution takes the next number, and a
237
- * result is applied only while its number is still the newest one, so a slow run cannot overwrite the verdict of
238
- * a faster one that started after it. The key is the field because one validator instance may be registered on
239
- * several fields, each with a sequence of its own.
240
- */
241
- o(this, "runs", /* @__PURE__ */ new WeakMap());
495
+ d(this, "source");
242
496
  this.source = Symbol(this.constructor.name);
243
497
  }
244
498
  /**
@@ -249,139 +503,262 @@ class f extends y {
249
503
  * including the non-enumerable ones, so it renders exactly like the instance it was made from.
250
504
  */
251
505
  claim(t) {
252
- const e = t.source;
253
- if (e === this.source) return t;
254
- const s = { value: this.source, enumerable: !1, configurable: !1 };
255
- if (e === void 0)
256
- return Object.defineProperty(t, "source", s), t;
506
+ const s = t.source;
507
+ if (s === this.source) return t;
508
+ const i = { value: this.source, enumerable: !1, configurable: !1 };
509
+ if (s === void 0)
510
+ return Object.defineProperty(t, "source", i), t;
257
511
  const r = Object.getOwnPropertyDescriptors(t);
258
- return Object.create(Object.getPrototypeOf(t), w(v({}, r), { source: s }));
512
+ return Object.create(Object.getPrototypeOf(t), x(p({}, r), { source: i }));
259
513
  }
260
514
  static get classIdentifier() {
261
- return Nt;
515
+ return de;
262
516
  }
263
517
  get eager() {
264
518
  return !0;
265
519
  }
266
- replacePlaceholdersFunction(t, e) {
520
+ /**
521
+ * What this validator remembers about one of the fields it validates. One instance may be registered on several
522
+ * fields - every row of a list carries the instances the item template carries - so each field has a record of
523
+ * its own. A subclass that remembers more widens the record by overriding `newBindingState`.
524
+ */
525
+ bindingState(t) {
526
+ return this.state(t, () => this.newBindingState());
527
+ }
528
+ /**
529
+ * The record a field starts with. `run` is the sequence number of the newest run over that field: every
530
+ * execution takes the next one and a result is applied only while its number is still the newest, so a slow run
531
+ * cannot overwrite the verdict of a faster one that started after it.
532
+ */
533
+ newBindingState() {
534
+ return { run: 0 };
535
+ }
536
+ replacePlaceholdersFunction(t, s) {
267
537
  return () => {
268
- let s = h(t);
269
- for (; k(s); )
270
- s = h(this.replacePlaceholders(s(), e));
271
- return s;
538
+ let i = b(t);
539
+ for (; H(i); )
540
+ i = b(this.replacePlaceholders(i(), s));
541
+ return i;
272
542
  };
273
543
  }
274
- replacePlaceholders(t, e) {
275
- if (k(t)) return this.replacePlaceholdersFunction(t, e);
276
- if (X(t)) return t;
277
- if (_t(t))
278
- return this.replacePlaceholdersFunction(() => h(t), e);
279
- let s = h(t);
280
- return Object.keys(e).forEach((r) => {
281
- s = s.replaceAll(`{${r}}`, e[r]);
282
- }), t instanceof O ? new O(s.toString(), t.options, t.plugins) : s;
544
+ replacePlaceholders(t, s) {
545
+ if (H(t)) return this.replacePlaceholdersFunction(t, s);
546
+ if (lt(t)) return t;
547
+ if (te(t))
548
+ return this.replacePlaceholdersFunction(() => b(t), s);
549
+ let i = b(t);
550
+ return Object.keys(s).forEach((r) => {
551
+ i = i.replaceAll(`{${r}}`, s[r]);
552
+ }), t instanceof U ? new U(i.toString(), t.options, t.plugins) : i;
283
553
  }
284
554
  }
285
- class L extends Map {
555
+ class M extends Map {
286
556
  constructor() {
287
557
  super(...arguments);
288
- o(this, "eagerActions", /* @__PURE__ */ new Set());
289
- o(this, "registeredActions", []);
558
+ d(this, "eagerActions", /* @__PURE__ */ new Set());
559
+ d(this, "registeredActions", []);
290
560
  }
291
561
  register(t) {
292
- if (!(t instanceof m)) throw new Error("Invalid action type");
562
+ if (!(t instanceof y)) throw new Error("Invalid action type");
293
563
  this.registeredActions.push(t);
294
- const e = t.classIdentifier, s = this.get(e) || (() => null);
295
- function r(a, ...l) {
296
- return t.execute(a, s, ...l);
564
+ const s = t.classIdentifier, i = this.get(s) || (() => null);
565
+ function r(a, ...o) {
566
+ return t.execute(a, i, ...o);
297
567
  }
298
- this.set(e, r), t.eager && this.eagerActions.add(t.classIdentifier);
568
+ this.set(s, r), t.eager && this.eagerActions.add(t.classIdentifier);
569
+ }
570
+ /**
571
+ * True when triggering this action would run something: a handler registered under the identifier, or - on the
572
+ * value change identifier, which trigger() answers with an eager pass as well - any eager action at all. A
573
+ * caller that has to build the parameters before it can trigger asks this first and skips building them when
574
+ * there is nothing to receive them.
575
+ */
576
+ willTrigger(t) {
577
+ return this.has(t) ? !0 : t === B && this.eagerActions.size > 0;
299
578
  }
300
- trigger(t, e, ...s) {
579
+ trigger(t, s, ...i) {
301
580
  const r = t.classIdentifier;
302
- r === lt && this.triggerEager(e, ...s);
303
- const a = this.get(r);
581
+ return r === B && this.triggerEager(s, ...i), this.triggerChain(r, s, ...i);
582
+ }
583
+ /**
584
+ * Runs the chain registered under one identifier and nothing else. A caller that has already run the eager
585
+ * pass - a transaction runs it at the write, so that the validators have decided before it commits - reaches
586
+ * the handlers through here, so the eager actions are not run a second time at the announcement.
587
+ */
588
+ triggerChain(t, s, ...i) {
589
+ const r = this.get(t);
304
590
  try {
305
- if (a) return a(e, ...s);
306
- } catch (l) {
307
- if (!(l instanceof W)) throw l;
591
+ if (r) return r(s, ...i);
592
+ } catch (a) {
593
+ if (!(a instanceof rt)) throw a;
308
594
  }
309
595
  return null;
310
596
  }
311
- triggerEager(t, ...e) {
312
- for (const s of this.eagerActions) {
313
- const r = this.get(s);
597
+ triggerEager(t, ...s) {
598
+ for (const i of this.eagerActions) {
599
+ const r = this.get(i);
314
600
  try {
315
- r && r(t, ...e);
601
+ r && r(t, ...s);
316
602
  } catch (a) {
317
- if (!(a instanceof W)) throw a;
603
+ if (!(a instanceof rt)) throw a;
318
604
  }
319
605
  }
320
606
  }
607
+ /** the validators registered in this map, in registration order */
608
+ get validators() {
609
+ return this.registeredActions.filter((t) => t instanceof v);
610
+ }
321
611
  clone() {
322
- const t = new L();
323
- return this.registeredActions.forEach((e) => t.register(e)), t;
612
+ const t = new M();
613
+ return this.registeredActions.forEach((s) => t.register(s)), t;
614
+ }
615
+ /**
616
+ * Tells every action in this map that it serves `owner`. A copied map holds the instances the original holds, so
617
+ * the element that took the copy on is announced to them here, the way registering an action announces the
618
+ * element it was registered on.
619
+ */
620
+ bindTo(t) {
621
+ this.registeredActions.forEach((s) => s.boundToBinding(t));
324
622
  }
623
+ /**
624
+ * A copy of this map carrying everything but the validators. It only leaves them out: releasing what a
625
+ * validator installed elsewhere is the caller's to do, and only once the transaction that dropped them has
626
+ * committed, because a rollback puts this map back with its validators in it.
627
+ */
325
628
  cloneWithoutValidators() {
326
- const t = new L();
327
- return this.registeredActions.forEach((e) => {
328
- e instanceof f ? e.unregister() : t.register(e);
629
+ const t = new M();
630
+ return this.registeredActions.forEach((s) => {
631
+ s instanceof v || t.register(s);
329
632
  }), t;
330
633
  }
331
634
  }
332
- const Ot = /* @__PURE__ */ Symbol("ConditionalStatementAction");
333
- class M extends y {
334
- constructor(t, e) {
335
- const s = (r, a, l, u) => {
336
- const d = t.evaluate();
337
- if (d !== this.lastResult) {
338
- for (const x of this.boundFields)
339
- e(x, d, this.lastResult);
340
- this.lastResult = d;
341
- }
342
- return a(r, l, u);
343
- };
344
- super(s);
345
- o(this, "lastResult");
346
- // boundField tracks the fields this action is bound to. so that it may perform the executorFn on them and not on the
347
- // ValueChangedAction fields that will call the actionExecutor
348
- o(this, "boundFields", /* @__PURE__ */ new Set());
349
- t.collectFields().forEach((r) => r.registerAction(new y(s)));
635
+ function T(n) {
636
+ let e = n;
637
+ for (; e.fieldName !== void 0 && e.parent; ) e = e.parent;
638
+ return e;
639
+ }
640
+ function fe(n) {
641
+ const e = [];
642
+ let t = n;
643
+ for (; t.fieldName !== void 0 && t.parent; )
644
+ e.unshift(t.fieldName), t = t.parent;
645
+ return e;
646
+ }
647
+ function ut(n, e) {
648
+ var s, i;
649
+ let t = e;
650
+ for (const r of fe(n))
651
+ if (t = (i = (s = t.field) == null ? void 0 : s.call(t, r)) != null ? i : void 0, !t) break;
652
+ return (t == null ? void 0 : t.declaration) === n ? t : T(n) === T(e.declaration) ? void 0 : n;
653
+ }
654
+ function Lt(n, e) {
655
+ const t = ut(n, e);
656
+ if (!t) return [];
657
+ if (t !== n) return [t];
658
+ const s = e.bindingsOf(n);
659
+ return s.length > 0 ? s : [n];
660
+ }
661
+ function pe(n, e) {
662
+ var s;
663
+ let t = e.parent;
664
+ for (; t; ) {
665
+ const i = (s = t.field) == null ? void 0 : s.call(t, n);
666
+ if (i) return i;
667
+ t = t.parent;
668
+ }
669
+ }
670
+ const me = /* @__PURE__ */ Symbol("ConditionalStatementAction");
671
+ class Q extends O {
672
+ constructor(t, s) {
673
+ super((r, a, o, c) => (this.applyIn(T(r)) || r.markRecordIncomplete(), a(r, o, c)));
674
+ d(this, "statement");
675
+ d(this, "conditionalExecutor");
676
+ /**
677
+ * What the elements this action was registered on were declared as. It holds declarations rather than the
678
+ * elements themselves, so one entry stands for every row of a list, and the element a result is applied to is
679
+ * the one that declaration names within the record the change happened in.
680
+ */
681
+ d(this, "declarations", /* @__PURE__ */ new Set());
682
+ /**
683
+ * The elements this action was registered on. Registration reaches one element at a time - the rows of a list
684
+ * take the action on one by one, as they are built from the item template that carries it - so this is what
685
+ * says which of the elements a declaration stands for the action actually drives.
686
+ */
687
+ d(this, "registrations", /* @__PURE__ */ new WeakSet());
688
+ this.statement = t, this.conditionalExecutor = s;
689
+ const i = new O((r, a, ...o) => (this.applyFrom(r), a(r, ...o)));
690
+ t.collectFields().forEach((r) => r.registerAction(i));
350
691
  }
351
692
  static get classIdentifier() {
352
- return Ot;
693
+ return me;
353
694
  }
354
695
  get eager() {
355
696
  return !0;
356
697
  }
357
- boundToField(t) {
358
- this.boundFields.add(t);
698
+ boundToBinding(t) {
699
+ this.declarations.add(t.declaration), this.registrations.add(t);
700
+ }
701
+ /**
702
+ * The elements of `scope` this action controls: what each declaration it serves names within that record, and of
703
+ * those the ones that took the action on. A row of a list that never took it on is not one this action drives.
704
+ */
705
+ targetsIn(t) {
706
+ const s = [];
707
+ return this.declarations.forEach(
708
+ (i) => Lt(i, t).forEach((r) => {
709
+ this.registrations.has(r) && s.push(r);
710
+ })
711
+ ), s;
712
+ }
713
+ /**
714
+ * Re-evaluates the statement over one record and applies the result where it changed. The result is recorded
715
+ * before the executor runs, because an executor that writes a value re-enters through that value's eager pass
716
+ * and what it has to find there is the result being applied. It answers whether the record held anything for
717
+ * this action to drive, which is how a caller learns that the record is not assembled yet.
718
+ */
719
+ applyIn(t) {
720
+ const s = this.targetsIn(t);
721
+ if (s.length === 0) return !1;
722
+ const i = this.state(t, () => ({ lastResult: void 0 })), r = this.statement.evaluate(t);
723
+ if (r === i.lastResult) return !0;
724
+ const a = i.lastResult;
725
+ return i.lastResult = r, s.forEach((o) => this.conditionalExecutor(o, r, a)), !0;
726
+ }
727
+ /**
728
+ * Re-evaluates the records a change of `source` speaks for. A field of the record the targets live in speaks for
729
+ * that record alone, which is what keeps one row of a list from answering for another; a field above them - a
730
+ * form field every row reads - speaks for every record below it, and for the record the action was declared in
731
+ * where the change reaches none.
732
+ */
733
+ applyFrom(t) {
734
+ const s = /* @__PURE__ */ new Set();
735
+ this.targetsIn(T(t)).forEach((i) => s.add(T(i))), s.forEach((i) => this.applyIn(i));
359
736
  }
360
737
  }
361
- class Lt extends M {
362
- constructor(i) {
363
- super(i, (t, e) => {
364
- t.visibility = e ? S.FULL : S.SUPPRESS;
738
+ class be extends Q {
739
+ constructor(e) {
740
+ super(e, (t, s) => {
741
+ t.visibility = s ? N.FULL : N.SUPPRESS;
365
742
  });
366
743
  }
367
744
  }
368
- class Rt extends M {
369
- constructor(i) {
370
- super(i, (t, e) => {
371
- t.enabled = e;
745
+ class ve extends Q {
746
+ constructor(e) {
747
+ super(e, (t, s) => {
748
+ t.enabled = s;
372
749
  });
373
750
  }
374
751
  }
375
- class Bt extends M {
376
- constructor(i, t) {
377
- super(i, (e, s) => {
378
- s && (e.value = t);
752
+ class Ve extends Q {
753
+ constructor(e, t) {
754
+ super(e, (s, i) => {
755
+ i && (s.value = t);
379
756
  });
380
757
  }
381
758
  }
382
- var R = /* @__PURE__ */ ((n) => (n[n.NOT = 0] = "NOT", n[n.OR = 1] = "OR", n[n.AND = 2] = "AND", n[n.XOR = 3] = "XOR", n[n.NAND = 4] = "NAND", n[n.NOR = 5] = "NOR", n[n.EQUALS = -1] = "EQUALS", n[n.NOT_EQUALS = -2] = "NOT_EQUALS", n[n.GT = -3] = "GT", n[n.LT = -4] = "LT", n[n.GE = -5] = "GE", n[n.LE = -6] = "LE", n[n.IN = -7] = "IN", n[n.NOT_IN = -8] = "NOT_IN", n[n.INCLUDES = -9] = "INCLUDES", n[n.NOT_INCLUDES = -10] = "NOT_INCLUDES", n))(R || {});
759
+ var W = /* @__PURE__ */ ((n) => (n[n.NOT = 0] = "NOT", n[n.OR = 1] = "OR", n[n.AND = 2] = "AND", n[n.XOR = 3] = "XOR", n[n.NAND = 4] = "NAND", n[n.NOR = 5] = "NOR", n[n.EQUALS = -1] = "EQUALS", n[n.NOT_EQUALS = -2] = "NOT_EQUALS", n[n.GT = -3] = "GT", n[n.LT = -4] = "LT", n[n.GE = -5] = "GE", n[n.LE = -6] = "LE", n[n.IN = -7] = "IN", n[n.NOT_IN = -8] = "NOT_IN", n[n.INCLUDES = -9] = "INCLUDES", n[n.NOT_INCLUDES = -10] = "NOT_INCLUDES", n))(W || {});
383
760
  ((n) => {
384
- function i(r) {
761
+ function e(r) {
385
762
  const a = r.toLowerCase();
386
763
  if (a === "not") return 0;
387
764
  if (a === "or") return 1;
@@ -401,185 +778,566 @@ var R = /* @__PURE__ */ ((n) => (n[n.NOT = 0] = "NOT", n[n.OR = 1] = "OR", n[n.A
401
778
  if (["not_includes", "not-includes", "not includes"].includes(a)) return -10;
402
779
  throw new Error(`Unrecognised operator ${a}`);
403
780
  }
404
- n.fromString = i;
781
+ n.fromString = e;
405
782
  function t(r) {
406
783
  const a = typeof r == "number" ? r : n.fromString(r);
407
784
  if (Object.values(n).includes(a)) return a;
408
785
  throw new Error(`Unrecognised operator ${r}`);
409
786
  }
410
787
  n.fromAny = t;
411
- function e(r) {
788
+ function s(r) {
412
789
  const a = typeof r == "number" ? r : n.fromString(r);
413
790
  return Object.values(n).includes(a);
414
791
  }
415
- n.isDefined = e;
416
- function s(r) {
792
+ n.isDefined = s;
793
+ function i(r) {
417
794
  return r >= 0;
418
795
  }
419
- n.isLogicOperator = s;
420
- })(R || (R = {}));
421
- Object.freeze(R);
422
- const c = R, Ut = /* @__PURE__ */ Symbol("EnabledChangingAction");
423
- class ut extends m {
424
- constructor(i) {
425
- super(i);
796
+ n.isLogicOperator = i;
797
+ })(W || (W = {}));
798
+ Object.freeze(W);
799
+ const m = W, we = /* @__PURE__ */ Symbol("EnabledChangingAction");
800
+ class Bt extends y {
801
+ constructor(e) {
802
+ super(e);
426
803
  }
427
804
  static get classIdentifier() {
428
- return Ut;
805
+ return we;
429
806
  }
430
- execute(i, t, e, s) {
431
- return super.execute(i, t, e, s);
807
+ execute(e, t, s, i) {
808
+ return super.execute(e, t, s, i);
432
809
  }
433
810
  }
434
- const kt = /* @__PURE__ */ Symbol("EnabledChangedAction");
435
- class ct extends m {
436
- constructor(i) {
437
- super(i);
811
+ const ye = /* @__PURE__ */ Symbol("EnabledChangedAction");
812
+ class Ut extends y {
813
+ constructor(e) {
814
+ super(e);
438
815
  }
439
816
  static get classIdentifier() {
440
- return kt;
817
+ return ye;
441
818
  }
442
- execute(i, t, e, s) {
443
- return super.execute(i, t, e, s);
819
+ execute(e, t, s, i) {
820
+ return super.execute(e, t, s, i);
444
821
  }
445
822
  }
446
- const Dt = /* @__PURE__ */ Symbol("ValidChangedAction");
447
- class ht extends m {
448
- constructor(i) {
449
- super(i);
823
+ const Ee = /* @__PURE__ */ Symbol("ValidChangedAction");
824
+ class Mt extends y {
825
+ constructor(e) {
826
+ super(e);
450
827
  }
451
828
  static get classIdentifier() {
452
- return Dt;
829
+ return Ee;
453
830
  }
454
- execute(i, t, e, s) {
455
- return super.execute(i, t, e, s);
831
+ execute(e, t, s, i) {
832
+ return super.execute(e, t, s, i);
456
833
  }
457
834
  }
458
- const Mt = /* @__PURE__ */ Symbol("VisibilityChangingAction");
459
- class dt extends m {
460
- constructor(i) {
461
- super(i);
835
+ const xe = /* @__PURE__ */ Symbol("VisibilityChangingAction");
836
+ class Wt extends y {
837
+ constructor(e) {
838
+ super(e);
462
839
  }
463
840
  static get classIdentifier() {
464
- return Mt;
841
+ return xe;
465
842
  }
466
- execute(i, t, e, s) {
467
- return super.execute(i, t, e, s);
843
+ execute(e, t, s, i) {
844
+ return super.execute(e, t, s, i);
468
845
  }
469
846
  }
470
- const $t = /* @__PURE__ */ Symbol("VisibilityChangedAction");
471
- class gt extends m {
472
- constructor(i) {
473
- super(i);
847
+ const Ce = /* @__PURE__ */ Symbol("VisibilityChangedAction");
848
+ class $t extends y {
849
+ constructor(e) {
850
+ super(e);
474
851
  }
475
852
  static get classIdentifier() {
476
- return $t;
853
+ return Ce;
477
854
  }
478
- execute(i, t, e, s) {
479
- return super.execute(i, t, e, s);
855
+ execute(e, t, s, i) {
856
+ return super.execute(e, t, s, i);
480
857
  }
481
858
  }
482
- class V {
483
- /**
484
- * A field is a Vue reactive proxy from construction onwards: the base constructor returns the proxy, and a
485
- * derived class's `this` is whatever super() returned, so every subclass constructor, field initializer and
486
- * method sees the proxy. Consequence: plain `field.property = value` is tracked, with no wrapper in between.
487
- */
488
- constructor() {
489
- // contains original field value as was provided at creation
490
- o(this, "validatingCount", 0);
491
- o(this, "_valid", !0);
492
- // is current value valid as per FE and BE validators?
493
- o(this, "errors", []);
494
- // when member of a Group, fieldName specifies the name of this field
495
- o(this, "actions", new L());
496
- // default property handlers
497
- o(this, "_visibility", S.FULL);
498
- o(this, "_enabled", !0);
499
- /**
500
- * While true, validate() on this field does nothing at all: it neither recomputes _valid nor emits
501
- * ValidChangedAction, and nothing climbs to the parent. A container that walks its members one by one - assigning
502
- * them a value, or revalidating them - sets it for the duration of the walk, so a member's upward climb cannot
503
- * announce the verdict of a half-applied value or of a half-revalidated set, and clears it in a finally block
504
- * followed by its own validate(). That call recomputes over the finished state and emits the net transition, so
505
- * the deferral cannot swallow a real change.
506
- */
507
- o(this, "suppressValidation", !1);
859
+ const It = /* @__PURE__ */ new WeakMap(), At = /* @__PURE__ */ new Set(["validators", "actions"]);
860
+ let st = 0;
861
+ var h, f;
862
+ class A {
863
+ constructor(e) {
508
864
  /**
509
- * While true, a validity change is still recomputed and still announced on this field, but it is not passed up to
510
- * the parent: the climb is only remembered and carried out by flushParentValidityClimb(). A setter that notifies
511
- * the parent of the new value itself holds it over the notifying region, so the parent forms its verdict once,
512
- * over the finished value, instead of once over the value being replaced and once over the value replacing it.
865
+ * The element's mutable state, in an object beside the element. `#state` is the tracked view of it: a slot read
866
+ * through it inside an effect subscribes the effect to that slot, and a write to the slot re-runs the effect.
867
+ * `#raw` is the same object without the proxy, for the bookkeeping nothing renders from.
868
+ *
869
+ * They are private class fields, so no reflection over the element reaches the state or the parent link it
870
+ * carries, and a subclass reads its own slot type through the accessors below.
513
871
  */
514
- o(this, "suppressParentValidityClimb", !1);
515
- o(this, "parentValidityClimbPending", !1);
516
- o(this, "_validationEpoch", 0);
517
- return Et(this);
872
+ Z(this, h);
873
+ Z(this, f);
874
+ tt(this, f, e), tt(this, h, ee(e));
875
+ }
876
+ /**
877
+ * Vue's getTargetType answers INVALID for an object that carries __v_skip, so reactive() hands an element back
878
+ * unwrapped and no element is ever behind a proxy of its own. isReactive() reads the second flag, and it stays
879
+ * true because what carries an element's reactivity - its state - is a reactive object.
880
+ *
881
+ * Two consequences for a consumer, both silent. watch(field, cb) with a bare element as the source registers
882
+ * no dependency, because the deep traversal Vue starts for a reactive source stops on __v_skip; the supported
883
+ * form is watch(() => field.value, cb). And readonly(field) hands the element straight back, so the value it
884
+ * returns is the element itself and a write through it reaches the field; what a caller hands out instead is
885
+ * the value, which is frozen, or a computed over it.
886
+ */
887
+ get __v_skip() {
888
+ return !0;
889
+ }
890
+ get __v_isReactive() {
891
+ return !0;
892
+ }
893
+ /** the tracked view of this element's state; a subclass narrows the return type to its own slots */
894
+ get state() {
895
+ return l(this, h);
896
+ }
897
+ /** the untracked view of this element's state; a subclass narrows the return type to its own slots */
898
+ get raw() {
899
+ return l(this, f);
900
+ }
901
+ /**
902
+ * Exchanges the data this element holds for `data`, in place. The element is the same instance afterwards - its
903
+ * identity, its actions, its extended properties and its place in whatever container holds it all stand - and it
904
+ * ends up in the state `bind(data)` would have produced: the values are written, the change history starts over
905
+ * and the validators run. It is what recycles one element across records, which is what a virtualised renderer
906
+ * does with the rows it keeps.
907
+ *
908
+ * The element makes no statement of its own about the exchange: no `ValueChangedAction` fires for it, the way
909
+ * none fires for an element that was just built. Its members do announce theirs, and a verdict that moves is
910
+ * announced as always - a rebound element that is invalid says so to the container holding it. A change an
911
+ * open transaction is already owed an announcement for stands: the commit reports the pair measured from
912
+ * where the element was when the transaction opened.
913
+ *
914
+ * The data is measured against the element's `declaration`, so a key a record leaves out is taken from the
915
+ * declaration rather than left as the previous record had it.
916
+ */
917
+ rebind(e) {
918
+ return g((t) => {
919
+ t.touch(this);
920
+ const s = t.willAnnounceValue(this), i = l(this, f).announcedValue;
921
+ this.resetTo(this.declaration, e), l(this, f).announcedValue = s ? i : this.value;
922
+ }), this;
923
+ }
924
+ /** contains original field value as was provided at creation */
925
+ get originalValue() {
926
+ return l(this, h).originalValue;
927
+ }
928
+ set originalValue(e) {
929
+ this.touchState(), l(this, h).originalValue = e;
930
+ }
931
+ /**
932
+ * The extended properties this element carries: what a consumer attached to it beyond the members the class
933
+ * declares, such as the label, hint or css class a UI layer binds to the input it renders the element with.
934
+ * The read is tracked, so a template rendering off `field.extra.label` re-renders when the property is written.
935
+ *
936
+ * Every property is optional here, whatever `X` states: a parameter object need not carry one and
937
+ * setExtendedValues writes as few as a caller likes, so a property `X` declares as required is present only
938
+ * once something has written it.
939
+ *
940
+ * The object is frozen and setExtendedValues is the way to change it: it is the object a transaction captured,
941
+ * and one written in place would leave a rollback with nothing to put back.
942
+ */
943
+ get extra() {
944
+ return l(this, h).extra;
945
+ }
946
+ /**
947
+ * Writes extended properties. The values given are merged over the ones the element carries, so a write of one
948
+ * property leaves the others standing, and the merged set replaces the object the element held.
949
+ */
950
+ setExtendedValues(e) {
951
+ this.touchState(), l(this, h).extra = Object.freeze(p(p({}, l(this, f).extra), e));
952
+ }
953
+ /**
954
+ * The extended properties a parameter object carries: every key the element does not answer for itself. A key
955
+ * the element answers for at the time the parameters are applied - `value`, `enabled`, an accessor a subclass
956
+ * adds - is the element's own; a key that only Object.prototype answers for is nobody's declaration and counts
957
+ * as extended, and `validators` and `actions` are neither, since they state what to register on the element.
958
+ *
959
+ * A member a subclass declares as a class field is not among the keys the element answers for: class fields are
960
+ * defined on the instance after the base constructor returns, and the parameters are applied inside it. A
961
+ * subclass that wants a parameter of its own name assigned to it declares that member as an accessor.
962
+ */
963
+ extendedOf(e) {
964
+ const t = /* @__PURE__ */ Object.create(null);
965
+ return Object.entries(e).forEach(([s, i]) => {
966
+ At.has(s) || (!(s in this) || Object.hasOwn(Object.prototype, s)) && (t[s] = i);
967
+ }), t;
968
+ }
969
+ /**
970
+ * Applies a parameter object: the members the element answers for are assigned to the element and the rest
971
+ * become its extended properties. Assigning a getter-only member throws a TypeError, which is what a caller
972
+ * naming `valid` or `parent` past the type system gets.
973
+ */
974
+ assignParams(e) {
975
+ const t = this.extendedOf(e);
976
+ Object.entries(e).forEach(([s, i]) => {
977
+ Object.hasOwn(t, s) || At.has(s) || (this[s] = i);
978
+ }), L(t) || this.setExtendedValues(t);
979
+ }
980
+ /**
981
+ * Takes this element into the record of the open transaction, where one is open. A write of a single slot that
982
+ * announces nothing calls it instead of opening a transaction of its own: on its own such a write is already
983
+ * atomic, and inside a transaction it has to be part of what a rollback puts back.
984
+ */
985
+ touchState() {
986
+ var e;
987
+ (e = kt()) == null || e.touch(this);
988
+ }
989
+ /**
990
+ * Records the whole of this element's mutable state, so that a rolled-back transaction can put it back exactly
991
+ * as it found it. The errors array is copied because a validator writes into the array it is handed rather than
992
+ * replacing it, and a subclass copies whatever else it holds by reference the same way.
993
+ *
994
+ * What is not in the snapshot is the action map, which no write touches: an operation that replaces it hands
995
+ * the transaction its own undo instead, so this stays the one shape every element captures.
996
+ */
997
+ [z]() {
998
+ return x(p({}, l(this, f)), { errors: [...l(this, f).errors] });
999
+ }
1000
+ /**
1001
+ * Puts a captured state back. It writes through the tracked view, so an effect that ran on the state the
1002
+ * transaction produced runs again on the state it is being returned to, and only for the slots that differ.
1003
+ *
1004
+ * validatingCount is the one slot the element keeps: it counts runs that are in flight, and a rollback cannot
1005
+ * un-start one. Put back, the count would no longer match the endValidating calls still to come.
1006
+ */
1007
+ [Pt](e) {
1008
+ const t = l(this, f).validatingCount;
1009
+ Object.assign(l(this, h), e), l(this, h).validatingCount = t;
518
1010
  }
519
1011
  /** true while at least one asynchronous validator is still running for this field */
520
1012
  get validating() {
521
- return this.validatingCount > 0;
1013
+ return l(this, h).validatingCount > 0;
522
1014
  }
523
1015
  /** announces the start of one asynchronous validation run; validators pair it with endValidating */
524
1016
  beginValidating() {
525
- this.validatingCount++;
1017
+ l(this, h).validatingCount++;
526
1018
  }
527
1019
  /** announces the end of one asynchronous validation run */
528
1020
  endValidating() {
529
- this.validatingCount = Math.max(0, this.validatingCount - 1);
1021
+ l(this, h).validatingCount = Math.max(0, l(this, h).validatingCount - 1);
530
1022
  }
531
- get visibility() {
532
- return this._visibility;
1023
+ /**
1024
+ * List of errors. The array handed out is the one the element holds, and a validator writes into it in place,
1025
+ * so a transaction that is open takes the element into its record here: a rollback that put back everything
1026
+ * except the errors would leave a state the form never held.
1027
+ */
1028
+ get errors() {
1029
+ return this.touchState(), l(this, h).errors;
1030
+ }
1031
+ set errors(e) {
1032
+ this.touchState(), l(this, h).errors = e;
1033
+ }
1034
+ /**
1035
+ * The container that holds this element: the Group it is a member of, or the List whose row it is, and
1036
+ * undefined while no container holds it. The container writes it; everyone else reads it. The read is tracked,
1037
+ * so an effect rendering off the link - `v-if="field.parent"` - re-runs when a container takes the element or
1038
+ * releases it.
1039
+ */
1040
+ get parent() {
1041
+ return l(this, h).parent;
1042
+ }
1043
+ /** when member of a Group, fieldName specifies the name of this field. Written by the group, read-only after */
1044
+ get fieldName() {
1045
+ return l(this, h).fieldName;
1046
+ }
1047
+ /**
1048
+ * The element this one was declared as: itself for an element built from parameters, and the element it was
1049
+ * bound from for a binding - transitively, so a binding of a binding names the same one. Every row a `List`
1050
+ * builds from an item template is a binding of it, so a row's member and the template's member it stands for
1051
+ * answer with the same element, and an action registered on the template can tell the two apart.
1052
+ */
1053
+ get declaration() {
1054
+ var e;
1055
+ return (e = l(this, f).declaration) != null ? e : this;
1056
+ }
1057
+ /** The elements this one holds: a Group's members, a List's rows, none for a leaf. */
1058
+ get members() {
1059
+ return [];
1060
+ }
1061
+ /**
1062
+ * Every element in this element's subtree, this element included, that was declared as `declaration`. It answers
1063
+ * the question a shared action asks when the record it changed in is not the record its targets live in - a form
1064
+ * field that every row of a list reacts to - and it costs the subtree, so it is the path taken only when the
1065
+ * cheaper one, resolving within a single record, does not apply.
1066
+ */
1067
+ bindingsOf(e) {
1068
+ const t = e.declaration, s = [], i = (r) => {
1069
+ r.declaration === t && s.push(r), r.members.forEach(i);
1070
+ };
1071
+ return i(this), s;
1072
+ }
1073
+ /**
1074
+ * States that an eager pass over this element reached an element it needs and did not find it, because the
1075
+ * record this element belongs to was not assembled at the time: a `List` row is built member by member and its
1076
+ * members are bound before any of them holds the row, so a validator comparing two of them runs before the
1077
+ * row exists. The container that finishes the record runs the pass again, and a pass that still reaches
1078
+ * nothing says so again, so the next container above answers for it.
1079
+ */
1080
+ markRecordIncomplete() {
1081
+ this._recordPending || (this._recordPending = !0, st++);
1082
+ }
1083
+ /**
1084
+ * Runs the eager passes outstanding in `element`'s subtree, now that the record it belongs to is assembled. A
1085
+ * container calls it where it has just made a record complete: a Group that has written its members, and a
1086
+ * List that has taken a row, which is what gives the row's fields the form above it.
1087
+ */
1088
+ completeRecords(e = this) {
1089
+ st !== 0 && g(() => {
1090
+ const t = (s) => {
1091
+ s._recordPending && (s._recordPending = !1, st--, s.rerunEagerActions()), s.members.forEach(t);
1092
+ };
1093
+ t(e);
1094
+ });
1095
+ }
1096
+ /** Runs this element's eager actions over the value it holds and re-forms the verdict they reach. */
1097
+ rerunEagerActions() {
1098
+ g((e) => {
1099
+ var t;
1100
+ (t = this._actions) == null || t.triggerEager(this, this.value, this.value), e.markValidityDirty(this);
1101
+ });
1102
+ }
1103
+ get actions() {
1104
+ return this._actions || (this._actions = new M()), this._actions;
1105
+ }
1106
+ set actions(e) {
1107
+ this._actions = e;
1108
+ }
1109
+ /**
1110
+ * Counts the writes that have changed the value of this element or of anything below it. A container reads it
1111
+ * before answering from its value cache, and the read is an ordinary tracked one, so an effect that took a
1112
+ * cached value still re-runs when a descendant is written.
1113
+ */
1114
+ get valueVersion() {
1115
+ return l(this, h).valueVersion;
1116
+ }
1117
+ /**
1118
+ * Marks the value of this element and of every ancestor as superseded. It walks the parent chain, so it costs
1119
+ * the nesting depth: an ancestor rebuilds its value the next time one is asked of it, instead of being walked
1120
+ * here for a reader that may never come. The walk also brings each element into the open transaction, so a
1121
+ * rollback puts the versions back and no reader is left holding a cache the tree no longer supports.
1122
+ */
1123
+ bumpValueVersion() {
1124
+ g((e) => {
1125
+ e.touch(this), l(this, h).valueVersion++;
1126
+ let t = this.parent;
1127
+ for (; t; )
1128
+ e.touch(t), l(t, h).valueVersion++, t = t.parent;
1129
+ });
533
1130
  }
534
- set visibility(i) {
535
- const t = this._visibility, e = this.actions.trigger(dt, this, i, t);
536
- if (!S.isDefined(e != null ? e : i)) throw new Error("visibility must be a DisplayMode constant");
537
- this._visibility = S.fromAny(e != null ? e : i), this.actions.trigger(gt, this, this._visibility, t);
1131
+ /**
1132
+ * States that this element's value changed and that every container above it therefore holds a different value
1133
+ * too. Nothing is announced here: the transaction works out at commit which of the elements enrolled actually
1134
+ * ends up holding a different value, and announces those once each.
1135
+ *
1136
+ * `force` states that the caller already knows this element's value changed - one item more or fewer is a
1137
+ * different list whatever the items compare as - so the commit announces it without composing a comparison.
1138
+ */
1139
+ propagateValueChanged(e = !1) {
1140
+ g((t) => {
1141
+ var s;
1142
+ t.markValueChanged(this, e), t.markValidityDirty(this), (s = this.parent) == null || s.notifyValueChanged();
1143
+ });
1144
+ }
1145
+ /**
1146
+ * Re-reads the value that the next ValueChangedAction will report as the one it replaces. A leaf records what
1147
+ * it announced at every announcement, so its copy is always current and there is nothing to re-read; a
1148
+ * container that skipped composing a value nobody was listening for overrides this.
1149
+ */
1150
+ refreshPreviousValue() {
1151
+ }
1152
+ /**
1153
+ * The verdict validate() records and announces: this element's own errors plus the tally of children that
1154
+ * reported themselves invalid, so a container forms it without walking its members. `valid` is the read path
1155
+ * and answers over the live errors arrays instead; the two differ only for an error written into a member
1156
+ * without a validate() call, which is the documented cost of pushing errors by hand.
1157
+ */
1158
+ get countedValid() {
1159
+ return l(this, f).errors.length === 0 && l(this, f).invalidChildren === 0;
1160
+ }
1161
+ /**
1162
+ * Makes this element the container of `child`: it installs the back-reference, records the name a Group holds
1163
+ * the child under, and takes the child into the invalid tally. An element belongs to one container at a time,
1164
+ * so a child that already carries the link is refused; releaseChild() takes the link away again, and an element
1165
+ * released that way can be handed on. The child's state is unreachable from outside FieldBase, so a container
1166
+ * writes the two slots through here rather than on the child.
1167
+ */
1168
+ takeChild(e, t) {
1169
+ g((s) => {
1170
+ if (e.parent) throw new TypeError("This element already belongs to a container - pass a bind() of it");
1171
+ s.touch(e), l(e, h).fieldName = t, l(e, h).parent = this, this.adoptChild(e);
1172
+ });
1173
+ }
1174
+ /** Takes a child into this element's invalid tally; a container calls it once the child's parent link exists. */
1175
+ adoptChild(e) {
1176
+ g((t) => {
1177
+ t.touch(this), l(e, f).valid || l(this, f).invalidChildren++, t.markValidityDirty(this);
1178
+ });
1179
+ }
1180
+ /**
1181
+ * Drops a child out of this element's invalid tally and takes its back-reference away. An element keeps no link
1182
+ * to a container that no longer holds it: it would go on moving that container's tally, and the link is what
1183
+ * stands in the way of the element being taken by another container.
1184
+ */
1185
+ releaseChild(e) {
1186
+ g((t) => {
1187
+ t.touch(this), t.touch(e), l(e, f).valid || l(this, f).invalidChildren--, l(e, h).parent = void 0, t.markValidityDirty(this);
1188
+ });
1189
+ }
1190
+ /**
1191
+ * Brings this element to the state a fresh binding of `source` carrying `value` would be in: `value` is written
1192
+ * where the caller supplied one and `source`'s own value where it did not, the change history - originalValue,
1193
+ * touched - starts over and the errors are dropped and re-established by the validators. A container that reuses
1194
+ * an element at a position it already holds calls it, so the element is indistinguishable from one built for
1195
+ * that position.
1196
+ */
1197
+ resetTo(e, t) {
1198
+ g(() => {
1199
+ const s = t === void 0 ? e.value : t, i = this.errors.length > 0;
1200
+ i && (this.errors = []), this.touched = !1;
1201
+ const r = this.enabled && this.value !== s;
1202
+ this.value = s, this.originalValue = this.value, this.validate(!r && i);
1203
+ });
1204
+ }
1205
+ /** Resets a member. It is what lets a container reach the reset of a child whose class it does not know. */
1206
+ resetChild(e, t, s) {
1207
+ e.resetTo(t, s);
1208
+ }
1209
+ /**
1210
+ * Records a child's new verdict in this element's tally. The child reports it as it settles, and the commit
1211
+ * settles the deepest element first, so the tally a container reads when its own turn comes is finished.
1212
+ */
1213
+ childValidityChanged(e) {
1214
+ l(this, f).invalidChildren += e ? -1 : 1;
1215
+ }
1216
+ /**
1217
+ * The composed verdict a container answers `valid` with, memoised by Vue. The walk over the members is what
1218
+ * makes an error pushed into one of them visible without a validate() call, and the computed keeps that walk
1219
+ * from repeating while nothing it read has moved.
1220
+ */
1221
+ get validRead() {
1222
+ let e = It.get(this);
1223
+ return e || (e = jt(() => this.composeValid()), It.set(this, e)), e.value;
1224
+ }
1225
+ /** What validRead computes. A leaf answers over its own errors; a container adds its members. */
1226
+ composeValid() {
1227
+ return l(this, h).errors.length === 0;
1228
+ }
1229
+ // default property handlers
1230
+ get visibility() {
1231
+ return l(this, h).visibility;
1232
+ }
1233
+ set visibility(e) {
1234
+ g((t) => {
1235
+ var r, a;
1236
+ const s = l(this, h).visibility, i = (r = this._actions) == null ? void 0 : r.trigger(Wt, this, e, s);
1237
+ if (!N.isDefined(i != null ? i : e))
1238
+ throw new Error("visibility must be a DisplayMode constant");
1239
+ t.touch(this), l(this, h).visibility = N.fromAny(i != null ? i : e), (a = this._actions) == null || a.trigger($t, this, l(this, h).visibility, s);
1240
+ });
538
1241
  }
539
1242
  get enabled() {
540
- return this._enabled;
1243
+ return l(this, h).enabled;
1244
+ }
1245
+ set enabled(e) {
1246
+ g((t) => {
1247
+ var r, a;
1248
+ const s = l(this, h).enabled, i = (r = this._actions) == null ? void 0 : r.trigger(Bt, this, e, s);
1249
+ if (!Kt(i != null ? i : e)) throw new Error("Enabled value must be boolean");
1250
+ t.touch(this), l(this, h).enabled = i != null ? i : e, l(this, h).enabled !== s && this.bumpValueVersion(), (a = this._actions) == null || a.trigger(Ut, this, l(this, h).enabled, s);
1251
+ });
541
1252
  }
542
- set enabled(i) {
543
- const t = this._enabled, e = this.actions.trigger(ut, this, i, t);
544
- if (!Vt(e != null ? e : i)) throw new Error("Enabled value must be boolean");
545
- this._enabled = e != null ? e : i, this.actions.trigger(ct, this, this._enabled, t);
1253
+ /**
1254
+ * True for an element whose value is composed of its members'. The commit builds such a value only where
1255
+ * something receives it, compares it by content rather than by identity, and runs the element's own validators
1256
+ * with the announcement: a container's validators read the composed value, which exists only once the members
1257
+ * have been written. A leaf's validators have run at the write instead, so its announcement carries no eager
1258
+ * pass of its own.
1259
+ */
1260
+ get composesValue() {
1261
+ return !1;
546
1262
  }
547
- /** Carries out the climb that a validity change made while suppressParentValidityClimb was held, if there was one. */
548
- flushParentValidityClimb() {
549
- var i;
550
- this.parentValidityClimbPending && (this.parentValidityClimbPending = !1, (i = this.parent) == null || i.validate());
1263
+ /**
1264
+ * Announces what this element's value became over the transaction. The pair carried is (value now, value at the
1265
+ * last announcement), so a value that went A -> B -> A within the transaction says nothing, and the events an
1266
+ * operation states rather than an element's state - an item added, an item removed - are emitted first, in the
1267
+ * order the operations happened.
1268
+ */
1269
+ [Ft](e, t, s, i) {
1270
+ if (i == null || i.forEach((c) => {
1271
+ var u;
1272
+ return (u = this._actions) == null ? void 0 : u.trigger(c.actionClass, this, c.item, c.index);
1273
+ }), !t) return;
1274
+ const r = this._actions;
1275
+ if (this.composesValue && !(r != null && r.willTrigger(B))) return;
1276
+ const a = this.value, o = l(this, f).announcedValue;
1277
+ !s && (this.composesValue ? nt(a, o) : a === o) || (e.touch(this), l(this, f).announcedValue = a, this.composesValue ? r == null || r.trigger(O, this, a, o) : r == null || r.triggerChain(B, this, a, o));
551
1278
  }
552
- validate(i = !1) {
553
- var e;
554
- if (this.suppressValidation) return;
555
- i && this.actions.triggerEager(this, this.value, this.value);
556
- const t = this._valid;
557
- this._valid = this.valid, this._valid !== t && (this.actions.trigger(ht, this, this.valid, t), this.suppressParentValidityClimb ? this.parentValidityClimbPending = !0 : (e = this.parent) == null || e.validate());
1279
+ /**
1280
+ * Forms the verdict this element ends the transaction with and announces a transition of it. The container is
1281
+ * told first, so a handler reads a tally that already includes this verdict, and it is enrolled in the same
1282
+ * transaction: its own verdict is composed of its members', so a member that moves without a value change - an
1283
+ * asynchronous validator, an error pushed in by hand - is what makes the container re-form its own. The
1284
+ * transaction settles the deepest element first, so a container is reached only once its members have decided.
1285
+ */
1286
+ [Nt](e) {
1287
+ var r;
1288
+ const t = l(this, f).valid, s = this.countedValid;
1289
+ if (s === t) return;
1290
+ e.touch(this), l(this, f).valid = s;
1291
+ const i = this.parent;
1292
+ i && (e.touch(i), i.childValidityChanged(s), e.markValidityDirty(i)), (r = this._actions) == null || r.trigger(Mt, this, s, t);
1293
+ }
1294
+ validate(e = !1) {
1295
+ g((t) => {
1296
+ var s;
1297
+ e && ((s = this._actions) == null || s.triggerEager(this, this.value, this.value)), t.markValidityDirty(this);
1298
+ });
558
1299
  }
559
1300
  get valid() {
560
- return this.errors.length === 0;
1301
+ return l(this, h).errors.length === 0;
561
1302
  }
562
1303
  get fullValue() {
563
1304
  return this.value;
564
1305
  }
565
1306
  get isChanged() {
566
- return !D(this.value, this.originalValue);
1307
+ return !nt(this.value, this.originalValue);
1308
+ }
1309
+ /**
1310
+ * Brings a fresh element into the state a binding of `source` is in: it records what it was declared as, takes
1311
+ * on the extended properties and the actions `source` carries, and runs the eager ones over the value it was
1312
+ * built with. The extended properties `overrides` states are written over the ones `source` carries, and they
1313
+ * are in place before the eager pass, so an action reading one sees what the binding ends up carrying. The
1314
+ * actions are the very instances `source` holds - what a binding takes on is data, not behaviour - and each is
1315
+ * told about this element as it is taken on, so an action serving several bindings knows all of them.
1316
+ */
1317
+ boundFrom(e, t, s, i) {
1318
+ l(this, f).declaration = e.declaration;
1319
+ const r = p(p({}, e.extra), i && this.extendedOf(i));
1320
+ L(r) || this.setExtendedValues(r);
1321
+ const a = e._actions;
1322
+ a && (this._actions = a.clone(), this._actions.bindTo(this), this._actions.triggerEager(this, t, s));
567
1323
  }
568
1324
  /**
569
1325
  * Registers the actions a constructor received in its parameters: registration without the eager trigger,
570
1326
  * because a constructor ends with a single this.actions.triggerEager(...) over the finished value, and an
571
1327
  * eager action registered here would otherwise also run once per registration, over a half-built field.
572
1328
  */
573
- registerInitialActions(i) {
574
- i.forEach((t) => {
575
- this.actions.register(t), t.boundToField(this);
1329
+ registerInitialActions(e) {
1330
+ e.forEach((t) => {
1331
+ this.actions.register(t), t.boundToBinding(this);
576
1332
  });
577
1333
  }
578
- registerAction(i) {
579
- return this.actions.register(i), i.boundToField(this), i.eager && this.actions.trigger(Object.getPrototypeOf(i).constructor, this, this.value, this.originalValue), this;
1334
+ registerAction(e) {
1335
+ return g((t) => {
1336
+ t.willAnnounceValue(this) || this.refreshPreviousValue(), this.actions.register(e), e.boundToBinding(this), e.eager && this.actions.trigger(Object.getPrototypeOf(e).constructor, this, this.value, this.originalValue);
1337
+ }), this;
580
1338
  }
581
- triggerAction(i, ...t) {
582
- return this.actions.trigger(i, this, ...t);
1339
+ triggerAction(e, ...t) {
1340
+ return this._actions ? this._actions.trigger(e, this, ...t) : null;
583
1341
  }
584
1342
  /**
585
1343
  * Generation counter of the validators attached to this field. A Validator reads it when a run starts and drops
@@ -587,70 +1345,97 @@ class V {
587
1345
  * cannot push an error onto a field that no longer has the validator that produced it.
588
1346
  */
589
1347
  get validationEpoch() {
590
- return this._validationEpoch;
1348
+ return l(this, h).validationEpoch;
591
1349
  }
592
1350
  clearValidators() {
593
- this._validationEpoch++, this.actions = this.actions.cloneWithoutValidators(), this.errors = [], this.validate();
1351
+ g((e) => {
1352
+ if (e.touch(this), l(this, h).validationEpoch++, this._actions) {
1353
+ const t = this._actions, s = t.validators;
1354
+ e.whenRolledBack(() => {
1355
+ this._actions = t;
1356
+ }), this.actions = t.cloneWithoutValidators(), e.whenCommitted(() => s.forEach((i) => i.unregisterFrom(this)));
1357
+ }
1358
+ this.errors = [], this.validate();
1359
+ });
594
1360
  }
595
1361
  }
596
- function qt(n, i) {
597
- return n ? !i : i;
1362
+ h = new WeakMap(), f = new WeakMap();
1363
+ function Se(n, e) {
1364
+ return n ? !e : e;
598
1365
  }
599
- class N {
600
- constructor(i, t, e) {
601
- o(this, "operand1");
602
- o(this, "operator");
603
- o(this, "operand2");
604
- this.operand1 = i, this.operator = t, this.operand2 = e;
1366
+ class I {
1367
+ constructor(e, t, s) {
1368
+ d(this, "operand1");
1369
+ d(this, "operator");
1370
+ d(this, "operand2");
1371
+ this.operand1 = e, this.operator = t, this.operand2 = s;
1372
+ }
1373
+ /**
1374
+ * The value an operand contributes. A field operand names a field of the record the statement is evaluated in:
1375
+ * the same statement over a `List` reads row 3's field while row 3 is the record, and a field belonging to no
1376
+ * record of the statement's own - a form field above the list - is read where it stands. A record that does not
1377
+ * hold the field yet contributes undefined, which is what a half-built row answers with.
1378
+ */
1379
+ static valueOf(e, t) {
1380
+ if (e instanceof I) return e.evaluate(t);
1381
+ if (e instanceof A) {
1382
+ const s = t ? ut(e, t) : e;
1383
+ return s ? b(s.value) : void 0;
1384
+ }
1385
+ return e;
605
1386
  }
606
1387
  get operand1Value() {
607
- return this.operand1 instanceof N ? this.operand1.evaluate() : this.operand1 instanceof V ? h(this.operand1.value) : this.operand1;
1388
+ return I.valueOf(this.operand1);
608
1389
  }
609
1390
  get operand2Value() {
610
- return this.operand2 instanceof N ? this.operand2.evaluate() : this.operand2 instanceof V ? h(this.operand2.value) : this.operand2;
1391
+ return I.valueOf(this.operand2);
611
1392
  }
612
- evaluate() {
613
- var e, s;
614
- const i = this.operand1Value, t = this.operand2Value;
1393
+ /**
1394
+ * The result of the statement, over the record `scope` belongs to where one is given and over the fields the
1395
+ * statement was built from where it is not.
1396
+ */
1397
+ evaluate(e) {
1398
+ var i, r;
1399
+ const t = I.valueOf(this.operand1, e), s = I.valueOf(this.operand2, e);
615
1400
  switch (this.operator) {
616
1401
  // logical operators
617
1402
  // `&&` and `||` evaluate to one of their operands, and the operands are of any type. Without the
618
1403
  // coercion evaluate() would hand out the operand itself, so `0` or `''` would reach callers that the
619
1404
  // signature promises a boolean, and consumers comparing results with !== would see a change where the
620
1405
  // logical value stayed the same.
621
- case c.AND:
622
- return !!(i && t);
623
- case c.OR:
624
- return !!(i || t);
625
- case c.NAND:
626
- return !(i && t);
627
- case c.NOR:
628
- return !(i || t);
629
- case c.XOR:
630
- return qt(!!i, !!t);
631
- case c.NOT:
632
- return !i;
1406
+ case m.AND:
1407
+ return !!(t && s);
1408
+ case m.OR:
1409
+ return !!(t || s);
1410
+ case m.NAND:
1411
+ return !(t && s);
1412
+ case m.NOR:
1413
+ return !(t || s);
1414
+ case m.XOR:
1415
+ return Se(!!t, !!s);
1416
+ case m.NOT:
1417
+ return !t;
633
1418
  // comparison operators
634
- case c.EQUALS:
635
- return i == t;
636
- case c.NOT_EQUALS:
637
- return i != t;
638
- case c.LT:
639
- return i < t;
640
- case c.LE:
641
- return i <= t;
642
- case c.GE:
643
- return i >= t;
644
- case c.GT:
645
- return i > t;
646
- case c.IN:
647
- return !!((e = t == null ? void 0 : t.includes) != null && e.call(t, i));
648
- case c.NOT_IN:
649
- return !((s = t == null ? void 0 : t.includes) != null && s.call(t, i));
650
- case c.INCLUDES:
651
- return A(i) && A(t) && i.indexOf(t) >= 0;
652
- case c.NOT_INCLUDES:
653
- return !(A(i) && A(t) && i.indexOf(t) >= 0);
1419
+ case m.EQUALS:
1420
+ return t == s;
1421
+ case m.NOT_EQUALS:
1422
+ return t != s;
1423
+ case m.LT:
1424
+ return t < s;
1425
+ case m.LE:
1426
+ return t <= s;
1427
+ case m.GE:
1428
+ return t >= s;
1429
+ case m.GT:
1430
+ return t > s;
1431
+ case m.IN:
1432
+ return !!((i = s == null ? void 0 : s.includes) != null && i.call(s, t));
1433
+ case m.NOT_IN:
1434
+ return !((r = s == null ? void 0 : s.includes) != null && r.call(s, t));
1435
+ case m.INCLUDES:
1436
+ return P(t) && P(s) && t.indexOf(s) >= 0;
1437
+ case m.NOT_INCLUDES:
1438
+ return !(P(t) && P(s) && t.indexOf(s) >= 0);
654
1439
  default:
655
1440
  throw new Error(`Operator not implemented ${this.operator}`);
656
1441
  }
@@ -660,55 +1445,97 @@ class N {
660
1445
  * @returns A set of all fields used in this statement
661
1446
  */
662
1447
  collectFields() {
663
- const i = /* @__PURE__ */ new Set();
664
- function t(e) {
665
- e instanceof V ? i.add(e) : e instanceof N && e.collectFields().forEach((r) => i.add(r));
1448
+ const e = /* @__PURE__ */ new Set();
1449
+ function t(s) {
1450
+ s instanceof A ? e.add(s) : s instanceof I && s.collectFields().forEach((r) => e.add(r));
666
1451
  }
667
- return t(this.operand1), t(this.operand2), i;
1452
+ return t(this.operand1), t(this.operand2), e;
668
1453
  }
669
1454
  }
670
- const Ht = /* @__PURE__ */ Symbol("ExecuteAction");
671
- class ft extends m {
672
- constructor(i) {
673
- super(i);
1455
+ const Ie = /* @__PURE__ */ Symbol("ExecuteAction");
1456
+ class qt extends y {
1457
+ constructor(e) {
1458
+ super(e);
674
1459
  }
675
1460
  static get classIdentifier() {
676
- return Ht;
1461
+ return Ie;
677
1462
  }
678
- execute(i, t, e) {
679
- return super.execute(i, t, e);
1463
+ execute(e, t, s) {
1464
+ return super.execute(e, t, s);
680
1465
  }
681
1466
  }
682
- const Qt = /* @__PURE__ */ Symbol("ListItemAddedAction");
683
- class z extends m {
684
- constructor(i) {
685
- super(i);
1467
+ const Ae = /* @__PURE__ */ Symbol("ListItemAddedAction");
1468
+ class at extends y {
1469
+ constructor(e) {
1470
+ super(e);
686
1471
  }
687
1472
  static get classIdentifier() {
688
- return Qt;
1473
+ return Ae;
689
1474
  }
690
- execute(i, t, e, s) {
691
- return super.execute(i, t, e, s);
1475
+ execute(e, t, s, i) {
1476
+ return super.execute(e, t, s, i);
692
1477
  }
693
1478
  }
694
- const Wt = /* @__PURE__ */ Symbol("ListItemRemovedAction");
695
- class pt extends m {
696
- constructor(i) {
697
- super(i);
1479
+ const _e = /* @__PURE__ */ Symbol("ListItemRemovedAction");
1480
+ class zt extends y {
1481
+ constructor(e) {
1482
+ super(e);
698
1483
  }
699
1484
  static get classIdentifier() {
700
- return Wt;
1485
+ return _e;
701
1486
  }
702
- execute(i, t, e, s) {
703
- return super.execute(i, t, e, s);
1487
+ execute(e, t, s, i) {
1488
+ return super.execute(e, t, s, i);
704
1489
  }
705
1490
  }
706
- class $ extends V {
707
- constructor(t) {
708
- super();
709
- o(this, "_value");
710
- o(this, "_touched", !1);
711
- this.init(t);
1491
+ const Te = Object.freeze({});
1492
+ function Ht() {
1493
+ return {
1494
+ originalValue: void 0,
1495
+ announcedValue: void 0,
1496
+ errors: [],
1497
+ visibility: N.FULL,
1498
+ enabled: !0,
1499
+ valueVersion: 0,
1500
+ validatingCount: 0,
1501
+ parent: void 0,
1502
+ fieldName: void 0,
1503
+ validationEpoch: 0,
1504
+ declaration: void 0,
1505
+ extra: Te,
1506
+ valid: !0,
1507
+ invalidChildren: 0
1508
+ };
1509
+ }
1510
+ function Oe() {
1511
+ return x(p({}, Ht()), { value: void 0, touched: !1 });
1512
+ }
1513
+ function Qt() {
1514
+ return x(p({}, Ht()), {
1515
+ announcedValue: null,
1516
+ cachedValue: null,
1517
+ cachedValueVersion: -1
1518
+ });
1519
+ }
1520
+ function je() {
1521
+ return x(p({}, Qt()), { rows: null });
1522
+ }
1523
+ class X extends A {
1524
+ get state() {
1525
+ return super.state;
1526
+ }
1527
+ get raw() {
1528
+ return super.raw;
1529
+ }
1530
+ /** the value slot itself, without the notifications the value setter carries around a write */
1531
+ get _value() {
1532
+ return this.state.value;
1533
+ }
1534
+ set _value(e) {
1535
+ this.state.value = e;
1536
+ }
1537
+ constructor(e) {
1538
+ super(Oe()), this.init(e);
712
1539
  }
713
1540
  /**
714
1541
  * Applies the constructor parameters. It is a hook so that a subclass needing different parameter handling
@@ -719,88 +1546,133 @@ class $ extends V {
719
1546
  * subclass initializes read as undefined inside it, and anything it writes to such a member is overwritten
720
1547
  * the moment the initializer runs.
721
1548
  */
722
- init(t) {
723
- if (t) {
724
- const e = t, { value: s, validators: r, actions: a } = e, l = F(e, ["value", "validators", "actions"]);
725
- this.registerInitialActions([...r || [], ...a || []]), Object.assign(this, l), this._value = s !== void 0 ? s : this.originalValue, this.originalValue === void 0 && (this.originalValue = this._value);
726
- }
727
- this.actions.triggerEager(this, this.value, this.originalValue), this.validate();
1549
+ init(e) {
1550
+ g(() => {
1551
+ var s;
1552
+ if (e) {
1553
+ const t = e, { value: i, validators: r, actions: a } = t, o = k(t, ["value", "validators", "actions"]);
1554
+ this.registerInitialActions([...r || [], ...a || []]), this.assignParams(o), this._value = i !== void 0 ? i : this.originalValue, this.originalValue === void 0 && (this.originalValue = this._value);
1555
+ }
1556
+ this.raw.announcedValue = this._value, (s = this._actions) == null || s.triggerEager(this, this.value, this.originalValue), this.validate();
1557
+ });
728
1558
  }
729
1559
  get value() {
730
1560
  return this._value;
731
1561
  }
732
- set value(t) {
733
- const e = this._value;
734
- if (!this.enabled || e === t) return;
735
- this._value = t;
736
- const s = this.suppressParentValidityClimb;
737
- this.suppressParentValidityClimb = !0;
738
- try {
739
- this.actions.trigger(y, this, this._value, e), this.parent && this.parent.notifyValueChanged();
740
- } finally {
741
- this.suppressParentValidityClimb = s, this.validate(), this.flushParentValidityClimb();
742
- }
1562
+ set value(e) {
1563
+ const t = this._value;
1564
+ !this.enabled || t === e || g((s) => {
1565
+ var i;
1566
+ s.touch(this), this._value = e, this.bumpValueVersion(), (i = this._actions) == null || i.triggerEager(this, e, t), this.propagateValueChanged();
1567
+ });
743
1568
  }
744
1569
  get touched() {
745
- return this._touched;
1570
+ return this.state.touched;
746
1571
  }
747
- set touched(t) {
748
- this._touched = t;
1572
+ set touched(e) {
1573
+ this.touchState(), this.state.touched = e;
749
1574
  }
750
- clone(t) {
1575
+ bind(e, t) {
751
1576
  var r, a;
752
- const e = this.constructor, s = new e(w(v({
753
- // an override value is one the caller supplied, and undefined is not one; an explicit null is, and clears
754
- value: (t == null ? void 0 : t.value) !== void 0 ? t.value : this.value
1577
+ const s = this.constructor, i = new s(x(p({
1578
+ // data is what the caller supplied, and undefined is not supplied; an explicit null is, and clears
1579
+ value: e !== void 0 ? e : this.value
755
1580
  }, t && "originalValue" in t ? { originalValue: t.originalValue } : {}), {
756
1581
  enabled: (r = t == null ? void 0 : t.enabled) != null ? r : this.enabled,
757
1582
  visibility: (a = t == null ? void 0 : t.visibility) != null ? a : this.visibility
758
1583
  }));
759
- return s.actions = this.actions.clone(), s.actions.triggerEager(s, s.value, s.originalValue), s;
1584
+ return i.boundFrom(this, i.value, i.originalValue, t), i;
760
1585
  }
761
1586
  }
762
- const zt = new $({ value: "EmptyField" }).registerAction(
763
- new y(() => {
1587
+ const Pe = new X({ value: "EmptyField" }).registerAction(
1588
+ new O(() => {
764
1589
  console.warn("Working with EmptyField! This should not happen");
765
1590
  })
766
- );
767
- function H(n, i) {
768
- return (n == null ? void 0 : n.label) == null && (n == null ? void 0 : n.icon) == null ? i : n;
769
- }
770
- class Xt extends $ {
771
- init(i) {
772
- if (this._value = { label: void 0, icon: void 0 }, i) {
773
- const t = i, { value: e, originalValue: s, validators: r, actions: a } = t, l = F(t, ["value", "originalValue", "validators", "actions"]);
774
- this.registerInitialActions([...r || [], ...a || []]), Object.assign(this, l);
775
- const u = H(e, this._value), d = Object.freeze({ label: s == null ? void 0 : s.label, icon: s == null ? void 0 : s.icon });
776
- this._value = H(u, v({}, d)), this.originalValue = H(d, u);
777
- }
778
- this.actions.triggerEager(this, this.value, this.originalValue), this.validate();
1591
+ ), _t = /* @__PURE__ */ new WeakMap();
1592
+ function it(n, e) {
1593
+ return (n == null ? void 0 : n.label) == null && (n == null ? void 0 : n.icon) == null ? e : n;
1594
+ }
1595
+ class Fe extends X {
1596
+ init(e) {
1597
+ g(() => {
1598
+ var s;
1599
+ if (this._value = { label: void 0, icon: void 0 }, e) {
1600
+ const t = e, { value: i, originalValue: r, validators: a, actions: o } = t, c = k(t, ["value", "originalValue", "validators", "actions"]);
1601
+ this.registerInitialActions([...a || [], ...o || []]), this.assignParams(c);
1602
+ const u = it(i, this._value), C = Object.freeze({ label: r == null ? void 0 : r.label, icon: r == null ? void 0 : r.icon });
1603
+ this._value = it(u, p({}, C)), this.originalValue = it(C, u);
1604
+ }
1605
+ this.raw.announcedValue = this._value, (s = this._actions) == null || s.triggerEager(this, this.value, this.originalValue), this.validate();
1606
+ });
1607
+ }
1608
+ /**
1609
+ * A copy of the value this action holds, carrying one member rewritten. A member handed undefined is dropped
1610
+ * from the copy rather than written into it: an own key holding undefined is invisible to a reader and to
1611
+ * JSON, but lodash isEqual compares own-key sets, so writing one would leave the action permanently changed
1612
+ * against a baseline that never carried the key.
1613
+ */
1614
+ valueWith(e, t) {
1615
+ const s = p({}, this.value);
1616
+ return t === void 0 ? delete s[e] : s[e] = t, s;
779
1617
  }
780
1618
  get icon() {
781
1619
  return this.value.icon;
782
1620
  }
783
- set icon(i) {
784
- this.value.icon = i;
1621
+ set icon(e) {
1622
+ this.value.icon !== e && (this.value = this.valueWith("icon", e));
785
1623
  }
786
1624
  get label() {
787
1625
  return this.value.label;
788
1626
  }
789
- set label(i) {
790
- this.value.label = i;
1627
+ /**
1628
+ * The two setters hand the value setter a new object rather than writing into the one the action holds, so each
1629
+ * is an ordinary value change: the handlers fire, isChanged answers over it, and a disabled action refuses it.
1630
+ * The new object is built only for a member that differs from the one held - the value setter compares by
1631
+ * identity and every copy is a new object, so without the comparison here a write of the value already held
1632
+ * would announce a change and invalidate the value cache of every container above.
1633
+ */
1634
+ set label(e) {
1635
+ this.value.label !== e && (this.value = this.valueWith("label", e));
1636
+ }
1637
+ /** the counter behind `busy`, allocated for this action the first time it is asked for */
1638
+ get busyRuns() {
1639
+ let e = _t.get(this);
1640
+ return e || (e = se(0), _t.set(this, e)), e;
1641
+ }
1642
+ /** true from the moment execute() is called until the handler it ran has settled, however it settles */
1643
+ get busy() {
1644
+ return this.busyRuns.value > 0;
791
1645
  }
792
- execute(i) {
793
- this.actions.trigger(ft, this, i);
1646
+ /**
1647
+ * Runs the ExecuteAction chain registered on this action and answers what the chain returned. `busy` stands for
1648
+ * the length of the run: the chain is entered synchronously, and the flag is cleared once the value it produced
1649
+ * has settled - a handler that returns a promise holds it for as long as that promise takes, and one that
1650
+ * rejects clears it as it rejects.
1651
+ *
1652
+ * The answer is a promise whatever the handler returns, so a handler that throws rejects it rather than throwing
1653
+ * out of this call: a caller that does not await the answer and does not attach a catch handler leaves that
1654
+ * rejection unhandled.
1655
+ */
1656
+ execute(e) {
1657
+ return wt(this, null, function* () {
1658
+ const t = this.busyRuns;
1659
+ t.value++;
1660
+ try {
1661
+ return yield this.triggerAction(qt, e);
1662
+ } finally {
1663
+ t.value--;
1664
+ }
1665
+ });
794
1666
  }
795
1667
  }
796
- const Gt = /* @__PURE__ */ It({
1668
+ const Ne = /* @__PURE__ */ ie({
797
1669
  __name: "messages-widget",
798
1670
  props: {
799
1671
  message: {},
800
1672
  classes: {}
801
1673
  },
802
1674
  setup(n) {
803
- const i = n, t = st("vue-markdown"), e = /* @__PURE__ */ new Set([
1675
+ const e = n, t = yt("vue-markdown"), s = /* @__PURE__ */ new Set([
804
1676
  "div",
805
1677
  "span",
806
1678
  "p",
@@ -856,37 +1728,37 @@ const Gt = /* @__PURE__ */ It({
856
1728
  "dl",
857
1729
  "dt",
858
1730
  "dd"
859
- ]), s = () => {
860
- if (typeof i.message == "string") return j("span", { class: i.classes }, i.message);
1731
+ ]), i = () => {
1732
+ if (typeof e.message == "string") return R("span", { class: e.classes }, e.message);
861
1733
  const r = [];
862
- return i.message.forEach((a) => {
1734
+ return e.message.forEach((a) => {
863
1735
  switch (a.componentName) {
864
1736
  case "template":
865
- r.push(j("div", { class: [i.classes, a.extraClasses] }, a.componentBody));
1737
+ r.push(R("div", { class: [e.classes, a.extraClasses] }, a.componentBody));
866
1738
  break;
867
1739
  case "vue-markdown":
868
1740
  if (typeof t == "string")
869
1741
  console.warn(
870
1742
  "You are using markdown for messages-widget, but you haven't registered a vue-markdown component"
871
- ), r.push(j("div", { class: [i.classes, a.extraClasses] }, a.componentBindings.source));
1743
+ ), r.push(R("div", { class: [e.classes, a.extraClasses] }, a.componentBindings.source));
872
1744
  else {
873
- const l = a.componentBindings;
1745
+ const o = a.componentBindings;
874
1746
  r.push(
875
- j(t, {
876
- class: [i.classes, a.extraClasses, "df-messages-widget-markdown"],
877
- source: l.source,
878
- options: l.options,
879
- plugins: l.plugins
1747
+ R(t, {
1748
+ class: [e.classes, a.extraClasses, "df-messages-widget-markdown"],
1749
+ source: o.source,
1750
+ options: o.options,
1751
+ plugins: o.plugins
880
1752
  })
881
1753
  );
882
1754
  }
883
1755
  break;
884
1756
  default:
885
1757
  r.push(
886
- j(
887
- e.has(a.componentName.toLowerCase()) ? a.componentName : st(a.componentName),
888
- v(v({
889
- class: [i.classes, a.extraClasses]
1758
+ R(
1759
+ s.has(a.componentName.toLowerCase()) ? a.componentName : yt(a.componentName),
1760
+ p(p({
1761
+ class: [e.classes, a.extraClasses]
890
1762
  }, a.componentBindings), a.componentBody ? { innerHTML: a.componentBody } : {})
891
1763
  )
892
1764
  );
@@ -894,465 +1766,619 @@ const Gt = /* @__PURE__ */ It({
894
1766
  }
895
1767
  }), r;
896
1768
  };
897
- return (r, a) => (At(), St(s));
1769
+ return (r, a) => (ne(), re(i));
898
1770
  }
899
1771
  });
900
- class C extends V {
901
- constructor(t, e) {
902
- super();
903
- o(this, "_fields");
904
- o(this, "_value", null);
905
- o(this, "suppressNotifyValueChanged", !1);
906
- if (!C.isValidFields(t)) throw new Error("Invalid fields object provided");
907
- if (this._fields = /* @__PURE__ */ Object.create(null), Object.entries(t).forEach(([r, a]) => this.addField(r, a)), e) {
908
- const s = e, { value: r, validators: a, actions: l } = s, u = F(s, ["value", "validators", "actions"]);
909
- this.registerInitialActions([...a || [], ...l || []]), Object.assign(this, u), r !== void 0 ? this.assignMembers(r) : this.originalValue !== void 0 && this.assignMembers(this.originalValue);
910
- }
911
- this.originalValue === void 0 && (this.originalValue = this.value), this._value = this.value, this.actions.triggerEager(this, this.value, this.originalValue), this.validate();
1772
+ class w extends A {
1773
+ constructor(t, s) {
1774
+ super(Qt());
1775
+ d(this, "_fields");
1776
+ if (!w.isValidFields(t)) throw new Error("Invalid fields object provided");
1777
+ this._fields = /* @__PURE__ */ Object.create(null), g(() => {
1778
+ var a;
1779
+ if (Object.entries(t).forEach(([o, c]) => this.addField(o, c)), s) {
1780
+ const r = s, { value: o, validators: c, actions: u } = r, C = k(r, ["value", "validators", "actions"]);
1781
+ this.registerInitialActions([...c || [], ...u || []]), this.assignParams(C), o !== void 0 ? this.assignMembers(o) : this.originalValue !== void 0 && this.assignMembers(this.originalValue);
1782
+ }
1783
+ this.completeRecords();
1784
+ const i = this.value;
1785
+ this.originalValue === void 0 && (this.originalValue = w.baseline(i)), this.raw.announcedValue = i, (a = this._actions) == null || a.triggerEager(this, i, this.originalValue), this.validate();
1786
+ });
1787
+ }
1788
+ get state() {
1789
+ return super.state;
1790
+ }
1791
+ get raw() {
1792
+ return super.raw;
1793
+ }
1794
+ /**
1795
+ * The copy of a built value that serves as a baseline. The value getter hands out one object per version, and
1796
+ * a baseline holding that same object would report every value as its own original.
1797
+ */
1798
+ static baseline(t) {
1799
+ return t == null ? t : p({}, t);
912
1800
  }
913
- addField(t, e) {
1801
+ addField(t, s) {
914
1802
  if (Object.hasOwn(this._fields, t))
915
1803
  throw new Error(`Field ${t} is already in this form`);
916
- Object.defineProperty(e, "parent", { get: () => this, configurable: !1, enumerable: !1 }), Object.defineProperty(e, "fieldName", { get: () => t, configurable: !1, enumerable: !1 }), Object.defineProperty(this._fields, t, { get: () => e, configurable: !1, enumerable: !0 });
1804
+ this.takeChild(s, t), Object.defineProperty(this._fields, t, { get: () => s, configurable: !1, enumerable: !0 });
917
1805
  }
918
1806
  static isValidFields(t) {
919
- function e(s) {
920
- return s instanceof V;
1807
+ function s(i) {
1808
+ return i instanceof A;
921
1809
  }
922
- return typeof t == "object" && t !== null && Object.entries(t).every(([, s]) => e(s));
1810
+ return typeof t == "object" && t !== null && Object.entries(t).every(([, i]) => s(i));
923
1811
  }
924
1812
  static createFromFormData(t) {
925
- if (t instanceof V)
1813
+ if (t instanceof A)
926
1814
  throw new Error("data is already a Form structure, should be a simple object");
927
- return new C(
928
- t == null ? {} : Object.fromEntries(Object.entries(t).map(([e, s]) => [e, new $({ value: s })]))
1815
+ return new w(
1816
+ t == null ? {} : Object.fromEntries(Object.entries(t).map(([s, i]) => [s, new X({ value: i })]))
929
1817
  );
930
1818
  }
931
1819
  field(t) {
932
- var e;
933
- return (e = this._fields[t]) != null ? e : null;
1820
+ var s;
1821
+ return (s = this._fields[t]) != null ? s : null;
934
1822
  }
935
1823
  get fields() {
936
1824
  return this._fields;
937
1825
  }
1826
+ get members() {
1827
+ return Object.values(this._fields);
1828
+ }
938
1829
  get value() {
939
- const t = /* @__PURE__ */ Object.create(null);
940
- return Object.entries(this._fields).forEach(([e, s]) => {
941
- const r = s.value;
942
- (s.enabled || s instanceof C && !Q(r)) && (t[e] = r);
943
- }), Q(t) ? null : v({}, t);
1830
+ const t = this.valueVersion;
1831
+ if (this.raw.cachedValueVersion === t) return this.raw.cachedValue;
1832
+ const s = /* @__PURE__ */ Object.create(null);
1833
+ Object.entries(this._fields).forEach(([r, a]) => {
1834
+ const o = a.value;
1835
+ (a.enabled || a instanceof w && !L(o)) && (s[r] = o);
1836
+ });
1837
+ const i = L(s) ? null : Object.freeze(p({}, s));
1838
+ return this.raw.cachedValue = i, this.raw.cachedValueVersion = t, i;
944
1839
  }
945
1840
  /**
946
- * Writes the members that the given value carries, without letting any single member announce the state in
947
- * between: the group's own value notification and its own validation are both held back for the duration, so
948
- * neither a ValueChangedAction nor a ValidChangedAction reports a verdict over a half-applied value. The
949
- * caller decides what to announce once the whole value is in place. Both flags are restored to what they were,
950
- * so a caller that is itself holding the group back stays in charge.
1841
+ * Writes the members that the given value carries. The members are written one by one and the group says
1842
+ * nothing in between: the transaction the assignment runs in measures the group's own value and its own verdict
1843
+ * once, over the finished set, and announces each at most once.
951
1844
  */
952
1845
  assignMembers(t) {
953
- const e = this.suppressNotifyValueChanged, s = this.suppressValidation;
954
- this.suppressNotifyValueChanged = !0, this.suppressValidation = !0;
955
- try {
956
- Object.entries(this._fields).forEach(([r, a]) => {
957
- (t == null || Object.hasOwn(t, r)) && (a.value = t == null ? null : t[r]);
1846
+ g(() => {
1847
+ Object.entries(this._fields).forEach(([s, i]) => {
1848
+ (t == null || Object.hasOwn(t, s)) && (i.value = t == null ? null : t[s]);
958
1849
  });
959
- } finally {
960
- this.suppressNotifyValueChanged = e, this.suppressValidation = s;
961
- }
1850
+ });
962
1851
  }
963
1852
  set value(t) {
964
- this.assignMembers(t), this.notifyValueChanged(), this.validate();
1853
+ g((s) => {
1854
+ this.assignMembers(t), s.markValidityDirty(this);
1855
+ });
1856
+ }
1857
+ /**
1858
+ * Members are reset one by one rather than assigned as a whole value: the value setter writes only the keys the
1859
+ * value carries, while a member the value leaves out has to end up holding what the template gives it. `source`
1860
+ * supplies that per member, so a group reset from the template it was bound from matches a fresh binding of it.
1861
+ */
1862
+ resetTo(t, s) {
1863
+ const i = t;
1864
+ g((r) => {
1865
+ r.touch(this), this.errors.length && (this.errors = []), Object.entries(this._fields).forEach(([o, c]) => {
1866
+ var C;
1867
+ let u;
1868
+ s === null ? u = null : s !== void 0 && Object.hasOwn(s, o) && (u = s[o]), this.resetChild(c, (C = i.field(o)) != null ? C : c, u);
1869
+ });
1870
+ const a = this.value;
1871
+ this.raw.announcedValue = a, this.originalValue = w.baseline(a), super.validate(!0);
1872
+ });
965
1873
  }
966
1874
  get touched() {
967
1875
  return Object.values(this._fields).some((t) => t.touched);
968
1876
  }
969
1877
  set touched(t) {
970
- Object.values(this._fields).forEach((e) => {
971
- e.touched = t;
1878
+ g(() => {
1879
+ Object.values(this._fields).forEach((s) => {
1880
+ s.touched = t;
1881
+ });
972
1882
  });
973
1883
  }
974
1884
  get fullValue() {
975
1885
  const t = /* @__PURE__ */ Object.create(null);
976
- return Object.entries(this._fields).forEach(([e, s]) => {
977
- t[e] = s.fullValue;
978
- }), v({}, t);
1886
+ return Object.entries(this._fields).forEach(([s, i]) => {
1887
+ t[s] = i.fullValue;
1888
+ }), p({}, t);
979
1889
  }
1890
+ /**
1891
+ * Records that a member changed its value, so that the transaction in progress works out at commit what this
1892
+ * group's own value became and announces it once. A mutation method calls it itself; you rarely need to.
1893
+ */
980
1894
  notifyValueChanged() {
981
- if (this.suppressNotifyValueChanged) return;
982
- const t = this.value;
983
- if (!D(t, this._value)) {
984
- const e = this._value;
985
- this._value = t;
986
- const s = this.suppressParentValidityClimb;
987
- this.suppressParentValidityClimb = !0;
988
- try {
989
- this.actions.trigger(y, this, t, e), this.parent && this.parent.notifyValueChanged();
990
- } finally {
991
- this.suppressParentValidityClimb = s, this.validate(), this.flushParentValidityClimb();
992
- }
993
- }
1895
+ this.propagateValueChanged();
1896
+ }
1897
+ get composesValue() {
1898
+ return !0;
1899
+ }
1900
+ /**
1901
+ * A group with nothing listening for its value does not compose one at all, so the copy it holds is from before
1902
+ * the changes nobody received. A registration that adds a listener brings it up to date here, and what the
1903
+ * listener is then told about is the change that follows it.
1904
+ */
1905
+ refreshPreviousValue() {
1906
+ this.raw.announcedValue = this.value;
994
1907
  }
995
1908
  get valid() {
996
- return super.valid && Object.values(this._fields).every((t) => t.valid);
1909
+ return this.validRead;
1910
+ }
1911
+ composeValid() {
1912
+ return this.state.errors.length === 0 && Object.values(this._fields).every((t) => t.valid);
997
1913
  }
998
1914
  validate(t = !1) {
999
- if (t) {
1000
- const e = this.suppressValidation;
1001
- this.suppressValidation = !0;
1002
- try {
1003
- Object.values(this._fields).forEach((s) => s.validate(!0));
1004
- } finally {
1005
- this.suppressValidation = e;
1006
- }
1007
- }
1008
- super.validate(t);
1915
+ g(() => {
1916
+ t && Object.values(this._fields).forEach((s) => s.validate(!0)), super.validate(t);
1917
+ });
1009
1918
  }
1010
- clone(t) {
1011
- var r, a;
1012
- const e = /* @__PURE__ */ Object.create(null);
1013
- Object.entries(this._fields).forEach(([l, u]) => {
1014
- e[l] = u.clone();
1919
+ bind(t, s) {
1920
+ var a, o;
1921
+ const i = /* @__PURE__ */ Object.create(null);
1922
+ Object.entries(this._fields).forEach(([c, u]) => {
1923
+ i[c] = u.bind();
1015
1924
  });
1016
- const s = new C(e, w(v({
1017
- // an override value is one the caller supplied, and undefined is not one; an explicit null is, and clears
1018
- value: (t == null ? void 0 : t.value) !== void 0 ? t.value : this.value
1019
- }, t && "originalValue" in t ? { originalValue: t.originalValue } : {}), {
1020
- enabled: (r = t == null ? void 0 : t.enabled) != null ? r : this.enabled,
1021
- visibility: (a = t == null ? void 0 : t.visibility) != null ? a : this.visibility
1925
+ const r = new w(i, x(p({
1926
+ // data is what the caller supplied, and undefined is not supplied; an explicit null is, and clears
1927
+ value: t !== void 0 ? t : this.value
1928
+ }, s && "originalValue" in s ? { originalValue: s.originalValue } : {}), {
1929
+ enabled: (a = s == null ? void 0 : s.enabled) != null ? a : this.enabled,
1930
+ visibility: (o = s == null ? void 0 : s.visibility) != null ? o : this.visibility
1022
1931
  }));
1023
- return s.actions = this.actions.clone(), s.actions.triggerEager(s, s.value, s.originalValue), s;
1932
+ return r.boundFrom(this, r.raw.announcedValue, r.originalValue, s), r;
1933
+ }
1934
+ /**
1935
+ * A record need not name every member: a key it leaves out is taken from the declaration, the same way a member
1936
+ * the constructor is given no value for takes the one it was declared with.
1937
+ */
1938
+ rebind(t) {
1939
+ return super.rebind(t);
1024
1940
  }
1025
1941
  }
1026
- class Y extends V {
1027
- constructor(t, e) {
1028
- super();
1029
- o(this, "_value", null);
1030
- o(this, "_itemTemplate");
1031
- o(this, "_previousValue");
1032
- if (this._itemTemplate = t, e) {
1033
- const s = e, { value: r, validators: a, actions: l } = s, u = F(s, ["value", "validators", "actions"]);
1034
- this.registerInitialActions([...a || [], ...l || []]), Object.assign(this, u), r != null && this.setValueInternal(r);
1035
- }
1036
- this.originalValue === void 0 && (this.originalValue = this.value), this._previousValue = this.value, this.actions.triggerEager(this, this.value, this.originalValue), this.validate();
1942
+ class D extends A {
1943
+ constructor(t, s) {
1944
+ super(je());
1945
+ d(this, "_itemTemplate");
1946
+ this._itemTemplate = t, g(() => {
1947
+ var r;
1948
+ if (s) {
1949
+ const i = s, { value: a, validators: o, actions: c } = i, u = k(i, ["value", "validators", "actions"]);
1950
+ this.registerInitialActions([...o || [], ...c || []]), this.assignParams(u), a != null && this.setValueInternal(a);
1951
+ }
1952
+ this.originalValue === void 0 && (this.originalValue = D.baseline(this.value)), this.raw.announcedValue = this.value, (r = this._actions) == null || r.triggerEager(this, this.value, this.originalValue), this.validate();
1953
+ });
1954
+ }
1955
+ get state() {
1956
+ return super.state;
1957
+ }
1958
+ get raw() {
1959
+ return super.raw;
1960
+ }
1961
+ /** The row array is copied as well: a rollback puts back the set the list held, not the array it went on to hold. */
1962
+ [z]() {
1963
+ const t = super[z]();
1964
+ return t.rows = this.raw.rows ? [...this.raw.rows] : this.raw.rows, t;
1965
+ }
1966
+ /**
1967
+ * The copy of a built value that serves as a baseline. The value getter hands out one array per version, and a
1968
+ * baseline holding that same array would report every value as its own original.
1969
+ */
1970
+ static baseline(t) {
1971
+ return t == null ? t : [...t];
1037
1972
  }
1038
1973
  processSetValueItem(t) {
1039
- let e;
1040
- return t instanceof C ? e = t : this._itemTemplate ? e = this._itemTemplate.clone({ value: t }) : e = C.createFromFormData(t), Object.defineProperty(e, "parent", { get: () => this, configurable: !1, enumerable: !1 }), e;
1974
+ let s;
1975
+ return t instanceof w ? s = t : this._itemTemplate ? s = this._itemTemplate.bind(t) : s = w.createFromFormData(t), this.takeChild(s), this.completeRecords(s), s;
1041
1976
  }
1042
1977
  /**
1043
- * Builds the item that fills a gap left by an insert beyond the end of the list: a copy of the item template with
1044
- * the template's own values, or an empty group when the list has no template.
1978
+ * Builds the item that fills a gap left by an insert beyond the end of the list: the item template bound to its
1979
+ * own values, or an empty group when the list has no template.
1045
1980
  */
1046
1981
  createPaddingItem() {
1047
- return this.processSetValueItem(this._itemTemplate ? this._itemTemplate.clone() : null);
1982
+ return this.processSetValueItem(this._itemTemplate ? this._itemTemplate.bind() : null);
1048
1983
  }
1049
1984
  setValueInternal(t) {
1050
- t == null ? this._value = null : Array.isArray(t) && (this._value = t.map((e) => this.processSetValueItem(e)));
1985
+ g((s) => {
1986
+ var i;
1987
+ if (s.touch(this), t == null)
1988
+ this.releaseRows(), this.state.rows = null;
1989
+ else if (Array.isArray(t)) {
1990
+ const r = (i = this.state.rows) != null ? i : [], a = new Array(t.length);
1991
+ for (let o = 0; o < t.length; o++) {
1992
+ const c = t[o], u = r[o];
1993
+ u && this._itemTemplate && !(c instanceof w) ? (this.resetChild(u, this._itemTemplate, c), a[o] = u) : (u && this.releaseChild(u), a[o] = this.processSetValueItem(c));
1994
+ }
1995
+ for (let o = t.length; o < r.length; o++) this.releaseChild(r[o]);
1996
+ this.state.rows = a;
1997
+ }
1998
+ this.bumpValueVersion();
1999
+ });
1051
2000
  }
1052
2001
  get value() {
1053
- var e;
1054
- const t = (e = this._value) == null ? void 0 : e.map((s) => s.value);
1055
- return Q(t) ? null : t;
2002
+ var r;
2003
+ const t = this.valueVersion;
2004
+ if (this.raw.cachedValueVersion === t) return this.raw.cachedValue;
2005
+ const s = (r = this.state.rows) == null ? void 0 : r.map((a) => a.value), i = L(s) ? null : Object.freeze(s);
2006
+ return this.raw.cachedValue = i, this.raw.cachedValueVersion = t, i;
1056
2007
  }
1057
2008
  set value(t) {
1058
- const e = this._previousValue;
1059
- this.setValueInternal(t);
1060
- const s = this.value;
1061
- this._previousValue = s;
1062
- const r = this.suppressParentValidityClimb;
1063
- this.suppressParentValidityClimb = !0;
1064
- try {
1065
- this.actions.trigger(y, this, s, e), this.parent && this.parent.notifyValueChanged();
1066
- } finally {
1067
- this.suppressParentValidityClimb = r, this.validate(), this.flushParentValidityClimb();
1068
- }
2009
+ g(() => {
2010
+ this.setValueInternal(t), this.propagateValueChanged(!0);
2011
+ });
2012
+ }
2013
+ /**
2014
+ * The rows are taken from `source` where the caller supplied no value of its own, so a list nested in a row that
2015
+ * a whole-list assignment reuses ends up holding what the template gives it rather than what it held before.
2016
+ */
2017
+ resetTo(t, s) {
2018
+ g((i) => {
2019
+ i.touch(this), this.errors.length && (this.errors = []), this.setValueInternal(s === void 0 ? t.value : s);
2020
+ const r = this.value;
2021
+ this.raw.announcedValue = r, this.originalValue = D.baseline(r), super.validate(!0);
2022
+ });
1069
2023
  }
1070
2024
  get touched() {
1071
2025
  var t;
1072
- return ((t = this._value) == null ? void 0 : t.some((e) => e.touched)) || !1;
2026
+ return ((t = this.state.rows) == null ? void 0 : t.some((s) => s.touched)) || !1;
1073
2027
  }
1074
2028
  set touched(t) {
1075
- var e;
1076
- (e = this._value) == null || e.forEach((s) => {
1077
- s.touched = t;
2029
+ g(() => {
2030
+ var s;
2031
+ (s = this.state.rows) == null || s.forEach((i) => {
2032
+ i.touched = t;
2033
+ });
1078
2034
  });
1079
2035
  }
1080
- clone(t) {
1081
- var s, r, a, l;
1082
- const e = new Y((s = this._itemTemplate) == null ? void 0 : s.clone(), w(v({
1083
- // an override value is one the caller supplied, and undefined is not one; an explicit null is, and clears
1084
- value: [...(r = (t == null ? void 0 : t.value) !== void 0 ? t.value : this.value) != null ? r : []]
1085
- }, t && "originalValue" in t ? { originalValue: t.originalValue } : {}), {
1086
- enabled: (a = t == null ? void 0 : t.enabled) != null ? a : this.enabled,
1087
- visibility: (l = t == null ? void 0 : t.visibility) != null ? l : this.visibility
2036
+ bind(t, s) {
2037
+ var r, a, o, c;
2038
+ const i = new D((r = this._itemTemplate) == null ? void 0 : r.bind(), x(p({
2039
+ // data is what the caller supplied, and undefined is not supplied; an explicit null is, and clears
2040
+ value: [...(a = t !== void 0 ? t : this.value) != null ? a : []]
2041
+ }, s && "originalValue" in s ? { originalValue: s.originalValue } : {}), {
2042
+ enabled: (o = s == null ? void 0 : s.enabled) != null ? o : this.enabled,
2043
+ visibility: (c = s == null ? void 0 : s.visibility) != null ? c : this.visibility
1088
2044
  }));
1089
- return e.actions = this.actions.clone(), e.actions.triggerEager(e, e.value, e.originalValue), e;
2045
+ return i.boundFrom(this, i.value, i.originalValue, s), i;
1090
2046
  }
2047
+ /**
2048
+ * Records that a row changed its value, so that the transaction in progress works out at commit what this
2049
+ * list's own value became and announces it once. The mutation methods call it themselves; you rarely need to.
2050
+ */
1091
2051
  notifyValueChanged() {
1092
- const t = this.value;
1093
- if (!D(t, this._previousValue)) {
1094
- const e = this._previousValue;
1095
- this._previousValue = t;
1096
- const s = this.suppressParentValidityClimb;
1097
- this.suppressParentValidityClimb = !0;
1098
- try {
1099
- this.actions.trigger(y, this, t, e), this.parent && this.parent.notifyValueChanged();
1100
- } finally {
1101
- this.suppressParentValidityClimb = s, this.validate(), this.flushParentValidityClimb();
1102
- }
1103
- }
2052
+ this.propagateValueChanged();
2053
+ }
2054
+ get composesValue() {
2055
+ return !0;
2056
+ }
2057
+ /**
2058
+ * A list with nothing listening for its value does not compose one at all, so the copy it holds is from before
2059
+ * the changes nobody received. A registration that adds a listener brings it up to date here, and what the
2060
+ * listener is then told about is the change that follows it.
2061
+ */
2062
+ refreshPreviousValue() {
2063
+ this.raw.announcedValue = this.value;
1104
2064
  }
1105
2065
  get valid() {
1106
- var t, e;
1107
- return super.valid && ((e = (t = this._value) == null ? void 0 : t.every((s) => s.valid)) != null ? e : !0);
2066
+ return this.validRead;
2067
+ }
2068
+ composeValid() {
2069
+ var t, s;
2070
+ return this.state.errors.length === 0 && ((s = (t = this.state.rows) == null ? void 0 : t.every((i) => i.valid)) != null ? s : !0);
1108
2071
  }
1109
2072
  validate(t = !1) {
1110
- var e;
1111
- if (t) {
1112
- const s = this.suppressValidation;
1113
- this.suppressValidation = !0;
1114
- try {
1115
- (e = this._value) == null || e.forEach((r) => r.validate(!0));
1116
- } finally {
1117
- this.suppressValidation = s;
1118
- }
1119
- }
1120
- super.validate(t);
2073
+ g(() => {
2074
+ var s;
2075
+ t && ((s = this.state.rows) == null || s.forEach((i) => i.validate(!0))), super.validate(t);
2076
+ });
2077
+ }
2078
+ get members() {
2079
+ var t;
2080
+ return (t = this.raw.rows) != null ? t : [];
1121
2081
  }
1122
2082
  get(t) {
1123
- return this._value != null ? this._value[t] : void 0;
2083
+ return this.state.rows != null ? this.state.rows[t] : void 0;
1124
2084
  }
1125
2085
  push(t) {
1126
- var e, s;
1127
- return this.insert(t, (s = (e = this._value) == null ? void 0 : e.length) != null ? s : 0) + 1;
2086
+ var s, i;
2087
+ return this.insert(t, (i = (s = this.state.rows) == null ? void 0 : s.length) != null ? i : 0) + 1;
1128
2088
  }
1129
2089
  pop() {
1130
- var t, e;
1131
- return this.remove(((e = (t = this._value) == null ? void 0 : t.length) != null ? e : 0) - 1);
2090
+ var t, s;
2091
+ return this.remove(((s = (t = this.state.rows) == null ? void 0 : t.length) != null ? s : 0) - 1);
1132
2092
  }
1133
2093
  remove(t) {
1134
- var s;
1135
- if (this._value == null || t < 0 || this._value.length <= t) return;
1136
- let e = (s = this._value.splice(t, 1)) == null ? void 0 : s[0];
1137
- return e && (e = e.clone(), this.actions.trigger(pt, this, e, t), this.notifyValueChanged()), e;
1138
- }
1139
- insert(t, e) {
1140
- this._value == null && (this._value = []);
1141
- const s = e < 0 ? Math.max(this._value.length + e, 0) : e;
1142
- for (; this._value.length < s; ) {
1143
- const a = this.createPaddingItem(), l = this._value.push(a) - 1;
1144
- this.actions.trigger(z, this, a, l);
1145
- }
1146
- const r = this.processSetValueItem(t);
1147
- return this._value.splice(s, 0, r), this.actions.trigger(z, this, r, s), this.notifyValueChanged(), s;
2094
+ let s;
2095
+ return g((i) => {
2096
+ var a;
2097
+ if (this.state.rows == null || t < 0 || this.state.rows.length <= t) return;
2098
+ i.touch(this);
2099
+ const r = (a = this.state.rows.splice(t, 1)) == null ? void 0 : a[0];
2100
+ r && (this.releaseChild(r), this.bumpValueVersion(), s = r, i.recordStructural(this, { actionClass: zt, item: s, index: t }), this.propagateValueChanged(!0));
2101
+ }), s;
2102
+ }
2103
+ insert(t, s) {
2104
+ let i = 0;
2105
+ return g((r) => {
2106
+ for (r.touch(this), this.state.rows == null && (this.state.rows = []), i = s < 0 ? Math.max(this.state.rows.length + s, 0) : s; this.state.rows.length < i; ) {
2107
+ const o = this.createPaddingItem(), c = this.state.rows.push(o) - 1;
2108
+ this.bumpValueVersion(), r.recordStructural(this, { actionClass: at, item: o, index: c });
2109
+ }
2110
+ const a = this.processSetValueItem(t);
2111
+ this.state.rows.splice(i, 0, a), r.recordStructural(this, { actionClass: at, item: a, index: i }), this.bumpValueVersion(), this.propagateValueChanged(!0);
2112
+ }), i;
2113
+ }
2114
+ /** Drops every row this list holds out of its tally, so a row that changes its verdict later is not counted. */
2115
+ releaseRows() {
2116
+ var t;
2117
+ (t = this.state.rows) == null || t.forEach((s) => this.releaseChild(s));
1148
2118
  }
1149
2119
  clear() {
1150
- this._value = null, this.notifyValueChanged();
2120
+ g((t) => {
2121
+ var i, r;
2122
+ const s = ((r = (i = this.state.rows) == null ? void 0 : i.length) != null ? r : 0) > 0;
2123
+ t.touch(this), this.releaseRows(), this.state.rows = null, this.bumpValueVersion(), this.propagateValueChanged(s);
2124
+ });
1151
2125
  }
1152
2126
  }
1153
- class Yt extends f {
1154
- constructor(t, e, s) {
1155
- let r = !1, a, l;
1156
- super((d, x, _) => (a = d, l = x, r || (r = !0, this.otherField.registerAction(
1157
- new y((P, B, p, E) => {
1158
- B(P, p, E), this.unregistered || this.execute(_, () => null, a, l);
2127
+ class ke extends v {
2128
+ constructor(t, s, i) {
2129
+ super((a, o, c) => {
2130
+ this.comparisonState(c).oldValue = o;
2131
+ const u = this.resolve(c);
2132
+ return u ? (this.listenOn(u), this.isValidComparison(b(a), b(u.value)) ? null : [
2133
+ new V(
2134
+ this.replacePlaceholders(i, { newValue: a, oldValue: o, field: c, otherField: u })
2135
+ )
2136
+ ]) : (c.markRecordIncomplete(), null);
2137
+ });
2138
+ d(this, "isValidComparison");
2139
+ d(this, "otherField");
2140
+ /**
2141
+ * The fields this validator is registered on. Registration reaches one element at a time - the rows of a list
2142
+ * take the validator on one by one, as they are built from the item template that carries it - so this is what
2143
+ * says which of the fields a declaration stands for actually carry the rule, and a field that never took it on
2144
+ * is left alone by a change of the compared field.
2145
+ */
2146
+ d(this, "registrations", /* @__PURE__ */ new WeakSet());
2147
+ /**
2148
+ * The fields this validator has installed its listener on. A binding of such a field carries the listener too -
2149
+ * a binding takes on the actions of the field it was bound from - so the field it was bound from is what is
2150
+ * asked about as well, and a list of a thousand rows installs one listener rather than a thousand.
2151
+ */
2152
+ d(this, "listening", /* @__PURE__ */ new WeakSet());
2153
+ /**
2154
+ * What the fields this validator was registered on were declared as. One entry stands for every binding of such a
2155
+ * field, so a change of a compared field finds the fields of the record that change happened in without a list
2156
+ * of a thousand rows being held here.
2157
+ */
2158
+ d(this, "declarations", /* @__PURE__ */ new Set());
2159
+ this.isValidComparison = s, this.otherField = t;
2160
+ }
2161
+ /** The field `field` is compared against, within the record `field` belongs to. */
2162
+ resolve(t) {
2163
+ var i;
2164
+ const s = this.otherField;
2165
+ return typeof s == "function" ? (i = s(t)) != null ? i : void 0 : typeof s == "string" ? pe(s, t) : ut(s, T(t));
2166
+ }
2167
+ /**
2168
+ * Makes a change of `other` re-run this comparison. The listener re-runs it over the fields of the record the
2169
+ * change happened in rather than over the field that installed it, so the listener a row inherits with the field
2170
+ * it was bound from serves that row; and it re-runs this one validator, not the chain around it.
2171
+ */
2172
+ listenOn(t) {
2173
+ this.listening.has(t) || this.listening.has(t.declaration) || (this.listening.add(t), t.registerAction(
2174
+ new O((s, i, r, a) => {
2175
+ i(s, r, a);
2176
+ const o = T(s);
2177
+ this.declarations.forEach(
2178
+ (c) => Lt(c, o).forEach((u) => {
2179
+ this.registrations.has(u) && this.execute(u, () => null, u.value, this.comparisonState(u).oldValue);
2180
+ })
2181
+ );
1159
2182
  })
1160
- )), this.isValidComparison(h(d), h(this.otherField.value)) ? null : [
1161
- new g(
1162
- this.replacePlaceholders(s, { newValue: d, oldValue: x, field: _, otherField: this.otherField })
1163
- )
1164
- ]));
1165
- o(this, "otherField");
1166
- o(this, "isValidComparison");
1167
- o(this, "unregistered", !1);
1168
- this.otherField = t, this.isValidComparison = e;
2183
+ ));
2184
+ }
2185
+ boundToBinding(t) {
2186
+ this.declarations.add(t.declaration), this.registrations.add(t);
1169
2187
  }
1170
- unregister() {
1171
- this.unregistered = !0;
2188
+ comparisonState(t) {
2189
+ return this.bindingState(t);
2190
+ }
2191
+ newBindingState() {
2192
+ return x(p({}, super.newBindingState()), { oldValue: void 0 });
2193
+ }
2194
+ unregisterFrom(t) {
2195
+ this.registrations.delete(t);
1172
2196
  }
1173
2197
  }
1174
- class Jt extends f {
1175
- constructor(i, t) {
1176
- const e = t || b("Must be one of [**{allowedAsText}**]");
1177
- let s = i.join(", ");
1178
- s.length > 60 && (s = Ct(s, {
2198
+ class Re extends v {
2199
+ constructor(e, t) {
2200
+ const s = t || E("Must be one of [**{allowedAsText}**]");
2201
+ let i = e.join(", ");
2202
+ i.length > 60 && (i = Zt(i, {
1179
2203
  length: 40,
1180
2204
  separator: ", ",
1181
- omission: `... (${i.length} items total)`
2205
+ omission: `... (${e.length} items total)`
1182
2206
  }));
1183
- const r = (a, l, u) => i.includes(h(a)) ? null : [
1184
- new g(
1185
- this.replacePlaceholders(e, { newValue: a, oldValue: l, field: u, allowedValues: i, allowedAsText: s })
2207
+ const r = (a, o, c) => e.includes(b(a)) ? null : [
2208
+ new V(
2209
+ this.replacePlaceholders(s, { newValue: a, oldValue: o, field: c, allowedValues: e, allowedAsText: i })
1186
2210
  )
1187
2211
  ];
1188
2212
  super(r);
1189
2213
  }
1190
2214
  }
1191
- function Kt(n) {
1192
- return n == null ? 0 : rt(n) || A(n) ? n.length : at(n) && Object.getPrototypeOf(n) === Object.prototype ? Object.keys(n).length : String(n).length;
2215
+ function De(n) {
2216
+ return n == null ? 0 : Tt(n) || P(n) ? n.length : Ot(n) && Object.getPrototypeOf(n) === Object.prototype ? Object.keys(n).length : String(n).length;
1193
2217
  }
1194
- class Zt extends f {
1195
- constructor(i) {
1196
- const t = i || b("Please enter a value"), e = (s, r, a) => Kt(h(s)) === 0 ? [new g(this.replacePlaceholders(t, { newValue: s, oldValue: r, field: a }))] : null;
1197
- super(e);
2218
+ class Le extends v {
2219
+ constructor(e) {
2220
+ const t = e || E("Please enter a value"), s = (i, r, a) => De(b(i)) === 0 ? [new V(this.replacePlaceholders(t, { newValue: i, oldValue: r, field: a }))] : null;
2221
+ super(s);
1198
2222
  }
1199
2223
  }
1200
- class te extends f {
1201
- constructor(i, t) {
1202
- const e = t || b("Value must be larger or equal to **{minValue}**"), s = (r, a, l) => r < i || r === void 0 ? [
1203
- new g(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, minValue: i }))
2224
+ class Be extends v {
2225
+ constructor(e, t) {
2226
+ const s = t || E("Value must be larger or equal to **{minValue}**"), i = (r, a, o) => r < e || r === void 0 ? [
2227
+ new V(this.replacePlaceholders(s, { newValue: r, oldValue: a, field: o, minValue: e }))
1204
2228
  ] : null;
1205
- super(s);
2229
+ super(i);
1206
2230
  }
1207
2231
  }
1208
- class ee extends f {
1209
- constructor(i, t) {
1210
- const e = t || b("Value must be less than or equal to **{maxValue}**"), s = (r, a, l) => r > i || r === void 0 ? [
1211
- new g(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, maxValue: i }))
2232
+ class Ue extends v {
2233
+ constructor(e, t) {
2234
+ const s = t || E("Value must be less than or equal to **{maxValue}**"), i = (r, a, o) => r > e || r === void 0 ? [
2235
+ new V(this.replacePlaceholders(s, { newValue: r, oldValue: a, field: o, maxValue: e }))
1212
2236
  ] : null;
1213
- super(s);
2237
+ super(i);
1214
2238
  }
1215
2239
  }
1216
- class ie extends f {
1217
- constructor(i, t, e) {
1218
- const s = e || b("Value must be between **{minValue}** and **{maxValue}**"), r = (a, l, u) => a < i || a > t || a === void 0 ? [
1219
- new g(
1220
- this.replacePlaceholders(s, { newValue: a, oldValue: l, field: u, minValue: i, maxValue: t })
2240
+ class Me extends v {
2241
+ constructor(e, t, s) {
2242
+ const i = s || E("Value must be between **{minValue}** and **{maxValue}**"), r = (a, o, c) => a < e || a > t || a === void 0 ? [
2243
+ new V(
2244
+ this.replacePlaceholders(i, { newValue: a, oldValue: o, field: c, minValue: e, maxValue: t })
1221
2245
  )
1222
2246
  ] : null;
1223
2247
  super(r);
1224
2248
  }
1225
2249
  }
1226
- function J(n) {
1227
- return n == null ? 0 : rt(n) || A(n) ? n.length : at(n) && Object.getPrototypeOf(n) === Object.prototype ? Object.keys(n).length : String(n).length;
2250
+ function ht(n) {
2251
+ return n == null ? 0 : Tt(n) || P(n) ? n.length : Ot(n) && Object.getPrototypeOf(n) === Object.prototype ? Object.keys(n).length : String(n).length;
1228
2252
  }
1229
- class se extends f {
1230
- constructor(i, t) {
1231
- const e = t || b("Length must be larger or equal to **{minLength}**"), s = (r, a, l) => J(r) < i ? [
1232
- new g(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, minLength: i }))
2253
+ class We extends v {
2254
+ constructor(e, t) {
2255
+ const s = t || E("Length must be larger or equal to **{minLength}**"), i = (r, a, o) => ht(r) < e ? [
2256
+ new V(this.replacePlaceholders(s, { newValue: r, oldValue: a, field: o, minLength: e }))
1233
2257
  ] : null;
1234
- super(s);
2258
+ super(i);
1235
2259
  }
1236
2260
  }
1237
- class ne extends f {
1238
- constructor(i, t) {
1239
- const e = t || b("Length must be less than or equal to **{maxLength}**"), s = (r, a, l) => J(r) > i ? [
1240
- new g(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, maxLength: i }))
2261
+ class $e extends v {
2262
+ constructor(e, t) {
2263
+ const s = t || E("Length must be less than or equal to **{maxLength}**"), i = (r, a, o) => ht(r) > e ? [
2264
+ new V(this.replacePlaceholders(s, { newValue: r, oldValue: a, field: o, maxLength: e }))
1241
2265
  ] : null;
1242
- super(s);
2266
+ super(i);
1243
2267
  }
1244
2268
  }
1245
- class re extends f {
1246
- constructor(i, t, e) {
1247
- const s = e || b("Length must be between **{minLength}** and **{maxLength}**"), r = (a, l, u) => {
1248
- const d = J(a);
1249
- return d < i || d > t ? [
1250
- new g(
1251
- this.replacePlaceholders(s, { newValue: a, oldValue: l, field: u, minLength: i, maxLength: t })
2269
+ class qe extends v {
2270
+ constructor(e, t, s) {
2271
+ const i = s || E("Length must be between **{minLength}** and **{maxLength}**"), r = (a, o, c) => {
2272
+ const u = ht(a);
2273
+ return u < e || u > t ? [
2274
+ new V(
2275
+ this.replacePlaceholders(i, { newValue: a, oldValue: o, field: c, minLength: e, maxLength: t })
1252
2276
  )
1253
2277
  ] : null;
1254
2278
  };
1255
2279
  super(r);
1256
2280
  }
1257
2281
  }
1258
- class ae extends f {
1259
- constructor(i, t) {
1260
- const e = t || b('Value must match pattern "**{pattern}**"'), s = (r, a, l) => i.test(String(h(r))) ? null : [
1261
- new g(this.replacePlaceholders(e, { newValue: r, oldValue: a, field: l, pattern: i }))
2282
+ class ze extends v {
2283
+ constructor(e, t) {
2284
+ const s = t || E('Value must match pattern "**{pattern}**"'), i = (r, a, o) => e.test(String(b(r))) ? null : [
2285
+ new V(this.replacePlaceholders(s, { newValue: r, oldValue: a, field: o, pattern: e }))
1262
2286
  ];
1263
- super(s);
2287
+ super(i);
1264
2288
  }
1265
2289
  }
1266
- const le = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2290
+ const He = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1267
2291
  __proto__: null,
1268
- CompareTo: Yt,
1269
- InAllowedValues: Jt,
1270
- LengthInRange: re,
1271
- MaxLength: ne,
1272
- MaxValue: ee,
1273
- MinLength: se,
1274
- MinValue: te,
1275
- Pattern: ae,
1276
- Required: Zt,
1277
- Validator: f,
1278
- ValueInRange: ie
1279
- }, Symbol.toStringTag, { value: "Module" })), de = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2292
+ CompareTo: ke,
2293
+ InAllowedValues: Re,
2294
+ LengthInRange: qe,
2295
+ MaxLength: $e,
2296
+ MaxValue: Ue,
2297
+ MinLength: We,
2298
+ MinValue: Be,
2299
+ Pattern: ze,
2300
+ Required: Le,
2301
+ Validator: v,
2302
+ ValueInRange: Me
2303
+ }, Symbol.toStringTag, { value: "Module" })), Je = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1280
2304
  __proto__: null,
1281
- AbortEventHandlingException: W,
1282
- Action: Xt,
1283
- ActionsMap: L,
1284
- ConditionalEnabledAction: Rt,
1285
- ConditionalStatementAction: M,
1286
- ConditionalValueAction: Bt,
1287
- ConditionalVisibilityAction: Lt,
1288
- DisplayMode: S,
1289
- EmptyField: zt,
1290
- EnabledChangedAction: ct,
1291
- EnabledChangingAction: ut,
1292
- ExecuteAction: ft,
1293
- Field: $,
1294
- FieldActionBase: m,
1295
- FieldBase: V,
1296
- Group: C,
1297
- List: Y,
1298
- ListItemAddedAction: z,
1299
- ListItemRemovedAction: pt,
1300
- MdString: O,
1301
- MessagesWidget: Gt,
1302
- Operator: c,
1303
- RenderableValue: jt,
1304
- Statement: N,
1305
- ValidChangedAction: ht,
1306
- ValidationError: G,
1307
- ValidationErrorRenderContent: g,
1308
- ValidationErrorText: Ft,
1309
- Validator: f,
1310
- Validators: le,
1311
- ValueChangedAction: y,
1312
- VisibilityChangedAction: gt,
1313
- VisibilityChangingAction: dt,
1314
- buildErrorMessage: b,
1315
- isCallableFunction: k,
1316
- isSimpleComponentDef: X
2305
+ AbortEventHandlingException: rt,
2306
+ Action: Fe,
2307
+ ActionsMap: M,
2308
+ ConditionalEnabledAction: ve,
2309
+ ConditionalStatementAction: Q,
2310
+ ConditionalValueAction: Ve,
2311
+ ConditionalVisibilityAction: be,
2312
+ DisplayMode: N,
2313
+ EmptyField: Pe,
2314
+ EnabledChangedAction: Ut,
2315
+ EnabledChangingAction: Bt,
2316
+ ExecuteAction: qt,
2317
+ Field: X,
2318
+ FieldActionBase: y,
2319
+ FieldBase: A,
2320
+ Group: w,
2321
+ List: D,
2322
+ ListItemAddedAction: at,
2323
+ ListItemRemovedAction: zt,
2324
+ MdString: U,
2325
+ MessagesWidget: Ne,
2326
+ Operator: m,
2327
+ RenderableValue: he,
2328
+ Statement: I,
2329
+ ValidChangedAction: Mt,
2330
+ ValidationError: ct,
2331
+ ValidationErrorRenderContent: V,
2332
+ ValidationErrorText: ue,
2333
+ Validator: v,
2334
+ Validators: He,
2335
+ ValueChangedAction: O,
2336
+ VisibilityChangedAction: $t,
2337
+ VisibilityChangingAction: Wt,
2338
+ buildErrorMessage: E,
2339
+ isCallableFunction: H,
2340
+ isSimpleComponentDef: lt,
2341
+ transaction: ot
1317
2342
  }, Symbol.toStringTag, { value: "Module" }));
1318
2343
  export {
1319
- W as AbortEventHandlingException,
1320
- Xt as Action,
1321
- L as ActionsMap,
1322
- Rt as ConditionalEnabledAction,
1323
- M as ConditionalStatementAction,
1324
- Bt as ConditionalValueAction,
1325
- Lt as ConditionalVisibilityAction,
1326
- S as DisplayMode,
1327
- zt as EmptyField,
1328
- ct as EnabledChangedAction,
1329
- ut as EnabledChangingAction,
1330
- ft as ExecuteAction,
1331
- $ as Field,
1332
- m as FieldActionBase,
1333
- V as FieldBase,
1334
- C as Group,
1335
- Y as List,
1336
- z as ListItemAddedAction,
1337
- pt as ListItemRemovedAction,
1338
- O as MdString,
1339
- Gt as MessagesWidget,
1340
- c as Operator,
1341
- jt as RenderableValue,
1342
- N as Statement,
1343
- ht as ValidChangedAction,
1344
- G as ValidationError,
1345
- g as ValidationErrorRenderContent,
1346
- Ft as ValidationErrorText,
1347
- f as Validator,
1348
- le as Validators,
1349
- y as ValueChangedAction,
1350
- gt as VisibilityChangedAction,
1351
- dt as VisibilityChangingAction,
1352
- b as buildErrorMessage,
1353
- de as default,
1354
- he as forms,
1355
- k as isCallableFunction,
1356
- X as isSimpleComponentDef
2344
+ rt as AbortEventHandlingException,
2345
+ Fe as Action,
2346
+ M as ActionsMap,
2347
+ ve as ConditionalEnabledAction,
2348
+ Q as ConditionalStatementAction,
2349
+ Ve as ConditionalValueAction,
2350
+ be as ConditionalVisibilityAction,
2351
+ N as DisplayMode,
2352
+ Pe as EmptyField,
2353
+ Ut as EnabledChangedAction,
2354
+ Bt as EnabledChangingAction,
2355
+ qt as ExecuteAction,
2356
+ X as Field,
2357
+ y as FieldActionBase,
2358
+ A as FieldBase,
2359
+ w as Group,
2360
+ D as List,
2361
+ at as ListItemAddedAction,
2362
+ zt as ListItemRemovedAction,
2363
+ U as MdString,
2364
+ Ne as MessagesWidget,
2365
+ m as Operator,
2366
+ he as RenderableValue,
2367
+ I as Statement,
2368
+ Mt as ValidChangedAction,
2369
+ ct as ValidationError,
2370
+ V as ValidationErrorRenderContent,
2371
+ ue as ValidationErrorText,
2372
+ v as Validator,
2373
+ He as Validators,
2374
+ O as ValueChangedAction,
2375
+ $t as VisibilityChangedAction,
2376
+ Wt as VisibilityChangingAction,
2377
+ E as buildErrorMessage,
2378
+ Je as default,
2379
+ Ye as forms,
2380
+ H as isCallableFunction,
2381
+ lt as isSimpleComponentDef,
2382
+ ot as transaction
1357
2383
  };
1358
2384
  //# sourceMappingURL=dynamicforms-vue-forms.js.map