@20baht/ui 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -8
- package/dist/components/baht-form.d.ts +17 -2
- package/dist/components/baht-form.js +48 -32
- package/dist/components/baht-workflow.d.ts +23 -9
- package/dist/components/baht-workflow.js +89 -63
- package/dist/components/define.js +1 -1
- package/dist/custom-elements.json +74 -12
- package/dist/vscode.html-custom-data.json +3 -3
- package/dist/web-types.json +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -237,11 +237,19 @@ const { state: after, events } = updateWorkflow(workflow, state, {
|
|
|
237
237
|
nextTarget(workflow, after); // the step after this one, or 'end'
|
|
238
238
|
```
|
|
239
239
|
|
|
240
|
-
Messages: `start`, `edit`, `patch`, `comment`, `next`, `decide`, `back`, `gotoStart`, `flags`, `restore
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
the
|
|
244
|
-
|
|
240
|
+
Messages: `start`, `edit`, `patch`, `comment`, `next`, `decide`, `back`, `gotoStart`, `flags`, `restore`;
|
|
241
|
+
anything else changes nothing. `decide` takes the `validity` and `gate` of the approval step's own fields,
|
|
242
|
+
like `next`. `snapshotOf(state)` is the run as JSON (`{ workflow_id, data, current, history, ended }`), a copy
|
|
243
|
+
the host may change (drop a `password` value before it is stored: a snapshot holds every value entered), and
|
|
244
|
+
`restore` picks it up again; a snapshot of another workflow restores as an empty run. `<baht-workflow>` has
|
|
245
|
+
the same pair as `getState()` / `restore(snapshot)`, for drafts, resume and undo. Pass the workflow with its
|
|
246
|
+
flags applied (`applyFlags`). Typed-input debounce and form validation stay with the caller: they are the
|
|
247
|
+
renderer's business.
|
|
248
|
+
|
|
249
|
+
A run that submitted, or that a rejection ended, is ended (`state.ended`: `'completed'` / `'rejected'`):
|
|
250
|
+
another press, decision, `back` or `gotoStart` does nothing, so a double click submits once. `start` or
|
|
251
|
+
`restore` begins again. The last press does not submit while the rules never settled (a `kind: 'data'`
|
|
252
|
+
rule error, which `@20baht/validator` refuses): it emits `baht-nav-blocked` with `reason: 'rule-error'`.
|
|
245
253
|
|
|
246
254
|
`<baht-workflow>` tells every step it takes as `baht-transition { msg, before, after, events }`, after
|
|
247
255
|
the step's own events. That is a log, a replay and an undo:
|
|
@@ -254,15 +262,18 @@ replayWorkflow(workflow, log.map((t) => t.msg)); // { state, events }: the same
|
|
|
254
262
|
el.restore(snapshotOf(log.at(-1).before)); // undo the last step
|
|
255
263
|
```
|
|
256
264
|
|
|
257
|
-
A replay is exact for the rules and the navigation
|
|
258
|
-
|
|
265
|
+
A replay is exact for the rules and the navigation, against the same definition: replay a log under the
|
|
266
|
+
workflow it was recorded with. What a host script wrote during the run is in the log only as the edits it
|
|
267
|
+
made; the script does not run again. A replay only folds states: it dispatches nothing and calls no
|
|
268
|
+
registry function. The log is the host's to bound: each transition holds two whole states.
|
|
259
269
|
|
|
260
270
|
### A form, headless
|
|
261
271
|
|
|
262
272
|
One form has the same shape: `updateForm(input, state, msg)` returns the next state and the events
|
|
263
273
|
`<baht-form>` would dispatch. `input` is what the host owns (the definition with its flags applied, the
|
|
264
274
|
starting `value`, the registry, rule-derived `fieldStates`, a `view`); `state` is what the form remembers
|
|
265
|
-
(the edits, the errors, what scripts set).
|
|
275
|
+
(the edits, the errors, what scripts set). `input.locale` gives the session its own message locale; unset,
|
|
276
|
+
it uses the catalog `setLocale` chose (`withLocale(locale, fn)` does the same for any synchronous call).
|
|
266
277
|
|
|
267
278
|
```ts
|
|
268
279
|
import { emptyFormState, formData, updateForm } from '@20baht/ui/engine';
|
|
@@ -130,8 +130,23 @@ export declare class BahtForm extends BahtElement {
|
|
|
130
130
|
/** `valueFor` for the render path: an unset collection field keeps one default array. */
|
|
131
131
|
private renderValueFor;
|
|
132
132
|
private valueFor;
|
|
133
|
-
/**
|
|
134
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Keystrokes still in a control's debounce land now: each emits its `baht-change`, as when the
|
|
135
|
+
* field loses focus. `getData()`, `validate()` and `setValue()` do this first, so a read never
|
|
136
|
+
* misses what was typed; `<baht-workflow>` calls it before reading its own data.
|
|
137
|
+
*/
|
|
138
|
+
flushTyped(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Forget keystrokes still in a control's debounce (all, or those of `keys`): the control shows
|
|
141
|
+
* `value` again and nothing is emitted. For a host replacing what the form shows (`restore()`).
|
|
142
|
+
*/
|
|
143
|
+
discardTyped(keys?: readonly string[]): void;
|
|
144
|
+
/** The rendered controls: the direct children of each .baht-field wrapper. */
|
|
145
|
+
private controls;
|
|
146
|
+
/**
|
|
147
|
+
* The whole form's data (not only the view's fields). Pending keystrokes land first, so a read
|
|
148
|
+
* can dispatch their `baht-change` before it returns.
|
|
149
|
+
*/
|
|
135
150
|
getData(): Record<string, unknown>;
|
|
136
151
|
/**
|
|
137
152
|
* Merge values programmatically. Runs each key's `change` scripts (like
|
|
@@ -2,9 +2,9 @@ import { nothing as c, html as y } from "lit";
|
|
|
2
2
|
import { property as p, state as I } from "lit/decorators.js";
|
|
3
3
|
import { repeat as V } from "lit/directives/repeat.js";
|
|
4
4
|
import { html as b } from "lit/static-html.js";
|
|
5
|
-
import { BahtElement as _, obj as
|
|
6
|
-
import { TAG_FOR_TYPE as
|
|
7
|
-
import { emptyFormState as B, updateForm as C, createScriptContext as K, applyFlags as A, resolveViewFields as
|
|
5
|
+
import { BahtElement as _, obj as D, hasDom as O } from "./base.js";
|
|
6
|
+
import { TAG_FOR_TYPE as q, WIDTH_CLASS as j, staticTag as P } from "./primitives/tag-map.js";
|
|
7
|
+
import { emptyFormState as B, updateForm as C, createScriptContext as K, applyFlags as A, resolveViewFields as T, formFieldState as W, defaultValue as E, formData as R, displayValue as U } from "@20baht/engine";
|
|
8
8
|
import "./primitives/baht-input.js";
|
|
9
9
|
import "./primitives/baht-textarea.js";
|
|
10
10
|
import "./primitives/baht-markdown.js";
|
|
@@ -29,13 +29,13 @@ import { customElement as G } from "./define.js";
|
|
|
29
29
|
import { ReferenceLabels as H } from "./reference-labels.js";
|
|
30
30
|
import { DynamicOptions as N } from "./form-options.js";
|
|
31
31
|
import { renderReadonlyField as Y } from "./form-readonly.js";
|
|
32
|
-
import { buildLayout as z, rowStyle as
|
|
32
|
+
import { buildLayout as z, rowStyle as $, isTabSection as J, tabClass as x, foldClass as M } from "./form-layout.js";
|
|
33
33
|
var Q = Object.defineProperty, X = Object.getOwnPropertyDescriptor, l = (t, e, s, r) => {
|
|
34
34
|
for (var i = r > 1 ? void 0 : r ? X(e, s) : e, o = t.length - 1, n; o >= 0; o--)
|
|
35
35
|
(n = t[o]) && (i = (r ? n(e, s, i) : n(i)) || i);
|
|
36
36
|
return r && i && Q(e, s, i), i;
|
|
37
37
|
};
|
|
38
|
-
const
|
|
38
|
+
const F = (t) => t.split("[")[0] ?? t, Z = /* @__PURE__ */ new Set([
|
|
39
39
|
"text",
|
|
40
40
|
"email",
|
|
41
41
|
"password",
|
|
@@ -161,7 +161,7 @@ let h = class extends _ {
|
|
|
161
161
|
willUpdate(t) {
|
|
162
162
|
var e;
|
|
163
163
|
if ((t.has("form") || t.has("flags")) && this.dynamicOptions.clear(), t.has("value")) {
|
|
164
|
-
const s =
|
|
164
|
+
const s = D(t.get("value"));
|
|
165
165
|
this.step({ type: "value", previous: s });
|
|
166
166
|
}
|
|
167
167
|
t.has("form") && (this.step({ type: "form", previous: t.get("form") }), this.folded = new Set(
|
|
@@ -182,8 +182,8 @@ let h = class extends _ {
|
|
|
182
182
|
return this.sortedCache = { form: t, view: this.view, out: s }, s;
|
|
183
183
|
}
|
|
184
184
|
resolveSortedFields(t) {
|
|
185
|
-
const e =
|
|
186
|
-
return e || (this.view !== void 0 && !this.warnedViews.has(this.view) && (this.warnedViews.add(this.view), console.warn(`[bahtui] unknown view "${this.view}" — showing the full form`)),
|
|
185
|
+
const e = T(t, this.view);
|
|
186
|
+
return e || (this.view !== void 0 && !this.warnedViews.has(this.view) && (this.warnedViews.add(this.view), console.warn(`[bahtui] unknown view "${this.view}" — showing the full form`)), T(t) ?? []);
|
|
187
187
|
}
|
|
188
188
|
tabLayout() {
|
|
189
189
|
var t, e;
|
|
@@ -210,9 +210,9 @@ let h = class extends _ {
|
|
|
210
210
|
}
|
|
211
211
|
/** After a validate(): when no error can be seen, open the first tab that has one. */
|
|
212
212
|
openTabWithError(t) {
|
|
213
|
-
const { owner: e, open: s, showing: r, section: i } = this.tabLayout(), o = t.map((a) => i.get(
|
|
213
|
+
const { owner: e, open: s, showing: r, section: i } = this.tabLayout(), o = t.map((a) => i.get(F(a.key)));
|
|
214
214
|
o.some((a) => a !== void 0 && this.folded.has(a)) && (this.folded = new Set([...this.folded].filter((a) => !o.includes(a))));
|
|
215
|
-
const n = t.filter((a) => a.key !== "$").map((a) => e.get(
|
|
215
|
+
const n = t.filter((a) => a.key !== "$").map((a) => e.get(F(a.key)));
|
|
216
216
|
if (n.some((a) => a === void 0 || a === s)) return;
|
|
217
217
|
const u = r.find((a) => n.includes(a.key));
|
|
218
218
|
u && this.selectTab(u.key);
|
|
@@ -221,7 +221,7 @@ let h = class extends _ {
|
|
|
221
221
|
if (t.showing.length === 0) return c;
|
|
222
222
|
const e = /* @__PURE__ */ new Map();
|
|
223
223
|
for (const r of this.errors) {
|
|
224
|
-
const i = t.owner.get(
|
|
224
|
+
const i = t.owner.get(F(r.key));
|
|
225
225
|
i && e.set(i, (e.get(i) ?? 0) + 1);
|
|
226
226
|
}
|
|
227
227
|
const s = t.showing.map(({ key: r, label: i }) => {
|
|
@@ -230,7 +230,7 @@ let h = class extends _ {
|
|
|
230
230
|
});
|
|
231
231
|
return y`<div
|
|
232
232
|
class="baht-form-tabs"
|
|
233
|
-
style=${t.first ?
|
|
233
|
+
style=${t.first ? $(t, t.first) : c}
|
|
234
234
|
>
|
|
235
235
|
<baht-tabs
|
|
236
236
|
.tabs=${s}
|
|
@@ -270,19 +270,40 @@ let h = class extends _ {
|
|
|
270
270
|
}
|
|
271
271
|
/** `valueFor` for the render path: an unset collection field keeps one default array. */
|
|
272
272
|
renderValueFor(t) {
|
|
273
|
-
return Object.hasOwn(this.edits, t.key) || Object.hasOwn(this.value, t.key) ? this.valueFor(t) : (this.defaultsSeen.has(t) || this.defaultsSeen.set(t,
|
|
273
|
+
return Object.hasOwn(this.edits, t.key) || Object.hasOwn(this.value, t.key) ? this.valueFor(t) : (this.defaultsSeen.has(t) || this.defaultsSeen.set(t, E(t)), this.defaultsSeen.get(t));
|
|
274
274
|
}
|
|
275
275
|
valueFor(t) {
|
|
276
|
-
return Object.hasOwn(this.edits, t.key) ? this.edits[t.key] : Object.hasOwn(this.value, t.key) ? this.value[t.key] :
|
|
276
|
+
return Object.hasOwn(this.edits, t.key) ? this.edits[t.key] : Object.hasOwn(this.value, t.key) ? this.value[t.key] : E(t);
|
|
277
277
|
}
|
|
278
278
|
// ---- public API (spec 01 §6) ----
|
|
279
|
-
/**
|
|
279
|
+
/**
|
|
280
|
+
* Keystrokes still in a control's debounce land now: each emits its `baht-change`, as when the
|
|
281
|
+
* field loses focus. `getData()`, `validate()` and `setValue()` do this first, so a read never
|
|
282
|
+
* misses what was typed; `<baht-workflow>` calls it before reading its own data.
|
|
283
|
+
*/
|
|
280
284
|
flushTyped() {
|
|
281
285
|
var t;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
for (const e of this.controls()) (t = e.flushTyped) == null || t.call(e);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Forget keystrokes still in a control's debounce (all, or those of `keys`): the control shows
|
|
290
|
+
* `value` again and nothing is emitted. For a host replacing what the form shows (`restore()`).
|
|
291
|
+
*/
|
|
292
|
+
discardTyped(t) {
|
|
293
|
+
var e, s;
|
|
294
|
+
for (const r of this.controls()) {
|
|
295
|
+
const i = ((e = r.parentElement) == null ? void 0 : e.getAttribute("data-key")) ?? "";
|
|
296
|
+
(!t || t.includes(i)) && ((s = r.discardTyped) == null || s.call(r));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/** The rendered controls: the direct children of each .baht-field wrapper. */
|
|
300
|
+
controls() {
|
|
301
|
+
return O() ? Array.from(this.querySelectorAll(":scope > .baht-form > .baht-field > *")) : [];
|
|
285
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* The whole form's data (not only the view's fields). Pending keystrokes land first, so a read
|
|
305
|
+
* can dispatch their `baht-change` before it returns.
|
|
306
|
+
*/
|
|
286
307
|
getData() {
|
|
287
308
|
this.flushTyped();
|
|
288
309
|
const t = this.effectiveForm;
|
|
@@ -302,12 +323,7 @@ let h = class extends _ {
|
|
|
302
323
|
* field back (spec 02 §4). Emits nothing and runs no scripts.
|
|
303
324
|
*/
|
|
304
325
|
revert(t) {
|
|
305
|
-
|
|
306
|
-
if (this.send({ type: "revert", keys: t }), !!$())
|
|
307
|
-
for (const r of this.querySelectorAll(":scope > .baht-form > .baht-field > *")) {
|
|
308
|
-
const i = ((e = r.parentElement) == null ? void 0 : e.getAttribute("data-key")) ?? "";
|
|
309
|
-
t.includes(i) && ((s = r.discardTyped) == null || s.call(r));
|
|
310
|
-
}
|
|
326
|
+
this.send({ type: "revert", keys: t }), this.discardTyped(t);
|
|
311
327
|
}
|
|
312
328
|
/**
|
|
313
329
|
* Full validation pass: validators, then `submit` scripts (spec 01 §14). A
|
|
@@ -348,7 +364,7 @@ let h = class extends _ {
|
|
|
348
364
|
}
|
|
349
365
|
updated(t) {
|
|
350
366
|
var s;
|
|
351
|
-
if (super.updated(t), this.lastVisible = this.nextVisible, this.nextVisible = {},
|
|
367
|
+
if (super.updated(t), this.lastVisible = this.nextVisible, this.nextVisible = {}, !O()) return;
|
|
352
368
|
const e = this.assignedForm;
|
|
353
369
|
e && this.loadedForm !== e && (this.loadedForm = e, (s = e.scripts) != null && s.length && (this.flushTyped(), this.send({ type: "load" })));
|
|
354
370
|
}
|
|
@@ -363,13 +379,13 @@ let h = class extends _ {
|
|
|
363
379
|
this.options.validateOn === "blur" && this.send({ type: "blur", key: t.key });
|
|
364
380
|
}
|
|
365
381
|
renderField(t, e) {
|
|
366
|
-
var
|
|
382
|
+
var S;
|
|
367
383
|
if (J(t))
|
|
368
384
|
return t.key === e.first ? this.renderTabStrip(e) : c;
|
|
369
|
-
const s =
|
|
385
|
+
const s = q[t.type];
|
|
370
386
|
if (!s)
|
|
371
387
|
return console.warn(`[bahtui] unknown field type "${t.type}" — skipped`), c;
|
|
372
|
-
const r = this.stateFor(t), i = j[t.width ?? "full"] ?? "baht-field--w-full", o = ((
|
|
388
|
+
const r = this.stateFor(t), i = j[t.width ?? "full"] ?? "baht-field--w-full", o = ((S = this.errors.find((f) => f.key === t.key)) == null ? void 0 : S.message) ?? null;
|
|
373
389
|
if (this.readonly && t.type !== "label" && t.type !== "section")
|
|
374
390
|
return this.renderReadonlyField(t, i, r.visible, e);
|
|
375
391
|
const n = this.dynamicOptions.withOptions(t), u = this.renderValueFor(t), a = !r.enabled || this.busy, v = this.readonly || r.readonly, w = this.options.inputDebounce, g = (f) => {
|
|
@@ -439,11 +455,11 @@ let h = class extends _ {
|
|
|
439
455
|
.debounce=${w}
|
|
440
456
|
@baht-input=${g}
|
|
441
457
|
></${d}>`;
|
|
442
|
-
const
|
|
458
|
+
const k = this.fieldMessages[t.key];
|
|
443
459
|
return y`<div
|
|
444
460
|
class="baht-field ${i} ${r.visible ? "" : "baht-field--hidden"}${this.revealClass(t.key, r.visible)}${x(e, t.key)}${M(e, t.key, this.folded)}"
|
|
445
461
|
data-column=${t.column ?? c}
|
|
446
|
-
style=${
|
|
462
|
+
style=${$(e, t.key)}
|
|
447
463
|
data-key=${t.key}
|
|
448
464
|
data-type=${t.type}
|
|
449
465
|
data-testid="${this.form.form_id}.${t.key}"
|
|
@@ -452,7 +468,7 @@ let h = class extends _ {
|
|
|
452
468
|
}}
|
|
453
469
|
>
|
|
454
470
|
${m}
|
|
455
|
-
${
|
|
471
|
+
${k ? this.renderFieldMsg(k) : c}
|
|
456
472
|
</div>`;
|
|
457
473
|
}
|
|
458
474
|
lookupFor(t, e) {
|
|
@@ -519,7 +535,7 @@ let h = class extends _ {
|
|
|
519
535
|
field: t,
|
|
520
536
|
shown: o,
|
|
521
537
|
classes: `baht-field ${e} baht-field--readonly ${s ? "" : "baht-field--hidden"}${this.revealClass(t.key, s)}${x(r, t.key)}${M(r, t.key, this.folded)}`,
|
|
522
|
-
style:
|
|
538
|
+
style: $(r, t.key),
|
|
523
539
|
testId: `${this.form.form_id}.${t.key}`
|
|
524
540
|
},
|
|
525
541
|
this.readonlyContext()
|
|
@@ -6,8 +6,11 @@ import { WorkflowSnapshot, Derived, FeatureFlags, NestedData, Registry, Validati
|
|
|
6
6
|
* internal <baht-form>, evaluates rules on every change, walks the visible forms
|
|
7
7
|
* in linear `order`, and owns the single Next/Submit button.
|
|
8
8
|
* Forms with kind 'approval' render a decision step instead (spec 03 §4):
|
|
9
|
-
* a summary of earlier answers
|
|
10
|
-
*
|
|
9
|
+
* a summary of earlier answers, the step's own fields when it has any (filled by
|
|
10
|
+
* the approver, validated before a decision like a form before Next), plus
|
|
11
|
+
* Approve/Reject (+ optional comment); the decision lands in data as
|
|
12
|
+
* `<form_name>.decision` so rules can branch on it. A run that submitted, or that
|
|
13
|
+
* a rejection ended, takes no further decision or press.
|
|
11
14
|
* The runtime navigates; the host acts (on baht-next / baht-submit / baht-approve /
|
|
12
15
|
* baht-reject / baht-complete).
|
|
13
16
|
* With `chrome="none"` it renders the current form only — no Next/Back/Submit, no
|
|
@@ -16,12 +19,12 @@ import { WorkflowSnapshot, Derived, FeatureFlags, NestedData, Registry, Validati
|
|
|
16
19
|
* @fires {CustomEvent<{ data: NestedData }>} baht-data-change - Any value changed.
|
|
17
20
|
* @fires {CustomEvent<{ form_name: string; order: number; data: NestedData; decision?: ApprovalDecision; comment?: string }>} baht-next - Moved forward to `form_name`.
|
|
18
21
|
* @fires {CustomEvent<{ form_name: string; order: number; direction: 'forward' | 'back' }>} baht-step-change - The visible step changed.
|
|
19
|
-
* @fires {CustomEvent<{ form_name: string | null; target: string; reason: 'self-transition' | 'target-hidden'; data: NestedData }>} baht-nav-blocked - Next resolved to no visible step.
|
|
22
|
+
* @fires {CustomEvent<{ form_name: string | null; target: string; reason: 'self-transition' | 'target-hidden' | 'rule-error'; data: NestedData }>} baht-nav-blocked - Next resolved to no visible step, or the last step would submit data whose rules never settled.
|
|
20
23
|
* @fires {CustomEvent<{ data: NestedData; decision?: ApprovalDecision; comment?: string }>} baht-submit - The last step was submitted.
|
|
21
24
|
* @fires {CustomEvent<{ data: NestedData; status: 'completed' | 'rejected' }>} baht-complete - The workflow ended.
|
|
22
25
|
* @fires {CustomEvent<{ form_name: string; decision: ApprovalDecision; comment: string; data: NestedData }>} baht-approve - An approval step was approved.
|
|
23
26
|
* @fires {CustomEvent<{ form_name: string; decision: ApprovalDecision; comment: string; data: NestedData }>} baht-reject - An approval step was rejected.
|
|
24
|
-
* @fires {CustomEvent<WorkflowTransition>} baht-transition - One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`).
|
|
27
|
+
* @fires {CustomEvent<WorkflowTransition>} baht-transition - One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`). The states hold every value entered, `password` fields included: redact before a log leaves the page.
|
|
25
28
|
* @fires {CustomEvent<{ errors: Derived['errors'] }>} baht-rule-error - The rules' errors changed (a rule aimed at nothing, rules that never settle); empty once they are gone.
|
|
26
29
|
*/
|
|
27
30
|
export declare class BahtWorkflow extends BahtElement {
|
|
@@ -58,7 +61,8 @@ export declare class BahtWorkflow extends BahtElement {
|
|
|
58
61
|
/**
|
|
59
62
|
* Debounce (ms) for the approval comment, the one typed field the workflow renders itself;
|
|
60
63
|
* unset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,
|
|
61
|
-
* leaving the box
|
|
64
|
+
* leaving the box, `back()`, `gotoStart()`, `getData()` and `getState()` flush what is pending;
|
|
65
|
+
* `restore()` and a new `value` drop it.
|
|
62
66
|
*/
|
|
63
67
|
debounce?: number;
|
|
64
68
|
/** Render a <baht-steps> progress indicator above the current form. */
|
|
@@ -109,7 +113,11 @@ export declare class BahtWorkflow extends BahtElement {
|
|
|
109
113
|
private get currentForm();
|
|
110
114
|
private get isLast();
|
|
111
115
|
private fieldStatesFor;
|
|
116
|
+
/** The step's own editable form: a data step's, or an approval step's fields (never the summary). */
|
|
112
117
|
private get formEl();
|
|
118
|
+
/** Keystrokes still in the step's controls, and the approval comment, land in the run now. */
|
|
119
|
+
private flushPending;
|
|
120
|
+
/** The run's data, with whatever is still being typed applied first. */
|
|
113
121
|
getData(): NestedData;
|
|
114
122
|
/**
|
|
115
123
|
* Host/store write into one form's data — same path a user edit takes
|
|
@@ -118,9 +126,9 @@ export declare class BahtWorkflow extends BahtElement {
|
|
|
118
126
|
*/
|
|
119
127
|
setValue(form_name: string, patch: Record<string, unknown>): void;
|
|
120
128
|
/**
|
|
121
|
-
* Validate the current form (rule-hidden fields skipped,
|
|
122
|
-
* applied) and show its errors, without advancing or emitting
|
|
123
|
-
* Valid with no errors when no
|
|
129
|
+
* Validate the current form, or an approval step's own fields (rule-hidden fields skipped,
|
|
130
|
+
* rule-derived `required` applied) and show its errors, without advancing or emitting
|
|
131
|
+
* navigation events. Valid with no errors when the step has no fields to fill.
|
|
124
132
|
*/
|
|
125
133
|
validate(): {
|
|
126
134
|
valid: boolean;
|
|
@@ -135,7 +143,8 @@ export declare class BahtWorkflow extends BahtElement {
|
|
|
135
143
|
back(): void;
|
|
136
144
|
gotoStart(): void;
|
|
137
145
|
/**
|
|
138
|
-
* The run as JSON: `{ data, current, history }
|
|
146
|
+
* The run as JSON: `{ workflow_id, data, current, history, ended }`, a copy (redact what must not be
|
|
147
|
+
* stored: it holds every value entered). Keep it (a draft on the server, the session)
|
|
139
148
|
* and hand it to `restore()` to pick the run up on the same step, or keep one per change for undo.
|
|
140
149
|
*/
|
|
141
150
|
getState(): WorkflowSnapshot;
|
|
@@ -160,6 +169,11 @@ export declare class BahtWorkflow extends BahtElement {
|
|
|
160
169
|
/** Forms the approval step summarizes: configured list, else every earlier plain form. */
|
|
161
170
|
private summary_forms;
|
|
162
171
|
private renderApproval;
|
|
172
|
+
/**
|
|
173
|
+
* The step's editable form: a data step, or the fields an approval step has of its own (a task's
|
|
174
|
+
* fields, filled by the approver). Enter submits a data step only; a decision is a button press.
|
|
175
|
+
*/
|
|
176
|
+
private renderStepForm;
|
|
163
177
|
protected render(): TemplateResult;
|
|
164
178
|
/** Back + Next/Submit (or Reject/Approve on an approval step). */
|
|
165
179
|
private renderNav;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { nothing as
|
|
1
|
+
import { nothing as d, html as h } from "lit";
|
|
2
2
|
import { property as u, state as b } from "lit/decorators.js";
|
|
3
3
|
import { keyed as v } from "lit/directives/keyed.js";
|
|
4
4
|
import { BahtFieldBase as w } from "./field-base.js";
|
|
5
|
-
import { boolOff as f, BahtElement as g, obj as y, stringOf as $ } from "./base.js";
|
|
6
|
-
import { applyFlags as
|
|
5
|
+
import { boolOff as f, BahtElement as g, obj as y, hasDom as k, stringOf as $ } from "./base.js";
|
|
6
|
+
import { applyFlags as _, updateWorkflow as C, sameData as p, t as m, visibleForms as x, nextTarget as F, snapshotOf as S } from "@20baht/engine";
|
|
7
7
|
import "./baht-form.js";
|
|
8
8
|
import "./primitives/baht-steps.js";
|
|
9
|
-
import { customElement as
|
|
10
|
-
var
|
|
9
|
+
import { customElement as E } from "./define.js";
|
|
10
|
+
var T = Object.defineProperty, j = Object.getOwnPropertyDescriptor, l = (t, e, r, i) => {
|
|
11
11
|
for (var s = i > 1 ? void 0 : i ? j(e, r) : e, o = t.length - 1, n; o >= 0; o--)
|
|
12
12
|
(n = t[o]) && (s = (i ? n(e, r, s) : n(s)) || s);
|
|
13
|
-
return i && s &&
|
|
13
|
+
return i && s && T(e, r, s), s;
|
|
14
14
|
};
|
|
15
15
|
let a = class extends g {
|
|
16
16
|
constructor() {
|
|
@@ -39,7 +39,7 @@ let a = class extends g {
|
|
|
39
39
|
get effectiveWorkflow() {
|
|
40
40
|
const t = this.assignedWorkflow;
|
|
41
41
|
if (t)
|
|
42
|
-
return (this.flagCache.workflow !== t || this.flagCache.flags !== this.flags) && (this.flagCache = { workflow: t, flags: this.flags, out:
|
|
42
|
+
return (this.flagCache.workflow !== t || this.flagCache.flags !== this.flags) && (this.flagCache = { workflow: t, flags: this.flags, out: _(t, this.flags) }), this.flagCache.out;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* One step of the run: the runtime works out the next state and the events, this element
|
|
@@ -48,7 +48,7 @@ let a = class extends g {
|
|
|
48
48
|
send(t) {
|
|
49
49
|
const e = this.effectiveWorkflow;
|
|
50
50
|
if (!e) return;
|
|
51
|
-
const r = this.run, { state: i, events: s } =
|
|
51
|
+
const r = this.run, { state: i, events: s } = C(e, r, t);
|
|
52
52
|
this.run = i;
|
|
53
53
|
for (const n of s)
|
|
54
54
|
this.warnAuthor(n), this.emit(n.name, n.detail);
|
|
@@ -61,15 +61,14 @@ let a = class extends g {
|
|
|
61
61
|
`[bahtui] workflow "${this.workflow.workflow_id}" rules: ` + t.detail.errors.map((e) => `${e.ref}: ${e.message}`).join("; ")
|
|
62
62
|
), t.name === "baht-nav-blocked") {
|
|
63
63
|
const { form_name: e, target: r, reason: i } = t.detail;
|
|
64
|
-
console.warn(
|
|
65
|
-
`[bahtui] cannot advance from "${e}": target "${r}" is ` + (i === "self-transition" ? "the current form (self-transition)" : "not visible")
|
|
66
|
-
);
|
|
64
|
+
console.warn(`[bahtui] cannot advance from "${e}": ${O(r, i)}`);
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
67
|
willUpdate(t) {
|
|
68
|
+
var r;
|
|
70
69
|
if (!this.assignedWorkflow) return;
|
|
71
|
-
const e = t.has("value") && !
|
|
72
|
-
t.has("workflow") || e ? (clearTimeout(this.commentTimer), this.pendingComment = null, this.send({ type: "start", value: y(this.value) }), this.pendingRestore !== void 0 && this.restore(this.pendingRestore)) : t.has("flags") && this.send({ type: "flags" });
|
|
70
|
+
const e = t.has("value") && !p(t.get("value"), this.value);
|
|
71
|
+
t.has("workflow") || e ? (clearTimeout(this.commentTimer), this.pendingComment = null, (r = this.formEl) == null || r.discardTyped(), this.send({ type: "start", value: y(this.value) }), this.pendingRestore !== void 0 && this.restore(this.pendingRestore)) : t.has("flags") && this.send({ type: "flags" });
|
|
73
72
|
}
|
|
74
73
|
/**
|
|
75
74
|
* Which way the last navigation went. Stamped on the step wrapper as
|
|
@@ -83,7 +82,7 @@ let a = class extends g {
|
|
|
83
82
|
/** Why the last decision was refused, in the current locale. */
|
|
84
83
|
get approvalError() {
|
|
85
84
|
var t;
|
|
86
|
-
return (t = this.run) != null && t.approvalError ?
|
|
85
|
+
return (t = this.run) != null && t.approvalError ? m(this.run.approvalError) : null;
|
|
87
86
|
}
|
|
88
87
|
/** The run's data: `{ form_name: { key: value } }`, as the rules left it. */
|
|
89
88
|
get data() {
|
|
@@ -95,7 +94,7 @@ let a = class extends g {
|
|
|
95
94
|
var s;
|
|
96
95
|
const t = this.effectiveWorkflow, e = ((s = this.run) == null ? void 0 : s.derived) ?? null, r = this.visibleCache;
|
|
97
96
|
if (r && r.workflow === t && r.derived === e) return r.out;
|
|
98
|
-
const i = t ?
|
|
97
|
+
const i = t ? x(t, e) : [];
|
|
99
98
|
return this.visibleCache = { workflow: t, derived: e, out: i }, i;
|
|
100
99
|
}
|
|
101
100
|
get currentForm() {
|
|
@@ -106,7 +105,7 @@ let a = class extends g {
|
|
|
106
105
|
}
|
|
107
106
|
get isLast() {
|
|
108
107
|
const t = this.effectiveWorkflow, e = this.run;
|
|
109
|
-
return !t || !(e != null && e.current) ? !1 :
|
|
108
|
+
return !t || !(e != null && e.current) ? !1 : F(t, e, this.visibleForms) === "end";
|
|
110
109
|
}
|
|
111
110
|
fieldStatesFor(t) {
|
|
112
111
|
var o;
|
|
@@ -116,14 +115,21 @@ let a = class extends g {
|
|
|
116
115
|
for (const [n, c] of Object.entries(r.fields))
|
|
117
116
|
n.startsWith(i) && (e[n.slice(i.length)] = c);
|
|
118
117
|
const s = this.statesSeen.get(t);
|
|
119
|
-
return s &&
|
|
118
|
+
return s && W(s, e) ? s : (this.statesSeen.set(t, e), e);
|
|
120
119
|
}
|
|
120
|
+
/** The step's own editable form: a data step's, or an approval step's fields (never the summary). */
|
|
121
121
|
get formEl() {
|
|
122
|
-
return this.querySelector("baht-form");
|
|
122
|
+
return k() ? this.querySelector("baht-form.baht-workflow-form") : null;
|
|
123
|
+
}
|
|
124
|
+
/** Keystrokes still in the step's controls, and the approval comment, land in the run now. */
|
|
125
|
+
flushPending() {
|
|
126
|
+
var t;
|
|
127
|
+
(t = this.formEl) == null || t.flushTyped(), this.flushComment();
|
|
123
128
|
}
|
|
124
129
|
// ---- public API (spec 03 §2) ----
|
|
130
|
+
/** The run's data, with whatever is still being typed applied first. */
|
|
125
131
|
getData() {
|
|
126
|
-
return this.
|
|
132
|
+
return this.flushPending(), this.data;
|
|
127
133
|
}
|
|
128
134
|
/**
|
|
129
135
|
* Host/store write into one form's data — same path a user edit takes
|
|
@@ -134,9 +140,9 @@ let a = class extends g {
|
|
|
134
140
|
this.send({ type: "patch", form_name: t, patch: e });
|
|
135
141
|
}
|
|
136
142
|
/**
|
|
137
|
-
* Validate the current form (rule-hidden fields skipped,
|
|
138
|
-
* applied) and show its errors, without advancing or emitting
|
|
139
|
-
* Valid with no errors when no
|
|
143
|
+
* Validate the current form, or an approval step's own fields (rule-hidden fields skipped,
|
|
144
|
+
* rule-derived `required` applied) and show its errors, without advancing or emitting
|
|
145
|
+
* navigation events. Valid with no errors when the step has no fields to fill.
|
|
140
146
|
*/
|
|
141
147
|
validate() {
|
|
142
148
|
var t;
|
|
@@ -161,20 +167,26 @@ let a = class extends g {
|
|
|
161
167
|
this.decide("rejected");
|
|
162
168
|
}
|
|
163
169
|
decide(t) {
|
|
164
|
-
this.flushComment(),
|
|
170
|
+
if (this.flushComment(), this.busy) return;
|
|
171
|
+
const e = this.formEl;
|
|
172
|
+
this.send(
|
|
173
|
+
e ? { type: "decide", decision: t, validity: e.validate(), gate: this.validateGate } : { type: "decide", decision: t }
|
|
174
|
+
);
|
|
165
175
|
}
|
|
166
176
|
back() {
|
|
167
177
|
this.busy || (this.flushComment(), this.send({ type: "back" }));
|
|
168
178
|
}
|
|
169
179
|
gotoStart() {
|
|
170
|
-
this.send({ type: "gotoStart" });
|
|
180
|
+
this.busy || (this.flushComment(), this.send({ type: "gotoStart" }));
|
|
171
181
|
}
|
|
172
182
|
/**
|
|
173
|
-
* The run as JSON: `{ data, current, history }
|
|
183
|
+
* The run as JSON: `{ workflow_id, data, current, history, ended }`, a copy (redact what must not be
|
|
184
|
+
* stored: it holds every value entered). Keep it (a draft on the server, the session)
|
|
174
185
|
* and hand it to `restore()` to pick the run up on the same step, or keep one per change for undo.
|
|
175
186
|
*/
|
|
176
187
|
getState() {
|
|
177
|
-
|
|
188
|
+
var e;
|
|
189
|
+
return this.flushPending(), this.run ? S(this.run) : { workflow_id: ((e = this.assignedWorkflow) == null ? void 0 : e.workflow_id) ?? "", data: {}, current: null, history: [], ended: null };
|
|
178
190
|
}
|
|
179
191
|
/**
|
|
180
192
|
* Pick up a run kept with `getState()`: its data, its step and its Back history. The rules run
|
|
@@ -182,18 +194,19 @@ let a = class extends g {
|
|
|
182
194
|
* events. Called before `workflow` is bound, it applies once it is.
|
|
183
195
|
*/
|
|
184
196
|
restore(t) {
|
|
197
|
+
var e;
|
|
185
198
|
if (!this.effectiveWorkflow) {
|
|
186
199
|
this.pendingRestore = t;
|
|
187
200
|
return;
|
|
188
201
|
}
|
|
189
|
-
this.pendingRestore = void 0, clearTimeout(this.commentTimer), this.pendingComment = null, this.send({ type: "restore", snapshot: t });
|
|
202
|
+
this.pendingRestore = void 0, clearTimeout(this.commentTimer), this.pendingComment = null, (e = this.formEl) == null || e.discardTyped(), this.send({ type: "restore", snapshot: t });
|
|
190
203
|
}
|
|
191
204
|
// ---- internal ----
|
|
192
205
|
onFormChange(t) {
|
|
193
206
|
var s, o;
|
|
194
207
|
t.stopPropagation();
|
|
195
208
|
const { form_name: e, key: r, value: i } = t.detail;
|
|
196
|
-
this.send({ type: "edit", form_name: e, key: r, value: i }),
|
|
209
|
+
this.send({ type: "edit", form_name: e, key: r, value: i }), p((s = this.data[e]) == null ? void 0 : s[r], i) || (o = this.formEl) == null || o.revert([r]);
|
|
197
210
|
}
|
|
198
211
|
/** The inner form's Enter submit: it already validated, so this is a passing Next press. */
|
|
199
212
|
onFormSubmit(t) {
|
|
@@ -233,7 +246,7 @@ let a = class extends g {
|
|
|
233
246
|
const e = ((i = t.approval) == null ? void 0 : i.comment) ?? "optional", r = this.summary_forms(t);
|
|
234
247
|
return h`<div class="baht-approval">
|
|
235
248
|
<div class="baht-approval-summary">
|
|
236
|
-
${r.length === 0 ? h`<p class="baht-approval-empty">${
|
|
249
|
+
${r.length === 0 ? h`<p class="baht-approval-empty">${m("nothingToReview")}</p>` : r.map(
|
|
237
250
|
(n) => h`<section class="baht-approval-group">
|
|
238
251
|
<h4 class="baht-approval-group-title">${n.form_name}</h4>
|
|
239
252
|
<baht-form
|
|
@@ -245,14 +258,15 @@ let a = class extends g {
|
|
|
245
258
|
</section>`
|
|
246
259
|
)}
|
|
247
260
|
</div>
|
|
261
|
+
${t.fields.length > 0 ? this.renderStepForm(t) : d}
|
|
248
262
|
${e !== "hidden" ? h`<label class="baht-approval-comment">
|
|
249
263
|
<span class="baht-approval-comment-label">
|
|
250
|
-
${
|
|
264
|
+
${m("comment")}${e === "required" ? m("commentRequiredSuffix") : ""}
|
|
251
265
|
</span>
|
|
252
266
|
<textarea
|
|
253
267
|
rows="3"
|
|
254
|
-
aria-required=${e === "required" ? "true" :
|
|
255
|
-
aria-invalid=${this.approvalError ? "true" :
|
|
268
|
+
aria-required=${e === "required" ? "true" : d}
|
|
269
|
+
aria-invalid=${this.approvalError ? "true" : d}
|
|
256
270
|
.value=${((s = this.pendingComment) == null ? void 0 : s.form_name) === t.form_name ? this.pendingComment.value : $((o = this.data[t.form_name]) == null ? void 0 : o.comment)}
|
|
257
271
|
@focusout=${() => {
|
|
258
272
|
this.flushComment();
|
|
@@ -261,10 +275,33 @@ let a = class extends g {
|
|
|
261
275
|
this.onCommentInput(t.form_name, n.target.value);
|
|
262
276
|
}}
|
|
263
277
|
></textarea>
|
|
264
|
-
</label>` :
|
|
265
|
-
${this.approvalError ? h`<p class="baht-error" role="alert">${this.approvalError}</p>` :
|
|
278
|
+
</label>` : d}
|
|
279
|
+
${this.approvalError ? h`<p class="baht-error" role="alert">${this.approvalError}</p>` : d}
|
|
266
280
|
</div>`;
|
|
267
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* The step's editable form: a data step, or the fields an approval step has of its own (a task's
|
|
284
|
+
* fields, filled by the approver). Enter submits a data step only; a decision is a button press.
|
|
285
|
+
*/
|
|
286
|
+
renderStepForm(t) {
|
|
287
|
+
const e = t.kind === "approval";
|
|
288
|
+
return h`<baht-form
|
|
289
|
+
class="baht-workflow-form"
|
|
290
|
+
.form=${t}
|
|
291
|
+
.value=${this.data[t.form_name] ?? {}}
|
|
292
|
+
.registry=${this.registry}
|
|
293
|
+
.fieldStates=${this.fieldStatesFor(t.form_name)}
|
|
294
|
+
.view=${t.view}
|
|
295
|
+
.submitOnEnter=${e ? !1 : this.submitOnEnter}
|
|
296
|
+
.busy=${this.busy}
|
|
297
|
+
@baht-change=${(r) => {
|
|
298
|
+
this.onFormChange(r);
|
|
299
|
+
}}
|
|
300
|
+
@baht-submit=${(r) => {
|
|
301
|
+
e ? r.stopPropagation() : this.onFormSubmit(r);
|
|
302
|
+
}}
|
|
303
|
+
></baht-form>`;
|
|
304
|
+
}
|
|
268
305
|
render() {
|
|
269
306
|
const t = this.currentForm;
|
|
270
307
|
if (!t) return h`<div class="baht-workflow"></div>`;
|
|
@@ -274,43 +311,29 @@ let a = class extends g {
|
|
|
274
311
|
data-step=${t.form_name}
|
|
275
312
|
data-testid="${this.workflow.workflow_id}.${t.form_name}"
|
|
276
313
|
>
|
|
277
|
-
${this.chrome === "none" ?
|
|
278
|
-
${
|
|
314
|
+
${this.chrome === "none" ? d : h`<div class="baht-visually-hidden" role="status">
|
|
315
|
+
${m("step", { current: i + 1, total: r.length })}
|
|
279
316
|
</div>`}
|
|
280
317
|
${this.showSteps ? h`<baht-steps
|
|
281
318
|
.steps=${r.map((s) => s.form_name)}
|
|
282
319
|
.current=${i}
|
|
283
320
|
.variant=${this.stepsVariant}
|
|
284
|
-
></baht-steps>` :
|
|
321
|
+
></baht-steps>` : d}
|
|
285
322
|
${v(
|
|
286
323
|
t.form_name,
|
|
287
324
|
h`<div
|
|
288
325
|
class="baht-workflow-step${this.direction ? ` baht-workflow-step--${this.direction}` : ""}"
|
|
289
326
|
>
|
|
290
|
-
${e ? this.renderApproval(t) :
|
|
291
|
-
.form=${t}
|
|
292
|
-
.value=${this.data[t.form_name] ?? {}}
|
|
293
|
-
.registry=${this.registry}
|
|
294
|
-
.fieldStates=${this.fieldStatesFor(t.form_name)}
|
|
295
|
-
.view=${t.view}
|
|
296
|
-
.submitOnEnter=${this.submitOnEnter}
|
|
297
|
-
.busy=${this.busy}
|
|
298
|
-
@baht-change=${(s) => {
|
|
299
|
-
this.onFormChange(s);
|
|
300
|
-
}}
|
|
301
|
-
@baht-submit=${(s) => {
|
|
302
|
-
this.onFormSubmit(s);
|
|
303
|
-
}}
|
|
304
|
-
></baht-form>`}
|
|
327
|
+
${e ? this.renderApproval(t) : this.renderStepForm(t)}
|
|
305
328
|
</div>`
|
|
306
329
|
)}
|
|
307
|
-
${this.chrome === "none" ?
|
|
330
|
+
${this.chrome === "none" ? d : this.renderNav(t)}
|
|
308
331
|
</div>`;
|
|
309
332
|
}
|
|
310
333
|
/** Back + Next/Submit (or Reject/Approve on an approval step). */
|
|
311
334
|
renderNav(t) {
|
|
312
335
|
var r;
|
|
313
|
-
const e = this.busy ? "true" :
|
|
336
|
+
const e = this.busy ? "true" : d;
|
|
314
337
|
return h`<div class="baht-workflow-nav">
|
|
315
338
|
${this.showBack && (((r = this.run) == null ? void 0 : r.history.length) ?? 0) > 0 ? h`<button type="button" class="baht-button baht-button--back"
|
|
316
339
|
aria-disabled=${e}
|
|
@@ -319,14 +342,14 @@ let a = class extends g {
|
|
|
319
342
|
this.back();
|
|
320
343
|
}}
|
|
321
344
|
>
|
|
322
|
-
${this.backLabel ??
|
|
323
|
-
</button>` :
|
|
345
|
+
${this.backLabel ?? m("back")}
|
|
346
|
+
</button>` : d}
|
|
324
347
|
${t.kind === "approval" ? this.renderDecision(t) : this.renderNext()}
|
|
325
348
|
</div>`;
|
|
326
349
|
}
|
|
327
350
|
renderDecision(t) {
|
|
328
351
|
var r, i;
|
|
329
|
-
const e = this.busy ? "true" :
|
|
352
|
+
const e = this.busy ? "true" : d;
|
|
330
353
|
return h`<button
|
|
331
354
|
type="button"
|
|
332
355
|
class="baht-button baht-button--reject"
|
|
@@ -336,7 +359,7 @@ let a = class extends g {
|
|
|
336
359
|
this.decide("rejected");
|
|
337
360
|
}}
|
|
338
361
|
>
|
|
339
|
-
${((r = t.approval) == null ? void 0 : r.reject_label) ??
|
|
362
|
+
${((r = t.approval) == null ? void 0 : r.reject_label) ?? m("reject")}
|
|
340
363
|
</button>
|
|
341
364
|
<button
|
|
342
365
|
type="button"
|
|
@@ -348,11 +371,11 @@ let a = class extends g {
|
|
|
348
371
|
this.decide("approved");
|
|
349
372
|
}}
|
|
350
373
|
>
|
|
351
|
-
${((i = t.approval) == null ? void 0 : i.approve_label) ??
|
|
374
|
+
${((i = t.approval) == null ? void 0 : i.approve_label) ?? m("approve")}
|
|
352
375
|
</button>`;
|
|
353
376
|
}
|
|
354
377
|
renderNext() {
|
|
355
|
-
const t = this.busy ? "true" :
|
|
378
|
+
const t = this.busy ? "true" : d;
|
|
356
379
|
return h`<button
|
|
357
380
|
type="button"
|
|
358
381
|
class="baht-button baht-button--next"
|
|
@@ -363,7 +386,7 @@ let a = class extends g {
|
|
|
363
386
|
this.next();
|
|
364
387
|
}}
|
|
365
388
|
>
|
|
366
|
-
${this.isLast ? this.submitLabel ??
|
|
389
|
+
${this.isLast ? this.submitLabel ?? m("submit") : this.nextLabel ?? m("next")}
|
|
367
390
|
</button>`;
|
|
368
391
|
}
|
|
369
392
|
};
|
|
@@ -416,13 +439,16 @@ l([
|
|
|
416
439
|
b()
|
|
417
440
|
], a.prototype, "run", 2);
|
|
418
441
|
a = l([
|
|
419
|
-
|
|
442
|
+
E("baht-workflow")
|
|
420
443
|
], a);
|
|
421
444
|
function O(t, e) {
|
|
445
|
+
return e === "rule-error" ? "the rules never settled, so the data is not submitted" : e === "self-transition" ? `target "${t}" is the current form (self-transition)` : `target "${t}" is not visible`;
|
|
446
|
+
}
|
|
447
|
+
function W(t, e) {
|
|
422
448
|
const r = Object.keys(t);
|
|
423
449
|
return r.length === Object.keys(e).length && r.every((i) => {
|
|
424
450
|
const s = t[i], o = e[i];
|
|
425
|
-
return s === o || !!s && !!o &&
|
|
451
|
+
return s === o || !!s && !!o && p(s, o);
|
|
426
452
|
});
|
|
427
453
|
}
|
|
428
454
|
export {
|
|
@@ -649,13 +649,42 @@
|
|
|
649
649
|
{
|
|
650
650
|
"kind": "method",
|
|
651
651
|
"name": "flushTyped",
|
|
652
|
-
"privacy": "private",
|
|
653
652
|
"return": {
|
|
654
653
|
"type": {
|
|
655
654
|
"text": "void"
|
|
656
655
|
}
|
|
657
656
|
},
|
|
658
|
-
"description": "
|
|
657
|
+
"description": "Keystrokes still in a control's debounce land now: each emits its `baht-change`, as when the\nfield loses focus. `getData()`, `validate()` and `setValue()` do this first, so a read never\nmisses what was typed; `<baht-workflow>` calls it before reading its own data."
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
"kind": "method",
|
|
661
|
+
"name": "discardTyped",
|
|
662
|
+
"return": {
|
|
663
|
+
"type": {
|
|
664
|
+
"text": "void"
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
"parameters": [
|
|
668
|
+
{
|
|
669
|
+
"name": "keys",
|
|
670
|
+
"optional": true,
|
|
671
|
+
"type": {
|
|
672
|
+
"text": "readonly string[]"
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
],
|
|
676
|
+
"description": "Forget keystrokes still in a control's debounce (all, or those of `keys`): the control shows\n`value` again and nothing is emitted. For a host replacing what the form shows (`restore()`)."
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
"kind": "method",
|
|
680
|
+
"name": "controls",
|
|
681
|
+
"privacy": "private",
|
|
682
|
+
"return": {
|
|
683
|
+
"type": {
|
|
684
|
+
"text": "Element[]"
|
|
685
|
+
}
|
|
686
|
+
},
|
|
687
|
+
"description": "The rendered controls: the direct children of each .baht-field wrapper."
|
|
659
688
|
},
|
|
660
689
|
{
|
|
661
690
|
"kind": "method",
|
|
@@ -664,7 +693,8 @@
|
|
|
664
693
|
"type": {
|
|
665
694
|
"text": "Record<string, unknown>"
|
|
666
695
|
}
|
|
667
|
-
}
|
|
696
|
+
},
|
|
697
|
+
"description": "The whole form's data (not only the view's fields). Pending keystrokes land first, so a read\ncan dispatch their `baht-change` before it returns."
|
|
668
698
|
},
|
|
669
699
|
{
|
|
670
700
|
"kind": "method",
|
|
@@ -1206,7 +1236,7 @@
|
|
|
1206
1236
|
"declarations": [
|
|
1207
1237
|
{
|
|
1208
1238
|
"kind": "class",
|
|
1209
|
-
"description": "<baht-workflow> — the optional brain (spec 03). Wraps the current form in an\ninternal <baht-form>, evaluates rules on every change, walks the visible forms\nin linear `order`, and owns the single Next/Submit button.\nForms with kind 'approval' render a decision step instead (spec 03 §4):\na summary of earlier answers plus
|
|
1239
|
+
"description": "<baht-workflow> — the optional brain (spec 03). Wraps the current form in an\ninternal <baht-form>, evaluates rules on every change, walks the visible forms\nin linear `order`, and owns the single Next/Submit button.\nForms with kind 'approval' render a decision step instead (spec 03 §4):\na summary of earlier answers, the step's own fields when it has any (filled by\nthe approver, validated before a decision like a form before Next), plus\nApprove/Reject (+ optional comment); the decision lands in data as\n`<form_name>.decision` so rules can branch on it. A run that submitted, or that\na rejection ended, takes no further decision or press.\nThe runtime navigates; the host acts (on baht-next / baht-submit / baht-approve /\nbaht-reject / baht-complete).\nWith `chrome=\"none\"` it renders the current form only — no Next/Back/Submit, no\nstep announcement — so a lone form with rules is a one-form workflow whose page\nowns the buttons and calls `validate()` / `next()` (spec 03 §2, \"Chrome\").",
|
|
1210
1240
|
"name": "BahtWorkflow",
|
|
1211
1241
|
"members": [
|
|
1212
1242
|
{
|
|
@@ -1322,7 +1352,7 @@
|
|
|
1322
1352
|
"type": {
|
|
1323
1353
|
"text": "number | undefined"
|
|
1324
1354
|
},
|
|
1325
|
-
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box
|
|
1355
|
+
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box, `back()`, `gotoStart()`, `getData()` and `getState()` flush what is pending;\n`restore()` and a new `value` drop it.",
|
|
1326
1356
|
"attribute": "debounce"
|
|
1327
1357
|
},
|
|
1328
1358
|
{
|
|
@@ -1540,8 +1570,20 @@
|
|
|
1540
1570
|
"text": "BahtForm | null"
|
|
1541
1571
|
},
|
|
1542
1572
|
"privacy": "private",
|
|
1573
|
+
"description": "The step's own editable form: a data step's, or an approval step's fields (never the summary).",
|
|
1543
1574
|
"readonly": true
|
|
1544
1575
|
},
|
|
1576
|
+
{
|
|
1577
|
+
"kind": "method",
|
|
1578
|
+
"name": "flushPending",
|
|
1579
|
+
"privacy": "private",
|
|
1580
|
+
"return": {
|
|
1581
|
+
"type": {
|
|
1582
|
+
"text": "void"
|
|
1583
|
+
}
|
|
1584
|
+
},
|
|
1585
|
+
"description": "Keystrokes still in the step's controls, and the approval comment, land in the run now."
|
|
1586
|
+
},
|
|
1545
1587
|
{
|
|
1546
1588
|
"kind": "method",
|
|
1547
1589
|
"name": "getData",
|
|
@@ -1549,7 +1591,8 @@
|
|
|
1549
1591
|
"type": {
|
|
1550
1592
|
"text": "NestedData"
|
|
1551
1593
|
}
|
|
1552
|
-
}
|
|
1594
|
+
},
|
|
1595
|
+
"description": "The run's data, with whatever is still being typed applied first."
|
|
1553
1596
|
},
|
|
1554
1597
|
{
|
|
1555
1598
|
"kind": "method",
|
|
@@ -1583,7 +1626,7 @@
|
|
|
1583
1626
|
"text": "{ valid: boolean; errors: ValidationError[] }"
|
|
1584
1627
|
}
|
|
1585
1628
|
},
|
|
1586
|
-
"description": "Validate the current form (rule-hidden fields skipped
|
|
1629
|
+
"description": "Validate the current form, or an approval step's own fields (rule-hidden fields skipped,\nrule-derived `required` applied) and show its errors, without advancing or emitting\nnavigation events. Valid with no errors when the step has no fields to fill."
|
|
1587
1630
|
},
|
|
1588
1631
|
{
|
|
1589
1632
|
"kind": "method",
|
|
@@ -1658,7 +1701,7 @@
|
|
|
1658
1701
|
"text": "WorkflowSnapshot"
|
|
1659
1702
|
}
|
|
1660
1703
|
},
|
|
1661
|
-
"description": "The run as JSON: `{ data, current, history }
|
|
1704
|
+
"description": "The run as JSON: `{ workflow_id, data, current, history, ended }`, a copy (redact what must not be\nstored: it holds every value entered). Keep it (a draft on the server, the session)\nand hand it to `restore()` to pick the run up on the same step, or keep one per change for undo."
|
|
1662
1705
|
},
|
|
1663
1706
|
{
|
|
1664
1707
|
"kind": "method",
|
|
@@ -1814,6 +1857,25 @@
|
|
|
1814
1857
|
}
|
|
1815
1858
|
]
|
|
1816
1859
|
},
|
|
1860
|
+
{
|
|
1861
|
+
"kind": "method",
|
|
1862
|
+
"name": "renderStepForm",
|
|
1863
|
+
"privacy": "private",
|
|
1864
|
+
"return": {
|
|
1865
|
+
"type": {
|
|
1866
|
+
"text": "TemplateResult"
|
|
1867
|
+
}
|
|
1868
|
+
},
|
|
1869
|
+
"parameters": [
|
|
1870
|
+
{
|
|
1871
|
+
"name": "form",
|
|
1872
|
+
"type": {
|
|
1873
|
+
"text": "WorkflowForm"
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
],
|
|
1877
|
+
"description": "The step's editable form: a data step, or the fields an approval step has of its own (a task's\nfields, filled by the approver). Enter submits a data step only; a decision is a button press."
|
|
1878
|
+
},
|
|
1817
1879
|
{
|
|
1818
1880
|
"kind": "method",
|
|
1819
1881
|
"name": "renderNav",
|
|
@@ -1972,9 +2034,9 @@
|
|
|
1972
2034
|
},
|
|
1973
2035
|
{
|
|
1974
2036
|
"type": {
|
|
1975
|
-
"text": "CustomEvent<{ form_name: string | null; target: string; reason: 'self-transition' | 'target-hidden'; data: NestedData }>"
|
|
2037
|
+
"text": "CustomEvent<{ form_name: string | null; target: string; reason: 'self-transition' | 'target-hidden' | 'rule-error'; data: NestedData }>"
|
|
1976
2038
|
},
|
|
1977
|
-
"description": "Next resolved to no visible step.",
|
|
2039
|
+
"description": "Next resolved to no visible step, or the last step would submit data whose rules never settled.",
|
|
1978
2040
|
"name": "baht-nav-blocked"
|
|
1979
2041
|
},
|
|
1980
2042
|
{
|
|
@@ -2009,7 +2071,7 @@
|
|
|
2009
2071
|
"type": {
|
|
2010
2072
|
"text": "CustomEvent<WorkflowTransition>"
|
|
2011
2073
|
},
|
|
2012
|
-
"description": "One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`).",
|
|
2074
|
+
"description": "One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`). The states hold every value entered, `password` fields included: redact before a log leaves the page.",
|
|
2013
2075
|
"name": "baht-transition"
|
|
2014
2076
|
},
|
|
2015
2077
|
{
|
|
@@ -2101,7 +2163,7 @@
|
|
|
2101
2163
|
"type": {
|
|
2102
2164
|
"text": "number | undefined"
|
|
2103
2165
|
},
|
|
2104
|
-
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box
|
|
2166
|
+
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box, `back()`, `gotoStart()`, `getData()` and `getState()` flush what is pending;\n`restore()` and a new `value` drop it.",
|
|
2105
2167
|
"fieldName": "debounce"
|
|
2106
2168
|
},
|
|
2107
2169
|
{
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"tags": [
|
|
5
5
|
{
|
|
6
6
|
"name": "baht-form",
|
|
7
|
-
"description": "<baht-form> — dumb controlled form renderer (spec 01).\nJSON in (form + value + registry) -> UI out; emits `baht-change` / `baht-validity`.\nNo buttons, no cross-field logic — that's <baht-workflow> or the host.\n---\n\n\n### **Events:**\n - **baht-tab-change** - A tab of a tabbed layout was picked.\n- **baht-submit** - `submit()` (or Enter with `submit-on-enter`) passed `validate()`.\n- **baht-change** - A field changed (an edit or a script); `data` is the whole form.\n- **baht-validity** - `validate()` ran.\n- **name**\n\n### **Methods:**\n - **setValue(patch: _Record<string, unknown>_): _void_** - Merge values programmatically. Runs each key's `change` scripts (like\nServiceNow's g_form.setValue) but emits no `baht-change` — the host\nalready knows, and a store adapter would otherwise loop.\n- **revert(keys: _readonly string[]_): _void_** - Drop the user's edits to these keys, so each shows `value` again. For a host that refused an\nedit and has no new `value` to say so with: `<baht-workflow>` calls it when a rule wrote the\nfield back (spec 02 §4). Emits nothing and runs no scripts.\n- **validate(): _{ valid: boolean; errors: ValidationError[] }_** - Full validation pass: validators, then `submit` scripts (spec 01 §14). A\nscript returning `false` blocks; its `addErrorMessage()` calls become\n`{ key: '$' }` errors so hosts see why.\n- **submit(): _boolean_** - The host's Save: `validate()`, then `baht-submit { data }` when it passes. Returns\nwhether it submitted (never while `busy`).\n\n",
|
|
7
|
+
"description": "<baht-form> — dumb controlled form renderer (spec 01).\nJSON in (form + value + registry) -> UI out; emits `baht-change` / `baht-validity`.\nNo buttons, no cross-field logic — that's <baht-workflow> or the host.\n---\n\n\n### **Events:**\n - **baht-tab-change** - A tab of a tabbed layout was picked.\n- **baht-submit** - `submit()` (or Enter with `submit-on-enter`) passed `validate()`.\n- **baht-change** - A field changed (an edit or a script); `data` is the whole form.\n- **baht-validity** - `validate()` ran.\n- **name**\n\n### **Methods:**\n - **flushTyped(): _void_** - Keystrokes still in a control's debounce land now: each emits its `baht-change`, as when the\nfield loses focus. `getData()`, `validate()` and `setValue()` do this first, so a read never\nmisses what was typed; `<baht-workflow>` calls it before reading its own data.\n- **discardTyped(keys: _readonly string[]_): _void_** - Forget keystrokes still in a control's debounce (all, or those of `keys`): the control shows\n`value` again and nothing is emitted. For a host replacing what the form shows (`restore()`).\n- **getData(): _Record<string, unknown>_** - The whole form's data (not only the view's fields). Pending keystrokes land first, so a read\ncan dispatch their `baht-change` before it returns.\n- **setValue(patch: _Record<string, unknown>_): _void_** - Merge values programmatically. Runs each key's `change` scripts (like\nServiceNow's g_form.setValue) but emits no `baht-change` — the host\nalready knows, and a store adapter would otherwise loop.\n- **revert(keys: _readonly string[]_): _void_** - Drop the user's edits to these keys, so each shows `value` again. For a host that refused an\nedit and has no new `value` to say so with: `<baht-workflow>` calls it when a rule wrote the\nfield back (spec 02 §4). Emits nothing and runs no scripts.\n- **validate(): _{ valid: boolean; errors: ValidationError[] }_** - Full validation pass: validators, then `submit` scripts (spec 01 §14). A\nscript returning `false` blocks; its `addErrorMessage()` calls become\n`{ key: '$' }` errors so hosts see why.\n- **submit(): _boolean_** - The host's Save: `validate()`, then `baht-submit { data }` when it passes. Returns\nwhether it submitted (never while `busy`).\n\n",
|
|
8
8
|
"attributes": [
|
|
9
9
|
{
|
|
10
10
|
"name": "show-optional",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
"name": "baht-workflow",
|
|
45
|
-
"description": "<baht-workflow> — the optional brain (spec 03). Wraps the current form in an\ninternal <baht-form>, evaluates rules on every change, walks the visible forms\nin linear `order`, and owns the single Next/Submit button.\nForms with kind 'approval' render a decision step instead (spec 03 §4):\na summary of earlier answers plus
|
|
45
|
+
"description": "<baht-workflow> — the optional brain (spec 03). Wraps the current form in an\ninternal <baht-form>, evaluates rules on every change, walks the visible forms\nin linear `order`, and owns the single Next/Submit button.\nForms with kind 'approval' render a decision step instead (spec 03 §4):\na summary of earlier answers, the step's own fields when it has any (filled by\nthe approver, validated before a decision like a form before Next), plus\nApprove/Reject (+ optional comment); the decision lands in data as\n`<form_name>.decision` so rules can branch on it. A run that submitted, or that\na rejection ended, takes no further decision or press.\nThe runtime navigates; the host acts (on baht-next / baht-submit / baht-approve /\nbaht-reject / baht-complete).\nWith `chrome=\"none\"` it renders the current form only — no Next/Back/Submit, no\nstep announcement — so a lone form with rules is a one-form workflow whose page\nowns the buttons and calls `validate()` / `next()` (spec 03 §2, \"Chrome\").\n---\n\n\n### **Events:**\n - **baht-data-change** - Any value changed.\n- **baht-next** - Moved forward to `form_name`.\n- **baht-step-change** - The visible step changed.\n- **baht-nav-blocked** - Next resolved to no visible step, or the last step would submit data whose rules never settled.\n- **baht-submit** - The last step was submitted.\n- **baht-complete** - The workflow ended.\n- **baht-approve** - An approval step was approved.\n- **baht-reject** - An approval step was rejected.\n- **baht-transition** - One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`). The states hold every value entered, `password` fields included: redact before a log leaves the page.\n- **baht-rule-error** - The rules' errors changed (a rule aimed at nothing, rules that never settle); empty once they are gone.\n- **name**\n\n### **Methods:**\n - **getData(): _NestedData_** - The run's data, with whatever is still being typed applied first.\n- **setValue(form_name: _string_, patch: _Record<string, unknown>_): _void_** - Host/store write into one form's data — same path a user edit takes\n(rules reevaluate, `baht-data-change` fires) but WITHOUT the step reset\nthat re-feeding the `value` prop causes.\n- **validate(): _{ valid: boolean; errors: ValidationError[] }_** - Validate the current form, or an approval step's own fields (rule-hidden fields skipped,\nrule-derived `required` applied) and show its errors, without advancing or emitting\nnavigation events. Valid with no errors when the step has no fields to fill.\n- **approve(): _void_** - Approve the current approval step (same as pressing its Approve button).\n- **reject(): _void_** - Reject the current approval step (same as pressing its Reject button).\n- **getState(): _WorkflowSnapshot_** - The run as JSON: `{ workflow_id, data, current, history, ended }`, a copy (redact what must not be\nstored: it holds every value entered). Keep it (a draft on the server, the session)\nand hand it to `restore()` to pick the run up on the same step, or keep one per change for undo.\n- **restore(snapshot: _unknown_): _void_** - Pick up a run kept with `getState()`: its data, its step and its Back history. The rules run\non the data again; a step they hide falls back to the first visible one. Emits no navigation\nevents. Called before `workflow` is bound, it applies once it is.\n\n",
|
|
46
46
|
"attributes": [
|
|
47
47
|
{ "name": "validate-gate", "values": [] },
|
|
48
48
|
{
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
{
|
|
72
72
|
"name": "debounce",
|
|
73
|
-
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box
|
|
73
|
+
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box, `back()`, `gotoStart()`, `getData()` and `getState()` flush what is pending;\n`restore()` and a new `value` drop it.",
|
|
74
74
|
"values": []
|
|
75
75
|
},
|
|
76
76
|
{
|
package/dist/web-types.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
|
|
3
3
|
"name": "@20baht/ui",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
8
8
|
"elements": [
|
|
9
9
|
{
|
|
10
10
|
"name": "baht-form",
|
|
11
|
-
"description": "<baht-form> — dumb controlled form renderer (spec 01).\nJSON in (form + value + registry) -> UI out; emits `baht-change` / `baht-validity`.\nNo buttons, no cross-field logic — that's <baht-workflow> or the host.\n---\n\n\n### **Events:**\n - **baht-tab-change** - A tab of a tabbed layout was picked.\n- **baht-submit** - `submit()` (or Enter with `submit-on-enter`) passed `validate()`.\n- **baht-change** - A field changed (an edit or a script); `data` is the whole form.\n- **baht-validity** - `validate()` ran.\n- **name**\n\n### **Methods:**\n - **setValue(patch: _Record<string, unknown>_): _void_** - Merge values programmatically. Runs each key's `change` scripts (like\nServiceNow's g_form.setValue) but emits no `baht-change` — the host\nalready knows, and a store adapter would otherwise loop.\n- **revert(keys: _readonly string[]_): _void_** - Drop the user's edits to these keys, so each shows `value` again. For a host that refused an\nedit and has no new `value` to say so with: `<baht-workflow>` calls it when a rule wrote the\nfield back (spec 02 §4). Emits nothing and runs no scripts.\n- **validate(): _{ valid: boolean; errors: ValidationError[] }_** - Full validation pass: validators, then `submit` scripts (spec 01 §14). A\nscript returning `false` blocks; its `addErrorMessage()` calls become\n`{ key: '$' }` errors so hosts see why.\n- **submit(): _boolean_** - The host's Save: `validate()`, then `baht-submit { data }` when it passes. Returns\nwhether it submitted (never while `busy`).\n\n",
|
|
11
|
+
"description": "<baht-form> — dumb controlled form renderer (spec 01).\nJSON in (form + value + registry) -> UI out; emits `baht-change` / `baht-validity`.\nNo buttons, no cross-field logic — that's <baht-workflow> or the host.\n---\n\n\n### **Events:**\n - **baht-tab-change** - A tab of a tabbed layout was picked.\n- **baht-submit** - `submit()` (or Enter with `submit-on-enter`) passed `validate()`.\n- **baht-change** - A field changed (an edit or a script); `data` is the whole form.\n- **baht-validity** - `validate()` ran.\n- **name**\n\n### **Methods:**\n - **flushTyped(): _void_** - Keystrokes still in a control's debounce land now: each emits its `baht-change`, as when the\nfield loses focus. `getData()`, `validate()` and `setValue()` do this first, so a read never\nmisses what was typed; `<baht-workflow>` calls it before reading its own data.\n- **discardTyped(keys: _readonly string[]_): _void_** - Forget keystrokes still in a control's debounce (all, or those of `keys`): the control shows\n`value` again and nothing is emitted. For a host replacing what the form shows (`restore()`).\n- **getData(): _Record<string, unknown>_** - The whole form's data (not only the view's fields). Pending keystrokes land first, so a read\ncan dispatch their `baht-change` before it returns.\n- **setValue(patch: _Record<string, unknown>_): _void_** - Merge values programmatically. Runs each key's `change` scripts (like\nServiceNow's g_form.setValue) but emits no `baht-change` — the host\nalready knows, and a store adapter would otherwise loop.\n- **revert(keys: _readonly string[]_): _void_** - Drop the user's edits to these keys, so each shows `value` again. For a host that refused an\nedit and has no new `value` to say so with: `<baht-workflow>` calls it when a rule wrote the\nfield back (spec 02 §4). Emits nothing and runs no scripts.\n- **validate(): _{ valid: boolean; errors: ValidationError[] }_** - Full validation pass: validators, then `submit` scripts (spec 01 §14). A\nscript returning `false` blocks; its `addErrorMessage()` calls become\n`{ key: '$' }` errors so hosts see why.\n- **submit(): _boolean_** - The host's Save: `validate()`, then `baht-submit { data }` when it passes. Returns\nwhether it submitted (never while `busy`).\n\n",
|
|
12
12
|
"doc-url": "",
|
|
13
13
|
"attributes": [
|
|
14
14
|
{
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
146
|
"name": "baht-workflow",
|
|
147
|
-
"description": "<baht-workflow> — the optional brain (spec 03). Wraps the current form in an\ninternal <baht-form>, evaluates rules on every change, walks the visible forms\nin linear `order`, and owns the single Next/Submit button.\nForms with kind 'approval' render a decision step instead (spec 03 §4):\na summary of earlier answers plus
|
|
147
|
+
"description": "<baht-workflow> — the optional brain (spec 03). Wraps the current form in an\ninternal <baht-form>, evaluates rules on every change, walks the visible forms\nin linear `order`, and owns the single Next/Submit button.\nForms with kind 'approval' render a decision step instead (spec 03 §4):\na summary of earlier answers, the step's own fields when it has any (filled by\nthe approver, validated before a decision like a form before Next), plus\nApprove/Reject (+ optional comment); the decision lands in data as\n`<form_name>.decision` so rules can branch on it. A run that submitted, or that\na rejection ended, takes no further decision or press.\nThe runtime navigates; the host acts (on baht-next / baht-submit / baht-approve /\nbaht-reject / baht-complete).\nWith `chrome=\"none\"` it renders the current form only — no Next/Back/Submit, no\nstep announcement — so a lone form with rules is a one-form workflow whose page\nowns the buttons and calls `validate()` / `next()` (spec 03 §2, \"Chrome\").\n---\n\n\n### **Events:**\n - **baht-data-change** - Any value changed.\n- **baht-next** - Moved forward to `form_name`.\n- **baht-step-change** - The visible step changed.\n- **baht-nav-blocked** - Next resolved to no visible step, or the last step would submit data whose rules never settled.\n- **baht-submit** - The last step was submitted.\n- **baht-complete** - The workflow ended.\n- **baht-approve** - An approval step was approved.\n- **baht-reject** - An approval step was rejected.\n- **baht-transition** - One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`). The states hold every value entered, `password` fields included: redact before a log leaves the page.\n- **baht-rule-error** - The rules' errors changed (a rule aimed at nothing, rules that never settle); empty once they are gone.\n- **name**\n\n### **Methods:**\n - **getData(): _NestedData_** - The run's data, with whatever is still being typed applied first.\n- **setValue(form_name: _string_, patch: _Record<string, unknown>_): _void_** - Host/store write into one form's data — same path a user edit takes\n(rules reevaluate, `baht-data-change` fires) but WITHOUT the step reset\nthat re-feeding the `value` prop causes.\n- **validate(): _{ valid: boolean; errors: ValidationError[] }_** - Validate the current form, or an approval step's own fields (rule-hidden fields skipped,\nrule-derived `required` applied) and show its errors, without advancing or emitting\nnavigation events. Valid with no errors when the step has no fields to fill.\n- **approve(): _void_** - Approve the current approval step (same as pressing its Approve button).\n- **reject(): _void_** - Reject the current approval step (same as pressing its Reject button).\n- **getState(): _WorkflowSnapshot_** - The run as JSON: `{ workflow_id, data, current, history, ended }`, a copy (redact what must not be\nstored: it holds every value entered). Keep it (a draft on the server, the session)\nand hand it to `restore()` to pick the run up on the same step, or keep one per change for undo.\n- **restore(snapshot: _unknown_): _void_** - Pick up a run kept with `getState()`: its data, its step and its Back history. The rules run\non the data again; a step they hide falls back to the first visible one. Emits no navigation\nevents. Called before `workflow` is bound, it applies once it is.\n\n",
|
|
148
148
|
"doc-url": "",
|
|
149
149
|
"attributes": [
|
|
150
150
|
{
|
|
@@ -182,7 +182,7 @@
|
|
|
182
182
|
},
|
|
183
183
|
{
|
|
184
184
|
"name": "debounce",
|
|
185
|
-
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box
|
|
185
|
+
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box, `back()`, `gotoStart()`, `getData()` and `getState()` flush what is pending;\n`restore()` and a new `value` drop it.",
|
|
186
186
|
"value": { "type": "number | undefined" }
|
|
187
187
|
},
|
|
188
188
|
{
|
|
@@ -218,8 +218,8 @@
|
|
|
218
218
|
},
|
|
219
219
|
{
|
|
220
220
|
"name": "baht-nav-blocked",
|
|
221
|
-
"type": "CustomEvent<{ form_name: string | null; target: string; reason: 'self-transition' | 'target-hidden'; data: NestedData }>",
|
|
222
|
-
"description": "Next resolved to no visible step."
|
|
221
|
+
"type": "CustomEvent<{ form_name: string | null; target: string; reason: 'self-transition' | 'target-hidden' | 'rule-error'; data: NestedData }>",
|
|
222
|
+
"description": "Next resolved to no visible step, or the last step would submit data whose rules never settled."
|
|
223
223
|
},
|
|
224
224
|
{
|
|
225
225
|
"name": "baht-submit",
|
|
@@ -244,7 +244,7 @@
|
|
|
244
244
|
{
|
|
245
245
|
"name": "baht-transition",
|
|
246
246
|
"type": "CustomEvent<WorkflowTransition>",
|
|
247
|
-
"description": "One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`)."
|
|
247
|
+
"description": "One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`). The states hold every value entered, `password` fields included: redact before a log leaves the page."
|
|
248
248
|
},
|
|
249
249
|
{
|
|
250
250
|
"name": "baht-rule-error",
|
|
@@ -293,7 +293,7 @@
|
|
|
293
293
|
},
|
|
294
294
|
{
|
|
295
295
|
"name": "debounce",
|
|
296
|
-
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box
|
|
296
|
+
"description": "Debounce (ms) for the approval comment, the one typed field the workflow renders itself;\nunset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,\nleaving the box, `back()`, `gotoStart()`, `getData()` and `getState()` flush what is pending;\n`restore()` and a new `value` drop it.",
|
|
297
297
|
"type": "number | undefined"
|
|
298
298
|
},
|
|
299
299
|
{
|
|
@@ -331,8 +331,8 @@
|
|
|
331
331
|
},
|
|
332
332
|
{
|
|
333
333
|
"name": "baht-nav-blocked",
|
|
334
|
-
"type": "CustomEvent<{ form_name: string | null; target: string; reason: 'self-transition' | 'target-hidden'; data: NestedData }>",
|
|
335
|
-
"description": "Next resolved to no visible step."
|
|
334
|
+
"type": "CustomEvent<{ form_name: string | null; target: string; reason: 'self-transition' | 'target-hidden' | 'rule-error'; data: NestedData }>",
|
|
335
|
+
"description": "Next resolved to no visible step, or the last step would submit data whose rules never settled."
|
|
336
336
|
},
|
|
337
337
|
{
|
|
338
338
|
"name": "baht-submit",
|
|
@@ -357,7 +357,7 @@
|
|
|
357
357
|
{
|
|
358
358
|
"name": "baht-transition",
|
|
359
359
|
"type": "CustomEvent<WorkflowTransition>",
|
|
360
|
-
"description": "One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`)."
|
|
360
|
+
"description": "One step of the run, after its own events: the message, the state before and after, the events. For a log, a replay (`replayWorkflow`) or undo (`restore(snapshotOf(before))`). The states hold every value entered, `password` fields included: redact before a log leaves the page."
|
|
361
361
|
},
|
|
362
362
|
{
|
|
363
363
|
"name": "baht-rule-error",
|