@20baht/ui 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- const i = "0.3.1";
1
+ const i = "0.3.3";
2
2
  function o(e) {
3
3
  return (n) => {
4
4
  const t = customElements.get(e);
package/dist/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export { BahtFieldBase } from './components/field-base.js';
5
5
  export { BahtElement, adoptLightChildren, hasDom, hasSsrMarkup, SSR_STASH, type BahtHydrate, } from './components/base.js';
6
6
  export { BahtForm } from './components/baht-form.js';
7
7
  export { BahtWorkflow } from './components/baht-workflow.js';
8
+ export { typedForm, typedWorkflow, type FormChange, type TypedForm, type TypedWorkflow, } from './typed.js';
package/dist/index.js CHANGED
@@ -12,13 +12,13 @@ import { BahtToast as R } from "./components/primitives/baht-toast.js";
12
12
  import { BahtTooltip as F } from "./components/primitives/baht-tooltip.js";
13
13
  import { BahtThemeToggle as A } from "./components/primitives/baht-theme-toggle.js";
14
14
  import { BahtSplitButton as b } from "./components/primitives/baht-split-button.js";
15
- import { BahtMenu as M } from "./components/primitives/baht-menu.js";
16
- import { BahtTabs as E } from "./components/primitives/baht-tabs.js";
15
+ import { BahtMenu as y } from "./components/primitives/baht-menu.js";
16
+ import { BahtTabs as O } from "./components/primitives/baht-tabs.js";
17
17
  import { BahtPopover as I } from "./components/primitives/baht-popover.js";
18
18
  import { BahtAlert as D } from "./components/primitives/baht-alert.js";
19
19
  import { BahtRating as N } from "./components/primitives/baht-rating.js";
20
- import { BahtRange as G } from "./components/primitives/baht-range.js";
21
- import { BahtOtp as W } from "./components/primitives/baht-otp.js";
20
+ import { BahtRange as _ } from "./components/primitives/baht-range.js";
21
+ import { BahtOtp as V } from "./components/primitives/baht-otp.js";
22
22
  import { BahtFilter as z } from "./components/primitives/baht-filter.js";
23
23
  import { BahtSwipeRow as U } from "./components/primitives/baht-swipe-row.js";
24
24
  import { BahtSkeleton as j } from "./components/primitives/baht-skeleton.js";
@@ -39,12 +39,12 @@ import { BahtTextarea as kr } from "./components/primitives/baht-textarea.js";
39
39
  import { BahtMarkdown as wr } from "./components/primitives/baht-markdown.js";
40
40
  import { BahtMarkdownView as Pr } from "./components/primitives/baht-markdown-view.js";
41
41
  import { BahtNumber as vr } from "./components/primitives/baht-number.js";
42
- import { BahtCurrency as Or } from "./components/primitives/baht-currency.js";
43
- import { BahtSelect as yr } from "./components/primitives/baht-select.js";
42
+ import { BahtCurrency as Mr } from "./components/primitives/baht-currency.js";
43
+ import { BahtSelect as Er } from "./components/primitives/baht-select.js";
44
44
  import { BahtMultiselect as Lr } from "./components/primitives/baht-multiselect.js";
45
45
  import { BahtTags as Hr } from "./components/primitives/baht-tags.js";
46
- import { BahtCheckbox as _r } from "./components/primitives/baht-checkbox.js";
47
- import { BahtRadio as Vr } from "./components/primitives/baht-radio.js";
46
+ import { BahtCheckbox as Wr } from "./components/primitives/baht-checkbox.js";
47
+ import { BahtRadio as Gr } from "./components/primitives/baht-radio.js";
48
48
  import { BahtToggle as qr } from "./components/primitives/baht-toggle.js";
49
49
  import { BahtDatepicker as Kr } from "./components/primitives/baht-datepicker.js";
50
50
  import { BahtFile as Yr } from "./components/primitives/baht-file.js";
@@ -61,13 +61,13 @@ import { BahtHeatmap as nt } from "./components/primitives/baht-heatmap.js";
61
61
  import { BahtMeter as ct } from "./components/primitives/baht-meter.js";
62
62
  import { BahtChartBase as St, chartColor as Tt, chartSeqColor as gt, foldOther as ut, formatValue as Ct, linearScale as Rt, minTickStep as kt, niceRange as Ft, niceTicks as wt, renderTableTwin as At } from "./components/primitives/charts.js";
63
63
  import { BahtEmptyState as bt } from "./components/primitives/baht-empty-state.js";
64
- import { BahtErrorState as Mt } from "./components/primitives/baht-error-state.js";
65
- import { BahtKeyvalueEditor as Et } from "./components/primitives/baht-keyvalue-editor.js";
64
+ import { BahtErrorState as yt } from "./components/primitives/baht-error-state.js";
65
+ import { BahtKeyvalueEditor as Ot } from "./components/primitives/baht-keyvalue-editor.js";
66
66
  import { BahtReferencePicker as It } from "./components/primitives/baht-reference-picker.js";
67
67
  import { BahtTypeahead as Dt } from "./components/primitives/baht-typeahead.js";
68
68
  import { BahtRepeater as Nt } from "./components/primitives/baht-repeater.js";
69
- import { BahtSteps as Gt } from "./components/primitives/baht-steps.js";
70
- import { TAG_FOR_TYPE as Wt } from "./components/primitives/tag-map.js";
69
+ import { BahtSteps as _t } from "./components/primitives/baht-steps.js";
70
+ import { TAG_FOR_TYPE as Vt } from "./components/primitives/tag-map.js";
71
71
  import { BahtComments as zt } from "./components/primitives/baht-comments.js";
72
72
  import { BahtEditTable as Ut } from "./components/primitives/baht-edit-table.js";
73
73
  import { BahtNotificationBell as jt } from "./components/primitives/baht-notification-bell.js";
@@ -87,12 +87,13 @@ import { BahtWizard as Ro } from "./components/primitives/baht-wizard.js";
87
87
  import { BahtReferenceDialog as Fo, pageOfRows as wo } from "./components/primitives/baht-reference-dialog.js";
88
88
  import { BahtColumnPicker as Po } from "./components/primitives/baht-column-picker.js";
89
89
  import { BahtSavedFilters as vo } from "./components/primitives/baht-saved-filters.js";
90
- import { filterFieldsOf as Oo, valueAt as Eo } from "./components/primitives/column-map.js";
90
+ import { filterFieldsOf as Mo, valueAt as Oo } from "./components/primitives/column-map.js";
91
91
  import { isIllustrationName as Io, renderIllustration as Lo } from "./components/primitives/illustrations.js";
92
92
  import { BahtFieldBase as Ho } from "./components/field-base.js";
93
- import { BahtElement as _o, SSR_STASH as Go, adoptLightChildren as Vo, hasDom as Wo, hasSsrMarkup as qo } from "./components/base.js";
93
+ import { BahtElement as Wo, SSR_STASH as _o, adoptLightChildren as Go, hasDom as Vo, hasSsrMarkup as qo } from "./components/base.js";
94
94
  import { BahtForm as Ko } from "./components/baht-form.js";
95
95
  import { BahtWorkflow as Yo } from "./components/baht-workflow.js";
96
+ import { typedForm as Jo, typedWorkflow as Qo } from "./typed.js";
96
97
  export {
97
98
  xr as BahtAccordion,
98
99
  D as BahtAlert,
@@ -107,18 +108,18 @@ export {
107
108
  ar as BahtCard,
108
109
  oo as BahtCatalogCard,
109
110
  St as BahtChartBase,
110
- _r as BahtCheckbox,
111
+ Wr as BahtCheckbox,
111
112
  so as BahtChoiceGroup,
112
113
  l as BahtCode,
113
114
  Po as BahtColumnPicker,
114
115
  zt as BahtComments,
115
- Or as BahtCurrency,
116
+ Mr as BahtCurrency,
116
117
  Kr as BahtDatepicker,
117
118
  ht as BahtDonutChart,
118
119
  Ut as BahtEditTable,
119
- _o as BahtElement,
120
+ Wo as BahtElement,
120
121
  bt as BahtEmptyState,
121
- Mt as BahtErrorState,
122
+ yt as BahtErrorState,
122
123
  no as BahtFacts,
123
124
  Ho as BahtFieldBase,
124
125
  mr as BahtFieldset,
@@ -128,28 +129,28 @@ export {
128
129
  Ko as BahtForm,
129
130
  nt as BahtHeatmap,
130
131
  Cr as BahtInput,
131
- Et as BahtKeyvalueEditor,
132
+ Ot as BahtKeyvalueEditor,
132
133
  it as BahtLineChart,
133
134
  Sr as BahtLink,
134
135
  s as BahtList,
135
136
  or as BahtLoadingOverlay,
136
137
  wr as BahtMarkdown,
137
138
  Pr as BahtMarkdownView,
138
- M as BahtMenu,
139
+ y as BahtMenu,
139
140
  ct as BahtMeter,
140
141
  u as BahtModal,
141
142
  Lr as BahtMultiselect,
142
143
  jt as BahtNotificationBell,
143
144
  vr as BahtNumber,
144
145
  ho as BahtOrderBox,
145
- W as BahtOtp,
146
+ V as BahtOtp,
146
147
  Bo as BahtPageHeader,
147
148
  T as BahtPagination,
148
149
  I as BahtPopover,
149
150
  Q as BahtProgress,
150
151
  Z as BahtProgressRing,
151
- Vr as BahtRadio,
152
- G as BahtRange,
152
+ Gr as BahtRadio,
153
+ _ as BahtRange,
153
154
  N as BahtRating,
154
155
  uo as BahtRecordBar,
155
156
  Fo as BahtReferenceDialog,
@@ -160,17 +161,17 @@ export {
160
161
  To as BahtSearch,
161
162
  $r as BahtSection,
162
163
  io as BahtSectionHeader,
163
- yr as BahtSelect,
164
+ Er as BahtSelect,
164
165
  j as BahtSkeleton,
165
166
  pt as BahtSparkline,
166
167
  rr as BahtSpinner,
167
168
  b as BahtSplitButton,
168
169
  et as BahtStat,
169
170
  tt as BahtStatChart,
170
- Gt as BahtSteps,
171
+ _t as BahtSteps,
171
172
  U as BahtSwipeRow,
172
173
  d as BahtTable,
173
- E as BahtTabs,
174
+ O as BahtTabs,
174
175
  Hr as BahtTags,
175
176
  Xr as BahtText,
176
177
  kr as BahtTextarea,
@@ -184,16 +185,16 @@ export {
184
185
  Jr as BahtUpload,
185
186
  Ro as BahtWizard,
186
187
  Yo as BahtWorkflow,
187
- Go as SSR_STASH,
188
- Wt as TAG_FOR_TYPE,
189
- Vo as adoptLightChildren,
188
+ _o as SSR_STASH,
189
+ Vt as TAG_FOR_TYPE,
190
+ Go as adoptLightChildren,
190
191
  cr as calendarRange,
191
192
  Tt as chartColor,
192
193
  gt as chartSeqColor,
193
- Oo as filterFieldsOf,
194
+ Mo as filterFieldsOf,
194
195
  ut as foldOther,
195
196
  Ct as formatValue,
196
- Wo as hasDom,
197
+ Vo as hasDom,
197
198
  qo as hasSsrMarkup,
198
199
  p as isIconName,
199
200
  Io as isIllustrationName,
@@ -206,5 +207,7 @@ export {
206
207
  m as renderIcon,
207
208
  Lo as renderIllustration,
208
209
  At as renderTableTwin,
209
- Eo as valueAt
210
+ Jo as typedForm,
211
+ Qo as typedWorkflow,
212
+ Oo as valueAt
210
213
  };
@@ -0,0 +1,50 @@
1
+ import { ApprovalDecision, FormDefinition, FormValues, ValidValues, WorkflowDefinition, WorkflowValues } from '@20baht/engine';
2
+ import { BahtForm } from './components/baht-form.js';
3
+ import { BahtWorkflow } from './components/baht-workflow.js';
4
+ /** One change of a form: `baht-change`, typed from the form. */
5
+ export interface FormChange<F extends FormDefinition> {
6
+ form_name: string;
7
+ key: keyof FormValues<F> & string;
8
+ value: unknown;
9
+ /** The whole form after the change. */
10
+ data: FormValues<F>;
11
+ }
12
+ export interface TypedForm<F extends FormDefinition> {
13
+ readonly element: BahtForm;
14
+ /** `element.getData()`: the whole form, every field as it stands (a required one may be empty). */
15
+ getData(): FormValues<F>;
16
+ /** `baht-change`. Returns the function that stops listening. */
17
+ onChange(listener: (change: FormChange<F>) => void): () => void;
18
+ /**
19
+ * `baht-submit`: `submit()` (or Enter with `submit-on-enter`) passed `validate()`, so a
20
+ * required field is never empty. With a `view`, `flags` or `fieldStates` on the element, what
21
+ * those leave out was not checked: the server's validation is the one to trust.
22
+ */
23
+ onSubmit(listener: (data: ValidValues<F>) => void): () => void;
24
+ }
25
+ export interface TypedWorkflow<W extends WorkflowDefinition> {
26
+ readonly element: BahtWorkflow;
27
+ /** `element.getData()`, keyed by form name. A form or field a rule hides is absent. */
28
+ getData(): WorkflowValues<W>;
29
+ /** `baht-data-change`. Returns the function that stops listening. */
30
+ onDataChange(listener: (data: WorkflowValues<W>) => void): () => void;
31
+ /** `baht-submit`: the last step was submitted. */
32
+ onSubmit(listener: (data: WorkflowValues<W>, decision: {
33
+ decision?: ApprovalDecision;
34
+ comment?: string;
35
+ }) => void): () => void;
36
+ /** `baht-complete`: the workflow ended. */
37
+ onComplete(listener: (data: WorkflowValues<W>, status: 'completed' | 'rejected') => void): () => void;
38
+ }
39
+ /**
40
+ * Sets `element.form = form` and returns the element's data and events typed from `form`:
41
+ *
42
+ * const contact = typedForm(document.querySelector('baht-form')!, contactForm);
43
+ * contact.onSubmit((data) => api.contact.post(data)); // data.name is `string`
44
+ *
45
+ * The types hold because the element was handed this form: set another one through
46
+ * `typedForm` again, not on the element.
47
+ */
48
+ export declare function typedForm<F extends FormDefinition>(element: BahtForm, form: F): TypedForm<F>;
49
+ /** `typedForm` for a `<baht-workflow>`: sets `element.workflow`, data typed by form name. */
50
+ export declare function typedWorkflow<W extends WorkflowDefinition>(element: BahtWorkflow, workflow: W): TypedWorkflow<W>;
package/dist/typed.js ADDED
@@ -0,0 +1,44 @@
1
+ function r(t, i, o) {
2
+ const a = (n) => {
3
+ n.target === t && n instanceof CustomEvent && o(n.detail);
4
+ };
5
+ return t.addEventListener(i, a), () => {
6
+ t.removeEventListener(i, a);
7
+ };
8
+ }
9
+ function c(t, i) {
10
+ return t.form = i, {
11
+ element: t,
12
+ getData: () => t.getData(),
13
+ onChange: (o) => r(t, "baht-change", (a) => {
14
+ o(a);
15
+ }),
16
+ onSubmit: (o) => r(t, "baht-submit", (a) => {
17
+ o(a.data);
18
+ })
19
+ };
20
+ }
21
+ function u(t, i) {
22
+ return t.workflow = i, {
23
+ element: t,
24
+ getData: () => t.getData(),
25
+ onDataChange: (o) => r(t, "baht-data-change", (a) => {
26
+ o(a.data);
27
+ }),
28
+ onSubmit: (o) => r(t, "baht-submit", (a) => {
29
+ const { data: n, decision: d, comment: s } = a;
30
+ o(n, {
31
+ ...d === void 0 ? {} : { decision: d },
32
+ ...s === void 0 ? {} : { comment: s }
33
+ });
34
+ }),
35
+ onComplete: (o) => r(t, "baht-complete", (a) => {
36
+ const n = a;
37
+ o(n.data, n.status);
38
+ })
39
+ };
40
+ }
41
+ export {
42
+ c as typedForm,
43
+ u as typedWorkflow
44
+ };
@@ -1,7 +1,7 @@
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.3.1",
4
+ "version": "0.3.3",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@20baht/ui",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "description": "JSON-driven form + workflow engine. Send JSON in, get an interactive form out.",
6
6
  "license": "MIT",
@@ -109,7 +109,7 @@
109
109
  },
110
110
  "dependencies": {
111
111
  "@lit-labs/ssr-client": "^1",
112
- "@20baht/engine": ">=0.3.0 <0.4.0",
112
+ "@20baht/engine": ">=0.3.2 <0.4.0",
113
113
  "lit": "^3.3.0"
114
114
  },
115
115
  "peerDependencies": {