@20baht/ui 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +512 -2
- package/dist/components/baht-form.d.ts +206 -0
- package/dist/components/baht-form.js +630 -0
- package/dist/components/baht-workflow.d.ts +187 -0
- package/dist/components/baht-workflow.js +455 -0
- package/dist/components/base.d.ts +92 -0
- package/dist/components/base.js +138 -0
- package/dist/components/combobox-controller.d.ts +65 -0
- package/dist/components/combobox-controller.js +82 -0
- package/dist/components/define.d.ts +7 -0
- package/dist/components/define.js +16 -0
- package/dist/components/field-base.d.ts +84 -0
- package/dist/components/field-base.js +152 -0
- package/dist/components/floating.d.ts +84 -0
- package/dist/components/floating.js +182 -0
- package/dist/components/form-layout.d.ts +39 -0
- package/dist/components/form-layout.js +67 -0
- package/dist/components/form-options.d.ts +39 -0
- package/dist/components/form-options.js +65 -0
- package/dist/components/form-readonly.d.ts +20 -0
- package/dist/components/form-readonly.js +70 -0
- package/dist/components/layers.d.ts +4 -0
- package/dist/components/layers.js +15 -0
- package/dist/components/menu-controller.d.ts +65 -0
- package/dist/components/menu-controller.js +134 -0
- package/dist/components/motion.d.ts +9 -0
- package/dist/components/motion.js +16 -0
- package/dist/components/primitives/baht-accordion.d.ts +29 -0
- package/dist/components/primitives/baht-accordion.js +66 -0
- package/dist/components/primitives/baht-alert.d.ts +20 -0
- package/dist/components/primitives/baht-alert.js +62 -0
- package/dist/components/primitives/baht-app-shell.d.ts +81 -0
- package/dist/components/primitives/baht-app-shell.js +161 -0
- package/dist/components/primitives/baht-approval-chain.d.ts +59 -0
- package/dist/components/primitives/baht-approval-chain.js +80 -0
- package/dist/components/primitives/baht-avatar.d.ts +19 -0
- package/dist/components/primitives/baht-avatar.js +43 -0
- package/dist/components/primitives/baht-badge.d.ts +24 -0
- package/dist/components/primitives/baht-badge.js +41 -0
- package/dist/components/primitives/baht-bar-chart.d.ts +78 -0
- package/dist/components/primitives/baht-bar-chart.js +361 -0
- package/dist/components/primitives/baht-breadcrumbs.d.ts +23 -0
- package/dist/components/primitives/baht-breadcrumbs.js +45 -0
- package/dist/components/primitives/baht-button.d.ts +89 -0
- package/dist/components/primitives/baht-button.js +146 -0
- package/dist/components/primitives/baht-calendar.d.ts +96 -0
- package/dist/components/primitives/baht-calendar.js +398 -0
- package/dist/components/primitives/baht-card.d.ts +34 -0
- package/dist/components/primitives/baht-card.js +70 -0
- package/dist/components/primitives/baht-catalog-card.d.ts +52 -0
- package/dist/components/primitives/baht-catalog-card.js +90 -0
- package/dist/components/primitives/baht-checkbox.d.ts +7 -0
- package/dist/components/primitives/baht-checkbox.js +40 -0
- package/dist/components/primitives/baht-choice-group.d.ts +52 -0
- package/dist/components/primitives/baht-choice-group.js +71 -0
- package/dist/components/primitives/baht-code.d.ts +18 -0
- package/dist/components/primitives/baht-code.js +33 -0
- package/dist/components/primitives/baht-column-picker.d.ts +69 -0
- package/dist/components/primitives/baht-column-picker.js +234 -0
- package/dist/components/primitives/baht-comments.d.ts +38 -0
- package/dist/components/primitives/baht-comments.js +102 -0
- package/dist/components/primitives/baht-currency.d.ts +13 -0
- package/dist/components/primitives/baht-currency.js +69 -0
- package/dist/components/primitives/baht-datepicker.d.ts +77 -0
- package/dist/components/primitives/baht-datepicker.js +235 -0
- package/dist/components/primitives/baht-donut-chart.d.ts +24 -0
- package/dist/components/primitives/baht-donut-chart.js +88 -0
- package/dist/components/primitives/baht-edit-table.d.ts +45 -0
- package/dist/components/primitives/baht-edit-table.js +176 -0
- package/dist/components/primitives/baht-empty-state.d.ts +26 -0
- package/dist/components/primitives/baht-empty-state.js +51 -0
- package/dist/components/primitives/baht-error-state.d.ts +21 -0
- package/dist/components/primitives/baht-error-state.js +44 -0
- package/dist/components/primitives/baht-facts.d.ts +42 -0
- package/dist/components/primitives/baht-facts.js +49 -0
- package/dist/components/primitives/baht-fieldset.d.ts +19 -0
- package/dist/components/primitives/baht-fieldset.js +42 -0
- package/dist/components/primitives/baht-file.d.ts +27 -0
- package/dist/components/primitives/baht-file.js +158 -0
- package/dist/components/primitives/baht-filter-builder.d.ts +39 -0
- package/dist/components/primitives/baht-filter-builder.js +201 -0
- package/dist/components/primitives/baht-filter.d.ts +36 -0
- package/dist/components/primitives/baht-filter.js +64 -0
- package/dist/components/primitives/baht-heatmap.d.ts +49 -0
- package/dist/components/primitives/baht-heatmap.js +168 -0
- package/dist/components/primitives/baht-input.d.ts +10 -0
- package/dist/components/primitives/baht-input.js +44 -0
- package/dist/components/primitives/baht-keyvalue-editor.d.ts +28 -0
- package/dist/components/primitives/baht-keyvalue-editor.js +106 -0
- package/dist/components/primitives/baht-line-chart.d.ts +45 -0
- package/dist/components/primitives/baht-line-chart.js +183 -0
- package/dist/components/primitives/baht-link.d.ts +26 -0
- package/dist/components/primitives/baht-link.js +48 -0
- package/dist/components/primitives/baht-list.d.ts +29 -0
- package/dist/components/primitives/baht-list.js +79 -0
- package/dist/components/primitives/baht-loading-overlay.d.ts +15 -0
- package/dist/components/primitives/baht-loading-overlay.js +33 -0
- package/dist/components/primitives/baht-markdown-view.d.ts +17 -0
- package/dist/components/primitives/baht-markdown-view.js +39 -0
- package/dist/components/primitives/baht-markdown.d.ts +34 -0
- package/dist/components/primitives/baht-markdown.js +177 -0
- package/dist/components/primitives/baht-menu.d.ts +53 -0
- package/dist/components/primitives/baht-menu.js +100 -0
- package/dist/components/primitives/baht-meter.d.ts +67 -0
- package/dist/components/primitives/baht-meter.js +107 -0
- package/dist/components/primitives/baht-modal.d.ts +71 -0
- package/dist/components/primitives/baht-modal.js +164 -0
- package/dist/components/primitives/baht-multiselect.d.ts +8 -0
- package/dist/components/primitives/baht-multiselect.js +47 -0
- package/dist/components/primitives/baht-notification-bell.d.ts +54 -0
- package/dist/components/primitives/baht-notification-bell.js +143 -0
- package/dist/components/primitives/baht-number.d.ts +5 -0
- package/dist/components/primitives/baht-number.js +39 -0
- package/dist/components/primitives/baht-order-box.d.ts +24 -0
- package/dist/components/primitives/baht-order-box.js +50 -0
- package/dist/components/primitives/baht-otp.d.ts +49 -0
- package/dist/components/primitives/baht-otp.js +109 -0
- package/dist/components/primitives/baht-page-header.d.ts +43 -0
- package/dist/components/primitives/baht-page-header.js +78 -0
- package/dist/components/primitives/baht-pagination.d.ts +33 -0
- package/dist/components/primitives/baht-pagination.js +86 -0
- package/dist/components/primitives/baht-popover.d.ts +45 -0
- package/dist/components/primitives/baht-popover.js +112 -0
- package/dist/components/primitives/baht-progress-ring.d.ts +22 -0
- package/dist/components/primitives/baht-progress-ring.js +62 -0
- package/dist/components/primitives/baht-progress.d.ts +17 -0
- package/dist/components/primitives/baht-progress.js +48 -0
- package/dist/components/primitives/baht-radio.d.ts +7 -0
- package/dist/components/primitives/baht-radio.js +74 -0
- package/dist/components/primitives/baht-range.d.ts +38 -0
- package/dist/components/primitives/baht-range.js +88 -0
- package/dist/components/primitives/baht-rating.d.ts +40 -0
- package/dist/components/primitives/baht-rating.js +107 -0
- package/dist/components/primitives/baht-record-bar.d.ts +30 -0
- package/dist/components/primitives/baht-record-bar.js +60 -0
- package/dist/components/primitives/baht-reference-dialog.d.ts +87 -0
- package/dist/components/primitives/baht-reference-dialog.js +418 -0
- package/dist/components/primitives/baht-reference-picker.d.ts +110 -0
- package/dist/components/primitives/baht-reference-picker.js +321 -0
- package/dist/components/primitives/baht-repeater.d.ts +59 -0
- package/dist/components/primitives/baht-repeater.js +315 -0
- package/dist/components/primitives/baht-rule-builder.d.ts +24 -0
- package/dist/components/primitives/baht-rule-builder.js +177 -0
- package/dist/components/primitives/baht-saved-filters.d.ts +41 -0
- package/dist/components/primitives/baht-saved-filters.js +126 -0
- package/dist/components/primitives/baht-search.d.ts +34 -0
- package/dist/components/primitives/baht-search.js +71 -0
- package/dist/components/primitives/baht-section-header.d.ts +28 -0
- package/dist/components/primitives/baht-section-header.js +48 -0
- package/dist/components/primitives/baht-section.d.ts +23 -0
- package/dist/components/primitives/baht-section.js +49 -0
- package/dist/components/primitives/baht-select.d.ts +49 -0
- package/dist/components/primitives/baht-select.js +197 -0
- package/dist/components/primitives/baht-skeleton.d.ts +16 -0
- package/dist/components/primitives/baht-skeleton.js +37 -0
- package/dist/components/primitives/baht-sparkline.d.ts +23 -0
- package/dist/components/primitives/baht-sparkline.js +56 -0
- package/dist/components/primitives/baht-spinner.d.ts +13 -0
- package/dist/components/primitives/baht-spinner.js +30 -0
- package/dist/components/primitives/baht-split-button.d.ts +43 -0
- package/dist/components/primitives/baht-split-button.js +87 -0
- package/dist/components/primitives/baht-stat-chart.d.ts +14 -0
- package/dist/components/primitives/baht-stat-chart.js +38 -0
- package/dist/components/primitives/baht-stat.d.ts +56 -0
- package/dist/components/primitives/baht-stat.js +117 -0
- package/dist/components/primitives/baht-steps.d.ts +33 -0
- package/dist/components/primitives/baht-steps.js +60 -0
- package/dist/components/primitives/baht-swipe-row.d.ts +64 -0
- package/dist/components/primitives/baht-swipe-row.js +178 -0
- package/dist/components/primitives/baht-table.d.ts +315 -0
- package/dist/components/primitives/baht-table.js +640 -0
- package/dist/components/primitives/baht-tabs.d.ts +54 -0
- package/dist/components/primitives/baht-tabs.js +128 -0
- package/dist/components/primitives/baht-tags.d.ts +96 -0
- package/dist/components/primitives/baht-tags.js +323 -0
- package/dist/components/primitives/baht-text.d.ts +10 -0
- package/dist/components/primitives/baht-text.js +29 -0
- package/dist/components/primitives/baht-textarea.d.ts +5 -0
- package/dist/components/primitives/baht-textarea.js +40 -0
- package/dist/components/primitives/baht-theme-toggle.d.ts +44 -0
- package/dist/components/primitives/baht-theme-toggle.js +101 -0
- package/dist/components/primitives/baht-timeline.d.ts +21 -0
- package/dist/components/primitives/baht-timeline.js +42 -0
- package/dist/components/primitives/baht-toast.d.ts +29 -0
- package/dist/components/primitives/baht-toast.js +83 -0
- package/dist/components/primitives/baht-toggle.d.ts +6 -0
- package/dist/components/primitives/baht-toggle.js +42 -0
- package/dist/components/primitives/baht-tooltip.d.ts +34 -0
- package/dist/components/primitives/baht-tooltip.js +85 -0
- package/dist/components/primitives/baht-tree.d.ts +58 -0
- package/dist/components/primitives/baht-tree.js +159 -0
- package/dist/components/primitives/baht-typeahead.d.ts +92 -0
- package/dist/components/primitives/baht-typeahead.js +258 -0
- package/dist/components/primitives/baht-upload.d.ts +108 -0
- package/dist/components/primitives/baht-upload.js +325 -0
- package/dist/components/primitives/baht-wizard.d.ts +57 -0
- package/dist/components/primitives/baht-wizard.js +147 -0
- package/dist/components/primitives/charts.d.ts +134 -0
- package/dist/components/primitives/charts.js +184 -0
- package/dist/components/primitives/column-map.d.ts +56 -0
- package/dist/components/primitives/column-map.js +70 -0
- package/dist/components/primitives/control-icons.d.ts +2 -0
- package/dist/components/primitives/control-icons.js +40 -0
- package/dist/components/primitives/icons.d.ts +24 -0
- package/dist/components/primitives/icons.js +86 -0
- package/dist/components/primitives/illustrations.d.ts +21 -0
- package/dist/components/primitives/illustrations.js +78 -0
- package/dist/components/primitives/index.d.ts +89 -0
- package/dist/components/primitives/kbd.d.ts +6 -0
- package/dist/components/primitives/kbd.js +9 -0
- package/dist/components/primitives/listbox.d.ts +2 -0
- package/dist/components/primitives/listbox.js +7 -0
- package/dist/components/primitives/markdown-render.d.ts +9 -0
- package/dist/components/primitives/markdown-render.js +77 -0
- package/dist/components/primitives/rule-rows.d.ts +55 -0
- package/dist/components/primitives/rule-rows.js +75 -0
- package/dist/components/primitives/tag-map.d.ts +6 -0
- package/dist/components/primitives/tag-map.js +39 -0
- package/dist/components/reference-labels.d.ts +22 -0
- package/dist/components/reference-labels.js +29 -0
- package/dist/components/shortcuts.d.ts +7 -0
- package/dist/components/shortcuts.js +43 -0
- package/dist/css/components.css +7517 -0
- package/dist/css/datepicker.css +346 -0
- package/dist/css/tokens.css +679 -0
- package/dist/custom-elements.json +45172 -0
- package/dist/engine.d.ts +1 -0
- package/dist/engine.js +1 -0
- package/dist/hydrate.d.ts +9 -0
- package/dist/hydrate.js +46 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +210 -0
- package/dist/overlay.d.ts +50 -0
- package/dist/overlay.js +140 -0
- package/dist/react.d.ts +557 -0
- package/dist/react.js +1 -0
- package/dist/register.d.ts +106 -0
- package/dist/register.js +99 -0
- package/dist/ssr.d.ts +16 -0
- package/dist/ssr.js +125 -0
- package/dist/tokens.css +8197 -0
- package/dist/vscode.css-custom-data.json +6 -0
- package/dist/vscode.html-custom-data.json +2261 -0
- package/dist/web-types.json +6523 -0
- package/package.json +157 -4
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit';
|
|
2
|
+
import { BahtElement } from './base.js';
|
|
3
|
+
import { WorkflowSnapshot, Derived, FeatureFlags, NestedData, Registry, ValidationError, WorkflowDefinition } from '@20baht/engine';
|
|
4
|
+
/**
|
|
5
|
+
* <baht-workflow> — the optional brain (spec 03). Wraps the current form in an
|
|
6
|
+
* internal <baht-form>, evaluates rules on every change, walks the visible forms
|
|
7
|
+
* in linear `order`, and owns the single Next/Submit button.
|
|
8
|
+
* Forms with kind 'approval' render a decision step instead (spec 03 §4):
|
|
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.
|
|
14
|
+
* The runtime navigates; the host acts (on baht-next / baht-submit / baht-approve /
|
|
15
|
+
* baht-reject / baht-complete).
|
|
16
|
+
* With `chrome="none"` it renders the current form only — no Next/Back/Submit, no
|
|
17
|
+
* step announcement — so a lone form with rules is a one-form workflow whose page
|
|
18
|
+
* owns the buttons and calls `validate()` / `next()` (spec 03 §2, "Chrome").
|
|
19
|
+
* @fires {CustomEvent<{ data: NestedData }>} baht-data-change - Any value changed.
|
|
20
|
+
* @fires {CustomEvent<{ form_name: string; order: number; data: NestedData; decision?: ApprovalDecision; comment?: string }>} baht-next - Moved forward to `form_name`.
|
|
21
|
+
* @fires {CustomEvent<{ form_name: string; order: number; direction: 'forward' | 'back' }>} baht-step-change - The visible step changed.
|
|
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.
|
|
23
|
+
* @fires {CustomEvent<{ data: NestedData; decision?: ApprovalDecision; comment?: string }>} baht-submit - The last step was submitted.
|
|
24
|
+
* @fires {CustomEvent<{ data: NestedData; status: 'completed' | 'rejected' }>} baht-complete - The workflow ended.
|
|
25
|
+
* @fires {CustomEvent<{ form_name: string; decision: ApprovalDecision; comment: string; data: NestedData }>} baht-approve - An approval step was approved.
|
|
26
|
+
* @fires {CustomEvent<{ form_name: string; decision: ApprovalDecision; comment: string; data: NestedData }>} baht-reject - An approval step was rejected.
|
|
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.
|
|
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.
|
|
29
|
+
*/
|
|
30
|
+
export declare class BahtWorkflow extends BahtElement {
|
|
31
|
+
workflow: WorkflowDefinition;
|
|
32
|
+
/**
|
|
33
|
+
* The starting data, not a live binding: the run keeps its own copy, read with `getData()` or
|
|
34
|
+
* `baht-data-change`. A new `value` restarts the run from it (data, history, first step); one
|
|
35
|
+
* equal by content to the last (a host re-feeding a copy) is ignored.
|
|
36
|
+
*/
|
|
37
|
+
value: NestedData;
|
|
38
|
+
registry: Registry;
|
|
39
|
+
validateGate: boolean;
|
|
40
|
+
/** Label attributes beat the i18n catalog; unset = t('next')/t('submit')/t('back'). */
|
|
41
|
+
nextLabel?: string;
|
|
42
|
+
submitLabel?: string;
|
|
43
|
+
backLabel?: string;
|
|
44
|
+
showBack: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* `full` (default) renders the step announcement and the Back + Next/Submit bar.
|
|
47
|
+
* `none` renders the current form only: the host supplies its own buttons and drives
|
|
48
|
+
* the runtime with `validate()`, `next()` and `back()`. Rules run either way.
|
|
49
|
+
*/
|
|
50
|
+
chrome: 'full' | 'none';
|
|
51
|
+
/** Enter in a single-line field of the current form presses Next/Submit (validated first). */
|
|
52
|
+
submitOnEnter: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* A save is in flight: the current form's fields are disabled, Enter, `next()`, `back()` and
|
|
55
|
+
* the approval decision do nothing, and the nav buttons carry `aria-busy` / `aria-disabled`.
|
|
56
|
+
* The host clears it when the request settles.
|
|
57
|
+
*/
|
|
58
|
+
busy: boolean;
|
|
59
|
+
/** Feature-flag values (spec 01 §12): flag-off steps/fields/rules vanish. */
|
|
60
|
+
flags: FeatureFlags;
|
|
61
|
+
/**
|
|
62
|
+
* Debounce (ms) for the approval comment, the one typed field the workflow renders itself;
|
|
63
|
+
* unset = the field default (`BahtFieldBase.defaultDebounce`), 0 = every keystroke. A decision,
|
|
64
|
+
* leaving the box, `back()`, `gotoStart()`, `getData()` and `getState()` flush what is pending;
|
|
65
|
+
* `restore()` and a new `value` drop it.
|
|
66
|
+
*/
|
|
67
|
+
debounce?: number;
|
|
68
|
+
/** Render a <baht-steps> progress indicator above the current form. */
|
|
69
|
+
showSteps: boolean;
|
|
70
|
+
/** 'default' horizontal markers, or 'sidebar' vertical nav list — forwarded to <baht-steps>. */
|
|
71
|
+
stepsVariant: 'default' | 'sidebar';
|
|
72
|
+
/** The run: its data, step and history, moved only by `send()` (core/engine/runtime.ts). */
|
|
73
|
+
private run;
|
|
74
|
+
get currentFormName(): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* What the rules could not do with the current data (spec 02 §6): `kind: 'schema'` for a rule
|
|
77
|
+
* aimed at a form or field that is not there, `kind: 'data'` for rules that never settle.
|
|
78
|
+
* Empty when all is well. `baht-rule-error` fires when it changes.
|
|
79
|
+
*/
|
|
80
|
+
get ruleErrors(): Derived['errors'];
|
|
81
|
+
/** applyFlags result, memoized on (workflow, flags) identity. */
|
|
82
|
+
private flagCache;
|
|
83
|
+
/**
|
|
84
|
+
* `workflow` as the host may actually have left it: a framework can connect the
|
|
85
|
+
* element before it binds the property, so internally it is optional until then.
|
|
86
|
+
*/
|
|
87
|
+
private get assignedWorkflow();
|
|
88
|
+
private get effectiveWorkflow();
|
|
89
|
+
/**
|
|
90
|
+
* One step of the run: the runtime works out the next state and the events, this element
|
|
91
|
+
* keeps the state and dispatches them in order. Every change to the run goes through here.
|
|
92
|
+
*/
|
|
93
|
+
private send;
|
|
94
|
+
/** The two events an author should also see in the console. */
|
|
95
|
+
private warnAuthor;
|
|
96
|
+
protected willUpdate(changed: Map<PropertyKey, unknown>): void;
|
|
97
|
+
/**
|
|
98
|
+
* Which way the last navigation went. Stamped on the step wrapper as
|
|
99
|
+
* `baht-workflow-step--forward|--back` so the stylesheet can slide the new
|
|
100
|
+
* step in from the matching side; null on first render (nothing to replay).
|
|
101
|
+
*/
|
|
102
|
+
private get direction();
|
|
103
|
+
/** Why the last decision was refused, in the current locale. */
|
|
104
|
+
private get approvalError();
|
|
105
|
+
/** The run's data: `{ form_name: { key: value } }`, as the rules left it. */
|
|
106
|
+
private get data();
|
|
107
|
+
/** Forms in ascending order whose derived visibility is true. */
|
|
108
|
+
private get visibleForms();
|
|
109
|
+
/** `visibleForms`, memoized on the (effective workflow, derived) pair it was computed for. */
|
|
110
|
+
private visibleCache;
|
|
111
|
+
/** `fieldStatesFor` results of the current `derived`, per form, reused while their content holds. */
|
|
112
|
+
private readonly statesSeen;
|
|
113
|
+
private get currentForm();
|
|
114
|
+
private get isLast();
|
|
115
|
+
private fieldStatesFor;
|
|
116
|
+
/** The step's own editable form: a data step's, or an approval step's fields (never the summary). */
|
|
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. */
|
|
121
|
+
getData(): NestedData;
|
|
122
|
+
/**
|
|
123
|
+
* Host/store write into one form's data — same path a user edit takes
|
|
124
|
+
* (rules reevaluate, `baht-data-change` fires) but WITHOUT the step reset
|
|
125
|
+
* that re-feeding the `value` prop causes.
|
|
126
|
+
*/
|
|
127
|
+
setValue(form_name: string, patch: Record<string, unknown>): void;
|
|
128
|
+
/**
|
|
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.
|
|
132
|
+
*/
|
|
133
|
+
validate(): {
|
|
134
|
+
valid: boolean;
|
|
135
|
+
errors: ValidationError[];
|
|
136
|
+
};
|
|
137
|
+
next(): void;
|
|
138
|
+
/** Approve the current approval step (same as pressing its Approve button). */
|
|
139
|
+
approve(): void;
|
|
140
|
+
/** Reject the current approval step (same as pressing its Reject button). */
|
|
141
|
+
reject(): void;
|
|
142
|
+
private decide;
|
|
143
|
+
back(): void;
|
|
144
|
+
gotoStart(): void;
|
|
145
|
+
/**
|
|
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)
|
|
148
|
+
* and hand it to `restore()` to pick the run up on the same step, or keep one per change for undo.
|
|
149
|
+
*/
|
|
150
|
+
getState(): WorkflowSnapshot;
|
|
151
|
+
/**
|
|
152
|
+
* Pick up a run kept with `getState()`: its data, its step and its Back history. The rules run
|
|
153
|
+
* on the data again; a step they hide falls back to the first visible one. Emits no navigation
|
|
154
|
+
* events. Called before `workflow` is bound, it applies once it is.
|
|
155
|
+
*/
|
|
156
|
+
restore(snapshot: unknown): void;
|
|
157
|
+
/** A `restore()` that arrived before the workflow did. */
|
|
158
|
+
private pendingRestore;
|
|
159
|
+
private onFormChange;
|
|
160
|
+
/** The inner form's Enter submit: it already validated, so this is a passing Next press. */
|
|
161
|
+
private onFormSubmit;
|
|
162
|
+
/** Keystrokes in the approval comment not yet applied (the debounce window). */
|
|
163
|
+
private pendingComment;
|
|
164
|
+
private commentTimer;
|
|
165
|
+
private onCommentInput;
|
|
166
|
+
/** Apply the pending comment now (blur, a decision, navigation, reads). Idempotent. */
|
|
167
|
+
private flushComment;
|
|
168
|
+
disconnectedCallback(): void;
|
|
169
|
+
/** Forms the approval step summarizes: configured list, else every earlier plain form. */
|
|
170
|
+
private summary_forms;
|
|
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;
|
|
177
|
+
protected render(): TemplateResult;
|
|
178
|
+
/** Back + Next/Submit (or Reject/Approve on an approval step). */
|
|
179
|
+
private renderNav;
|
|
180
|
+
private renderDecision;
|
|
181
|
+
private renderNext;
|
|
182
|
+
}
|
|
183
|
+
declare global {
|
|
184
|
+
interface HTMLElementTagNameMap {
|
|
185
|
+
'baht-workflow': BahtWorkflow;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { nothing as m, html as h } from "lit";
|
|
2
|
+
import { property as u, state as b } from "lit/decorators.js";
|
|
3
|
+
import { keyed as v } from "lit/directives/keyed.js";
|
|
4
|
+
import { BahtFieldBase as w } from "./field-base.js";
|
|
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 d, visibleForms as x, nextTarget as F, snapshotOf as S } from "@20baht/engine";
|
|
7
|
+
import "./baht-form.js";
|
|
8
|
+
import "./primitives/baht-steps.js";
|
|
9
|
+
import { customElement as E } from "./define.js";
|
|
10
|
+
var T = Object.defineProperty, j = Object.getOwnPropertyDescriptor, l = (t, e, r, i) => {
|
|
11
|
+
for (var s = i > 1 ? void 0 : i ? j(e, r) : e, o = t.length - 1, n; o >= 0; o--)
|
|
12
|
+
(n = t[o]) && (s = (i ? n(e, r, s) : n(s)) || s);
|
|
13
|
+
return i && s && T(e, r, s), s;
|
|
14
|
+
};
|
|
15
|
+
let a = class extends g {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments), this.value = {}, this.registry = {}, this.validateGate = !0, this.showBack = !0, this.chrome = "full", this.submitOnEnter = !1, this.busy = !1, this.flags = {}, this.showSteps = !1, this.stepsVariant = "default", this.run = null, this.flagCache = {}, this.visibleCache = null, this.statesSeen = /* @__PURE__ */ new Map(), this.pendingComment = null;
|
|
18
|
+
}
|
|
19
|
+
get currentFormName() {
|
|
20
|
+
var t;
|
|
21
|
+
return ((t = this.run) == null ? void 0 : t.current) ?? null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* What the rules could not do with the current data (spec 02 §6): `kind: 'schema'` for a rule
|
|
25
|
+
* aimed at a form or field that is not there, `kind: 'data'` for rules that never settle.
|
|
26
|
+
* Empty when all is well. `baht-rule-error` fires when it changes.
|
|
27
|
+
*/
|
|
28
|
+
get ruleErrors() {
|
|
29
|
+
var t;
|
|
30
|
+
return ((t = this.run) == null ? void 0 : t.derived.errors) ?? [];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `workflow` as the host may actually have left it: a framework can connect the
|
|
34
|
+
* element before it binds the property, so internally it is optional until then.
|
|
35
|
+
*/
|
|
36
|
+
get assignedWorkflow() {
|
|
37
|
+
return this.workflow;
|
|
38
|
+
}
|
|
39
|
+
get effectiveWorkflow() {
|
|
40
|
+
const t = this.assignedWorkflow;
|
|
41
|
+
if (t)
|
|
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
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* One step of the run: the runtime works out the next state and the events, this element
|
|
46
|
+
* keeps the state and dispatches them in order. Every change to the run goes through here.
|
|
47
|
+
*/
|
|
48
|
+
send(t) {
|
|
49
|
+
const e = this.effectiveWorkflow;
|
|
50
|
+
if (!e) return;
|
|
51
|
+
const r = this.run, { state: i, events: s } = C(e, r, t);
|
|
52
|
+
this.run = i;
|
|
53
|
+
for (const n of s)
|
|
54
|
+
this.warnAuthor(n), this.emit(n.name, n.detail);
|
|
55
|
+
const o = { msg: t, before: r, after: i, events: s };
|
|
56
|
+
this.emit("baht-transition", o);
|
|
57
|
+
}
|
|
58
|
+
/** The two events an author should also see in the console. */
|
|
59
|
+
warnAuthor(t) {
|
|
60
|
+
if (t.name === "baht-rule-error" && t.detail.errors.length > 0 && console.warn(
|
|
61
|
+
`[bahtui] workflow "${this.workflow.workflow_id}" rules: ` + t.detail.errors.map((e) => `${e.ref}: ${e.message}`).join("; ")
|
|
62
|
+
), t.name === "baht-nav-blocked") {
|
|
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
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
willUpdate(t) {
|
|
70
|
+
var r;
|
|
71
|
+
if (!this.assignedWorkflow) return;
|
|
72
|
+
const e = t.has("value") && !p(t.get("value"), this.value);
|
|
73
|
+
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" });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Which way the last navigation went. Stamped on the step wrapper as
|
|
77
|
+
* `baht-workflow-step--forward|--back` so the stylesheet can slide the new
|
|
78
|
+
* step in from the matching side; null on first render (nothing to replay).
|
|
79
|
+
*/
|
|
80
|
+
get direction() {
|
|
81
|
+
var t;
|
|
82
|
+
return ((t = this.run) == null ? void 0 : t.direction) ?? null;
|
|
83
|
+
}
|
|
84
|
+
/** Why the last decision was refused, in the current locale. */
|
|
85
|
+
get approvalError() {
|
|
86
|
+
var t;
|
|
87
|
+
return (t = this.run) != null && t.approvalError ? d(this.run.approvalError) : null;
|
|
88
|
+
}
|
|
89
|
+
/** The run's data: `{ form_name: { key: value } }`, as the rules left it. */
|
|
90
|
+
get data() {
|
|
91
|
+
var t;
|
|
92
|
+
return ((t = this.run) == null ? void 0 : t.derived.data) ?? {};
|
|
93
|
+
}
|
|
94
|
+
/** Forms in ascending order whose derived visibility is true. */
|
|
95
|
+
get visibleForms() {
|
|
96
|
+
var s;
|
|
97
|
+
const t = this.effectiveWorkflow, e = ((s = this.run) == null ? void 0 : s.derived) ?? null, r = this.visibleCache;
|
|
98
|
+
if (r && r.workflow === t && r.derived === e) return r.out;
|
|
99
|
+
const i = t ? x(t, e) : [];
|
|
100
|
+
return this.visibleCache = { workflow: t, derived: e, out: i }, i;
|
|
101
|
+
}
|
|
102
|
+
get currentForm() {
|
|
103
|
+
return this.visibleForms.find((t) => {
|
|
104
|
+
var e;
|
|
105
|
+
return t.form_name === ((e = this.run) == null ? void 0 : e.current);
|
|
106
|
+
}) ?? null;
|
|
107
|
+
}
|
|
108
|
+
get isLast() {
|
|
109
|
+
const t = this.effectiveWorkflow, e = this.run;
|
|
110
|
+
return !t || !(e != null && e.current) ? !1 : F(t, e, this.visibleForms) === "end";
|
|
111
|
+
}
|
|
112
|
+
fieldStatesFor(t) {
|
|
113
|
+
var o;
|
|
114
|
+
const e = {}, r = (o = this.run) == null ? void 0 : o.derived;
|
|
115
|
+
if (!r) return e;
|
|
116
|
+
const i = `${t}.`;
|
|
117
|
+
for (const [n, c] of Object.entries(r.fields))
|
|
118
|
+
n.startsWith(i) && (e[n.slice(i.length)] = c);
|
|
119
|
+
const s = this.statesSeen.get(t);
|
|
120
|
+
return s && O(s, e) ? s : (this.statesSeen.set(t, e), e);
|
|
121
|
+
}
|
|
122
|
+
/** The step's own editable form: a data step's, or an approval step's fields (never the summary). */
|
|
123
|
+
get formEl() {
|
|
124
|
+
return k() ? this.querySelector("baht-form.baht-workflow-form") : null;
|
|
125
|
+
}
|
|
126
|
+
/** Keystrokes still in the step's controls, and the approval comment, land in the run now. */
|
|
127
|
+
flushPending() {
|
|
128
|
+
var t;
|
|
129
|
+
(t = this.formEl) == null || t.flushTyped(), this.flushComment();
|
|
130
|
+
}
|
|
131
|
+
// ---- public API (spec 03 §2) ----
|
|
132
|
+
/** The run's data, with whatever is still being typed applied first. */
|
|
133
|
+
getData() {
|
|
134
|
+
return this.flushPending(), this.data;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Host/store write into one form's data — same path a user edit takes
|
|
138
|
+
* (rules reevaluate, `baht-data-change` fires) but WITHOUT the step reset
|
|
139
|
+
* that re-feeding the `value` prop causes.
|
|
140
|
+
*/
|
|
141
|
+
setValue(t, e) {
|
|
142
|
+
this.send({ type: "patch", form_name: t, patch: e });
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Validate the current form, or an approval step's own fields (rule-hidden fields skipped,
|
|
146
|
+
* rule-derived `required` applied) and show its errors, without advancing or emitting
|
|
147
|
+
* navigation events. Valid with no errors when the step has no fields to fill.
|
|
148
|
+
*/
|
|
149
|
+
validate() {
|
|
150
|
+
var t;
|
|
151
|
+
return ((t = this.formEl) == null ? void 0 : t.validate()) ?? { valid: !0, errors: [] };
|
|
152
|
+
}
|
|
153
|
+
next() {
|
|
154
|
+
const t = this.currentForm;
|
|
155
|
+
if (!(!t || this.busy)) {
|
|
156
|
+
if (t.kind === "approval") {
|
|
157
|
+
this.decide("approved");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this.send({ type: "next", validity: this.validate(), gate: this.validateGate });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** Approve the current approval step (same as pressing its Approve button). */
|
|
164
|
+
approve() {
|
|
165
|
+
this.decide("approved");
|
|
166
|
+
}
|
|
167
|
+
/** Reject the current approval step (same as pressing its Reject button). */
|
|
168
|
+
reject() {
|
|
169
|
+
this.decide("rejected");
|
|
170
|
+
}
|
|
171
|
+
decide(t) {
|
|
172
|
+
if (this.flushComment(), this.busy) return;
|
|
173
|
+
const e = this.formEl;
|
|
174
|
+
this.send(
|
|
175
|
+
e ? { type: "decide", decision: t, validity: e.validate(), gate: this.validateGate } : { type: "decide", decision: t }
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
back() {
|
|
179
|
+
this.busy || (this.flushComment(), this.send({ type: "back" }));
|
|
180
|
+
}
|
|
181
|
+
gotoStart() {
|
|
182
|
+
this.busy || (this.flushComment(), this.send({ type: "gotoStart" }));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The run as JSON: `{ workflow_id, data, current, history, ended }`, a copy (redact what must not be
|
|
186
|
+
* stored: it holds every value entered). Keep it (a draft on the server, the session)
|
|
187
|
+
* and hand it to `restore()` to pick the run up on the same step, or keep one per change for undo.
|
|
188
|
+
*/
|
|
189
|
+
getState() {
|
|
190
|
+
var e;
|
|
191
|
+
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 };
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Pick up a run kept with `getState()`: its data, its step and its Back history. The rules run
|
|
195
|
+
* on the data again; a step they hide falls back to the first visible one. Emits no navigation
|
|
196
|
+
* events. Called before `workflow` is bound, it applies once it is.
|
|
197
|
+
*/
|
|
198
|
+
restore(t) {
|
|
199
|
+
var e;
|
|
200
|
+
if (!this.effectiveWorkflow) {
|
|
201
|
+
this.pendingRestore = t;
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
this.pendingRestore = void 0, clearTimeout(this.commentTimer), this.pendingComment = null, (e = this.formEl) == null || e.discardTyped(), this.send({ type: "restore", snapshot: t });
|
|
205
|
+
}
|
|
206
|
+
// ---- internal ----
|
|
207
|
+
onFormChange(t) {
|
|
208
|
+
var s, o;
|
|
209
|
+
t.stopPropagation();
|
|
210
|
+
const { form_name: e, key: r, value: i } = t.detail;
|
|
211
|
+
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]);
|
|
212
|
+
}
|
|
213
|
+
/** The inner form's Enter submit: it already validated, so this is a passing Next press. */
|
|
214
|
+
onFormSubmit(t) {
|
|
215
|
+
t.stopPropagation(), !this.busy && this.send({ type: "next", validity: { valid: !0, errors: [] }, gate: !0 });
|
|
216
|
+
}
|
|
217
|
+
onCommentInput(t, e) {
|
|
218
|
+
this.pendingComment = { form_name: t, value: e }, clearTimeout(this.commentTimer);
|
|
219
|
+
const r = this.debounce ?? w.defaultDebounce;
|
|
220
|
+
if (r <= 0) {
|
|
221
|
+
this.flushComment();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
this.commentTimer = setTimeout(() => {
|
|
225
|
+
this.flushComment();
|
|
226
|
+
}, r);
|
|
227
|
+
}
|
|
228
|
+
/** Apply the pending comment now (blur, a decision, navigation, reads). Idempotent. */
|
|
229
|
+
flushComment() {
|
|
230
|
+
clearTimeout(this.commentTimer), this.commentTimer = void 0;
|
|
231
|
+
const t = this.pendingComment;
|
|
232
|
+
t && (this.pendingComment = null, this.send({ type: "comment", form_name: t.form_name, value: t.value }));
|
|
233
|
+
}
|
|
234
|
+
disconnectedCallback() {
|
|
235
|
+
this.flushComment(), super.disconnectedCallback();
|
|
236
|
+
}
|
|
237
|
+
// ---- approval summary (spec 03 §4) ----
|
|
238
|
+
/** Forms the approval step summarizes: configured list, else every earlier plain form. */
|
|
239
|
+
summary_forms(t) {
|
|
240
|
+
var i;
|
|
241
|
+
const e = (i = t.approval) == null ? void 0 : i.summary_forms, r = this.visibleForms.filter(
|
|
242
|
+
(s) => s.form_name !== t.form_name && s.kind !== "approval"
|
|
243
|
+
);
|
|
244
|
+
return e ? r.filter((s) => e.includes(s.form_name)) : r.filter((s) => s.order < t.order);
|
|
245
|
+
}
|
|
246
|
+
renderApproval(t) {
|
|
247
|
+
var i, s, o;
|
|
248
|
+
const e = ((i = t.approval) == null ? void 0 : i.comment) ?? "optional", r = this.summary_forms(t);
|
|
249
|
+
return h`<div class="baht-approval">
|
|
250
|
+
<div class="baht-approval-summary">
|
|
251
|
+
${r.length === 0 ? h`<p class="baht-approval-empty">${d("nothingToReview")}</p>` : r.map(
|
|
252
|
+
(n) => h`<section class="baht-approval-group">
|
|
253
|
+
<h4 class="baht-approval-group-title">${n.form_name}</h4>
|
|
254
|
+
<baht-form
|
|
255
|
+
readonly
|
|
256
|
+
.form=${n}
|
|
257
|
+
.value=${this.data[n.form_name] ?? {}}
|
|
258
|
+
.fieldStates=${this.fieldStatesFor(n.form_name)}
|
|
259
|
+
></baht-form>
|
|
260
|
+
</section>`
|
|
261
|
+
)}
|
|
262
|
+
</div>
|
|
263
|
+
${t.fields.length > 0 ? this.renderStepForm(t) : m}
|
|
264
|
+
${e !== "hidden" ? h`<label class="baht-approval-comment">
|
|
265
|
+
<span class="baht-approval-comment-label">
|
|
266
|
+
${d("comment")}${e === "required" ? d("commentRequiredSuffix") : ""}
|
|
267
|
+
</span>
|
|
268
|
+
<textarea
|
|
269
|
+
rows="3"
|
|
270
|
+
aria-required=${e === "required" ? "true" : m}
|
|
271
|
+
aria-invalid=${this.approvalError ? "true" : m}
|
|
272
|
+
.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)}
|
|
273
|
+
@focusout=${() => {
|
|
274
|
+
this.flushComment();
|
|
275
|
+
}}
|
|
276
|
+
@input=${(n) => {
|
|
277
|
+
this.onCommentInput(t.form_name, n.target.value);
|
|
278
|
+
}}
|
|
279
|
+
></textarea>
|
|
280
|
+
</label>` : m}
|
|
281
|
+
${this.approvalError ? h`<p class="baht-error" role="alert">${this.approvalError}</p>` : m}
|
|
282
|
+
</div>`;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* The step's editable form: a data step, or the fields an approval step has of its own (a task's
|
|
286
|
+
* fields, filled by the approver). Enter submits a data step only; a decision is a button press.
|
|
287
|
+
*/
|
|
288
|
+
renderStepForm(t) {
|
|
289
|
+
const e = t.kind === "approval";
|
|
290
|
+
return h`<baht-form
|
|
291
|
+
class="baht-workflow-form"
|
|
292
|
+
.form=${t}
|
|
293
|
+
.value=${this.data[t.form_name] ?? {}}
|
|
294
|
+
.registry=${this.registry}
|
|
295
|
+
.fieldStates=${this.fieldStatesFor(t.form_name)}
|
|
296
|
+
.view=${t.view}
|
|
297
|
+
.submitOnEnter=${e ? !1 : this.submitOnEnter}
|
|
298
|
+
.busy=${this.busy}
|
|
299
|
+
@baht-change=${(r) => {
|
|
300
|
+
this.onFormChange(r);
|
|
301
|
+
}}
|
|
302
|
+
@baht-submit=${(r) => {
|
|
303
|
+
e ? r.stopPropagation() : this.onFormSubmit(r);
|
|
304
|
+
}}
|
|
305
|
+
></baht-form>`;
|
|
306
|
+
}
|
|
307
|
+
render() {
|
|
308
|
+
const t = this.currentForm;
|
|
309
|
+
if (!t) return h`<div class="baht-workflow"></div>`;
|
|
310
|
+
const e = t.kind === "approval", r = this.visibleForms, i = r.findIndex((s) => s.form_name === t.form_name);
|
|
311
|
+
return h`<div
|
|
312
|
+
class="baht-workflow"
|
|
313
|
+
data-step=${t.form_name}
|
|
314
|
+
data-testid="${this.workflow.workflow_id}.${t.form_name}"
|
|
315
|
+
>
|
|
316
|
+
${this.chrome === "none" ? m : h`<div class="baht-visually-hidden" role="status">
|
|
317
|
+
${d("step", { current: i + 1, total: r.length })}
|
|
318
|
+
</div>`}
|
|
319
|
+
${this.showSteps ? h`<baht-steps
|
|
320
|
+
.steps=${r.map((s) => s.form_name)}
|
|
321
|
+
.current=${i}
|
|
322
|
+
.variant=${this.stepsVariant}
|
|
323
|
+
></baht-steps>` : m}
|
|
324
|
+
${v(
|
|
325
|
+
t.form_name,
|
|
326
|
+
h`<div
|
|
327
|
+
class="baht-workflow-step${this.direction ? ` baht-workflow-step--${this.direction}` : ""}"
|
|
328
|
+
>
|
|
329
|
+
${e ? this.renderApproval(t) : this.renderStepForm(t)}
|
|
330
|
+
</div>`
|
|
331
|
+
)}
|
|
332
|
+
${this.chrome === "none" ? m : this.renderNav(t)}
|
|
333
|
+
</div>`;
|
|
334
|
+
}
|
|
335
|
+
/** Back + Next/Submit (or Reject/Approve on an approval step). */
|
|
336
|
+
renderNav(t) {
|
|
337
|
+
var r;
|
|
338
|
+
const e = this.busy ? "true" : m;
|
|
339
|
+
return h`<div class="baht-workflow-nav">
|
|
340
|
+
${this.showBack && (((r = this.run) == null ? void 0 : r.history.length) ?? 0) > 0 ? h`<button type="button" class="baht-button baht-button--back"
|
|
341
|
+
aria-disabled=${e}
|
|
342
|
+
data-testid="${this.workflow.workflow_id}.back"
|
|
343
|
+
@click=${() => {
|
|
344
|
+
this.back();
|
|
345
|
+
}}
|
|
346
|
+
>
|
|
347
|
+
${this.backLabel ?? d("back")}
|
|
348
|
+
</button>` : m}
|
|
349
|
+
${t.kind === "approval" ? this.renderDecision(t) : this.renderNext()}
|
|
350
|
+
</div>`;
|
|
351
|
+
}
|
|
352
|
+
renderDecision(t) {
|
|
353
|
+
var r, i;
|
|
354
|
+
const e = this.busy ? "true" : m;
|
|
355
|
+
return h`<button
|
|
356
|
+
type="button"
|
|
357
|
+
class="baht-button baht-button--reject"
|
|
358
|
+
aria-disabled=${e}
|
|
359
|
+
data-testid="${this.workflow.workflow_id}.reject"
|
|
360
|
+
@click=${() => {
|
|
361
|
+
this.decide("rejected");
|
|
362
|
+
}}
|
|
363
|
+
>
|
|
364
|
+
${((r = t.approval) == null ? void 0 : r.reject_label) ?? d("reject")}
|
|
365
|
+
</button>
|
|
366
|
+
<button
|
|
367
|
+
type="button"
|
|
368
|
+
class="baht-button baht-button--next baht-button--approve"
|
|
369
|
+
aria-busy=${e}
|
|
370
|
+
aria-disabled=${e}
|
|
371
|
+
data-testid="${this.workflow.workflow_id}.approve"
|
|
372
|
+
@click=${() => {
|
|
373
|
+
this.decide("approved");
|
|
374
|
+
}}
|
|
375
|
+
>
|
|
376
|
+
${((i = t.approval) == null ? void 0 : i.approve_label) ?? d("approve")}
|
|
377
|
+
</button>`;
|
|
378
|
+
}
|
|
379
|
+
renderNext() {
|
|
380
|
+
const t = this.busy ? "true" : m;
|
|
381
|
+
return h`<button
|
|
382
|
+
type="button"
|
|
383
|
+
class="baht-button baht-button--next"
|
|
384
|
+
aria-busy=${t}
|
|
385
|
+
aria-disabled=${t}
|
|
386
|
+
data-testid="${this.workflow.workflow_id}.next"
|
|
387
|
+
@click=${() => {
|
|
388
|
+
this.next();
|
|
389
|
+
}}
|
|
390
|
+
>
|
|
391
|
+
${this.isLast ? this.submitLabel ?? d("submit") : this.nextLabel ?? d("next")}
|
|
392
|
+
</button>`;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
l([
|
|
396
|
+
u({ attribute: !1 })
|
|
397
|
+
], a.prototype, "workflow", 2);
|
|
398
|
+
l([
|
|
399
|
+
u({ attribute: !1 })
|
|
400
|
+
], a.prototype, "value", 2);
|
|
401
|
+
l([
|
|
402
|
+
u({ attribute: !1 })
|
|
403
|
+
], a.prototype, "registry", 2);
|
|
404
|
+
l([
|
|
405
|
+
u({ attribute: "validate-gate", converter: f })
|
|
406
|
+
], a.prototype, "validateGate", 2);
|
|
407
|
+
l([
|
|
408
|
+
u({ attribute: "next-label" })
|
|
409
|
+
], a.prototype, "nextLabel", 2);
|
|
410
|
+
l([
|
|
411
|
+
u({ attribute: "submit-label" })
|
|
412
|
+
], a.prototype, "submitLabel", 2);
|
|
413
|
+
l([
|
|
414
|
+
u({ attribute: "back-label" })
|
|
415
|
+
], a.prototype, "backLabel", 2);
|
|
416
|
+
l([
|
|
417
|
+
u({ attribute: "show-back", converter: f })
|
|
418
|
+
], a.prototype, "showBack", 2);
|
|
419
|
+
l([
|
|
420
|
+
u()
|
|
421
|
+
], a.prototype, "chrome", 2);
|
|
422
|
+
l([
|
|
423
|
+
u({ type: Boolean, attribute: "submit-on-enter" })
|
|
424
|
+
], a.prototype, "submitOnEnter", 2);
|
|
425
|
+
l([
|
|
426
|
+
u({ type: Boolean, reflect: !0 })
|
|
427
|
+
], a.prototype, "busy", 2);
|
|
428
|
+
l([
|
|
429
|
+
u({ attribute: !1 })
|
|
430
|
+
], a.prototype, "flags", 2);
|
|
431
|
+
l([
|
|
432
|
+
u({ type: Number })
|
|
433
|
+
], a.prototype, "debounce", 2);
|
|
434
|
+
l([
|
|
435
|
+
u({ type: Boolean, attribute: "show-steps" })
|
|
436
|
+
], a.prototype, "showSteps", 2);
|
|
437
|
+
l([
|
|
438
|
+
u({ attribute: "steps-variant" })
|
|
439
|
+
], a.prototype, "stepsVariant", 2);
|
|
440
|
+
l([
|
|
441
|
+
b()
|
|
442
|
+
], a.prototype, "run", 2);
|
|
443
|
+
a = l([
|
|
444
|
+
E("baht-workflow")
|
|
445
|
+
], a);
|
|
446
|
+
function O(t, e) {
|
|
447
|
+
const r = Object.keys(t);
|
|
448
|
+
return r.length === Object.keys(e).length && r.every((i) => {
|
|
449
|
+
const s = t[i], o = e[i];
|
|
450
|
+
return s === o || !!s && !!o && p(s, o);
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
export {
|
|
454
|
+
a as BahtWorkflow
|
|
455
|
+
};
|