@20baht/ui 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 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";
5
+ import { BahtElement as D, obj as q, hasDom as O } from "./base.js";
6
+ import { tagForField as _, 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 W, resolveViewFields as E, formFieldState as A, defaultValue as T, 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";
@@ -25,9 +25,9 @@ import "./primitives/baht-text.js";
25
25
  import "./primitives/baht-section.js";
26
26
  import "./primitives/baht-tabs.js";
27
27
  import "./primitives/baht-repeater.js";
28
- import { customElement as G } from "./define.js";
29
- import { ReferenceLabels as H } from "./reference-labels.js";
30
- import { DynamicOptions as N } from "./form-options.js";
28
+ import { customElement as H } from "./define.js";
29
+ import { ReferenceLabels as N } from "./reference-labels.js";
30
+ import { DynamicOptions as G } from "./form-options.js";
31
31
  import { renderReadonlyField as Y } from "./form-readonly.js";
32
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) => {
@@ -43,11 +43,11 @@ const F = (t) => t.split("[")[0] ?? t, Z = /* @__PURE__ */ new Set([
43
43
  "currency",
44
44
  "time"
45
45
  ]);
46
- let h = class extends _ {
46
+ let h = class extends D {
47
47
  constructor() {
48
- super(...arguments), this.value = {}, this.registry = {}, this.showOptional = !1, this.options = {}, this.fieldStates = {}, this.flags = {}, this.tab = "", this.readonly = !1, this.submitOnEnter = !1, this.busy = !1, this.session = B, this.folded = /* @__PURE__ */ new Set(), this.stepping = !1, this.queued = [], this.stepSink = null, this.scriptContext = null, this.referenceLabels = new H(() => {
48
+ super(...arguments), this.value = {}, this.registry = {}, this.showOptional = !1, this.options = {}, this.fieldStates = {}, this.flags = {}, this.tab = "", this.readonly = !1, this.submitOnEnter = !1, this.busy = !1, this.session = B, this.folded = /* @__PURE__ */ new Set(), this.stepping = !1, this.queued = [], this.stepSink = null, this.scriptContext = null, this.referenceLabels = new N(() => {
49
49
  this.requestUpdate();
50
- }), this.warnedLookups = /* @__PURE__ */ new Set(), this.loadedForm = null, this.dynamicOptions = new N({
50
+ }), this.warnedLookups = /* @__PURE__ */ new Set(), this.loadedForm = null, this.dynamicOptions = new G({
51
51
  form: () => this.effectiveForm,
52
52
  data: () => this.getData(),
53
53
  registry: () => this.registry,
@@ -156,12 +156,12 @@ let h = class extends _ {
156
156
  get effectiveForm() {
157
157
  const t = this.assignedForm;
158
158
  if (t)
159
- return (this.flagCache.form !== t || this.flagCache.flags !== this.flags) && (this.flagCache = { form: t, flags: this.flags, out: A(t, this.flags) }), this.flagCache.out;
159
+ return (this.flagCache.form !== t || this.flagCache.flags !== this.flags) && (this.flagCache = { form: t, flags: this.flags, out: W(t, this.flags) }), this.flagCache.out;
160
160
  }
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 = D(t.get("value"));
164
+ const s = q(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 = 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) ?? []);
185
+ const e = E(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`)), E(t) ?? []);
187
187
  }
188
188
  tabLayout() {
189
189
  var t, e;
@@ -247,7 +247,7 @@ let h = class extends _ {
247
247
  }
248
248
  stateFor(t) {
249
249
  const e = this.effectiveForm;
250
- return W(
250
+ return A(
251
251
  e ? this.sessionInput(e) : { form: this.form },
252
252
  this.session,
253
253
  t
@@ -270,10 +270,10 @@ 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, E(t)), this.defaultsSeen.get(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, T(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] : E(t);
276
+ return Object.hasOwn(this.edits, t.key) ? this.edits[t.key] : Object.hasOwn(this.value, t.key) ? this.value[t.key] : T(t);
277
277
  }
278
278
  // ---- public API (spec 01 §6) ----
279
279
  /**
@@ -382,13 +382,13 @@ let h = class extends _ {
382
382
  var S;
383
383
  if (J(t))
384
384
  return t.key === e.first ? this.renderTabStrip(e) : c;
385
- const s = q[t.type];
385
+ const s = _(t.type, this.registry);
386
386
  if (!s)
387
387
  return console.warn(`[bahtui] unknown field type "${t.type}" — skipped`), c;
388
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;
389
389
  if (this.readonly && t.type !== "label" && t.type !== "section")
390
390
  return this.renderReadonlyField(t, i, r.visible, e);
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) => {
391
+ const n = this.dynamicOptions.withOptions(t), u = this.renderValueFor(t), a = !r.enabled || this.busy, g = this.readonly || r.readonly, w = this.options.inputDebounce, v = (f) => {
392
392
  this.onControlInput(t.key, f);
393
393
  }, d = P(s);
394
394
  let m;
@@ -406,7 +406,7 @@ let h = class extends _ {
406
406
  .field=${n}
407
407
  .value=${u}
408
408
  .disabled=${a}
409
- .readonly=${v}
409
+ .readonly=${g}
410
410
  .required=${r.required}
411
411
  .showOptional=${this.showOptional}
412
412
  .error=${o}
@@ -414,19 +414,20 @@ let h = class extends _ {
414
414
  .rowErrors=${f}
415
415
  .rowStates=${L}
416
416
  .rowLookup=${this.rowLookup}
417
- @baht-input=${g}
417
+ .registry=${this.registry}
418
+ @baht-input=${v}
418
419
  ></${d}>`;
419
420
  } else if (t.type === "reference")
420
421
  m = b`<${d}
421
422
  .field=${n}
422
423
  .value=${u}
423
424
  .disabled=${a}
424
- .readonly=${v}
425
+ .readonly=${g}
425
426
  .required=${r.required}
426
427
  .showOptional=${this.showOptional}
427
428
  .error=${o}
428
429
  .lookup=${this.lookupFor(t)}
429
- @baht-input=${g}
430
+ @baht-input=${v}
430
431
  ></${d}>`;
431
432
  else if (t.type === "file" || t.type === "markdown") {
432
433
  const f = this.uploaderFor(t);
@@ -434,26 +435,26 @@ let h = class extends _ {
434
435
  .field=${n}
435
436
  .value=${u}
436
437
  .disabled=${a}
437
- .readonly=${v}
438
+ .readonly=${g}
438
439
  .required=${r.required}
439
440
  .showOptional=${this.showOptional}
440
441
  .error=${o}
441
442
  .debounce=${w}
442
443
  .uploader=${f}
443
444
  .allowImage=${this.registry.markdownImage}
444
- @baht-input=${g}
445
+ @baht-input=${v}
445
446
  ></${d}>`;
446
447
  } else
447
448
  m = b`<${d}
448
449
  .field=${n}
449
450
  .value=${u}
450
451
  .disabled=${a}
451
- .readonly=${v}
452
+ .readonly=${g}
452
453
  .required=${r.required}
453
454
  .showOptional=${this.showOptional}
454
455
  .error=${o}
455
456
  .debounce=${w}
456
- @baht-input=${g}
457
+ @baht-input=${v}
457
458
  ></${d}>`;
458
459
  const k = this.fieldMessages[t.key];
459
460
  return y`<div
@@ -528,7 +529,8 @@ let h = class extends _ {
528
529
  const i = this.dynamicOptions.optionsFor(t), o = U(
529
530
  this.dynamicOptions.withOptions(t),
530
531
  this.valueFor(t),
531
- i
532
+ i,
533
+ this.registry
532
534
  );
533
535
  return Y(
534
536
  {
@@ -619,7 +621,7 @@ l([
619
621
  I()
620
622
  ], h.prototype, "folded", 2);
621
623
  h = l([
622
- G("baht-form")
624
+ H("baht-form")
623
625
  ], h);
624
626
  function tt(t, e) {
625
627
  const s = Object.keys(t);
@@ -1,4 +1,4 @@
1
- const i = "0.1.2";
1
+ const i = "0.3.0";
2
2
  function o(e) {
3
3
  return (n) => {
4
4
  const t = customElements.get(e);
@@ -1,6 +1,6 @@
1
1
  import { TemplateResult } from 'lit';
2
2
  import { BahtFieldBase } from '../field-base.js';
3
- import { DerivedFieldState, FieldDescriptor, ValidationError } from '@20baht/engine';
3
+ import { DerivedFieldState, FieldDescriptor, Registry, ValidationError } from '@20baht/engine';
4
4
  import { FieldReferenceLookup } from './baht-reference-picker.js';
5
5
  /** The lookup of a `reference` column; `row` reads the row it is in when asked. */
6
6
  export type RowLookup = (sub: FieldDescriptor, row: () => Record<string, unknown>) => FieldReferenceLookup | null;
@@ -20,6 +20,12 @@ export declare class BahtRepeater extends BahtFieldBase {
20
20
  rowStates: Record<string, DerivedFieldState>;
21
21
  /** Set by the host form: what makes a `reference` column searchable. */
22
22
  rowLookup: RowLookup | null;
23
+ /**
24
+ * Set by the host form: its registry. A column of a type of the app's own (spec 01 §5.1)
25
+ * renders, reads and checks through `registry.fieldTypes`; the row dialog runs the column's
26
+ * `custom` validators from it.
27
+ */
28
+ registry: Registry;
23
29
  private draft;
24
30
  private readonly labels;
25
31
  private get rows();
@@ -1,24 +1,24 @@
1
1
  import { nothing as d, html as l } from "lit";
2
- import { property as $, state as R } from "lit/decorators.js";
3
- import { repeat as u } from "lit/directives/repeat.js";
2
+ import { property as f, state as R } from "lit/decorators.js";
3
+ import { repeat as b } from "lit/directives/repeat.js";
4
4
  import { html as w } from "lit/static-html.js";
5
- import { hasDom as _ } from "../base.js";
6
- import { BahtFieldBase as F } from "../field-base.js";
7
- import { TAG_FOR_TYPE as m, staticTag as v, WIDTH_CLASS as k } from "./tag-map.js";
8
- import { defaultValue as b, validateField as S, displayValue as O, t as n } from "@20baht/engine";
5
+ import { hasDom as F } from "../base.js";
6
+ import { BahtFieldBase as S } from "../field-base.js";
7
+ import { tagForField as m, staticTag as v, WIDTH_CLASS as k } from "./tag-map.js";
8
+ import { defaultValue as $, validateField as _, displayValue as O, t as n } from "@20baht/engine";
9
9
  import { customElement as T } from "../define.js";
10
10
  import { ReferenceLabels as x } from "../reference-labels.js";
11
11
  import "./baht-button.js";
12
12
  import "./baht-modal.js";
13
- var I = Object.defineProperty, q = Object.getOwnPropertyDescriptor, c = (e, t, r, i) => {
14
- for (var o = i > 1 ? void 0 : i ? q(t, r) : t, a = e.length - 1, s; a >= 0; a--)
15
- (s = e[a]) && (o = (i ? s(t, r, o) : s(o)) || o);
16
- return i && o && I(t, r, o), o;
13
+ var I = Object.defineProperty, q = Object.getOwnPropertyDescriptor, c = (e, t, r, o) => {
14
+ for (var i = o > 1 ? void 0 : o ? q(t, r) : t, a = e.length - 1, s; a >= 0; a--)
15
+ (s = e[a]) && (i = (o ? s(t, r, i) : s(i)) || i);
16
+ return o && i && I(t, r, i), i;
17
17
  };
18
18
  const D = 4;
19
- let p = class extends F {
19
+ let p = class extends S {
20
20
  constructor() {
21
- super(...arguments), this.rowErrors = [], this.rowStates = {}, this.rowLookup = null, this.draft = null, this.labels = new x(() => {
21
+ super(...arguments), this.rowErrors = [], this.rowStates = {}, this.rowLookup = null, this.registry = {}, this.draft = null, this.labels = new x(() => {
22
22
  this.requestUpdate();
23
23
  }), this.subFieldsCache = [];
24
24
  }
@@ -31,13 +31,13 @@ let p = class extends F {
31
31
  return e !== this.subFieldsSource && (this.subFieldsSource = e, this.subFieldsCache = [...e ?? []].sort((t, r) => t.order - r.order).filter((t) => t.type !== "repeater")), this.subFieldsCache;
32
32
  }
33
33
  patchRow(e, t, r) {
34
- const i = [...this.rows];
35
- i[e] = { ...i[e], [t]: r }, this.emitInput(i);
34
+ const o = [...this.rows];
35
+ o[e] = { ...o[e], [t]: r }, this.emitInput(o);
36
36
  }
37
37
  blankRow() {
38
38
  const e = {};
39
39
  for (const t of this.subFields)
40
- t.type === "label" || t.type === "section" || (e[t.key] = b(t));
40
+ t.type === "label" || t.type === "section" || (e[t.key] = $(t));
41
41
  return e;
42
42
  }
43
43
  addRow() {
@@ -49,7 +49,7 @@ let p = class extends F {
49
49
  /** Pending keystrokes in any row land in the array before the host reads it. */
50
50
  flushTyped() {
51
51
  var e;
52
- if (!_()) {
52
+ if (!F()) {
53
53
  super.flushTyped();
54
54
  return;
55
55
  }
@@ -67,15 +67,15 @@ let p = class extends F {
67
67
  /** A stored id in the row table: its label once known, the id until then. */
68
68
  referenceLabel(e, t) {
69
69
  var a;
70
- const r = `${e.reference ?? ""}\0${t}`, i = this.labels.get(r);
71
- if (i !== void 0) return i;
72
- const o = (a = this.lookupOf(e, () => ({}))) == null ? void 0 : a.resolve;
73
- return o && this.labels.request(r, t, o), t;
70
+ const r = `${e.reference ?? ""}\0${t}`, o = this.labels.get(r);
71
+ if (o !== void 0) return o;
72
+ const i = (a = this.lookupOf(e, () => ({}))) == null ? void 0 : a.resolve;
73
+ return i && this.labels.request(r, t, i), t;
74
74
  }
75
75
  errorFor(e, t) {
76
- var i;
76
+ var o;
77
77
  const r = `${this.field.key}[${e}].${t}`;
78
- return ((i = this.rowErrors.find((o) => o.key === r)) == null ? void 0 : i.message) ?? null;
78
+ return ((o = this.rowErrors.find((i) => i.key === r)) == null ? void 0 : o.message) ?? null;
79
79
  }
80
80
  /**
81
81
  * Sub-controls render declaratively (one static-tag template per primitive, rows
@@ -83,21 +83,21 @@ let p = class extends F {
83
83
  * focus, same as <baht-form> — and the whole thing renders on the server.
84
84
  */
85
85
  renderSub(e, t, r) {
86
- const i = m[r.type];
87
- if (!i) return d;
88
- const o = v(i), a = k[r.width ?? "full"] ?? "baht-field--w-full", s = this.rowStates[`${this.field.key}[${t}].${r.key}`], h = (y) => {
86
+ const o = m(r.type, this.registry);
87
+ if (!o) return d;
88
+ const i = v(o), a = k[r.width ?? "full"] ?? "baht-field--w-full", s = this.rowStates[`${this.field.key}[${t}].${r.key}`], h = (y) => {
89
89
  y.stopPropagation();
90
90
  const { value: g } = y.detail;
91
91
  this.patchRow(t, r.key, g);
92
- }, f = r.hidden === !0 || s !== void 0 && !s.visible;
92
+ }, u = r.hidden === !0 || s !== void 0 && !s.visible;
93
93
  return l`<div
94
- class="baht-field ${a}${f ? " baht-field--hidden" : ""}"
94
+ class="baht-field ${a}${u ? " baht-field--hidden" : ""}"
95
95
  data-key=${r.key}
96
96
  data-type=${r.type}
97
97
  >
98
- ${w`<${o}
98
+ ${w`<${i}
99
99
  .field=${r}
100
- .value=${Object.hasOwn(e, r.key) ? e[r.key] : b(r)}
100
+ .value=${Object.hasOwn(e, r.key) ? e[r.key] : $(r)}
101
101
  .disabled=${this.disabled || s !== void 0 && !s.enabled}
102
102
  .readonly=${this.readonly || ((s == null ? void 0 : s.readonly) ?? !1)}
103
103
  .required=${s ? s.required : !!r.required}
@@ -105,19 +105,19 @@ let p = class extends F {
105
105
  .debounce=${this.debounce}
106
106
  .lookup=${this.lookupOf(r, () => this.rows[t] ?? {})}
107
107
  @baht-input=${h}
108
- ></${o}>`}
108
+ ></${i}>`}
109
109
  </div>`;
110
110
  }
111
111
  /** The dialog's copy of a row: edits stay in it until Save. */
112
112
  renderDraftSub(e, t) {
113
113
  var s;
114
- const r = m[t.type];
114
+ const r = m(t.type, this.registry);
115
115
  if (!r || t.hidden) return d;
116
- const i = v(r), o = k[t.width ?? "full"] ?? "baht-field--w-full", a = ((s = e.errors.find((h) => h.key === t.key)) == null ? void 0 : s.message) ?? null;
117
- return l`<div class="baht-field ${o}" data-key=${t.key} data-type=${t.type}>
118
- ${w`<${i}
116
+ const o = v(r), i = k[t.width ?? "full"] ?? "baht-field--w-full", a = ((s = e.errors.find((h) => h.key === t.key)) == null ? void 0 : s.message) ?? null;
117
+ return l`<div class="baht-field ${i}" data-key=${t.key} data-type=${t.type}>
118
+ ${w`<${o}
119
119
  .field=${t}
120
- .value=${Object.hasOwn(e.row, t.key) ? e.row[t.key] : b(t)}
120
+ .value=${Object.hasOwn(e.row, t.key) ? e.row[t.key] : $(t)}
121
121
  .required=${!!t.required}
122
122
  .error=${a}
123
123
  .debounce=${this.debounce}
@@ -127,10 +127,10 @@ let p = class extends F {
127
127
  })}
128
128
  @baht-input=${(h) => {
129
129
  h.stopPropagation();
130
- const { value: f } = h.detail;
131
- this.draft && (this.draft = { ...this.draft, row: { ...this.draft.row, [t.key]: f } });
130
+ const { value: u } = h.detail;
131
+ this.draft && (this.draft = { ...this.draft, row: { ...this.draft.row, [t.key]: u } });
132
132
  }}
133
- ></${i}>`}
133
+ ></${o}>`}
134
134
  </div>`;
135
135
  }
136
136
  saveDraft() {
@@ -138,7 +138,7 @@ let p = class extends F {
138
138
  const e = this.draft;
139
139
  if (!e) return;
140
140
  const t = this.subFields.flatMap(
141
- (i) => i.type === "label" || i.type === "section" || i.hidden ? [] : S(i, e.row[i.key], {}, e.row, {})
141
+ (o) => o.type === "label" || o.type === "section" || o.hidden ? [] : _(o, e.row[o.key], this.registry, e.row, {})
142
142
  );
143
143
  if (t.length > 0) {
144
144
  this.draft = { ...e, errors: t };
@@ -148,12 +148,12 @@ let p = class extends F {
148
148
  e.index === null ? r.push(e.row) : r[e.index] = e.row, this.draft = null, this.emitInput(r);
149
149
  }
150
150
  cellText(e, t) {
151
- const r = O(e, t[e.key]);
152
- return r.kind === "text" ? e.type === "reference" ? this.referenceLabel(e, r.text) : r.text : r.kind === "chips" ? r.items.join(", ") : r.kind === "files" ? r.items.map((i) => i.name).join(", ") : "";
151
+ const r = O(e, t[e.key], e.options, this.registry);
152
+ return r.kind === "text" ? e.type === "reference" ? this.referenceLabel(e, r.text) : r.text : r.kind === "chips" ? r.items.join(", ") : r.kind === "files" ? r.items.map((o) => o.name).join(", ") : "";
153
153
  }
154
154
  /** `row_editor: 'dialog'`: the rows as a table, one opened at a time in a modal. */
155
155
  renderTable(e, t) {
156
- const r = this.subFields.filter((o) => o.type !== "label" && o.type !== "section" && !o.hidden).slice(0, D), i = this.draft;
156
+ const r = this.subFields.filter((i) => i.type !== "label" && i.type !== "section" && !i.hidden).slice(0, D), o = this.draft;
157
157
  return l`<div
158
158
  class="baht-repeater baht-repeater--table"
159
159
  id=${this.controlId}
@@ -164,17 +164,17 @@ let p = class extends F {
164
164
  ${this.rows.length > 0 ? l`<table class="baht-repeater-table">
165
165
  <thead>
166
166
  <tr>
167
- ${r.map((o) => l`<th scope="col">${o.label ?? o.key}</th>`)}
167
+ ${r.map((i) => l`<th scope="col">${i.label ?? i.key}</th>`)}
168
168
  ${e ? l`<th scope="col"></th>` : d}
169
169
  </tr>
170
170
  </thead>
171
171
  <tbody>
172
172
  ${this.rows.map(
173
- (o, a) => l`<tr
173
+ (i, a) => l`<tr
174
174
  data-row=${a}
175
175
  class=${this.rowErrors.some((s) => s.key.startsWith(`${this.field.key}[${String(a)}]`)) ? "baht-repeater-table-row--invalid" : ""}
176
176
  >
177
- ${r.map((s) => l`<td>${this.cellText(s, o)}</td>`)}
177
+ ${r.map((s) => l`<td>${this.cellText(s, i)}</td>`)}
178
178
  ${e ? l`<td class="baht-repeater-table-actions">
179
179
  <button
180
180
  type="button"
@@ -182,7 +182,7 @@ let p = class extends F {
182
182
  aria-label=${n("editRowN", { n: a + 1 })}
183
183
  title=${n("editRowN", { n: a + 1 })}
184
184
  @click=${() => {
185
- this.draft = { index: a, row: { ...o }, errors: [] };
185
+ this.draft = { index: a, row: { ...i }, errors: [] };
186
186
  }}
187
187
  >
188
188
  ✎
@@ -214,17 +214,17 @@ let p = class extends F {
214
214
  + ${this.field.add_label ?? n("addRow")}
215
215
  </button>` : d}
216
216
  <baht-modal
217
- .open=${i !== null}
217
+ .open=${o !== null}
218
218
  .heading=${this.field.label ?? ""}
219
- @baht-close=${(o) => {
220
- o.stopPropagation(), this.draft = null;
219
+ @baht-close=${(i) => {
220
+ i.stopPropagation(), this.draft = null;
221
221
  }}
222
222
  >
223
223
  <div class="baht-repeater-dialog">
224
- ${i ? u(
224
+ ${o ? b(
225
225
  this.subFields,
226
- (o) => o.key,
227
- (o) => this.renderDraftSub(i, o)
226
+ (i) => i.key,
227
+ (i) => this.renderDraftSub(o, i)
228
228
  ) : d}
229
229
  <div class="baht-repeater-dialog-actions">
230
230
  <baht-button
@@ -255,27 +255,27 @@ let p = class extends F {
255
255
  aria-labelledby=${this.field.label ? this.labelId : d}
256
256
  aria-describedby=${this.describedBy}
257
257
  >
258
- ${u(
258
+ ${b(
259
259
  e,
260
- (i, o) => o,
261
- (i, o) => l`<div
260
+ (o, i) => i,
261
+ (o, i) => l`<div
262
262
  class="baht-repeater-row"
263
- data-row=${o}
263
+ data-row=${i}
264
264
  role="group"
265
- aria-label=${n("row", { n: o + 1 })}
265
+ aria-label=${n("row", { n: i + 1 })}
266
266
  >
267
- ${u(
267
+ ${b(
268
268
  this.subFields,
269
269
  (a) => a.key,
270
- (a) => this.renderSub(i, o, a)
270
+ (a) => this.renderSub(o, i, a)
271
271
  )}
272
272
  ${t ? l`<button
273
273
  type="button"
274
274
  class="baht-repeater-remove"
275
- aria-label=${n("removeRowN", { n: o + 1 })}
276
- title=${n("removeRowN", { n: o + 1 })}
275
+ aria-label=${n("removeRowN", { n: i + 1 })}
276
+ title=${n("removeRowN", { n: i + 1 })}
277
277
  @click=${() => {
278
- this.removeRow(o);
278
+ this.removeRow(i);
279
279
  }}
280
280
  >
281
281
  ✕
@@ -296,14 +296,17 @@ let p = class extends F {
296
296
  }
297
297
  };
298
298
  c([
299
- $({ attribute: !1 })
299
+ f({ attribute: !1 })
300
300
  ], p.prototype, "rowErrors", 2);
301
301
  c([
302
- $({ attribute: !1 })
302
+ f({ attribute: !1 })
303
303
  ], p.prototype, "rowStates", 2);
304
304
  c([
305
- $({ attribute: !1 })
305
+ f({ attribute: !1 })
306
306
  ], p.prototype, "rowLookup", 2);
307
+ c([
308
+ f({ attribute: !1 })
309
+ ], p.prototype, "registry", 2);
307
310
  c([
308
311
  R()
309
312
  ], p.prototype, "draft", 2);
@@ -1,6 +1,17 @@
1
1
  import { StaticValue } from 'lit/static-html.js';
2
- import { FieldType } from '@20baht/engine';
3
- export declare const TAG_FOR_TYPE: Record<FieldType, string>;
2
+ import { BuiltInFieldType, Registry } from '@20baht/engine';
3
+ /**
4
+ * field descriptor `type` -> primitive tag (used by <baht-form>, <baht-repeater>
5
+ * and the builder), read from the engine's one table of built-in types. Lives in its own module
6
+ * so baht-repeater can read it without importing the primitives barrel (which would be circular).
7
+ */
8
+ export declare const TAG_FOR_TYPE: Record<BuiltInFieldType, string>;
4
9
  /** `field.width` -> layout class, shared by <baht-form> and <baht-repeater>. */
5
10
  export declare const WIDTH_CLASS: Record<string, string>;
6
11
  export declare function staticTag(tag: string): StaticValue;
12
+ /**
13
+ * The tag that renders a field type: the built-in primitive, else the element the app
14
+ * registered for a type of its own (`registry.fieldTypes[type].tag`, spec 01 §5.1). Undefined
15
+ * for a type nobody knows, and for a registered tag that is not a custom element name.
16
+ */
17
+ export declare function tagForField(type: string, registry: Pick<Registry, 'fieldTypes'> | undefined): string | undefined;
@@ -1,39 +1,28 @@
1
- import { unsafeStatic as b } from "lit/static-html.js";
2
- const e = "baht-input", n = {
3
- text: e,
4
- email: e,
5
- password: e,
6
- textarea: "baht-textarea",
7
- markdown: "baht-markdown",
8
- number: "baht-number",
9
- currency: "baht-currency",
10
- dropdown: "baht-select",
11
- multiselect: "baht-multiselect",
12
- checkbox: "baht-checkbox",
13
- radio: "baht-radio",
14
- toggle: "baht-toggle",
15
- date: "baht-datepicker",
16
- time: e,
17
- file: "baht-file",
18
- label: "baht-text",
19
- section: "baht-section",
20
- repeater: "baht-repeater",
21
- tags: "baht-tags",
22
- rating: "baht-rating",
23
- range: "baht-range",
24
- reference: "baht-reference-picker"
25
- }, c = {
1
+ import { unsafeStatic as f } from "lit/static-html.js";
2
+ import { BUILT_IN_FIELD_TYPES as T, BUILT_IN_TYPES as l, builtInType as r, fieldTypeSpec as _ } from "@20baht/engine";
3
+ const E = Object.fromEntries(
4
+ T.map((t) => [t, l[t].tag])
5
+ ), I = {
26
6
  "1/4": "baht-field--w-1-4",
27
7
  "1/2": "baht-field--w-1-2",
28
8
  "3/4": "baht-field--w-3-4",
29
9
  full: "baht-field--w-full"
30
- }, r = /* @__PURE__ */ new Map();
31
- function i(a) {
32
- let t = r.get(a);
33
- return t || (t = b(a), r.set(a, t)), t;
10
+ }, o = /* @__PURE__ */ new Map();
11
+ function d(t) {
12
+ let e = o.get(t);
13
+ return e || (e = f(t), o.set(t, e)), e;
14
+ }
15
+ const c = /^[a-z][a-z0-9._]*-[a-z0-9._-]*$/;
16
+ function S(t, e) {
17
+ var a;
18
+ const n = r(t);
19
+ if (n) return n.tag;
20
+ const i = (a = _(e, t)) == null ? void 0 : a.tag;
21
+ return i !== void 0 && c.test(i) ? i : void 0;
34
22
  }
35
23
  export {
36
- n as TAG_FOR_TYPE,
37
- c as WIDTH_CLASS,
38
- i as staticTag
24
+ E as TAG_FOR_TYPE,
25
+ I as WIDTH_CLASS,
26
+ d as staticTag,
27
+ S as tagForField
39
28
  };
@@ -29096,6 +29096,15 @@
29096
29096
  "default": "null",
29097
29097
  "description": "Set by the host form: what makes a `reference` column searchable."
29098
29098
  },
29099
+ {
29100
+ "kind": "field",
29101
+ "name": "registry",
29102
+ "type": {
29103
+ "text": "Registry"
29104
+ },
29105
+ "default": "{}",
29106
+ "description": "Set by the host form: its registry. A column of a type of the app's own (spec 01 §5.1)\nrenders, reads and checks through `registry.fieldTypes`; the row dialog runs the column's\n`custom` validators from it."
29107
+ },
29099
29108
  {
29100
29109
  "kind": "field",
29101
29110
  "name": "draft",
@@ -45069,10 +45078,8 @@
45069
45078
  {
45070
45079
  "kind": "variable",
45071
45080
  "name": "TAG_FOR_TYPE",
45072
- "type": {
45073
- "text": "Record<FieldType, string>"
45074
- },
45075
- "default": "{ text: INPUT, email: INPUT, password: INPUT, textarea: 'baht-textarea', markdown: 'baht-markdown', number: 'baht-number', currency: 'baht-currency', dropdown: 'baht-select', multiselect: 'baht-multiselect', checkbox: 'baht-checkbox', radio: 'baht-radio', toggle: 'baht-toggle', date: 'baht-datepicker', time: INPUT, file: 'baht-file', label: 'baht-text', section: 'baht-section', repeater: 'baht-repeater', tags: 'baht-tags', rating: 'baht-rating', range: 'baht-range', reference: 'baht-reference-picker', }"
45081
+ "default": "Object.fromEntries( BUILT_IN_FIELD_TYPES.map((type) => [type, BUILT_IN_TYPES[type].tag]), )",
45082
+ "description": "field descriptor `type` -> primitive tag (used by <baht-form>, <baht-repeater>\nand the builder), read from the engine's one table of built-in types. Lives in its own module\nso baht-repeater can read it without importing the primitives barrel (which would be circular)."
45076
45083
  },
45077
45084
  {
45078
45085
  "kind": "variable",
@@ -45099,6 +45106,30 @@
45099
45106
  }
45100
45107
  }
45101
45108
  ]
45109
+ },
45110
+ {
45111
+ "kind": "function",
45112
+ "name": "tagForField",
45113
+ "return": {
45114
+ "type": {
45115
+ "text": "string | undefined"
45116
+ }
45117
+ },
45118
+ "parameters": [
45119
+ {
45120
+ "name": "type",
45121
+ "type": {
45122
+ "text": "string"
45123
+ }
45124
+ },
45125
+ {
45126
+ "name": "registry",
45127
+ "type": {
45128
+ "text": "Pick<Registry, 'fieldTypes'> | undefined"
45129
+ }
45130
+ }
45131
+ ],
45132
+ "description": "The tag that renders a field type: the built-in primitive, else the element the app\nregistered for a type of its own (`registry.fieldTypes[type].tag`, spec 01 §5.1). Undefined\nfor a type nobody knows, and for a registered tag that is not a custom element name."
45102
45133
  }
45103
45134
  ],
45104
45135
  "exports": [
@@ -45125,6 +45156,14 @@
45125
45156
  "name": "staticTag",
45126
45157
  "module": "src/components/primitives/tag-map.ts"
45127
45158
  }
45159
+ },
45160
+ {
45161
+ "kind": "js",
45162
+ "name": "tagForField",
45163
+ "declaration": {
45164
+ "name": "tagForField",
45165
+ "module": "src/components/primitives/tag-map.ts"
45166
+ }
45128
45167
  }
45129
45168
  ]
45130
45169
  },