@atscript/vue-form 0.1.181 → 0.1.182
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/dist/as-action.d.cts +1 -1
- package/dist/as-action.d.mts +1 -1
- package/dist/{as-action.vue-CQbDa3g4.d.mts → as-action.vue-BmHLq5PU.d.cts} +1 -1
- package/dist/{as-action.vue-Cp9Q8a-6.d.cts → as-action.vue-BskkSynK.d.mts} +1 -1
- package/dist/as-array.d.cts +1 -1
- package/dist/as-array.d.mts +1 -1
- package/dist/{as-array.vue-Cgfjz2I-.d.cts → as-array.vue-BWUhWKKn.d.cts} +1 -1
- package/dist/{as-array.vue-DpKFsuRS.d.mts → as-array.vue-C4mSQIUB.d.mts} +1 -1
- package/dist/as-checkbox.d.cts +1 -1
- package/dist/as-checkbox.d.mts +1 -1
- package/dist/{as-checkbox.vue-CXiUHIZj.d.cts → as-checkbox.vue-B_LntkDl.d.cts} +1 -1
- package/dist/{as-checkbox.vue-Db6OT_lL.d.mts → as-checkbox.vue-CPLwFPve.d.mts} +1 -1
- package/dist/as-collapsible.d.cts +1 -1
- package/dist/as-collapsible.d.mts +1 -1
- package/dist/{as-collapsible.vue-BXwe24OV.d.cts → as-collapsible.vue-9XMYb39s.d.cts} +1 -1
- package/dist/{as-collapsible.vue-By-ZBZt3.d.mts → as-collapsible.vue-BtUZuqGF.d.mts} +1 -1
- package/dist/as-date.d.cts +1 -1
- package/dist/as-date.d.mts +1 -1
- package/dist/{as-date.vue-BUaHHI42.d.mts → as-date.vue-CQZp-yqF.d.mts} +1 -1
- package/dist/{as-date.vue-axahL_Zv.d.cts → as-date.vue-DQVHGLMc.d.cts} +1 -1
- package/dist/as-datetime.d.cts +1 -1
- package/dist/as-datetime.d.mts +1 -1
- package/dist/{as-datetime.vue-C6ILTI-7.d.cts → as-datetime.vue-DrWth1Pe.d.mts} +1 -1
- package/dist/{as-datetime.vue-D3WJpAVe.d.mts → as-datetime.vue-TMgV54Z5.d.cts} +1 -1
- package/dist/as-decimal.d.cts +1 -1
- package/dist/as-decimal.d.mts +1 -1
- package/dist/{as-decimal.vue-BVDyP4LN.d.mts → as-decimal.vue-Bw9vY0br.d.mts} +1 -1
- package/dist/{as-decimal.vue-Dgfz9UDJ.d.cts → as-decimal.vue-D-C_ywhy.d.cts} +1 -1
- package/dist/as-field-shell.d.cts +1 -1
- package/dist/as-field-shell.d.mts +1 -1
- package/dist/{as-field-shell.vue-DAcRqi7G.d.cts → as-field-shell.vue-CouocQ2f.d.cts} +1 -1
- package/dist/{as-field-shell.vue-DBufTHVO.d.mts → as-field-shell.vue-DIYpxzud.d.mts} +1 -1
- package/dist/{as-form-DroFS2lv.cjs → as-form-BTNctHb9.cjs} +15 -7
- package/dist/{as-form-B9hRTvod.mjs → as-form-CRDqdXnl.mjs} +15 -7
- package/dist/as-form.cjs +1 -1
- package/dist/as-form.d.cts +1 -1
- package/dist/as-form.d.mts +1 -1
- package/dist/as-form.mjs +1 -1
- package/dist/{as-form.vue-BdCoE0YG.d.mts → as-form.vue-BI5mC0o7.d.cts} +15 -389
- package/dist/{as-form.vue-CPrH175H.d.cts → as-form.vue-BJ79OYA6.d.mts} +15 -389
- package/dist/as-input.d.cts +1 -1
- package/dist/as-input.d.mts +1 -1
- package/dist/{as-input.vue-BiPsULeF.d.mts → as-input.vue-D4UQSSmo.d.cts} +1 -1
- package/dist/{as-input.vue-mZ0h1Q2J.d.cts → as-input.vue-Q5EXxW3x.d.mts} +1 -1
- package/dist/as-multi-select.d.cts +1 -1
- package/dist/as-multi-select.d.mts +1 -1
- package/dist/{as-multi-select.vue-Bmngkww7.d.mts → as-multi-select.vue-Ce-V2A81.d.mts} +1 -1
- package/dist/{as-multi-select.vue-DAFz9hZR.d.cts → as-multi-select.vue-Iy3G3eu8.d.cts} +1 -1
- package/dist/as-number.d.cts +1 -1
- package/dist/as-number.d.mts +1 -1
- package/dist/{as-number.vue-BsJdJS36.d.cts → as-number.vue-FKc6UVot.d.mts} +1 -1
- package/dist/{as-number.vue-C2QSKpVL.d.mts → as-number.vue-PH0wnd3B.d.cts} +1 -1
- package/dist/as-object.d.cts +1 -1
- package/dist/as-object.d.mts +1 -1
- package/dist/{as-object.vue-DFo_5DXv.d.mts → as-object.vue-B0qKMWPB.d.cts} +1 -1
- package/dist/{as-object.vue-DduGoHKD.d.cts → as-object.vue-DLCEWLe4.d.mts} +1 -1
- package/dist/as-paragraph.d.cts +1 -1
- package/dist/as-paragraph.d.mts +1 -1
- package/dist/{as-paragraph.vue-BJSA27kd.d.cts → as-paragraph.vue-BIrekTzU.d.mts} +1 -1
- package/dist/{as-paragraph.vue-DiHaNFSX.d.mts → as-paragraph.vue-C8JeTZ1s.d.cts} +1 -1
- package/dist/as-radio.d.cts +1 -1
- package/dist/as-radio.d.mts +1 -1
- package/dist/{as-radio.vue-C_ZjbI4s.d.mts → as-radio.vue-Rwknlgr7.d.mts} +1 -1
- package/dist/{as-radio.vue-Dw1QaJoY.d.cts → as-radio.vue-jeHiMfc7.d.cts} +1 -1
- package/dist/as-ref.d.cts +1 -1
- package/dist/as-ref.d.mts +1 -1
- package/dist/{as-ref.vue-CvY88H7p.d.cts → as-ref.vue-D0A4vPXL.d.mts} +1 -1
- package/dist/{as-ref.vue-DaXQsjsX.d.mts → as-ref.vue-WufE6ltR.d.cts} +1 -1
- package/dist/as-select.d.cts +1 -1
- package/dist/as-select.d.mts +1 -1
- package/dist/{as-select.vue-7xiuC9JG.d.cts → as-select.vue-BIpvu4ba.d.mts} +1 -1
- package/dist/{as-select.vue-IGtjEyQD.d.mts → as-select.vue-eMp1zUQE.d.cts} +1 -1
- package/dist/as-time.d.cts +1 -1
- package/dist/as-time.d.mts +1 -1
- package/dist/{as-time.vue-CKVgGb-m.d.mts → as-time.vue-DAeXJ0Zv.d.cts} +1 -1
- package/dist/{as-time.vue-CQhIKAs0.d.cts → as-time.vue-DudhL8yx.d.mts} +1 -1
- package/dist/as-tuple.d.cts +1 -1
- package/dist/as-tuple.d.mts +1 -1
- package/dist/{as-tuple.vue-BSh2-1uv.d.cts → as-tuple.vue-C2KTK2RH.d.cts} +1 -1
- package/dist/{as-tuple.vue-CDOHXKBr.d.mts → as-tuple.vue-CLIDqVFv.d.mts} +1 -1
- package/dist/as-union.d.cts +1 -1
- package/dist/as-union.d.mts +1 -1
- package/dist/{as-union.vue-BcaUH5bH.d.mts → as-union.vue-43Gq2Lh0.d.cts} +1 -1
- package/dist/{as-union.vue-CnF4bNex.d.cts → as-union.vue-CllUYjuh.d.mts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +22 -22
- package/dist/index.d.mts +22 -22
- package/dist/index.mjs +1 -1
- package/dist/types-BbGuPzZk.d.cts +705 -0
- package/dist/types-DxmDaJXr.d.mts +705 -0
- package/package.json +10 -10
- package/dist/types-B0Ey_eD-.d.mts +0 -309
- package/dist/types-DoLxVJhd.d.cts +0 -309
|
@@ -0,0 +1,705 @@
|
|
|
1
|
+
import { Component, ComputedRef, Ref } from "vue";
|
|
2
|
+
import { ClientFactory, FormDef, FormDiffOptions, FormFieldChange, FormFieldDef, FormRebaseOptions, FormUnionVariant, TFormAction, TFormEntryOptions, ValueHelpInfo } from "@atscript/ui";
|
|
3
|
+
|
|
4
|
+
//#region src/composables/use-as-form-patch.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Result of {@link AsFormPatchHandle.rebaseOnto}. Aliases the `@atscript/ui`
|
|
7
|
+
* rebase shape (minus `next`, which is written into the live container rather
|
|
8
|
+
* than returned): the surviving local diff on top of the NEW baseline plus the
|
|
9
|
+
* conflict paths.
|
|
10
|
+
*/
|
|
11
|
+
interface RebaseOntoResult {
|
|
12
|
+
/** Paths changed on both sides to different values, plus ancestor-clear paths. */
|
|
13
|
+
conflicts: string[];
|
|
14
|
+
/** Local edits that survive on top of the new (upstream) baseline. */
|
|
15
|
+
reapplied: FormFieldChange[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Change-tracking handle for a single `<AsForm>`. Exposed three ways:
|
|
19
|
+
*
|
|
20
|
+
* 1. injected via {@link useAsFormPatch} inside any descendant component,
|
|
21
|
+
* 2. spread into every `<AsForm>` slot (`isDirty` / `changes` / `getPatch` /
|
|
22
|
+
* `getChanges` — so a footer slot can gate a Save button), and
|
|
23
|
+
* 3. `defineExpose`d on `<AsForm>` (so a parent template ref can call
|
|
24
|
+
* `asForm.value.getPatch()`).
|
|
25
|
+
*
|
|
26
|
+
* Built on `@atscript/ui`'s `buildFormDiff`, which diffs the form's CURRENT
|
|
27
|
+
* data against a BASELINE snapshot and produces both a per-field change list
|
|
28
|
+
* and an `@atscript/db` patch object (keyed-array `$update`/`$insert`/`$remove`,
|
|
29
|
+
* `$cas` optimistic-concurrency sibling, revert-aware).
|
|
30
|
+
*/
|
|
31
|
+
interface AsFormPatchHandle {
|
|
32
|
+
/**
|
|
33
|
+
* Reactive dirtiness — `true` when current data differs from the baseline.
|
|
34
|
+
* Revert-aware: a value edited back to its baseline flips this back to
|
|
35
|
+
* `false`. Memoised by Vue; recomputes only when the form data changes.
|
|
36
|
+
*/
|
|
37
|
+
isDirty: ComputedRef<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Reactive per-field change list (revert-aware — reverted fields drop out).
|
|
40
|
+
* `before` / `after` hold live references into the baseline / current data.
|
|
41
|
+
*/
|
|
42
|
+
changes: ComputedRef<FormFieldChange[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Builds the `@atscript/db` patch object on demand against the baseline
|
|
45
|
+
* snapshot. Safe to call at submit time (a fresh re-snapshot point). Returns
|
|
46
|
+
* `{}` when nothing changed. Carries a top-level `$cas` sibling when the form
|
|
47
|
+
* has a `@db.column.version` column and `opts.cas` is on (default).
|
|
48
|
+
*/
|
|
49
|
+
getPatch: (opts?: FormDiffOptions) => Record<string, unknown>;
|
|
50
|
+
/** Builds the per-field change list on demand (same data as `changes`). */
|
|
51
|
+
getChanges: () => FormFieldChange[];
|
|
52
|
+
/**
|
|
53
|
+
* Reactive per-field dirty predicate. `true` when the field at the dot-path
|
|
54
|
+
* `path` differs from the baseline. Reads the reactive {@link changes} list,
|
|
55
|
+
* so a per-field `isDirty` derived from this recomputes whenever the change
|
|
56
|
+
* list does.
|
|
57
|
+
*
|
|
58
|
+
* Granularity matches the change list (leaf-grained for scalars/objects,
|
|
59
|
+
* WHOLE-ARRAY for arrays): a field is dirty iff some change path equals
|
|
60
|
+
* `path` OR starts with `path + "."`. Object/section containers light up via
|
|
61
|
+
* the prefix branch; whole-array fields via exact match; an array-ITEM leaf
|
|
62
|
+
* (e.g. `items.0.qty`) returns `false` (the array container lights up
|
|
63
|
+
* instead — a known, documented limitation of the array diff). The empty
|
|
64
|
+
* root path `''` is dirty iff there are ANY changes. Backed by an O(1)
|
|
65
|
+
* `Set.has` against `@atscript/ui`'s `collectDirtyPaths` precompute, whose
|
|
66
|
+
* membership matches `isPathDirty` exactly (locked by an invariant test).
|
|
67
|
+
*/
|
|
68
|
+
isDirtyPath: (path: string) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Re-baseline to the current data. Call after a successful save so the form
|
|
71
|
+
* becomes clean again WITHOUT a remount. No-op when tracking is inactive.
|
|
72
|
+
*/
|
|
73
|
+
rebase: () => void;
|
|
74
|
+
/**
|
|
75
|
+
* 3-way rebase onto a fresh upstream snapshot. Sets the baseline to
|
|
76
|
+
* `upstream` and rewrites the live form to `upstream` + the local diff
|
|
77
|
+
* (current vs. old baseline) reapplied on top:
|
|
78
|
+
*
|
|
79
|
+
* - fields the user never touched adopt `upstream`'s value,
|
|
80
|
+
* - local edits survive,
|
|
81
|
+
* - fields changed on both sides to a different value are conflicts, resolved
|
|
82
|
+
* by `opts.conflict` (`'ours'` default keeps local, `'theirs'` takes
|
|
83
|
+
* upstream).
|
|
84
|
+
*
|
|
85
|
+
* `upstream` is the WRAPPED form-data container (`{ value }`). The live form
|
|
86
|
+
* data is rewritten in a SINGLE mutation (the bound `:form-data` container
|
|
87
|
+
* identity is preserved, so the consumer's ref stays the same object). After
|
|
88
|
+
* the write the baseline becomes a deep clone of `upstream`, so a subsequent
|
|
89
|
+
* `getPatch()` carries exactly the surviving local diff (`reapplied`).
|
|
90
|
+
*
|
|
91
|
+
* Returns the conflict paths and the surviving local diff. No-op returning
|
|
92
|
+
* empty when tracking is inactive.
|
|
93
|
+
*/
|
|
94
|
+
rebaseOnto: (upstream: Record<string, unknown>, opts?: FormRebaseOptions) => RebaseOntoResult;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Reactive read-only access to the form's change-tracking handle from any
|
|
98
|
+
* descendant of an `<AsForm track-changes>`. Mirrors the `useAsData` /
|
|
99
|
+
* `useAsPath` injector pattern.
|
|
100
|
+
*
|
|
101
|
+
* THROWS when called outside a form, or inside a form that did not enable
|
|
102
|
+
* `track-changes` — fail loud rather than silently report "not dirty".
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```vue
|
|
106
|
+
* <script setup lang="ts">
|
|
107
|
+
* import { useAsFormPatch } from "@atscript/vue-form";
|
|
108
|
+
* const { isDirty, getPatch } = useAsFormPatch();
|
|
109
|
+
* </script>
|
|
110
|
+
* <template>
|
|
111
|
+
* <button :disabled="!isDirty" @click="save(getPatch())">Save</button>
|
|
112
|
+
* </template>
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
declare function useAsFormPatch(): AsFormPatchHandle;
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/composables/types.d.ts
|
|
118
|
+
type TFormRule<TValue, TFormData, TContext> = (v: TValue, data?: TFormData, context?: TContext) => boolean | string;
|
|
119
|
+
/**
|
|
120
|
+
* One validation error of a submit: what `<AsForm>`'s `error` event (and the
|
|
121
|
+
* `error` callback of `useAsForm`) carries a list of. `path` is the field's
|
|
122
|
+
* dotted path; a failing `@ui.form.validate` on the form's interface is `__form`.
|
|
123
|
+
* A type alias (not an interface), so an entry stays assignable to
|
|
124
|
+
* `Record<string, string>`.
|
|
125
|
+
*
|
|
126
|
+
* @since 0.1.182
|
|
127
|
+
*/
|
|
128
|
+
type TAsFormError = {
|
|
129
|
+
path: string;
|
|
130
|
+
message: string;
|
|
131
|
+
};
|
|
132
|
+
interface TFormFieldCallbacks {
|
|
133
|
+
validate: () => boolean | string;
|
|
134
|
+
clearErrors: () => void;
|
|
135
|
+
reset: () => void;
|
|
136
|
+
setExternalError: (msg?: string) => void;
|
|
137
|
+
/**
|
|
138
|
+
* Read the error message the field is DISPLAYING right now (external >
|
|
139
|
+
* submit > live-validated per `firstValidation` gating), or `undefined`
|
|
140
|
+
* when clean. Feeds the form-level live error aggregation (descendant
|
|
141
|
+
* error-count badges / auto-open), so badges track what's on screen
|
|
142
|
+
* without waiting for a submit. Optional so manually built registrations
|
|
143
|
+
* keep working — a field that omits it simply doesn't contribute live
|
|
144
|
+
* errors (submit-time errors still count through the form's own map).
|
|
145
|
+
*/
|
|
146
|
+
getError?: () => string | undefined;
|
|
147
|
+
}
|
|
148
|
+
interface TFormFieldRegistration {
|
|
149
|
+
path: () => string;
|
|
150
|
+
callbacks: TFormFieldCallbacks;
|
|
151
|
+
}
|
|
152
|
+
interface TFormState {
|
|
153
|
+
firstSubmitHappened: boolean;
|
|
154
|
+
firstValidation: "on-change" | "touched-on-blur" | "on-blur" | "on-submit" | "none";
|
|
155
|
+
/**
|
|
156
|
+
* Fields registered AFTER `firstSubmitHappened` flipped to true. They stay
|
|
157
|
+
* in this set until either the user edits the field (model watch removes
|
|
158
|
+
* the id) or the next submit fires (set is cleared). Live validation is
|
|
159
|
+
* suppressed for these fields so a freshly-added array item doesn't render
|
|
160
|
+
* red required-field errors before the user has had a chance to type.
|
|
161
|
+
*/
|
|
162
|
+
freshFields: Set<symbol>;
|
|
163
|
+
register: (id: symbol, registration: TFormFieldRegistration) => void;
|
|
164
|
+
unregister: (id: symbol) => void;
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/composables/use-as-form.d.ts
|
|
168
|
+
/**
|
|
169
|
+
* Options for {@link useAsForm}. Each reactive prop is supplied as a
|
|
170
|
+
* **getter** so the composable can subscribe to its changes without owning
|
|
171
|
+
* a `Ref`. Pass component-level `defineProps` accessors verbatim:
|
|
172
|
+
*
|
|
173
|
+
* ```ts
|
|
174
|
+
* useAsForm({
|
|
175
|
+
* def: () => props.def,
|
|
176
|
+
* formData: () => props.formData,
|
|
177
|
+
* types: () => props.types,
|
|
178
|
+
* // ...
|
|
179
|
+
* emits: { submit: (data) => emit("submit", data), ... },
|
|
180
|
+
* })
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* Generic `TFormData` / `TFormContext` mirror the `<AsForm>` component
|
|
184
|
+
* generics. They flow through to emitted callbacks; if you build a custom
|
|
185
|
+
* form root with a known data shape, pin them at the call site.
|
|
186
|
+
*/
|
|
187
|
+
interface UseAsFormOptions<TFormData = unknown, TFormContext = unknown> {
|
|
188
|
+
/** Form definition produced by `createAsFormDef(type)`. Reactive. */
|
|
189
|
+
def: () => FormDef;
|
|
190
|
+
/**
|
|
191
|
+
* Externally-managed form data container `{ value: domainData }`. When
|
|
192
|
+
* unset, the composable creates an internal one initialized to `{}`.
|
|
193
|
+
*/
|
|
194
|
+
formData?: () => TFormData | undefined;
|
|
195
|
+
/** Reactive form context — exposed to validators, scope, slots, and emits. */
|
|
196
|
+
formContext?: () => TFormContext | undefined;
|
|
197
|
+
/** First-validation strategy. Defaults to `"on-change"`. */
|
|
198
|
+
firstValidation?: () => TFormState["firstValidation"] | undefined;
|
|
199
|
+
/** Custom field components keyed by field name (matches `Props.components`). */
|
|
200
|
+
components?: () => Record<string, Component<TAsComponentProps>> | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* Type-to-component map keyed by field type (matches `Props.types`). Optional
|
|
203
|
+
* since 0.1.182: a form root that renders its own inputs and no `<AsField>`
|
|
204
|
+
* can leave it out (the map is then empty).
|
|
205
|
+
*/
|
|
206
|
+
types?: () => TAsTypeComponents | undefined;
|
|
207
|
+
/** Server-supplied errors keyed by absolute dotted path (`__form` for form-level). */
|
|
208
|
+
errors?: () => Record<string, string | undefined> | undefined;
|
|
209
|
+
/** Per-form value-help client factory. Falls back to the app-wide default when unset. */
|
|
210
|
+
clientFactory?: () => ClientFactory | undefined;
|
|
211
|
+
/** Suppress the root field's title (use when the chrome already shows the form's label). */
|
|
212
|
+
hideRootTitle?: () => boolean | undefined;
|
|
213
|
+
/**
|
|
214
|
+
* Busy-state flag. When `true`, the form is locked (inert + overlay) and the
|
|
215
|
+
* default submit button is disabled. `<AsWfForm>` wires this to its
|
|
216
|
+
* server round-trip so consumers can drop their own submit overrides.
|
|
217
|
+
*/
|
|
218
|
+
loading?: () => boolean | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* Enable change tracking. When `true`, the composable captures a deep-clone
|
|
221
|
+
* baseline of the form data (the moment it becomes available) and exposes a
|
|
222
|
+
* {@link AsFormPatchHandle} via `slotProps`, the return value (`patch`), and
|
|
223
|
+
* `provide(FORM_PATCH_KEY)` (read with `useAsFormPatch()`). When falsy
|
|
224
|
+
* (default), there is ZERO overhead — no baseline, no deep watch, and
|
|
225
|
+
* `useAsFormPatch()` throws. Reactive.
|
|
226
|
+
*/
|
|
227
|
+
trackChanges?: () => boolean | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* Outbound callbacks. Customer form roots typically wire these to
|
|
230
|
+
* `defineEmits`; advanced uses can pass plain functions.
|
|
231
|
+
*/
|
|
232
|
+
emits?: {
|
|
233
|
+
submit?: (data: TAsFormValue<TFormData>) => void;
|
|
234
|
+
error?: (errors: TAsFormError[]) => void;
|
|
235
|
+
action?: (name: string, data: TAsFormValue<TFormData>) => void;
|
|
236
|
+
unsupportedAction?: (name: string, data: TAsFormValue<TFormData>) => void;
|
|
237
|
+
change?: (type: TAsChangeType, path: string, value: unknown, formData: TAsFormValue<TFormData>) => void;
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The value inside a `{ value }` form-data container (`value` may be
|
|
242
|
+
* optional): what the `submit`, `action`, `unsupportedAction` and `change`
|
|
243
|
+
* callbacks (and `<AsForm>`'s events) receive. `any` for an `any` container,
|
|
244
|
+
* `unknown` when the container has no `value`.
|
|
245
|
+
*/
|
|
246
|
+
type TAsFormValue<TFormData> = 0 extends 1 & TFormData ? any : TFormData extends {
|
|
247
|
+
value?: infer V;
|
|
248
|
+
} ? V : unknown;
|
|
249
|
+
/**
|
|
250
|
+
* What a submit returns (`useAsForm().onSubmit()`, `submit()` on an `<AsForm>`
|
|
251
|
+
* template ref and in its slots), next to the `submit` / `error` it emits:
|
|
252
|
+
* `{ ok: true, data }` with the data `submit` carries, or `{ ok: false, errors }`
|
|
253
|
+
* with the errors `error` carries. With `firstValidation: "none"` nothing is
|
|
254
|
+
* validated, so a submit always returns `ok: true`.
|
|
255
|
+
*
|
|
256
|
+
* @since 0.1.182
|
|
257
|
+
*/
|
|
258
|
+
type TAsFormSubmitResult<TFormData> = {
|
|
259
|
+
ok: true;
|
|
260
|
+
data: TAsFormValue<TFormData>;
|
|
261
|
+
} | {
|
|
262
|
+
ok: false;
|
|
263
|
+
errors: TAsFormError[];
|
|
264
|
+
};
|
|
265
|
+
interface UseAsFormReturn<TFormData = unknown, TFormContext = unknown> {
|
|
266
|
+
/** Reactive form-data container `{ value: domainData }`. */
|
|
267
|
+
data: ComputedRef<TFormData>;
|
|
268
|
+
/** Effective external errors (post-dismissal), excluding `__form`. */
|
|
269
|
+
errors: ComputedRef<Record<string, string | undefined> | undefined>;
|
|
270
|
+
/**
|
|
271
|
+
* Form-level error message (post banner-dismissal): the root interface's
|
|
272
|
+
* `@ui.form.validate` error (live after the first submit), else the
|
|
273
|
+
* external `__form` error.
|
|
274
|
+
*/
|
|
275
|
+
formError: ComputedRef<string | undefined>;
|
|
276
|
+
/** Errors discovered by the local validator on the most-recent submit. */
|
|
277
|
+
internalErrors: Ref<Record<string, string>>;
|
|
278
|
+
/**
|
|
279
|
+
* Return the form's fields to what a newly created form holds
|
|
280
|
+
* (`createFormData` — annotation defaults included, optional fields absent;
|
|
281
|
+
* loaded values are not kept). Properties of the data that are not form
|
|
282
|
+
* fields (an edit form's version column, navigation rows) are left as they
|
|
283
|
+
* are. The field subtree remounts (`remountKey`); touched state, submit and
|
|
284
|
+
* live errors are cleared; a server error (`errors`) is dismissed where the
|
|
285
|
+
* reset changed the value — on other paths, and the external `__form`
|
|
286
|
+
* banner, it stays. When `trackChanges` is enabled, the post-reset state
|
|
287
|
+
* becomes the new clean baseline. Focus is left alone: `<AsForm>` moves it
|
|
288
|
+
* to the first field control when the reset removed or disabled the
|
|
289
|
+
* focused element.
|
|
290
|
+
*/
|
|
291
|
+
reset: () => Promise<void>;
|
|
292
|
+
/**
|
|
293
|
+
* Imperatively clear ALL error state: per-field (touched / blur / submit /
|
|
294
|
+
* external via `useAsState().clearErrors`) plus the form-level submit-time
|
|
295
|
+
* error map that feeds the descendant-count badges.
|
|
296
|
+
*/
|
|
297
|
+
clearErrors: () => void;
|
|
298
|
+
/** Imperatively set external-error messages by path. */
|
|
299
|
+
setErrors: (errors: Record<string, string>) => void;
|
|
300
|
+
/**
|
|
301
|
+
* Trigger submit. Applies the type's `@normalize.*` (trim, case) to the data,
|
|
302
|
+
* validates the result and emits it with `submit` on success, `error` on
|
|
303
|
+
* validation failure. The form data itself is left as typed. Returns the
|
|
304
|
+
* outcome ({@link TAsFormSubmitResult}, since 0.1.182).
|
|
305
|
+
*/
|
|
306
|
+
onSubmit: () => TAsFormSubmitResult<TFormData>;
|
|
307
|
+
/** Resolved submit-button text (`@ui.form.submit.text` / fn variant). */
|
|
308
|
+
submitText: ComputedRef<string>;
|
|
309
|
+
/** Resolved submit-button disabled state (`@ui.form.fn.submitDisabled`). */
|
|
310
|
+
submitDisabled: ComputedRef<boolean>;
|
|
311
|
+
/** Resolved form-level title (`@ui.form.fn.title` / `@meta.label`); may be `undefined`. */
|
|
312
|
+
title: ComputedRef<string | undefined>;
|
|
313
|
+
/** Resolved form-level description (`@ui.form.fn.description` / `@meta.description`). */
|
|
314
|
+
description: ComputedRef<string | undefined>;
|
|
315
|
+
/** Unified slot-props bag spread onto every `<AsForm>` slot. */
|
|
316
|
+
slotProps: ComputedRef<{
|
|
317
|
+
title: string | undefined;
|
|
318
|
+
description: string | undefined;
|
|
319
|
+
data: TFormData;
|
|
320
|
+
errors: Record<string, string | undefined> | undefined;
|
|
321
|
+
formError: string | undefined;
|
|
322
|
+
disabled: boolean;
|
|
323
|
+
loading: boolean;
|
|
324
|
+
submitText: string;
|
|
325
|
+
submit: () => TAsFormSubmitResult<TFormData>;
|
|
326
|
+
reset: () => Promise<void>;
|
|
327
|
+
clearErrors: () => void;
|
|
328
|
+
setErrors: (errors: Record<string, string>) => void;
|
|
329
|
+
dismissError: (path: string) => void;
|
|
330
|
+
dismissFormError: () => void;
|
|
331
|
+
formContext: TFormContext | undefined; /** True when `track-changes` is on AND data differs from baseline. */
|
|
332
|
+
isDirty: boolean; /** Revert-aware per-field change list (empty when tracking is off). */
|
|
333
|
+
changes: readonly FormFieldChange[]; /** Build the `@atscript/db` patch on demand (`{}` when tracking is off). */
|
|
334
|
+
getPatch: (opts?: FormDiffOptions) => Record<string, unknown>; /** Build the per-field change list on demand (`[]` when tracking is off). */
|
|
335
|
+
getChanges: () => FormFieldChange[]; /** Per-field dirty predicate (`false` for every path when tracking is off). */
|
|
336
|
+
isDirtyPath: (path: string) => boolean;
|
|
337
|
+
}>;
|
|
338
|
+
/**
|
|
339
|
+
* Change-tracking handle — present ONLY when `trackChanges` is enabled.
|
|
340
|
+
* `undefined` otherwise. Read it from descendants with `useAsFormPatch()`.
|
|
341
|
+
*/
|
|
342
|
+
patch: AsFormPatchHandle | undefined;
|
|
343
|
+
/**
|
|
344
|
+
* Remount key for the field subtree. Bound as `:key` on the root `<AsField>`
|
|
345
|
+
* (and on the pushed-down fields). Bumped by every `reset()`, and — with
|
|
346
|
+
* `trackChanges` — when `patch.rebaseOnto` or a swap of the data's `value`
|
|
347
|
+
* lands a different union variant, forcing the variant picker to re-detect.
|
|
348
|
+
*/
|
|
349
|
+
remountKey: Ref<number>;
|
|
350
|
+
/** Dispatch an action — invoked by `<AsAction>`. */
|
|
351
|
+
invokeAction: (name: string) => void;
|
|
352
|
+
/** Dismiss a single external leaf error. */
|
|
353
|
+
dismissError: (path: string) => void;
|
|
354
|
+
/** Dismiss the form-level banner. */
|
|
355
|
+
dismissFormError: () => void;
|
|
356
|
+
/** Form-context getter (mirrors `options.formContext()`). */
|
|
357
|
+
formContext: ComputedRef<TFormContext | undefined>;
|
|
358
|
+
/** Internal change-dispatcher used by `<AsField>` and structured components. */
|
|
359
|
+
handleChange: (type: TAsChangeType, path: string, value: unknown) => void;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Composable backing `<AsForm>`. Owns the entire form state machine —
|
|
363
|
+
* data container, internal validator, external-error dismissal, action
|
|
364
|
+
* routing, change merging, descendant counts, auto-open, and all
|
|
365
|
+
* provide/inject wiring. Customers building a custom form root can
|
|
366
|
+
* call this directly and render their own `<form>` template.
|
|
367
|
+
*
|
|
368
|
+
* MUST be called from a component's `<script setup>` (it issues
|
|
369
|
+
* `provide()` calls that need an active component instance).
|
|
370
|
+
*/
|
|
371
|
+
declare function useAsForm<TFormData = unknown, TFormContext = unknown>(options: UseAsFormOptions<TFormData, TFormContext>): UseAsFormReturn<TFormData, TFormContext>;
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region src/components/types.d.ts
|
|
374
|
+
/**
|
|
375
|
+
* Shared base props available to all custom form components.
|
|
376
|
+
*/
|
|
377
|
+
interface TAsBaseComponentProps {
|
|
378
|
+
/** Whether this component is disabled. */
|
|
379
|
+
disabled?: boolean;
|
|
380
|
+
/** Whether this component is hidden. */
|
|
381
|
+
hidden?: boolean;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Props contract for custom field components used with `AsForm` / `AsField`.
|
|
385
|
+
*
|
|
386
|
+
* Implement this interface in your UI components so that `AsField` can pass
|
|
387
|
+
* all resolved field state (value, label, validation errors, etc.) as props.
|
|
388
|
+
*
|
|
389
|
+
* @typeParam V - The field value type
|
|
390
|
+
* @typeParam TFormData - The full form data object type
|
|
391
|
+
* @typeParam TFormContext - The external context object type
|
|
392
|
+
*/
|
|
393
|
+
interface TAsComponentProps<V = unknown> extends TAsBaseComponentProps {
|
|
394
|
+
/** Called on field blur — triggers validation. */
|
|
395
|
+
onBlur: () => void;
|
|
396
|
+
/** Validation error message for this field, if any. */
|
|
397
|
+
error?: string;
|
|
398
|
+
/** Reactive model wrapping the field value. Bind with `v-model="model.value"`. */
|
|
399
|
+
model: {
|
|
400
|
+
value: V;
|
|
401
|
+
};
|
|
402
|
+
/** Phantom field display value from `@meta.default` / `@ui.form.fn.value` (paragraphs, actions). `undefined` for data fields. */
|
|
403
|
+
value?: unknown;
|
|
404
|
+
/** Resolved field label from `@meta.label` or `@ui.form.fn.label`. */
|
|
405
|
+
label?: string;
|
|
406
|
+
/** Resolved field description from `@meta.description` or `@ui.form.fn.description`. */
|
|
407
|
+
description?: string;
|
|
408
|
+
/** Resolved hint text from `@ui.form.hint` or `@ui.form.fn.hint`. */
|
|
409
|
+
hint?: string;
|
|
410
|
+
/** Resolved placeholder from `@ui.form.placeholder` or `@ui.form.fn.placeholder`. */
|
|
411
|
+
placeholder?: string;
|
|
412
|
+
/** Resolved CSS class painting the prefix icon glyph from `@ui.form.prefix.icon`. Consumer manages safelist / preset coverage. Rendered as the leftmost adornment, before the `prefix` text. */
|
|
413
|
+
prefixIcon?: string;
|
|
414
|
+
/** Resolved CSS class painting the suffix icon glyph from `@ui.form.suffix.icon`. Consumer manages safelist / preset coverage. Rendered as the rightmost adornment, after the `suffix` text. */
|
|
415
|
+
suffixIcon?: string;
|
|
416
|
+
/** CSS class(es) from `@ui.form.classes` or `@ui.form.fn.classes`. */
|
|
417
|
+
class?: Record<string, boolean> | string;
|
|
418
|
+
/** Inline styles from `@ui.form.styles` or `@ui.form.fn.styles`. */
|
|
419
|
+
style?: Record<string, string> | string;
|
|
420
|
+
/** Whether the field is optional (not required). */
|
|
421
|
+
optional?: boolean | undefined;
|
|
422
|
+
/** Toggle an optional field on/off. `true` sets default value; `false` sets `undefined`. Only present when `optional` is true. */
|
|
423
|
+
onToggleOptional?: (enabled: boolean) => void;
|
|
424
|
+
/** Whether the field is required (inverse of optional). */
|
|
425
|
+
required?: boolean | undefined;
|
|
426
|
+
/** Whether the field is read-only. */
|
|
427
|
+
readonly?: boolean | undefined;
|
|
428
|
+
/** The resolved field input type (e.g., `'text'`, `'select'`, `'checkbox'`). */
|
|
429
|
+
type: string;
|
|
430
|
+
/** Form action from `@ui.form.action`. Contains the action id and display label. */
|
|
431
|
+
formAction?: TFormAction;
|
|
432
|
+
/** The field name (last segment of the dot-separated path). */
|
|
433
|
+
name?: string;
|
|
434
|
+
/** The full FormFieldDef for advanced use cases. */
|
|
435
|
+
field?: FormFieldDef;
|
|
436
|
+
/** Resolved options for select/radio/checkbox fields. */
|
|
437
|
+
options?: TFormEntryOptions[];
|
|
438
|
+
/** Max length constraint from `@expect.maxLength`. */
|
|
439
|
+
maxLength?: number;
|
|
440
|
+
/** Autocomplete hint from `@ui.form.autocomplete`. */
|
|
441
|
+
autocomplete?: string;
|
|
442
|
+
/** Resolved title from `@ui.form.fn.title` / `@meta.label` for structure/array fields. */
|
|
443
|
+
title?: string;
|
|
444
|
+
/** Nesting level for structure/array fields. Root structure is 0, each nested structure/array increments by 1. */
|
|
445
|
+
level?: number;
|
|
446
|
+
/** Callback to remove this item from its parent array. Present when rendered inside an array. */
|
|
447
|
+
onRemove?: () => void;
|
|
448
|
+
/** Whether removal is allowed (respects minLength constraints). */
|
|
449
|
+
canRemove?: boolean;
|
|
450
|
+
/** Label for the remove button (from `@ui.array.remove.label`). */
|
|
451
|
+
removeLabel?: string;
|
|
452
|
+
/** Zero-based index when rendered as a direct array item. `undefined` otherwise. */
|
|
453
|
+
arrayIndex?: number;
|
|
454
|
+
/** Absolute dotted path to this field inside the form data. Empty string at the root. */
|
|
455
|
+
path: string;
|
|
456
|
+
/** Resolved value-help descriptor for FK ref fields (`@db.rel.FK` → `@db.http.path`). */
|
|
457
|
+
valueHelp?: ValueHelpInfo;
|
|
458
|
+
/** Singular label for array fields (`@ui.form.label.singular`) — used in "Add <singular>" affordances. */
|
|
459
|
+
singularLabel?: string;
|
|
460
|
+
/** Stable input element id, suitable for `<label :for>`. Co-resolved with `errorId` / `descId` so a11y wiring is consistent. Always populated by AsField. */
|
|
461
|
+
inputId: string;
|
|
462
|
+
/** Stable id for the error/hint container. Pair with `aria-describedby` (already resolved as `ariaDescribedBy`). Always populated by AsField. */
|
|
463
|
+
errorId: string;
|
|
464
|
+
/** Stable id for the description container. Always populated by AsField. */
|
|
465
|
+
descId: string;
|
|
466
|
+
/**
|
|
467
|
+
* Stable id for the field's a11y status node — the screen-reader-only
|
|
468
|
+
* "modified" announcement rendered by `AsFieldShell`'s `status` slot.
|
|
469
|
+
* Always populated by AsField; a custom `status` slot that renders its own
|
|
470
|
+
* node must put this id on it so `aria-describedby` still resolves.
|
|
471
|
+
*
|
|
472
|
+
* Optional in the type (unlike the `inputId` / `errorId` / `descId` trio) so
|
|
473
|
+
* code that mounts `AsFieldShell` standalone against the pre-0.1.133 prop set
|
|
474
|
+
* keeps type-checking — the shell falls back to `` `${inputId}-status` ``.
|
|
475
|
+
*
|
|
476
|
+
* @since 0.1.133
|
|
477
|
+
*/
|
|
478
|
+
statusId?: string;
|
|
479
|
+
/**
|
|
480
|
+
* Pre-resolved `aria-describedby` target — `errorId` when error/hint is
|
|
481
|
+
* present, else `descId`; `statusId` is appended (space-separated) while the
|
|
482
|
+
* field is dirty, so AT reads the "modified" status together with the
|
|
483
|
+
* error/description. `undefined` when there is nothing to point at.
|
|
484
|
+
*/
|
|
485
|
+
ariaDescribedBy?: string;
|
|
486
|
+
/**
|
|
487
|
+
* Resolved currency code (post-sibling resolution).
|
|
488
|
+
*
|
|
489
|
+
* Resolution chain at AsField: `@db.amount.currency 'EUR'` literal →
|
|
490
|
+
* `@db.amount.currency.ref 'fieldName'` sibling-field read → `undefined`.
|
|
491
|
+
* Useful for tooltips/titles (e.g. hovering an AsDecimal shell shows
|
|
492
|
+
* "USD"). Note: when `prefix` is also resolved from currency, the
|
|
493
|
+
* `currencyCode` here is the symbolic identifier; `prefix` carries
|
|
494
|
+
* the locale-aware narrow symbol.
|
|
495
|
+
*/
|
|
496
|
+
currencyCode?: string;
|
|
497
|
+
/**
|
|
498
|
+
* Resolved unit-of-measure code (post-sibling resolution).
|
|
499
|
+
*
|
|
500
|
+
* Resolution chain at AsField: `@db.unit 'kg'` literal →
|
|
501
|
+
* `@db.unit.ref 'fieldName'` sibling-field read → `undefined`. Useful
|
|
502
|
+
* for tooltips. Note: when `suffix` is also resolved from `@db.unit*`,
|
|
503
|
+
* `unitCode` and `suffix` carry the same string.
|
|
504
|
+
*/
|
|
505
|
+
unitCode?: string;
|
|
506
|
+
/**
|
|
507
|
+
* Decimal scale storage cap (the DB column's fractional-digit limit) —
|
|
508
|
+
* raw second arg of `@db.column.precision precision, scale`. The
|
|
509
|
+
* composables pad outgoing strings to this; for display, use `scale`
|
|
510
|
+
* (which may be tighter due to currency natural digits).
|
|
511
|
+
*/
|
|
512
|
+
precisionScale?: number;
|
|
513
|
+
/**
|
|
514
|
+
* Resolved input prefix adornment.
|
|
515
|
+
*
|
|
516
|
+
* Resolution chain at AsField: explicit `@ui.form.prefix 'value'` →
|
|
517
|
+
* `@ui.form.prefix.ref 'fieldName'` sibling-field read → currency
|
|
518
|
+
* symbol (locale-narrow form, when currency is resolved) → `undefined`.
|
|
519
|
+
* Applied by AsInput, AsNumber, AsDecimal.
|
|
520
|
+
*/
|
|
521
|
+
prefix?: string;
|
|
522
|
+
/**
|
|
523
|
+
* Resolved input suffix adornment.
|
|
524
|
+
*
|
|
525
|
+
* Resolution chain at AsField: explicit `@ui.form.suffix 'value'` →
|
|
526
|
+
* `@ui.form.suffix.ref 'fieldName'` sibling-field read → unit code
|
|
527
|
+
* (resolved `unitCode`) → `undefined`. Applied by AsInput, AsNumber,
|
|
528
|
+
* AsDecimal.
|
|
529
|
+
*/
|
|
530
|
+
suffix?: string;
|
|
531
|
+
/**
|
|
532
|
+
* Effective display scale (fractional digits) — composables enforce
|
|
533
|
+
* this when editing decimals.
|
|
534
|
+
*
|
|
535
|
+
* Resolution: `min(currencyDecimals, precisionScale)` when currency is
|
|
536
|
+
* resolved, else `currencyDecimals` (currency only), else
|
|
537
|
+
* `precisionScale` (DB only), else `undefined`. Smaller than
|
|
538
|
+
* `precisionScale` is fine — storage stays at the DB cap, display
|
|
539
|
+
* truncates to this.
|
|
540
|
+
*/
|
|
541
|
+
scale?: number;
|
|
542
|
+
/**
|
|
543
|
+
* Whether AsField found at least one adornment-driving annotation on
|
|
544
|
+
* this field (`@db.amount.currency*`, `@db.unit*`, `@ui.form.prefix*`,
|
|
545
|
+
* `@ui.form.suffix*`). Used by AsNumber / AsDecimal to keep the
|
|
546
|
+
* merged-chrome shell visible even when a sibling-ref source is
|
|
547
|
+
* currently empty — without this flag, the shell would flicker as
|
|
548
|
+
* the user picks a source value.
|
|
549
|
+
*
|
|
550
|
+
* Always populated by AsField; defaults to `false` when no adornment
|
|
551
|
+
* annotation is present on the prop.
|
|
552
|
+
*/
|
|
553
|
+
hasAdornment?: boolean;
|
|
554
|
+
/**
|
|
555
|
+
* Whether this field has changed since the change-tracking baseline.
|
|
556
|
+
*
|
|
557
|
+
* `true` only when the enclosing `<AsForm>` has `track-changes` enabled AND
|
|
558
|
+
* this field's value differs from the baseline; `false` (or absent) when
|
|
559
|
+
* tracking is off. AsField resolves it from the change list and surfaces it
|
|
560
|
+
* here so default components — and custom swaps — can drive a visual hook
|
|
561
|
+
* (the default `AsFieldShell` paints a `data-dirty` attribute from it) without
|
|
562
|
+
* re-deriving the predicate. Granularity matches the change list: object /
|
|
563
|
+
* section containers light up via their leaves; whole-array fields exactly;
|
|
564
|
+
* an array-ITEM field stays `false` (the array container lights up instead).
|
|
565
|
+
*/
|
|
566
|
+
isDirty?: boolean;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Public emits contract for custom field components used with `AsForm` /
|
|
570
|
+
* `AsField`. Type your `defineEmits` against this interface so the
|
|
571
|
+
* action-button surface stays compatible with the framework.
|
|
572
|
+
*
|
|
573
|
+
* `_V` is reserved for forward-compat with value-typed emits in Phase 4
|
|
574
|
+
* (e.g. `(e: 'change-value', value: _V)`); the underscore prefix marks it
|
|
575
|
+
* as deliberately unused under both biome and eslint conventions.
|
|
576
|
+
*
|
|
577
|
+
* @typeParam _V - The field value type (reserved for future emits)
|
|
578
|
+
*/
|
|
579
|
+
interface TAsComponentEmits<_V = unknown> {
|
|
580
|
+
/**
|
|
581
|
+
* Action invocation — emitted by phantom action buttons. The form
|
|
582
|
+
* routes the named action through its `@action` handler.
|
|
583
|
+
*/
|
|
584
|
+
(e: "action", name: string): void;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Discriminated type for the `change` event emitted by `AsForm`.
|
|
588
|
+
*
|
|
589
|
+
* - `'update'` — leaf field value committed (blur)
|
|
590
|
+
* - `'array-add'` — array item added
|
|
591
|
+
* - `'array-remove'` — array item removed
|
|
592
|
+
* - `'union-switch'` — union variant switched
|
|
593
|
+
*/
|
|
594
|
+
type TAsChangeType = "update" | "array-add" | "array-remove" | "union-switch";
|
|
595
|
+
/**
|
|
596
|
+
* Type-to-component map for `AsForm`. Lists the built-in field types and
|
|
597
|
+
* accepts additional custom types via index signature. Every key is optional:
|
|
598
|
+
* a map may name only the types its forms use (a field whose type has no
|
|
599
|
+
* entry renders a "No component" notice).
|
|
600
|
+
*
|
|
601
|
+
* Use {@link createDefaultTypes} to get a pre-built map with all defaults.
|
|
602
|
+
*/
|
|
603
|
+
type TAsTypeComponents = {
|
|
604
|
+
text?: Component;
|
|
605
|
+
textarea?: Component;
|
|
606
|
+
password?: Component;
|
|
607
|
+
select?: Component;
|
|
608
|
+
multiselect?: Component;
|
|
609
|
+
tags?: Component;
|
|
610
|
+
radio?: Component;
|
|
611
|
+
checkbox?: Component;
|
|
612
|
+
paragraph?: Component;
|
|
613
|
+
action?: Component;
|
|
614
|
+
object?: Component;
|
|
615
|
+
array?: Component;
|
|
616
|
+
union?: Component;
|
|
617
|
+
tuple?: Component;
|
|
618
|
+
ref?: Component;
|
|
619
|
+
decimal?: Component;
|
|
620
|
+
number?: Component;
|
|
621
|
+
date?: Component;
|
|
622
|
+
datetime?: Component;
|
|
623
|
+
time?: Component;
|
|
624
|
+
} & Record<string, Component>;
|
|
625
|
+
/**
|
|
626
|
+
* Union context provided by `AsUnion` via `UNION_CONTEXT_KEY`.
|
|
627
|
+
* Consumed by `AsFieldShell` to render the variant picker inline with the
|
|
628
|
+
* item's own header.
|
|
629
|
+
*/
|
|
630
|
+
interface TAsUnionContext {
|
|
631
|
+
/** All available union variant branches. */
|
|
632
|
+
variants: FormUnionVariant[];
|
|
633
|
+
/** Reactive index of the currently selected variant. */
|
|
634
|
+
currentIndex: Ref<number>;
|
|
635
|
+
/** Switch to a different variant (rewrites model data). */
|
|
636
|
+
changeVariant: (index: number) => void;
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Public props contract for the standalone `AsCollapsible` section component.
|
|
640
|
+
*/
|
|
641
|
+
interface TAsCollapsibleProps {
|
|
642
|
+
title?: string;
|
|
643
|
+
description?: string;
|
|
644
|
+
level: number;
|
|
645
|
+
optional?: boolean;
|
|
646
|
+
optionalEnabled?: boolean;
|
|
647
|
+
path: string;
|
|
648
|
+
error?: string;
|
|
649
|
+
defaultOpen?: boolean;
|
|
650
|
+
hidden?: boolean;
|
|
651
|
+
arrayIndex?: number;
|
|
652
|
+
/**
|
|
653
|
+
* Whether the section this collapsible wraps has changed since the
|
|
654
|
+
* change-tracking baseline. Forwarded by the structured defaults
|
|
655
|
+
* (`AsObject` / `AsArray` / `AsTuple`) from their own `isDirty` prop, which
|
|
656
|
+
* `AsField` resolves from the change list. `AsCollapsible` paints
|
|
657
|
+
* `data-dirty=""` on its root and on its heading element ONLY — never on
|
|
658
|
+
* descendants — so a dirty container does not make every child label inside
|
|
659
|
+
* it look modified. Styling hook: `as-collapsible-section` /
|
|
660
|
+
* `as-collapsible-island` / `as-collapsible-title*` (see
|
|
661
|
+
* `@atscript/ui-styles`).
|
|
662
|
+
*
|
|
663
|
+
* @since 0.1.133
|
|
664
|
+
*/
|
|
665
|
+
isDirty?: boolean;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Slots exposed by `AsCollapsible` — all header slots render inside `<summary>`.
|
|
669
|
+
*/
|
|
670
|
+
interface TAsCollapsibleSlots {
|
|
671
|
+
"title-extras"(): unknown;
|
|
672
|
+
badges(): unknown;
|
|
673
|
+
actions(): unknown;
|
|
674
|
+
body(): unknown;
|
|
675
|
+
empty(): unknown;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* What a template ref to `<AsForm>` exposes. `TFormData` is the type of the
|
|
679
|
+
* form's `formData` container (`typeof formData`); `<AsForm>` is a generic
|
|
680
|
+
* component, so type the ref with this interface:
|
|
681
|
+
* `const asForm = ref<AsFormExposed<typeof formData>>()`.
|
|
682
|
+
*
|
|
683
|
+
* The change-tracking members need `track-changes`; without it they return
|
|
684
|
+
* empty (`isDirty` is `false`, `getPatch()` is `{}`).
|
|
685
|
+
*
|
|
686
|
+
* @since 0.1.182
|
|
687
|
+
*/
|
|
688
|
+
interface AsFormExposed<TFormData = any> extends Pick<AsFormPatchHandle, "getPatch" | "getChanges" | "isDirtyPath" | "rebase" | "rebaseOnto"> {
|
|
689
|
+
/** Validate and submit, as the submit button does: emits `submit` or `error` and returns the outcome. */
|
|
690
|
+
submit: () => TAsFormSubmitResult<TFormData>;
|
|
691
|
+
/** Fire a form action as its button would: emits `action` (or `unsupported-action`) with the normalized data, not validated. */
|
|
692
|
+
action: (name: string) => void;
|
|
693
|
+
/** Return the fields to a new form's values and clear all errors (also re-baselines change tracking). */
|
|
694
|
+
reset: () => Promise<void>;
|
|
695
|
+
/** Clear all error state (per-field and the submit-time map behind the badges). */
|
|
696
|
+
clearErrors: () => void;
|
|
697
|
+
/** Set error messages by path (e.g. mapping a server 400). */
|
|
698
|
+
setErrors: (errors: Record<string, string>) => void;
|
|
699
|
+
/** `true` when change tracking is on and the data differs from the baseline. */
|
|
700
|
+
readonly isDirty: boolean;
|
|
701
|
+
/** Per-field change list (empty when tracking is off). */
|
|
702
|
+
readonly changes: readonly FormFieldChange[];
|
|
703
|
+
}
|
|
704
|
+
//#endregion
|
|
705
|
+
export { useAsFormPatch as S, TFormFieldRegistration as _, TAsCollapsibleSlots as a, AsFormPatchHandle as b, TAsTypeComponents as c, TAsFormValue as d, UseAsFormOptions as f, TFormFieldCallbacks as g, TAsFormError as h, TAsCollapsibleProps as i, TAsUnionContext as l, useAsForm as m, TAsBaseComponentProps as n, TAsComponentEmits as o, UseAsFormReturn as p, TAsChangeType as r, TAsComponentProps as s, AsFormExposed as t, TAsFormSubmitResult as u, TFormRule as v, RebaseOntoResult as x, TFormState as y };
|