@foormjs/vue 0.2.3 → 0.2.5

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.
@@ -0,0 +1,266 @@
1
+ # Default Components — @foormjs/vue
2
+
3
+ > Built-in field components, what each renders, internal helpers, and how to use or override them.
4
+
5
+ ## Using Default Components
6
+
7
+ ### Option 1: Use `createDefaultTypes()` for all defaults
8
+
9
+ ```ts
10
+ import { createDefaultTypes } from '@foormjs/vue'
11
+
12
+ const types = createDefaultTypes()
13
+ ```
14
+
15
+ ### Option 2: Spread and override specific types
16
+
17
+ ```ts
18
+ import { createDefaultTypes } from '@foormjs/vue'
19
+ import MyInput from './components/MyInput.vue'
20
+ import MySelect from './components/MySelect.vue'
21
+
22
+ const types = { ...createDefaultTypes(), text: MyInput, select: MySelect }
23
+ ```
24
+
25
+ ### Option 3: Build from scratch (full control)
26
+
27
+ ```ts
28
+ import type { TFoormTypeComponents } from '@foormjs/vue'
29
+ import {
30
+ OoInput,
31
+ OoSelect,
32
+ OoRadio,
33
+ OoCheckbox,
34
+ OoParagraph,
35
+ OoAction,
36
+ OoObject,
37
+ OoArray,
38
+ OoUnion,
39
+ OoTuple,
40
+ } from '@foormjs/vue'
41
+
42
+ const types: TFoormTypeComponents = {
43
+ text: OoInput,
44
+ password: OoInput,
45
+ number: OoInput,
46
+ select: OoSelect,
47
+ radio: OoRadio,
48
+ checkbox: OoCheckbox,
49
+ paragraph: OoParagraph,
50
+ action: OoAction,
51
+ object: OoObject,
52
+ array: OoArray,
53
+ union: OoUnion,
54
+ tuple: OoTuple,
55
+ }
56
+ ```
57
+
58
+ ### Option 4: Add custom type keys
59
+
60
+ ```ts
61
+ const types = { ...createDefaultTypes(), textarea: MyTextarea, date: MyDatePicker }
62
+ ```
63
+
64
+ Use `@foorm.type 'textarea'` or `@foorm.type 'date'` in the schema to route to your component.
65
+
66
+ ### Option 5: Per-field named component override
67
+
68
+ Use `@foorm.component` in the schema + `components` prop on OoForm:
69
+
70
+ ```
71
+ // schema.as — @foorm.component takes priority over @foorm.type / auto-inferred type
72
+ @foorm.component 'StarRating'
73
+ rating?: number
74
+ ```
75
+
76
+ ```vue
77
+ <OoForm :types="types" :components="{ StarRating: MyStarRating }" ... />
78
+ ```
79
+
80
+ ## Default Type-to-Component Map
81
+
82
+ | Type key | Component | Schema trigger |
83
+ | ----------- | ----------- | -------------------------------------- |
84
+ | `text` | OoInput | `string` fields (default) |
85
+ | `password` | OoInput | `@foorm.type 'password'` |
86
+ | `number` | OoInput | `number` fields |
87
+ | `select` | OoSelect | `foorm.select` primitive |
88
+ | `radio` | OoRadio | `foorm.radio` primitive |
89
+ | `checkbox` | OoCheckbox | `boolean` / `foorm.checkbox` |
90
+ | `paragraph` | OoParagraph | `foorm.paragraph` phantom |
91
+ | `action` | OoAction | `foorm.action` phantom |
92
+ | `object` | OoObject | nested objects / `@foorm.title` groups |
93
+ | `array` | OoArray | `type[]` arrays |
94
+ | `union` | OoUnion | union types (`A \| B`) |
95
+ | `tuple` | OoTuple | tuple types `[A, B]` |
96
+
97
+ ## Responsibility Matrix — What Each Default Handles
98
+
99
+ | | OoInput/Select/Radio/Checkbox | OoObject | OoArray | OoUnion | OoTuple | OoParagraph | OoAction |
100
+ | ----------------------- | ----------------------------------------- | ---------------------- | ------------------------------------- | -------------------- | ---------------------- | ----------- | -------------- |
101
+ | **Label** | via OoFieldShell | — | — | — | — | — | — |
102
+ | **Title** | — | OoStructuredHeader | OoStructuredHeader | — | OoStructuredHeader | — | — |
103
+ | **Description** | via OoFieldShell | — | — | — | — | — | — |
104
+ | **Hint** | via OoFieldShell | — | — | — | — | — | — |
105
+ | **Error** | via OoFieldShell | inline div | inline div | — | inline div | — | — |
106
+ | **Remove/clear button** | via OoFieldShell | OoStructuredHeader | — | — | OoStructuredHeader | — | — |
107
+ | **Variant picker** | via OoFieldShell | OoStructuredHeader | OoStructuredHeader | — (provides context) | OoStructuredHeader | — | — |
108
+ | **Optional N/A** | via OoFieldShell (OoNoData) | OoNoData | OoNoData | OoNoData | OoNoData | — | — |
109
+ | **Sub-field iteration** | — | OoIterator | OoField per item | OoField (inner) | OoField per pos | — | — |
110
+ | **Composables** | useConsumeUnionContext (via OoFieldShell) | useConsumeUnionContext | useFoormArray, useConsumeUnionContext | useFoormUnion | useConsumeUnionContext | — | — |
111
+ | **Change events** | — (OoField handles) | — | via useFoormArray | via useFoormUnion | — | — | emits `action` |
112
+
113
+ ## Default Component Details
114
+
115
+ ### OoInput (text, password, number)
116
+
117
+ Wraps `<input>` in OoFieldShell. The `type` prop determines the HTML input type.
118
+
119
+ - **Label/description/hint/error:** Delegated to OoFieldShell
120
+ - **Remove button:** Delegated to OoFieldShell (renders when `onRemove` provided)
121
+ - **Optional N/A:** Delegated to OoFieldShell
122
+ - **Variant picker:** Delegated to OoFieldShell (renders inline if union context present)
123
+ - **Bindings:** `v-model` on input, `@blur` → `onBlur`
124
+ - **Accessibility:** `aria-required`, `aria-invalid`, `aria-describedby` (via OoFieldShell)
125
+
126
+ ### OoSelect
127
+
128
+ Wraps `<select>` with `<option>` per entry in OoFieldShell.
129
+
130
+ - **All chrome:** Delegated to OoFieldShell (same as OoInput)
131
+ - **Options:** Uses `optKey()`/`optLabel()` from `@foormjs/atscript`
132
+ - **Placeholder:** Disabled first `<option>` when `placeholder` prop present
133
+ - **Bindings:** `v-model` on select, `@change` and `@blur` both call `onBlur`
134
+
135
+ ### OoRadio
136
+
137
+ Wraps radio group in OoFieldShell with custom header slot.
138
+
139
+ - **All chrome:** Delegated to OoFieldShell
140
+ - **Custom header:** Renders label + description in OoFieldShell's `#header` slot (not as default label)
141
+ - **Radios:** `v-for` over options, grouped by `name` prop, `role="radiogroup"`
142
+
143
+ ### OoCheckbox
144
+
145
+ Wraps checkbox in OoFieldShell with custom header slot.
146
+
147
+ - **All chrome:** Delegated to OoFieldShell
148
+ - **Custom header:** Renders label only when optional && not enabled (in `#header` slot)
149
+ - **Label:** Wraps checkbox input for click area
150
+ - **Description:** In `#after-input` slot (after the checkbox label)
151
+ - **Binding:** `:checked` + `@change` manual update + `onBlur()`
152
+
153
+ ### OoParagraph (phantom)
154
+
155
+ Simple `<p>` tag displaying `value` prop. No OoFieldShell, no model, no validation. Respects `v-show="!hidden"`.
156
+
157
+ ### OoAction (phantom)
158
+
159
+ Button that emits `action` event with `altAction.id`. No OoFieldShell, no model, no validation. OoField catches the `action` emit and forwards to OoForm.
160
+
161
+ ### OoObject
162
+
163
+ Container for nested object fields.
164
+
165
+ - **Title:** OoStructuredHeader (h2 at level 0, h3 at deeper levels)
166
+ - **Remove button:** OoStructuredHeader (when `onRemove` provided)
167
+ - **Variant picker:** OoStructuredHeader (when union context has multiple variants)
168
+ - **Optional N/A:** OoNoData placeholder
169
+ - **Sub-fields:** OoIterator with the nested `objectDef`
170
+ - **Composables:** `useConsumeUnionContext()` — reads and clears union context
171
+ - **Array index:** `formatIndexedLabel()` for titles like "Address #1"
172
+
173
+ ### OoArray
174
+
175
+ List container with add/remove buttons.
176
+
177
+ - **Title:** OoStructuredHeader
178
+ - **Items:** `<OoField>` per item (NOT OoIterator) with stable keys from `useFoormArray`
179
+ - **Remove:** Passed as `onRemove` prop to each item's OoField
180
+ - **Add button:** Simple button for scalar items; dropdown with variant options for union items (via `useDropdown()`)
181
+ - **Variant picker:** OoStructuredHeader (when union context present)
182
+ - **Optional N/A:** OoNoData placeholder
183
+ - **Composables:** `useFoormArray()` (manages state + emits `array-add`/`array-remove`), `useConsumeUnionContext()`, `useDropdown()`
184
+ - **Constraints:** `canAdd` respects `@expect.maxLength`, `canRemove` respects `@expect.minLength`
185
+
186
+ ### OoUnion
187
+
188
+ Variant selector that provides context to children.
189
+
190
+ - **Variant management:** `useFoormUnion()` — manages variant index, data stashing (saves/restores data on switch)
191
+ - **Provides:** `__foorm_union` context `{ variants, currentIndex, changeVariant }` — consumed by the inner field's component (object/tuple renders variant picker in its header)
192
+ - **Inner field:** Renders `<OoField :key="localUnionIndex">` for the selected variant
193
+ - **Optional N/A:** OoNoData with variant picker dropdown for multiple variants
194
+ - **Does NOT render:** title, label, variant picker, remove button (delegates all to inner field)
195
+ - **Passes through:** `onRemove`/`canRemove`/`removeLabel`/`arrayIndex` to the inner OoField
196
+
197
+ ### OoTuple
198
+
199
+ Fixed-length field list.
200
+
201
+ - **Title:** OoStructuredHeader
202
+ - **Items:** `<OoField>` per position from `tupleField.itemFields` (fixed count, no add/remove)
203
+ - **Remove button:** OoStructuredHeader (when `onRemove` provided)
204
+ - **Variant picker:** OoStructuredHeader (when union context present)
205
+ - **Optional N/A:** OoNoData placeholder
206
+ - **Composables:** `useConsumeUnionContext()`
207
+
208
+ ## Internal Components (Not Exported)
209
+
210
+ Used by default components. Custom components must handle these responsibilities themselves.
211
+
212
+ ### OoFieldShell
213
+
214
+ Wrapper for leaf field components. Provides:
215
+
216
+ - Header row: label + required indicator + optional clear button + remove button
217
+ - Inline variant picker (when `__foorm_union` context exists with multiple variants)
218
+ - Optional N/A state (OoNoData)
219
+ - Input slot for the actual element
220
+ - Error/hint display
221
+ - Accessibility IDs: `inputId`, `errorId`, `descId`
222
+ - Slots: `#header`, `#default` (input), `#after-input`
223
+
224
+ ### OoStructuredHeader
225
+
226
+ Header for structural components (object, array, tuple). Provides:
227
+
228
+ - Title: `<h2>` at level 0, `<h3>` at deeper levels
229
+ - Inline variant picker (OoVariantPicker) when union context has multiple variants
230
+ - Optional clear button
231
+ - Remove button (when `onRemove` provided)
232
+ - Flexbox layout: title left, buttons right
233
+
234
+ ### OoNoData
235
+
236
+ Clickable placeholder for optional fields in N/A state.
237
+
238
+ - Dashed border with "No Data" text
239
+ - Hover state: "Edit" text
240
+ - Click/keyboard triggers `onEdit` callback
241
+
242
+ ### OoVariantPicker
243
+
244
+ Dropdown for switching union variants.
245
+
246
+ - Three-dot icon button
247
+ - Dropdown menu listing all variants
248
+ - Active variant highlighted
249
+ - Uses `useDropdown()` for open/close + click-outside
250
+
251
+ ## Styles
252
+
253
+ ```ts
254
+ import '@foormjs/vue/styles' // optional — provides CSS for default components
255
+ ```
256
+
257
+ CSS classes use `oo-` prefix: `oo-form`, `oo-field`, `oo-object`, `oo-array`, etc.
258
+
259
+ ## Gotchas
260
+
261
+ - Internal components (OoFieldShell, OoStructuredHeader, OoNoData, OoVariantPicker) are NOT exported — custom components must handle label/error/hint/N/A rendering themselves
262
+ - OoInput serves three type keys (`text`, `password`, `number`) — the `type` prop determines behavior
263
+ - OoObject without `@foorm.title` still renders as a container — just without a visible title
264
+ - OoArray uses `<OoField>` per item (not OoIterator) because it needs per-item remove props and stable keys
265
+ - OoUnion renders NO chrome — it provides context and delegates everything to the inner variant's component
266
+ - Default styles are optional but recommended when using default components
@@ -0,0 +1,175 @@
1
+ # Rendering Architecture — @foormjs/vue
2
+
3
+ > OoField internals, component resolution, nesting levels, provide/inject keys, and the allStatic optimization.
4
+
5
+ ## Rendering Chain
6
+
7
+ ```
8
+ OoForm (provides context, renders rootField)
9
+ └── OoField(def.rootField) → types['object'] → OoObject
10
+ └── OoIterator (iterates def.fields)
11
+ ├── OoField (leaf) → types['text'] → OoInput / your component
12
+ ├── OoField (object with @foorm.title) → types['object'] → OoObject
13
+ │ └── OoIterator → OoField ...
14
+ ├── OoField (array) → types['array'] → OoArray
15
+ │ └── OoField (per item via useFoormArray) → ...
16
+ ├── OoField (union) → types['union'] → OoUnion
17
+ │ └── OoField (selected variant) → ...
18
+ └── OoField (tuple) → types['tuple'] → OoTuple
19
+ └── OoField (per position) → ...
20
+ ```
21
+
22
+ ## OoField — Universal Renderer
23
+
24
+ `OoField` is the core of the rendering pipeline. For each field it:
25
+
26
+ 1. **Injects** types, components, errors, action handler, change handler from parent OoForm
27
+ 2. **Resolves component**: `@foorm.component` → `components[name]`, else → `types[field.type]`
28
+ 3. **Resolves all field props** (label, placeholder, disabled, hidden, options, etc.)
29
+ 4. **Tracks nesting level** via `__foorm_level` inject/provide
30
+ 5. **Renders** via `<component :is="resolvedComponent" v-bind="componentProps" />`
31
+
32
+ ### Two-Path Optimization
33
+
34
+ OoField detects whether a field has any computed annotations:
35
+
36
+ - **`allStatic` fast path** — no `@foorm.fn.*` or `@foorm.validate` annotations. All props resolved once at setup, no Vue `computed()` refs created. Significantly reduces reactive overhead.
37
+ - **Dynamic path** — per-property static/dynamic detection. Only properties with `@foorm.fn.*` become computed refs; static props remain plain values.
38
+
39
+ The `allStatic` flag is set by `createFoormDef` via `hasComputedAnnotations()`.
40
+
41
+ ### Lazy Scope Construction
42
+
43
+ OoField builds scopes in two phases (dual-scope pattern):
44
+
45
+ 1. **`baseScope`** — `{ v, data, context }` — resolves constraints (disabled, hidden, readonly)
46
+ 2. **`fullScope`** — `{ v, data, context, entry }` — resolves display props (label, placeholder, options)
47
+
48
+ This prevents circular dependency: options can reference constraint state via `entry.disabled`.
49
+
50
+ ### Component Resolution Order
51
+
52
+ 1. `@foorm.component` annotation value → lookup in `components` prop
53
+ 2. `types[field.type]` → lookup in `types` prop
54
+ 3. If not found → renders error div: `[label] No component for type "X"`
55
+
56
+ ## OoIterator
57
+
58
+ Iterates `def.fields` and renders `<OoField>` per field. Used by object and tuple components.
59
+
60
+ ```vue
61
+ <OoIterator :def="objectDef" />
62
+
63
+ <!-- With path prefix (for array items) -->
64
+ <OoIterator :def="objectDef" path-prefix="[0]" />
65
+
66
+ <!-- With remove props (passed through to child fields) -->
67
+ <OoIterator
68
+ :def="objectDef"
69
+ :on-remove="onRemove"
70
+ :can-remove="canRemove"
71
+ :remove-label="removeLabel"
72
+ />
73
+ ```
74
+
75
+ **Props:**
76
+
77
+ - `def: FoormDef` — form definition to iterate
78
+ - `pathPrefix?: string` — custom path segment (e.g., `[0]` for array items)
79
+ - `onRemove?`, `canRemove?`, `removeLabel?` — passed through to child `OoField`
80
+
81
+ ## Nesting Level Tracking
82
+
83
+ `OoField` manages nesting depth via `__foorm_level` inject/provide:
84
+
85
+ - Root object = level 0 (inject default: -1, increments for object/array/tuple types)
86
+ - Each nested object/array/tuple increments the level
87
+ - **Union fields do NOT increment** — prevents double-counting (union → inner object would be +2 otherwise)
88
+
89
+ Level-aware rendering in default components:
90
+
91
+ - Level 0: title rendered as `<h2>`, no left border
92
+ - Level > 0: title rendered as `<h3>`, left border + padding
93
+
94
+ ## Provide/Inject Keys
95
+
96
+ ### Set by OoForm
97
+
98
+ | Key | Type | Description |
99
+ | ------------------------ | ---------------------------------------- | -------------------------------- |
100
+ | `__foorm_root_data` | `ComputedRef<TFormData>` | Reactive form data |
101
+ | `__foorm_path_prefix` | `ComputedRef<string>` | Current path prefix ('' at root) |
102
+ | `__foorm_types` | `ComputedRef<TFoormTypeComponents>` | Type-to-component map |
103
+ | `__foorm_components` | `ComputedRef<Record<string, Component>>` | Named component map |
104
+ | `__foorm_errors` | `ComputedRef<Record<string, string>>` | External errors |
105
+ | `__foorm_action_handler` | `(name, data) => void` | Action event forwarder |
106
+ | `__foorm_change_handler` | `(type, path, value) => void` | Change event emitter |
107
+
108
+ ### Set by OoField
109
+
110
+ | Key | Type | Description |
111
+ | --------------------- | --------------------- | ------------------------- |
112
+ | `__foorm_path_prefix` | `ComputedRef<string>` | Updated path for children |
113
+ | `__foorm_level` | `number` | Incremented nesting level |
114
+
115
+ ### Set by useFoormForm (from @foormjs/composables)
116
+
117
+ | Key | Type | Description |
118
+ | ---------------------- | ------------------------ | --------------------------------- |
119
+ | `__foorm_form` | `TFoormState` | Form state (validation, registry) |
120
+ | `__foorm_form_data` | `ComputedRef<TFormData>` | Form data wrapper |
121
+ | `__foorm_form_context` | `ComputedRef<TContext>` | External context |
122
+
123
+ ### Set by useFoormUnion
124
+
125
+ | Key | Type | Description |
126
+ | --------------- | -------------------- | ------------------------------- |
127
+ | `__foorm_union` | `TFoormUnionContext` | Variant state + change function |
128
+
129
+ ## useFoormContext (Internal)
130
+
131
+ Internal composable used by default components to access form state and build scopes.
132
+
133
+ ```ts
134
+ const {
135
+ foormState, // TFoormState
136
+ rootFormData, // () => Record<string, unknown>
137
+ pathPrefix, // ComputedRef<string>
138
+ formContext, // ComputedRef<Record<string, unknown>>
139
+ joinPath, // (segment | fn) => ComputedRef<string>
140
+ buildPath, // (segment) => string
141
+ getByPath, // (path) => unknown
142
+ setByPath, // (path, value) => void
143
+ buildScope, // (v?, entry?) => TFoormFnScope
144
+ } = useFoormContext('MyComponent')
145
+ ```
146
+
147
+ Not publicly exported — use `getByPath`/`setByPath` from `@foormjs/atscript` directly in custom components.
148
+
149
+ ## Change Events
150
+
151
+ OoField and composables emit change events via `__foorm_change_handler`:
152
+
153
+ | Source | Type | When |
154
+ | ------------- | ---------------- | ----------------------------------------- |
155
+ | OoField | `'update'` | On blur, if value changed since last blur |
156
+ | useFoormArray | `'array-add'` | After `addItem()` |
157
+ | useFoormArray | `'array-remove'` | After `removeItem()` |
158
+ | useFoormUnion | `'union-switch'` | After `changeVariant()` |
159
+
160
+ Note: `'update'` fires on blur (not on every keystroke) to reduce noise.
161
+
162
+ ## Best Practices
163
+
164
+ - Use `OoIterator` in custom object components — don't manually iterate `objectDef.fields`
165
+ - Pass through `onRemove`/`canRemove`/`removeLabel` from your component to `OoField` or `OoIterator`
166
+ - Don't access provide/inject keys directly in custom components — use the composables (`useFoormArray`, etc.)
167
+ - The `allStatic` optimization is automatic — no action needed from custom components
168
+
169
+ ## Gotchas
170
+
171
+ - Union fields provide `__foorm_path_prefix` but NOT an incremented `__foorm_level` — prevents double nesting visuals
172
+ - `OoIterator` provides its own `__foorm_path_prefix` — nested iterators correctly stack path segments
173
+ - `__foorm_level` defaults to `-1` when injected, so the first object/array increments it to `0`
174
+ - Change events are batched per-field — multiple rapid changes to the same field only emit once on blur
175
+ - Missing component for a field type renders an error div, not an exception — check console for warnings
@@ -1,3 +0,0 @@
1
- (function(k,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(k=typeof globalThis<"u"?globalThis:k||self,e(k.index={},k.Vue))})(this,function(k,e){"use strict";var we=Object.defineProperty;var Ae=(k,e,V)=>e in k?we(k,e,{enumerable:!0,configurable:!0,writable:!0,value:V}):k[e]=V;var v=(k,e,V)=>Ae(k,typeof e!="symbol"?e+"":e,V);function V(n,t){return typeof n=="function"?n(t):n}const O=new Set(["action","paragraph"]);function U(n){var t;const o={};for(const s of n)if(!O.has(s.type)){const a={v:void 0,data:o,context:{},entry:{field:s.field,type:s.type,component:s.component,name:s.name||s.field}};o[s.field]=(t=V(s.value,a))!==null&&t!==void 0?t:void 0}return o}function q(n,t){return n.fields.some(o=>o.altAction===t)}function M(n,t){if(!n)return;const o={};for(const[s,a]of Object.entries(n))o[s]=V(a,t);return o}const I=e.defineComponent({__name:"VuilessField",props:e.mergeModels({rules:{}},{modelValue:{},modelModifiers:{}}),emits:["update:modelValue"],setup(n){const t=n,o=e.useModel(n,"modelValue"),s=e.inject("vuiless"),a=e.ref(),l=e.ref(!1),i=e.ref(!1),d=e.computed(()=>{var p;if((p=s==null?void 0:s.value)!=null&&p.firstValidation)switch(s.value.firstValidation){case"on-change":return s.value.firstSubmitHappened||l.value;case"touched-on-blur":return s.value.firstSubmitHappened||i.value&&l.value;case"on-blur":return s.value.firstSubmitHappened||i.value;case"on-submit":return s.value.firstSubmitHappened;case"none":return!1}return!1}),f=e.computed(()=>{if(d.value||a.value)return u()});e.watch([o],()=>{a.value=void 0,l.value=!0}),e.onUnmounted(()=>{var p;(p=s==null?void 0:s.value)==null||p.unregister(e.getCurrentInstance())}),s!=null&&s.value&&s.value.register(e.getCurrentInstance(),{validate:()=>(a.value=u(),a.value||!0),clearErrors:()=>{l.value=!1,i.value=!1,a.value=void 0},reset:()=>{o.value=""}});function u(){var p,m,S;if((p=t.rules)!=null&&p.length)for(const g of t.rules){const x=g(o.value,(m=s==null?void 0:s.value)==null?void 0:m.formData,(S=s==null?void 0:s.value)==null?void 0:S.formContext);if(x!==!0)return x||"Wrong value"}}function h(){i.value=!0}const y={v:e.computed({get:()=>o.value,set:p=>o.value=p})};return(p,m)=>{var S,g;return e.renderSlot(p.$slots,"default",{onBlur:h,error:f.value,formData:(S=e.unref(s))==null?void 0:S.formData,formContext:(g=e.unref(s))==null?void 0:g.formContext,model:y.v})}}}),z=e.defineComponent({__name:"VuilessForm",props:{formData:{},formContext:{},firstValidation:{default:"on-change"}},emits:["submit"],setup(n,{emit:t}){const o=n,s=t,a=new Map,l=e.ref(!1),i=e.computed(()=>({firstSubmitHappened:l.value,firstValidation:o.firstValidation,register:(h,y)=>{a.set(h,y)},unregister:h=>a.delete(h),formData:o.formData,formContext:o.formContext}));e.provide("vuiless",i);function d(){l.value=!1;for(const{clearErrors:h}of a.values())h()}async function f(){for(const{reset:h}of a.values())h();await e.nextTick(),d()}function u(){l.value=!0;let h=!1;if(o.firstValidation!=="none")for(const{validate:y}of a.values())y()!==!0&&(h=!0);h||s("submit",o.formData)}return(h,y)=>(e.openBlock(),e.createElementBlock("form",{onSubmit:e.withModifiers(u,["prevent"])},[e.renderSlot(h.$slots,"default",{clearErrors:d,reset:f})],32))}}),F=e.defineComponent({__name:"oo-field",props:{field:{},type:{},component:{},autocomplete:{},altAction:{},order:{},name:{},label:{type:[String,Function]},description:{type:[String,Function]},hint:{type:[String,Function]},placeholder:{type:[String,Function]},optional:{type:[Boolean,Function]},disabled:{type:[Boolean,Function]},hidden:{type:[Boolean,Function]},readonly:{type:[Boolean,Function]},classes:{type:[String,Object,Function]},styles:{type:[String,Object,Function]},options:{type:[Array,Function]},attrs:{},value:{type:Function},validators:{},maxLength:{},minLength:{},min:{},max:{},error:{}},setup(n){const t=n,o=e.inject("vuiless");function s(c,b,B){return typeof c=="function"?e.computed(()=>c(b.value)):c??B}const a=c=>typeof c=="object"&&c!==null&&"value"in c?c.value:c,l=e.computed(()=>({v:o.value.formData[t.field],data:o.value.formData,context:o.value.formContext??{},entry:void 0})),i=s(t.optional,l,!1),d=s(t.disabled,l,!1),f=s(t.hidden,l,!1),u=s(t.readonly,l,!1),h=e.computed(()=>!a(i)),y=e.computed(()=>({v:o.value.formData[t.field],data:o.value.formData,context:o.value.formContext??{},entry:{field:t.field,type:t.type,component:t.component,name:t.name||t.field,optional:a(i),disabled:a(d),hidden:a(f),readonly:a(u)}})),p=s(t.label,y,void 0),m=s(t.description,y,void 0),S=s(t.hint,y,void 0),g=s(t.placeholder,y,void 0),x=s(t.options,y,void 0),_=s(t.styles,y,void 0),r=e.computed(()=>{const c=typeof t.classes=="function"?t.classes(y.value):t.classes;return typeof c=="string"?{[c]:!0,disabled:a(d),required:!a(i)}:{...c,disabled:a(d),required:!a(i)}});function C(c,b){return{...r.value,error:!!c||!!b}}const $=e.computed(()=>M(t.attrs,y.value));if(typeof t.value=="function"){const c=e.computed(()=>{if(a(u))return t.value(y.value)});e.watch(c,b=>{b!==void 0&&a(u)&&(o.value.formData[t.field]=b)},{immediate:!0})}const w=t.validators.map(c=>(b,B,P)=>c({v:b,data:B,context:P??{},entry:y.value.entry}));return(c,b)=>(e.openBlock(),e.createBlock(e.unref(I),{modelValue:e.unref(o).formData[t.field],"onUpdate:modelValue":b[0]||(b[0]=B=>e.unref(o).formData[t.field]=B),rules:e.unref(w)},{default:e.withCtx(B=>[e.renderSlot(c.$slots,"default",{onBlur:B.onBlur,error:n.error||B.error,model:B.model,formData:e.unref(o).formData,formContext:e.unref(o).formContext,label:e.unref(p),description:e.unref(m),hint:e.unref(S),placeholder:e.unref(g),classes:C(n.error,B.error),styles:e.unref(_),optional:e.unref(i),disabled:e.unref(d),hidden:e.unref(f),readonly:e.unref(u),type:n.type,altAction:n.altAction,component:n.component,vName:n.name,field:n.field,options:e.unref(x),maxLength:n.maxLength,required:h.value,autocomplete:n.autocomplete,attrs:$.value})]),_:3},8,["modelValue","rules"]))}}),H={key:0},R={key:1},G={key:0},K=["onUpdate:modelValue","onBlur","placeholder","autocomplete","name","type","disabled","readonly"],W={class:"oo-error-slot"},X={key:4},Y={key:0},Q=["onUpdate:modelValue","onBlur","name","disabled","readonly"],J={key:0,value:"",disabled:""},Z=["value"],ee={class:"oo-error-slot"},te={class:"oo-field-label"},oe={key:0},ne={class:"oo-radio-group"},re=["value","onUpdate:modelValue","onBlur","name","disabled","readonly"],se={class:"oo-error-slot"},ae=["onUpdate:modelValue","onBlur","name","disabled","readonly"],le={key:0},ie={class:"oo-error-slot"},ce=["onClick"],pe={key:9},de=["disabled"],ue=e.defineComponent({__name:"oo-form",props:{form:{},formData:{},formContext:{},firstValidation:{},components:{},types:{},errors:{}},emits:["submit","action","unsupported-action"],setup(n,{emit:t}){const o=n,s=e.ref({}),a=e.computed(()=>o.formData||s.value),l=e.computed(()=>({v:void 0,data:a.value,context:o.formContext??{},entry:void 0})),i=e.computed(()=>V(o.form.title,l.value)),d=e.computed(()=>V(o.form.submit.text,l.value)),f=e.computed(()=>V(o.form.submit.disabled,l.value));function u(m){q(o.form,m)?h("action",m,a.value):h("unsupported-action",m,a.value)}const h=t;function y(m){return typeof m=="string"?m:m.key}function p(m){return typeof m=="string"?m:m.label}return(m,S)=>(e.openBlock(),e.createBlock(e.unref(z),{"first-validation":n.firstValidation,onSubmit:S[0]||(S[0]=g=>h("submit",g)),"form-data":a.value,"form-context":n.formContext},{default:e.withCtx(g=>[e.renderSlot(m.$slots,"form.header",{clearErrors:g.clearErrors,reset:g.reset,title:i.value,formContext:n.formContext,disabled:f.value},()=>[i.value?(e.openBlock(),e.createElementBlock("h2",H,e.toDisplayString(i.value),1)):e.createCommentVNode("",!0)]),e.renderSlot(m.$slots,"form.before",{clearErrors:g.clearErrors,reset:g.reset}),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.form.fields,x=>{var _;return e.openBlock(),e.createBlock(F,e.mergeProps({key:x.field},{ref_for:!0},x,{error:(_=n.errors)==null?void 0:_[x.field]}),{default:e.withCtx(r=>[e.renderSlot(m.$slots,`field:${r.type}`,e.mergeProps({ref_for:!0},r),()=>{var C,$,w;return[x.component&&((C=o.components)!=null&&C[x.component])?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.components[x.component]),e.mergeProps({key:0,"on-blur":r.onBlur,error:r.error,model:r.model,"form-data":r.formData,"form-context":r.formContext,label:r.label,description:r.description,hint:r.hint,placeholder:r.placeholder,class:r.classes,style:r.styles,optional:r.optional,required:!r.required,disabled:r.disabled,hidden:r.hidden,type:r.type,"alt-action":r.altAction,name:r.vName,field:r,options:r.options,"max-length":r.maxLength,autocomplete:r.autocomplete,onAction:u},{ref_for:!0},r.attrs,{modelValue:r.model.value,"onUpdate:modelValue":c=>r.model.value=c}),null,16,["on-blur","error","model","form-data","form-context","label","description","hint","placeholder","class","style","optional","required","disabled","hidden","type","alt-action","name","field","options","max-length","autocomplete","modelValue","onUpdate:modelValue"])):x.component&&!(($=o.components)!=null&&$[x.component])?(e.openBlock(),e.createElementBlock("div",R," ["+e.toDisplayString(r.label)+'] Component "'+e.toDisplayString(r.component)+'" not supplied ',1)):(w=o.types)!=null&&w[x.type]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.types[x.type]),e.mergeProps({key:2,"on-blur":r.onBlur,error:r.error,model:r.model,"form-data":r.formData,"form-context":r.formContext,label:r.label,description:r.description,hint:r.hint,placeholder:r.placeholder,class:r.classes,style:r.styles,optional:r.optional,required:!r.required,disabled:r.disabled,hidden:r.hidden,type:r.type,"alt-action":r.altAction,name:r.vName,field:r,options:r.options,"max-length":r.maxLength,autocomplete:r.autocomplete,onAction:u},{ref_for:!0},r.attrs,{modelValue:r.model.value,"onUpdate:modelValue":c=>r.model.value=c}),null,16,["on-blur","error","model","form-data","form-context","label","description","hint","placeholder","class","style","optional","required","disabled","hidden","type","alt-action","name","field","options","max-length","autocomplete","modelValue","onUpdate:modelValue"])):["text","password","number"].includes(r.type)?e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:3,class:e.normalizeClass(["oo-default-field",r.classes])},[e.createElementVNode("label",null,e.toDisplayString(r.label),1),r.description?(e.openBlock(),e.createElementBlock("span",G,e.toDisplayString(r.description),1)):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("input",e.mergeProps({"onUpdate:modelValue":c=>r.model.value=c,onBlur:r.onBlur,placeholder:r.placeholder,autocomplete:r.autocomplete,name:r.vName,type:r.type,disabled:r.disabled,readonly:r.readonly},{ref_for:!0},r.attrs),null,16,K),[[e.vModelDynamic,r.model.value]]),e.createElementVNode("div",W,e.toDisplayString(r.error||r.hint),1)],2)),[[e.vShow,!r.hidden]]):r.type==="paragraph"?(e.openBlock(),e.createElementBlock("p",X,e.toDisplayString(r.description),1)):r.type==="select"?e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:5,class:e.normalizeClass(["oo-default-field",r.classes])},[e.createElementVNode("label",null,e.toDisplayString(r.label),1),r.description?(e.openBlock(),e.createElementBlock("span",Y,e.toDisplayString(r.description),1)):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("select",e.mergeProps({"onUpdate:modelValue":c=>r.model.value=c,onBlur:r.onBlur,name:r.vName,disabled:r.disabled,readonly:r.readonly},{ref_for:!0},r.attrs),[r.placeholder?(e.openBlock(),e.createElementBlock("option",J,e.toDisplayString(r.placeholder),1)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.options,c=>(e.openBlock(),e.createElementBlock("option",{key:y(c),value:y(c)},e.toDisplayString(p(c)),9,Z))),128))],16,Q),[[e.vModelSelect,r.model.value]]),e.createElementVNode("div",ee,e.toDisplayString(r.error||r.hint),1)],2)),[[e.vShow,!r.hidden]]):r.type==="radio"?e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:6,class:e.normalizeClass(["oo-default-field oo-radio-field",r.classes])},[e.createElementVNode("span",te,e.toDisplayString(r.label),1),r.description?(e.openBlock(),e.createElementBlock("span",oe,e.toDisplayString(r.description),1)):e.createCommentVNode("",!0),e.createElementVNode("div",ne,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.options,c=>(e.openBlock(),e.createElementBlock("label",{key:y(c)},[e.withDirectives(e.createElementVNode("input",e.mergeProps({type:"radio",value:y(c),"onUpdate:modelValue":b=>r.model.value=b,onBlur:r.onBlur,name:r.vName,disabled:r.disabled,readonly:r.readonly},{ref_for:!0},r.attrs),null,16,re),[[e.vModelRadio,r.model.value]]),e.createTextVNode(" "+e.toDisplayString(p(c)),1)]))),128))]),e.createElementVNode("div",se,e.toDisplayString(r.error||r.hint),1)],2)),[[e.vShow,!r.hidden]]):r.type==="checkbox"?e.withDirectives((e.openBlock(),e.createElementBlock("div",{key:7,class:e.normalizeClass(["oo-default-field oo-checkbox-field",r.classes])},[e.createElementVNode("label",null,[e.withDirectives(e.createElementVNode("input",e.mergeProps({type:"checkbox","onUpdate:modelValue":c=>r.model.value=c,onBlur:r.onBlur,name:r.vName,disabled:r.disabled,readonly:r.readonly},{ref_for:!0},r.attrs),null,16,ae),[[e.vModelCheckbox,r.model.value]]),e.createTextVNode(" "+e.toDisplayString(r.label),1)]),r.description?(e.openBlock(),e.createElementBlock("span",le,e.toDisplayString(r.description),1)):e.createCommentVNode("",!0),e.createElementVNode("div",ie,e.toDisplayString(r.error||r.hint),1)],2)),[[e.vShow,!r.hidden]]):r.type==="action"?(e.openBlock(),e.createElementBlock("div",{key:8,class:e.normalizeClass(["oo-default-field oo-action-field",r.classes])},[e.createElementVNode("button",{type:"button",onClick:c=>u(r.altAction)},e.toDisplayString(r.label),9,ce)],2)):(e.openBlock(),e.createElementBlock("div",pe," ["+e.toDisplayString(r.label)+'] Not supported field type "'+e.toDisplayString(r.type)+'" '+e.toDisplayString(r.component),1))]})]),_:2},1040,["error"])}),128)),e.renderSlot(m.$slots,"form.after",{clearErrors:g.clearErrors,reset:g.reset,disabled:f.value,formContext:n.formContext}),e.renderSlot(m.$slots,"form.submit",{disabled:f.value,text:d.value,clearErrors:g.clearErrors,reset:g.reset,formContext:n.formContext},()=>[e.createElementVNode("button",{disabled:f.value},e.toDisplayString(d.value),9,de)]),e.renderSlot(m.$slots,"form.footer",{disabled:f.value,clearErrors:g.clearErrors,reset:g.reset,formContext:n.formContext})]),_:3},8,["first-validation","form-data","form-context"]))}}),me={global:null,process:null,Buffer:null,require:null,__filename:null,__dirname:null,exports:null,module:null,setImmediate:null,clearImmediate:null,setTimeout:null,clearTimeout:null,setInterval:null,clearInterval:null,queueMicrotask:null,queueGlobalMicrotask:null,globalThis:null,window:null,self:null,document:null,localStorage:null,sessionStorage:null,indexedDB:null,caches:null,console:null,performance:null,fetch:null,XMLHttpRequest:null,Image:null,Audio:null,navigator:null,navigation:null,location:null,history:null,screen:null,requestAnimationFrame:null,cancelAnimationFrame:null,cancelIdleCallback:null,captureEvents:null,chrome:null,clientInformation:null,addEventListener:null,removeEventListener:null,blur:null,close:null,closed:null,confirm:null,alert:null,customElements:null,dispatchEvent:null,debug:null,focus:null,find:null,frames:null,getSelection:null,getScreenDetails:null,getEventListeners:null,keys:null,launchQueue:null,parent:null,postMessage:null,print:null,profile:null,profileEnd:null,prompt:null,queryLocalFonts:null,queryObjects:null,releaseEvents:null,reportError:null,resizeBy:null,resizeTo:null,scheduler:null,stop:null,scroll:null,scrollBy:null,scrollTo:null,scrollY:null,scrollX:null,top:null,eval:null,__ctx__:null};class fe{constructor(){v(this,"cache",new Map)}call(t,o){return this.getFn(t)(o)}getFn(t){let o=this.cache.get(t);return o||(o=he(t),this.cache.set(t,o)),o}}function he(n){const t=`with(__ctx__){
2
- ${n}
3
- }`,o=new Function("__ctx__",t);return s=>{const a=Object.freeze(Object.assign({},me,s));return o(a)}}const A=new fe;function N(n){const t=`return (${n})(v, data, context, entry)`;return A.getFn(t)}function T(n){const t=`return (${n})(data, context)`;return A.getFn(t)}function ye(n){const t=`return (${n})(v, data, context, entry)`;return A.getFn(t)}function ge(n,t){switch(n.type.kind){case"":{const o=n;return t.phantom&&o.type.designType==="phantom"?t.phantom(o):t.final(o)}case"object":return t.object(n);case"array":return t.array(n);case"union":return t.union(n);case"intersection":return t.intersection(n);case"tuple":return t.tuple(n);default:throw new Error(`Unknown type kind "${n.type.kind}"`)}}function D(n,t,o){return t in n?Object.defineProperty(n,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):n[t]=o,n}const j=new Map;var be=class{isLimitExceeded(){return this.stackErrors.length>0?this.stackErrors[this.stackErrors.length-1].length>=this.opts.errorLimit:this.errors.length>=this.opts.errorLimit}push(n){this.stackPath.push(n),this.stackErrors.push([])}pop(n){this.stackPath.pop();const t=this.stackErrors.pop();return n&&(t!=null&&t.length)&&t.forEach(o=>{this.error(o.message,o.path,o.details)}),t}clear(){this.stackErrors[this.stackErrors.length-1]=[]}error(n,t,o){const s=this.stackErrors[this.stackErrors.length-1]||this.errors,a={path:t||this.path,message:n};o!=null&&o.length&&(a.details=o),s.push(a)}throw(){throw new xe(this.errors)}validate(n,t){this.push(""),this.errors=[],this.stackErrors=[];const o=this.validateSafe(this.def,n);if(this.pop(!o),!o){if(t)return!1;this.throw()}return!0}validateSafe(n,t){if(this.isLimitExceeded())return!1;if(!ke(n))throw new Error("Can not validate not-annotated type");if(typeof this.opts.replace=="function"&&(n=this.opts.replace(n,this.path)),n.optional&&t===void 0)return!0;for(const o of this.opts.plugins){const s=o(this,n,t);if(s===!1||s===!0)return s}return this.validateAnnotatedType(n,t)}get path(){return this.stackPath.slice(1).join(".")}validateAnnotatedType(n,t){return ge(n,{final:o=>this.validatePrimitive(o,t),phantom:()=>!0,object:o=>this.validateObject(o,t),array:o=>this.validateArray(o,t),union:o=>this.validateUnion(o,t),intersection:o=>this.validateIntersection(o,t),tuple:o=>this.validateTuple(o,t)})}validateUnion(n,t){let o=0;const s=[];for(const l of n.type.items){if(this.push(`[${l.type.kind||l.type.designType}(${o})]`),this.validateSafe(l,t))return this.pop(!1),!0;const i=this.pop(!1);i&&s.push(...i),o++}this.clear();const a=n.type.items.map((l,i)=>`[${l.type.kind||l.type.designType}(${i})]`).join(", ");return this.error(`Value does not match any of the allowed types: ${a}`,void 0,s),!1}validateIntersection(n,t){for(const o of n.type.items)if(!this.validateSafe(o,t))return!1;return!0}validateTuple(n,t){if(!Array.isArray(t)||t.length!==n.type.items.length)return this.error(`Expected array of length ${n.type.items.length}`),!1;let o=0;for(const s of n.type.items){if(this.push(`[${o}]`),!this.validateSafe(s,t[o]))return this.pop(!0),!1;this.pop(!1),o++}return!0}validateArray(n,t){if(!Array.isArray(t))return this.error("Expected array"),!1;const o=n.metadata.get("expect.minLength");if(o){const i=typeof o=="number"?o:o.length;if(t.length<i){const d=typeof o=="object"&&o.message?o.message:`Expected minimum length of ${i} items, got ${t.length} items`;return this.error(d),!1}}const s=n.metadata.get("expect.maxLength");if(s){const i=typeof s=="number"?s:s.length;if(t.length>i){const d=typeof s=="object"&&s.message?s.message:`Expected maximum length of ${i} items, got ${t.length} items`;return this.error(d),!1}}let a=0,l=!0;for(const i of t){if(this.push(`[${a}]`),this.validateSafe(n.type.of,i))this.pop(!1);else if(l=!1,this.pop(!0),this.isLimitExceeded())return!1;a++}return l}validateObject(n,t){if(typeof t!="object"||t===null||Array.isArray(t))return this.error("Expected object"),!1;let o=!0;const s=new Set(Object.keys(t)),a=new Set,l=new Set;if(this.opts.skipList){const d=this.stackPath.length>1?`${this.path}.`:"";this.opts.skipList.forEach(f=>{if(f.startsWith(d)){const u=f.slice(d.length);l.add(u),s.delete(u)}})}let i=!1;typeof this.opts.partial=="function"&&(i=this.opts.partial(n,this.path));for(const[d,f]of n.type.props.entries())if(!(l.has(d)||Ee(f))&&(a.add(d),!(t[d]===void 0&&(i||this.opts.partial==="deep"||this.opts.partial===!0&&this.stackPath.length<=1)))){if(this.push(d),this.validateSafe(f,t[d]))this.pop(!1);else if(o=!1,this.pop(!0),this.isLimitExceeded())return!1}for(const d of s)if(!a.has(d)){const f=[];for(const{pattern:u,def:h}of n.type.propsPatterns)u.test(d)&&f.push({pattern:u,def:h});if(f.length){let u=!1;for(const{def:h}of f)if(this.validateSafe(h,t[d])){this.pop(!1),u=!0;break}if(!u&&(this.push(d),this.validateSafe(f[0].def,t[d]),this.pop(!0),o=!1,this.isLimitExceeded()))return!1}else if(this.opts.unknwonProps!=="ignore")if(this.opts.unknwonProps==="error"){if(this.push(d),this.error("Unexpected property"),this.pop(!0),this.isLimitExceeded())return!1;o=!1}else this.opts.unknwonProps==="strip"&&delete t[d]}return o}validatePrimitive(n,t){if(typeof n.type.value<"u")return t!==n.type.value?(this.error(`Expected ${n.type.value}, got ${t}`),!1):!0;const o=Array.isArray(t)?"array":typeof t;switch(n.type.designType){case"never":return this.error("This type is impossible, must be an internal problem"),!1;case"any":return!0;case"string":return o!==n.type.designType?(this.error(`Expected ${n.type.designType}, got ${o}`),!1):this.validateString(n,t);case"number":return o!==n.type.designType?(this.error(`Expected ${n.type.designType}, got ${o}`),!1):this.validateNumber(n,t);case"boolean":return o!==n.type.designType?(this.error(`Expected ${n.type.designType}, got ${o}`),!1):!0;case"undefined":return t!==void 0?(this.error(`Expected ${n.type.designType}, got ${o}`),!1):!0;case"null":return t!==null?(this.error(`Expected ${n.type.designType}, got ${o}`),!1):!0;default:throw new Error(`Unknown type "${n.type.designType}"`)}}validateString(n,t){const o=n.metadata.get("expect.minLength");if(o){const l=typeof o=="number"?o:o.length;if(t.length<l){const i=typeof o=="object"&&o.message?o.message:`Expected minimum length of ${l} characters, got ${t.length} characters`;return this.error(i),!1}}const s=n.metadata.get("expect.maxLength");if(s){const l=typeof s=="number"?s:s.length;if(t.length>l){const i=typeof s=="object"&&s.message?s.message:`Expected maximum length of ${l} characters, got ${t.length} characters`;return this.error(i),!1}}const a=n.metadata.get("expect.pattern");for(const{pattern:l,flags:i,message:d}of a||[]){if(!l)continue;const f=`${l}//${i||""}`;let u=j.get(f);if(u||(u=new RegExp(l,i),j.set(f,u)),!u.test(t))return this.error(d||`Value is expected to match pattern "${l}"`),!1}return!0}validateNumber(n,t){const o=n.metadata.get("expect.int");if(o&&t%1!==0){const l=typeof o=="object"&&o.message?o.message:`Expected integer, got ${t}`;return this.error(l),!1}const s=n.metadata.get("expect.min");if(s){const l=typeof s=="number"?s:s.minValue;if(t<l){const i=typeof s=="object"&&s.message?s.message:`Expected minimum ${l}, got ${t}`;return this.error(i),!1}}const a=n.metadata.get("expect.max");if(a){const l=typeof a=="number"?a:a.maxValue;if(t>l){const i=typeof a=="object"&&a.message?a.message:`Expected maximum ${l}, got ${t}`;return this.error(i),!1}}return!0}constructor(n,t){D(this,"def",void 0),D(this,"opts",void 0),D(this,"errors",void 0),D(this,"stackErrors",void 0),D(this,"stackPath",void 0),this.def=n,this.errors=[],this.stackErrors=[],this.stackPath=[],this.opts={partial:!1,unknwonProps:"error",errorLimit:10,...t,plugins:(t==null?void 0:t.plugins)||[]}}},xe=class extends Error{constructor(n){super(`${n[0].path?n[0].path+": ":""}${n[0].message}`),D(this,"errors",void 0),D(this,"name",void 0),this.errors=n,this.name="Validation Error"}};function ke(n){return n&&n.__is_atscript_annotated_type}function Ee(n){return n.type.kind===""&&n.type.designType==="phantom"}const Se=new Set(["action","paragraph","select","radio","checkbox"]);function Be(n){return(Array.isArray(n)?n:[n]).map(o=>{if(typeof o=="object"&&o!==null&&"label"in o){const{label:s,value:a}=o;return a!==void 0?{key:a,label:s}:s}return String(o)})}function E(n,t,o,s){const{transform:a,defaultValue:l,staticAsBoolean:i=!1,compiler:d=N}=s??{},f=o.get(n);if(typeof f=="string")return d(f);if(t!==void 0){const u=o.get(t);if(u!==void 0)return i?!0:a?a(u):u}return l}function Ve(n,t){var o,s,a,l;return{optional:(o=E("foorm.fn.optional",void 0,n))!==null&&o!==void 0?o:t??!1,disabled:(s=E("foorm.fn.disabled","foorm.disabled",n,{staticAsBoolean:!0}))!==null&&s!==void 0?s:!1,hidden:(a=E("foorm.fn.hidden","foorm.hidden",n,{staticAsBoolean:!0}))!==null&&a!==void 0?a:!1,readonly:(l=E("foorm.fn.readonly","foorm.readonly",n,{staticAsBoolean:!0}))!==null&&l!==void 0?l:!1}}function _e(n,t){return{label:E("foorm.fn.label","meta.label",n,{defaultValue:t}),description:E("foorm.fn.description","meta.description",n),hint:E("foorm.fn.hint","meta.hint",n),placeholder:E("foorm.fn.placeholder","meta.placeholder",n)}}function De(n){const t=n.get("foorm.attr"),o=n.get("foorm.fn.attr");if(!t&&!o)return;const s={};if(t){const a=Array.isArray(t)?t:[t];for(const l of a)if(typeof l=="object"&&l!==null&&"name"in l&&"value"in l){const{name:i,value:d}=l;s[i]=d}}if(o){const a=Array.isArray(o)?o:[o];for(const l of a)if(typeof l=="object"&&l!==null&&"name"in l&&"fn"in l){const{name:i,fn:d}=l;s[i]=N(d)}}return Object.keys(s).length>0?s:void 0}function Ce(n){var t,o;const s=n.metadata,a=n.type.props,l=E("foorm.fn.title","foorm.title",s,{compiler:T,defaultValue:""}),i=E("foorm.fn.submit.text","foorm.submit.text",s,{compiler:T,defaultValue:"Submit"}),d=E("foorm.fn.submit.disabled","foorm.submit.disabled",s,{compiler:T,defaultValue:!1}),f={text:i,disabled:d},u=[];for(const[h,y]of a.entries()){const p=y.metadata,m=(t=y.type)===null||t===void 0?void 0:t.tags,S=p.get("foorm.type"),g=m?[...m].find(c=>Se.has(c)):void 0,x=(o=S??g)!==null&&o!==void 0?o:"text",_=[],r=p.get("foorm.validate");if(r){const c=Array.isArray(r)?r:[r];for(const b of c)typeof b=="string"&&_.push(ye(b))}const C=p.get("expect.pattern")!==void 0||p.get("expect.min")!==void 0||p.get("expect.max")!==void 0||p.get("expect.minLength")!==void 0||p.get("expect.maxLength")!==void 0||p.get("expect.int")!==void 0,$=m&&m.size>0;if(C||$){const c=new be(y);_.push(b=>{var B;if(c.validate(b.v,!0))return!0;const L=(B=c.errors)===null||B===void 0?void 0:B[0];return(L==null?void 0:L.message)||"Validation failed"})}const w=Object.assign(Object.assign(Object.assign({field:h,type:x,component:p.get("foorm.component"),autocomplete:p.get("foorm.autocomplete"),altAction:p.get("foorm.altAction"),order:p.get("foorm.order"),name:h},_e(p,h)),Ve(p,y.optional)),{classes:E("foorm.fn.classes",void 0,p),styles:E("foorm.fn.styles",void 0,p),options:E("foorm.fn.options","foorm.options",p,{transform:Be}),value:E("foorm.fn.value","foorm.value",p),validators:_,attrs:De(p),maxLength:p.get("expect.maxLength"),minLength:p.get("expect.minLength"),min:p.get("expect.min"),max:p.get("expect.max")});u.push(w)}return u.sort((h,y)=>{var p,m;return((p=h.order)!==null&&p!==void 0?p:1/0)-((m=y.order)!==null&&m!==void 0?m:1/0)}),{title:l,submit:f,fields:u}}function $e(n){const t=Ce(n),o=e.reactive(U(t.fields));return{form:t,formData:o}}k.OoField=F,k.OoForm=ue,k.useFoorm=$e,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
package/dist/style.css DELETED
@@ -1 +0,0 @@
1
- .oo-default-field{display:flex;flex-direction:column;gap:4px;margin-bottom:4px}.oo-default-field label{font-size:13px;font-weight:600;color:#374151}.oo-default-field.required label:after{content:" *";color:#ef4444}.oo-default-field span{font-size:12px;color:#6b7280}.oo-default-field input,.oo-default-field select{padding:8px 12px;border:1px solid #d1d5db;border-radius:6px;font-size:14px;color:#1d1d1f;background:#fff;transition:border-color .15s,box-shadow .15s;outline:none}.oo-default-field input::placeholder{color:#9ca3af}.oo-default-field input:focus,.oo-default-field select:focus{border-color:#6366f1;box-shadow:0 0 0 3px #6366f126}.oo-default-field input:disabled,.oo-default-field select:disabled{background:#f3f4f6;color:#9ca3af;cursor:not-allowed}.oo-default-field.error input,.oo-default-field.error select{border-color:#ef4444}.oo-default-field.error input:focus,.oo-default-field.error select:focus{box-shadow:0 0 0 3px #ef444426}.oo-default-field .oo-field-label{font-size:13px;font-weight:600;color:#374151}.oo-radio-group{display:flex;flex-direction:column;gap:6px}.oo-radio-group label{display:flex;align-items:center;gap:8px;font-size:14px;font-weight:400;color:#1d1d1f;cursor:pointer}.oo-radio-group input[type=radio]{padding:0;border:none;box-shadow:none}.oo-checkbox-field>label{display:flex;align-items:center;gap:8px;font-size:14px;font-weight:400;color:#1d1d1f;cursor:pointer}.oo-checkbox-field>label input[type=checkbox]{padding:0;border:none;box-shadow:none}.oo-default-field .oo-error-slot{min-height:16px;line-height:16px;font-size:12px;color:#6b7280}.oo-default-field.error .oo-error-slot{color:#ef4444}.oo-default-field.oo-action-field button{padding:8px 16px;border:1px solid #d1d5db;border-radius:6px;background:#fff;font-size:13px;font-weight:500;color:#374151;cursor:pointer;transition:background .15s,border-color .15s}.oo-default-field.oo-action-field button:hover{background:#f9fafb;border-color:#9ca3af}h2{margin:0 0 8px;font-size:20px;font-weight:700;color:#111827}p{margin:0 0 4px;font-size:14px;color:#6b7280}button[type=submit],button:not([type]){margin-top:8px;padding:10px 20px;border:none;border-radius:6px;background:#6366f1;color:#fff;font-size:14px;font-weight:600;cursor:pointer;transition:background .15s}button[type=submit]:hover,button:not([type]):hover{background:#4f46e5}button[type=submit]:disabled,button:not([type]):disabled{background:#c7d2fe;cursor:not-allowed}