@20baht/angular 0.3.1 → 0.3.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 CHANGED
@@ -68,6 +68,20 @@ export class RequestComponent {
68
68
  ```
69
69
  - `<baht-form>` and `<baht-workflow>` have no `[(value)]`: their `value` is the starting data. Listen to
70
70
  `(bahtChange)` / `(bahtDataChange)`, or bind a store (below).
71
+ - **Their outputs are typed from the schema you bind.** The two directives take a type parameter that Angular
72
+ infers from `[form]` / `[workflow]`. Declare the schema with `defineForm` / `defineWorkflow` (or fetch it
73
+ from a typed Elysia route) and `$event.data` needs no cast:
74
+
75
+ ```ts
76
+ // <baht-form [form]="contactForm" (bahtChange)="draft = $event.data" (bahtSubmit)="send($event.data)" />
77
+ readonly contactForm = defineForm({ … });
78
+ send(data: ValidValues<typeof this.contactForm>): void {} // `required` fields are never null here
79
+ draft: FormValues<typeof this.contactForm> | null = null; // as held: a required one may still be empty
80
+ ```
81
+
82
+ `(bahtSubmit)` passed `validate()`, hence `ValidValues`; with a `view`, `flags` or `fieldStates` on the
83
+ element, what those leave out was not checked, and the server's validation is the one to trust. A workflow's
84
+ outputs carry `WorkflowValues<W>`. A schema typed `FormDefinition` reads as `Record<string, unknown>`, as before.
71
85
 
72
86
  ## Table cells as templates
73
87
 
@@ -112,6 +126,10 @@ readonly all = bahtStore(this.store); // the whole tr
112
126
 
113
127
  Call them in an injection context; they unsubscribe on destroy. `@20baht/store` is an optional peer.
114
128
 
129
+ A store told its shape needs no type argument: `createBahtStore<WorkflowValues<typeof workflow>>()`, then
130
+ `bahtSignal(this.store, 'Request.days')` is a `WritableSignal<number | null | undefined>` and `bahtStore(this.store)`
131
+ a `Signal` of the whole shape.
132
+
115
133
  ## Stickers
116
134
 
117
135
  `@20baht/angular/stickers` has the directives for [@20baht/stickers](https://www.npmjs.com/package/@20baht/stickers)'
@@ -1,4 +1,4 @@
1
- import type { ApprovalDecision, BahtAccordion, BahtAlert, BahtAppShell, BahtApprovalChain, BahtAvatar, BahtBadge, BahtBarChart, BahtBreadcrumbs, BahtButton, BahtCalendar, BahtCard, BahtCatalogCard, BahtCheckbox, BahtChoiceGroup, BahtCode, BahtColumnPicker, BahtComments, BahtCurrency, BahtDatepicker, BahtDonutChart, BahtEditTable, BahtEmptyState, BahtErrorState, BahtFacts, BahtFieldset, BahtFile, BahtFilter, BahtFilterBuilder, BahtForm, BahtHeatmap, BahtInput, BahtKeyvalueEditor, BahtLineChart, BahtLink, BahtList, BahtLoadingOverlay, BahtMarkdown, BahtMarkdownView, BahtMenu, BahtMeter, BahtModal, BahtMultiselect, BahtNotificationBell, BahtNumber, BahtOrderBox, BahtOtp, BahtPageHeader, BahtPagination, BahtPopover, BahtProgress, BahtProgressRing, BahtRadio, BahtRange, BahtRating, BahtRecordBar, BahtReferenceDialog, BahtReferencePicker, BahtRepeater, BahtRuleBuilder, BahtSavedFilters, BahtSearch, BahtSection, BahtSectionHeader, BahtSelect, BahtSkeleton, BahtSparkline, BahtSpinner, BahtSplitButton, BahtStat, BahtStatChart, BahtSteps, BahtSwipeRow, BahtTable, BahtTabs, BahtTags, BahtText, BahtTextarea, BahtThemeToggle, BahtTimeline, BahtToast, BahtToggle, BahtTooltip, BahtTree, BahtTypeahead, BahtUpload, BahtWizard, BahtWorkflow, CalendarEvent, CalendarNavigateDetail, ColumnsChangeDetail, Crumb, Derived, EditRow, FilterValue, GroupToggleDetail, ListItem, MenuItem, NestedData, RowMenuSelectDetail, Rule, SavedFilter, SortDirection, ThemeName, TreeNode, TypeaheadOption, UploadChangeDetail, UploadErrorDetail, UploadProgressDetail, ValidationError, WorkflowTransition } from '@20baht/ui';
1
+ import type { ApprovalDecision, BahtAccordion, BahtAlert, BahtAppShell, BahtApprovalChain, BahtAvatar, BahtBadge, BahtBarChart, BahtBreadcrumbs, BahtButton, BahtCalendar, BahtCard, BahtCatalogCard, BahtCheckbox, BahtChoiceGroup, BahtCode, BahtColumnPicker, BahtComments, BahtCurrency, BahtDatepicker, BahtDonutChart, BahtEditTable, BahtEmptyState, BahtErrorState, BahtFacts, BahtFieldset, BahtFile, BahtFilter, BahtFilterBuilder, BahtForm, BahtHeatmap, BahtInput, BahtKeyvalueEditor, BahtLineChart, BahtLink, BahtList, BahtLoadingOverlay, BahtMarkdown, BahtMarkdownView, BahtMenu, BahtMeter, BahtModal, BahtMultiselect, BahtNotificationBell, BahtNumber, BahtOrderBox, BahtOtp, BahtPageHeader, BahtPagination, BahtPopover, BahtProgress, BahtProgressRing, BahtRadio, BahtRange, BahtRating, BahtRecordBar, BahtReferenceDialog, BahtReferencePicker, BahtRepeater, BahtRuleBuilder, BahtSavedFilters, BahtSearch, BahtSection, BahtSectionHeader, BahtSelect, BahtSkeleton, BahtSparkline, BahtSpinner, BahtSplitButton, BahtStat, BahtStatChart, BahtSteps, BahtSwipeRow, BahtTable, BahtTabs, BahtTags, BahtText, BahtTextarea, BahtThemeToggle, BahtTimeline, BahtToast, BahtToggle, BahtTooltip, BahtTree, BahtTypeahead, BahtUpload, BahtWizard, BahtWorkflow, CalendarEvent, CalendarNavigateDetail, ColumnsChangeDetail, Crumb, Derived, EditRow, FilterValue, FormDefinition, FormValues, GroupToggleDetail, ListItem, MenuItem, RowMenuSelectDetail, Rule, SavedFilter, SortDirection, ThemeName, TreeNode, TypeaheadOption, UploadChangeDetail, UploadErrorDetail, UploadProgressDetail, ValidValues, ValidationError, WorkflowDefinition, WorkflowTransition, WorkflowValues } from '@20baht/ui';
2
2
  import * as i0 from "@angular/core";
3
3
  /** `<baht-accordion>`: Accordion */
4
4
  export declare class BahtAccordionDirective {
@@ -618,10 +618,10 @@ export declare class BahtFilterBuilderDirective {
618
618
  static ɵdir: i0.ɵɵDirectiveDeclaration<BahtFilterBuilderDirective, "baht-filter-builder", ["bahtFilterBuilder"], { "fields": { "alias": "fields"; "required": false; }; "value": { "alias": "value"; "required": false; }; }, { "bahtChange": "bahtChange"; "valueChange": "valueChange"; }, never, never, true, never>;
619
619
  }
620
620
  /** `<baht-form>`: <baht-form> — dumb controlled form renderer (spec 01) */
621
- export declare class BahtFormDirective {
621
+ export declare class BahtFormDirective<F extends FormDefinition = FormDefinition> {
622
622
  /** The element itself, for its methods. */
623
623
  readonly element: BahtForm;
624
- set form(v: BahtForm['form']);
624
+ set form(v: F);
625
625
  /** The starting data, not a live binding: the user's edits sit over it. Setting a new `value` drops the edits to the keys it changes (compared by content) and keeps the rest, so a host that re-feeds a copy of the same data loses nothing. Read the current data with `getData()` or `baht-change`. */
626
626
  set value(v: BahtForm['value']);
627
627
  set registry(v: BahtForm['registry']);
@@ -648,14 +648,14 @@ export declare class BahtFormDirective {
648
648
  }>;
649
649
  /** `submit()` (or Enter with `submit-on-enter`) passed `validate()`. */
650
650
  readonly bahtSubmit: import("@angular/core").OutputEmitterRef<{
651
- data: Record<string, unknown>;
651
+ data: ValidValues<F>;
652
652
  }>;
653
653
  /** A field changed (an edit or a script); `data` is the whole form. */
654
654
  readonly bahtChange: import("@angular/core").OutputEmitterRef<{
655
655
  form_name: string;
656
656
  key: string;
657
657
  value: unknown;
658
- data: Record<string, unknown>;
658
+ data: FormValues<F>;
659
659
  }>;
660
660
  /** `validate()` ran. */
661
661
  readonly bahtValidity: import("@angular/core").OutputEmitterRef<{
@@ -663,8 +663,8 @@ export declare class BahtFormDirective {
663
663
  errors: ValidationError[];
664
664
  }>;
665
665
  constructor();
666
- static ɵfac: i0.ɵɵFactoryDeclaration<BahtFormDirective, never>;
667
- static ɵdir: i0.ɵɵDirectiveDeclaration<BahtFormDirective, "baht-form", ["bahtForm"], { "form": { "alias": "form"; "required": false; }; "value": { "alias": "value"; "required": false; }; "registry": { "alias": "registry"; "required": false; }; "showOptional": { "alias": "showOptional"; "required": false; }; "options": { "alias": "options"; "required": false; }; "fieldStates": { "alias": "fieldStates"; "required": false; }; "view": { "alias": "view"; "required": false; }; "flags": { "alias": "flags"; "required": false; }; "tab": { "alias": "tab"; "required": false; }; "readonly": { "alias": "readonly"; "required": false; }; "submitOnEnter": { "alias": "submitOnEnter"; "required": false; }; "busy": { "alias": "busy"; "required": false; }; }, { "bahtTabChange": "bahtTabChange"; "bahtSubmit": "bahtSubmit"; "bahtChange": "bahtChange"; "bahtValidity": "bahtValidity"; }, never, never, true, never>;
666
+ static ɵfac: i0.ɵɵFactoryDeclaration<BahtFormDirective<any>, never>;
667
+ static ɵdir: i0.ɵɵDirectiveDeclaration<BahtFormDirective<any>, "baht-form", ["bahtForm"], { "form": { "alias": "form"; "required": false; }; "value": { "alias": "value"; "required": false; }; "registry": { "alias": "registry"; "required": false; }; "showOptional": { "alias": "showOptional"; "required": false; }; "options": { "alias": "options"; "required": false; }; "fieldStates": { "alias": "fieldStates"; "required": false; }; "view": { "alias": "view"; "required": false; }; "flags": { "alias": "flags"; "required": false; }; "tab": { "alias": "tab"; "required": false; }; "readonly": { "alias": "readonly"; "required": false; }; "submitOnEnter": { "alias": "submitOnEnter"; "required": false; }; "busy": { "alias": "busy"; "required": false; }; }, { "bahtTabChange": "bahtTabChange"; "bahtSubmit": "bahtSubmit"; "bahtChange": "bahtChange"; "bahtValidity": "bahtValidity"; }, never, never, true, never>;
668
668
  static ngAcceptInputType_showOptional: unknown;
669
669
  static ngAcceptInputType_readonly: unknown;
670
670
  static ngAcceptInputType_submitOnEnter: unknown;
@@ -2228,10 +2228,10 @@ export declare class BahtWizardDirective {
2228
2228
  static ngAcceptInputType_busy: unknown;
2229
2229
  }
2230
2230
  /** `<baht-workflow>`: <baht-workflow> — the optional brain (spec 03) */
2231
- export declare class BahtWorkflowDirective {
2231
+ export declare class BahtWorkflowDirective<W extends WorkflowDefinition = WorkflowDefinition> {
2232
2232
  /** The element itself, for its methods. */
2233
2233
  readonly element: BahtWorkflow;
2234
- set workflow(v: BahtWorkflow['workflow']);
2234
+ set workflow(v: W);
2235
2235
  /** The starting data, not a live binding: the run keeps its own copy, read with `getData()` or `baht-data-change`. A new `value` restarts the run from it (data, history, first step); one equal by content to the last (a host re-feeding a copy) is ignored. */
2236
2236
  set value(v: BahtWorkflow['value']);
2237
2237
  set registry(v: BahtWorkflow['registry']);
@@ -2257,13 +2257,13 @@ export declare class BahtWorkflowDirective {
2257
2257
  set stepsVariant(v: BahtWorkflow['stepsVariant']);
2258
2258
  /** Any value changed. */
2259
2259
  readonly bahtDataChange: import("@angular/core").OutputEmitterRef<{
2260
- data: NestedData;
2260
+ data: WorkflowValues<W>;
2261
2261
  }>;
2262
2262
  /** Moved forward to `form_name`. */
2263
2263
  readonly bahtNext: import("@angular/core").OutputEmitterRef<{
2264
2264
  form_name: string;
2265
2265
  order: number;
2266
- data: NestedData;
2266
+ data: WorkflowValues<W>;
2267
2267
  decision?: ApprovalDecision;
2268
2268
  comment?: string;
2269
2269
  }>;
@@ -2278,17 +2278,17 @@ export declare class BahtWorkflowDirective {
2278
2278
  form_name: string | null;
2279
2279
  target: string;
2280
2280
  reason: "self-transition" | "target-hidden" | "rule-error";
2281
- data: NestedData;
2281
+ data: WorkflowValues<W>;
2282
2282
  }>;
2283
2283
  /** The last step was submitted. */
2284
2284
  readonly bahtSubmit: import("@angular/core").OutputEmitterRef<{
2285
- data: NestedData;
2285
+ data: WorkflowValues<W>;
2286
2286
  decision?: ApprovalDecision;
2287
2287
  comment?: string;
2288
2288
  }>;
2289
2289
  /** The workflow ended. */
2290
2290
  readonly bahtComplete: import("@angular/core").OutputEmitterRef<{
2291
- data: NestedData;
2291
+ data: WorkflowValues<W>;
2292
2292
  status: "completed" | "rejected";
2293
2293
  }>;
2294
2294
  /** An approval step was approved. */
@@ -2296,14 +2296,14 @@ export declare class BahtWorkflowDirective {
2296
2296
  form_name: string;
2297
2297
  decision: ApprovalDecision;
2298
2298
  comment: string;
2299
- data: NestedData;
2299
+ data: WorkflowValues<W>;
2300
2300
  }>;
2301
2301
  /** An approval step was rejected. */
2302
2302
  readonly bahtReject: import("@angular/core").OutputEmitterRef<{
2303
2303
  form_name: string;
2304
2304
  decision: ApprovalDecision;
2305
2305
  comment: string;
2306
- data: NestedData;
2306
+ data: WorkflowValues<W>;
2307
2307
  }>;
2308
2308
  /** 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. */
2309
2309
  readonly bahtTransition: import("@angular/core").OutputEmitterRef<WorkflowTransition>;
@@ -2312,8 +2312,8 @@ export declare class BahtWorkflowDirective {
2312
2312
  errors: Derived["errors"];
2313
2313
  }>;
2314
2314
  constructor();
2315
- static ɵfac: i0.ɵɵFactoryDeclaration<BahtWorkflowDirective, never>;
2316
- static ɵdir: i0.ɵɵDirectiveDeclaration<BahtWorkflowDirective, "baht-workflow", ["bahtWorkflow"], { "workflow": { "alias": "workflow"; "required": false; }; "value": { "alias": "value"; "required": false; }; "registry": { "alias": "registry"; "required": false; }; "validateGate": { "alias": "validateGate"; "required": false; }; "nextLabel": { "alias": "nextLabel"; "required": false; }; "submitLabel": { "alias": "submitLabel"; "required": false; }; "backLabel": { "alias": "backLabel"; "required": false; }; "showBack": { "alias": "showBack"; "required": false; }; "chrome": { "alias": "chrome"; "required": false; }; "submitOnEnter": { "alias": "submitOnEnter"; "required": false; }; "busy": { "alias": "busy"; "required": false; }; "flags": { "alias": "flags"; "required": false; }; "debounce": { "alias": "debounce"; "required": false; }; "showSteps": { "alias": "showSteps"; "required": false; }; "stepsVariant": { "alias": "stepsVariant"; "required": false; }; }, { "bahtDataChange": "bahtDataChange"; "bahtNext": "bahtNext"; "bahtStepChange": "bahtStepChange"; "bahtNavBlocked": "bahtNavBlocked"; "bahtSubmit": "bahtSubmit"; "bahtComplete": "bahtComplete"; "bahtApprove": "bahtApprove"; "bahtReject": "bahtReject"; "bahtTransition": "bahtTransition"; "bahtRuleError": "bahtRuleError"; }, never, never, true, never>;
2315
+ static ɵfac: i0.ɵɵFactoryDeclaration<BahtWorkflowDirective<any>, never>;
2316
+ static ɵdir: i0.ɵɵDirectiveDeclaration<BahtWorkflowDirective<any>, "baht-workflow", ["bahtWorkflow"], { "workflow": { "alias": "workflow"; "required": false; }; "value": { "alias": "value"; "required": false; }; "registry": { "alias": "registry"; "required": false; }; "validateGate": { "alias": "validateGate"; "required": false; }; "nextLabel": { "alias": "nextLabel"; "required": false; }; "submitLabel": { "alias": "submitLabel"; "required": false; }; "backLabel": { "alias": "backLabel"; "required": false; }; "showBack": { "alias": "showBack"; "required": false; }; "chrome": { "alias": "chrome"; "required": false; }; "submitOnEnter": { "alias": "submitOnEnter"; "required": false; }; "busy": { "alias": "busy"; "required": false; }; "flags": { "alias": "flags"; "required": false; }; "debounce": { "alias": "debounce"; "required": false; }; "showSteps": { "alias": "showSteps"; "required": false; }; "stepsVariant": { "alias": "stepsVariant"; "required": false; }; }, { "bahtDataChange": "bahtDataChange"; "bahtNext": "bahtNext"; "bahtStepChange": "bahtStepChange"; "bahtNavBlocked": "bahtNavBlocked"; "bahtSubmit": "bahtSubmit"; "bahtComplete": "bahtComplete"; "bahtApprove": "bahtApprove"; "bahtReject": "bahtReject"; "bahtTransition": "bahtTransition"; "bahtRuleError": "bahtRuleError"; }, never, never, true, never>;
2317
2317
  static ngAcceptInputType_validateGate: unknown;
2318
2318
  static ngAcceptInputType_showBack: unknown;
2319
2319
  static ngAcceptInputType_submitOnEnter: unknown;
package/dist/store.d.ts CHANGED
@@ -1,12 +1,17 @@
1
1
  import { type Signal, type WritableSignal } from '@angular/core';
2
- import type { BahtStore } from '@20baht/store';
2
+ import type { BahtStore, TypedBahtStore, ValueAt } from '@20baht/store';
3
3
  /**
4
4
  * One ref of a store as a `WritableSignal`: reading follows the store (a bound form's edits
5
5
  * included), `set()` writes through `store.set`, so a bound element updates in place. Call it in
6
6
  * an injection context (a field initializer or constructor); it unsubscribes on destroy.
7
7
  *
8
8
  * readonly days = bahtSignal<number>(this.store, 'Request.days');
9
+ *
10
+ * A store told its shape (`createBahtStore<WorkflowValues<typeof workflow>>()`) needs no type
11
+ * argument: the signal's type is the ref's.
9
12
  */
13
+ export declare function bahtSignal<D extends Record<string, unknown>, R extends string>(store: TypedBahtStore<D>, ref: R): WritableSignal<ValueAt<D, R>>;
10
14
  export declare function bahtSignal<T = unknown>(store: BahtStore, ref: string): WritableSignal<T>;
11
15
  /** The whole store as a read-only signal (stable identity between changes). */
16
+ export declare function bahtStore<D extends Record<string, unknown>>(store: TypedBahtStore<D>): Signal<D>;
12
17
  export declare function bahtStore(store: BahtStore): Signal<Record<string, unknown>>;
package/dist/store.js CHANGED
@@ -1,12 +1,5 @@
1
1
  // @20baht/store as Angular signals: the counterpart of @20baht/store/react's hooks.
2
2
  import { DestroyRef, inject, signal } from '@angular/core';
3
- /**
4
- * One ref of a store as a `WritableSignal`: reading follows the store (a bound form's edits
5
- * included), `set()` writes through `store.set`, so a bound element updates in place. Call it in
6
- * an injection context (a field initializer or constructor); it unsubscribes on destroy.
7
- *
8
- * readonly days = bahtSignal<number>(this.store, 'Request.days');
9
- */
10
3
  export function bahtSignal(store, ref) {
11
4
  const value = signal(store.get(ref), /* @ts-ignore */
12
5
  ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
@@ -25,7 +18,6 @@ export function bahtSignal(store, ref) {
25
18
  asReadonly: () => value.asReadonly(),
26
19
  });
27
20
  }
28
- /** The whole store as a read-only signal (stable identity between changes). */
29
21
  export function bahtStore(store) {
30
22
  const value = signal(store.get(), /* @ts-ignore */
31
23
  ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@20baht/angular",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "Angular adapter for @20baht/ui: typed directives on the real <baht-*> elements, with typed outputs, [(value)] two-way binding and the Angular binding gotchas handled. Generated from the elements' manifest.",
6
6
  "license": "MIT",
@@ -55,8 +55,8 @@
55
55
  "peerDependencies": {
56
56
  "@angular/core": ">=20.0.0",
57
57
  "@20baht/stickers": ">=0.1.0 <0.2.0",
58
- "@20baht/store": ">=0.3.0 <0.4.0",
59
- "@20baht/ui": ">=0.3.0 <0.4.0"
58
+ "@20baht/store": ">=0.3.2 <0.4.0",
59
+ "@20baht/ui": ">=0.3.2 <0.4.0"
60
60
  },
61
61
  "peerDependenciesMeta": {
62
62
  "@20baht/store": {