@morscherlab/mld-sdk 0.6.5 → 0.7.1
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/__tests__/composables/formBuilderRegistry.test.d.ts +1 -0
- package/dist/__tests__/composables/useFormBuilder.test.d.ts +1 -0
- package/dist/components/BaseButton.vue.d.ts +1 -1
- package/dist/components/BasePill.vue.d.ts +1 -1
- package/dist/components/DropdownButton.vue.d.ts +1 -1
- package/dist/components/FormActions.vue.d.ts +33 -0
- package/dist/components/FormActions.vue.js +76 -0
- package/dist/components/FormActions.vue.js.map +1 -0
- package/dist/components/FormActions.vue3.js +6 -0
- package/dist/components/FormActions.vue3.js.map +1 -0
- package/dist/components/FormBuilder.vue.js +205 -0
- package/dist/components/FormBuilder.vue.js.map +1 -0
- package/dist/components/FormBuilder.vue3.js +6 -0
- package/dist/components/FormBuilder.vue3.js.map +1 -0
- package/dist/components/FormFieldRenderer.vue.d.ts +31 -0
- package/dist/components/FormFieldRenderer.vue.js +48 -0
- package/dist/components/FormFieldRenderer.vue.js.map +1 -0
- package/dist/components/FormFieldRenderer.vue2.js +5 -0
- package/dist/components/FormFieldRenderer.vue2.js.map +1 -0
- package/dist/components/FormSection.vue.d.ts +43 -0
- package/dist/components/FormSection.vue.js +117 -0
- package/dist/components/FormSection.vue.js.map +1 -0
- package/dist/components/FormSection.vue3.js +6 -0
- package/dist/components/FormSection.vue3.js.map +1 -0
- package/dist/components/IconButton.vue.d.ts +1 -1
- package/dist/components/LoadingSpinner.vue.d.ts +1 -1
- package/dist/components/ProgressBar.vue.d.ts +1 -1
- package/dist/components/ReagentList.vue.d.ts +2 -2
- package/dist/components/ResourceCard.vue.d.ts +1 -1
- package/dist/components/SegmentedControl.vue.d.ts +1 -1
- package/dist/components/WellEditPopup.vue.d.ts +2 -2
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +19 -8
- package/dist/components/index.js.map +1 -1
- package/dist/composables/formBuilderRegistry.d.ts +13 -0
- package/dist/composables/formBuilderRegistry.js +87 -0
- package/dist/composables/formBuilderRegistry.js.map +1 -0
- package/dist/composables/index.d.ts +3 -0
- package/dist/composables/index.js +8 -0
- package/dist/composables/index.js.map +1 -1
- package/dist/composables/useFormBuilder.d.ts +23 -0
- package/dist/composables/useFormBuilder.js +264 -0
- package/dist/composables/useFormBuilder.js.map +1 -0
- package/dist/composables/usePluginConfig.d.ts +12 -0
- package/dist/composables/usePluginConfig.js +77 -0
- package/dist/composables/usePluginConfig.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/styles.css +247 -6
- package/dist/types/form-builder.d.ts +167 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/__tests__/composables/formBuilderRegistry.test.ts +187 -0
- package/src/__tests__/composables/useFormBuilder.test.ts +917 -0
- package/src/components/FormActions.vue +92 -0
- package/src/components/FormBuilder.vue +214 -0
- package/src/components/FormFieldRenderer.vue +58 -0
- package/src/components/FormSection.vue +90 -0
- package/src/components/index.ts +6 -0
- package/src/composables/formBuilderRegistry.ts +79 -0
- package/src/composables/index.ts +7 -0
- package/src/composables/useFormBuilder.ts +382 -0
- package/src/composables/usePluginConfig.ts +92 -0
- package/src/index.ts +3 -0
- package/src/styles/components/app-container.css +1 -0
- package/src/styles/components/app-layout.css +1 -2
- package/src/styles/components/form-builder.css +69 -0
- package/src/styles/components/number-input.css +4 -1
- package/src/styles/index.css +1 -0
- package/src/types/form-builder.ts +197 -0
- package/src/types/index.ts +14 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { FieldRules } from '../composables/useForm'
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Field types
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
/** All supported field types that map to SDK components. */
|
|
8
|
+
export type FormFieldType =
|
|
9
|
+
| 'text'
|
|
10
|
+
| 'email'
|
|
11
|
+
| 'password'
|
|
12
|
+
| 'number'
|
|
13
|
+
| 'tel'
|
|
14
|
+
| 'url'
|
|
15
|
+
| 'search'
|
|
16
|
+
| 'textarea'
|
|
17
|
+
| 'select'
|
|
18
|
+
| 'multiselect'
|
|
19
|
+
| 'checkbox'
|
|
20
|
+
| 'toggle'
|
|
21
|
+
| 'radio'
|
|
22
|
+
| 'slider'
|
|
23
|
+
| 'tags'
|
|
24
|
+
| 'date'
|
|
25
|
+
| 'time'
|
|
26
|
+
| 'datetime'
|
|
27
|
+
| 'file'
|
|
28
|
+
| 'formula'
|
|
29
|
+
| 'sequence'
|
|
30
|
+
| 'molecule'
|
|
31
|
+
| 'concentration'
|
|
32
|
+
| 'unit'
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Conditions (JSON-serializable)
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
export type FieldCondition =
|
|
39
|
+
| { field: string; eq: unknown }
|
|
40
|
+
| { field: string; neq: unknown }
|
|
41
|
+
| { field: string; gt: number }
|
|
42
|
+
| { field: string; lt: number }
|
|
43
|
+
| { field: string; gte: number }
|
|
44
|
+
| { field: string; lte: number }
|
|
45
|
+
| { field: string; in: unknown[] }
|
|
46
|
+
| { field: string; notIn: unknown[] }
|
|
47
|
+
| { field: string; truthy: true }
|
|
48
|
+
| { field: string; falsy: true }
|
|
49
|
+
| { field: string; contains: string }
|
|
50
|
+
| { and: FieldCondition[] }
|
|
51
|
+
| { or: FieldCondition[] }
|
|
52
|
+
| { not: FieldCondition }
|
|
53
|
+
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
// Validation (JSON-safe subset of FieldRules)
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
|
|
58
|
+
export interface FieldValidation {
|
|
59
|
+
required?: boolean | string
|
|
60
|
+
minLength?: number | { value: number; message: string }
|
|
61
|
+
maxLength?: number | { value: number; message: string }
|
|
62
|
+
min?: number | { value: number; message: string }
|
|
63
|
+
max?: number | { value: number; message: string }
|
|
64
|
+
/** Pattern as a string (converted to RegExp at runtime). */
|
|
65
|
+
pattern?: string | { value: string; message: string }
|
|
66
|
+
email?: boolean | string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// Field schema
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
export interface FormFieldSchema {
|
|
74
|
+
name: string
|
|
75
|
+
label: string
|
|
76
|
+
type: FormFieldType
|
|
77
|
+
defaultValue?: unknown
|
|
78
|
+
placeholder?: string
|
|
79
|
+
hint?: string
|
|
80
|
+
size?: 'sm' | 'md' | 'lg'
|
|
81
|
+
disabled?: boolean
|
|
82
|
+
readonly?: boolean
|
|
83
|
+
validation?: FieldValidation
|
|
84
|
+
condition?: FieldCondition
|
|
85
|
+
/** Grid column span (1-3). Defaults to 1. */
|
|
86
|
+
colSpan?: number
|
|
87
|
+
/** Extra props passed directly to the underlying component. */
|
|
88
|
+
props?: Record<string, unknown>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
// Section schema
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
export interface FormSectionSchema {
|
|
96
|
+
id: string
|
|
97
|
+
title: string
|
|
98
|
+
description?: string
|
|
99
|
+
collapsible?: boolean
|
|
100
|
+
defaultOpen?: boolean
|
|
101
|
+
/** Number of grid columns (1-3). Defaults to 1. */
|
|
102
|
+
columns?: 1 | 2 | 3
|
|
103
|
+
fields: FormFieldSchema[]
|
|
104
|
+
condition?: FieldCondition
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
// Wizard step schema
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
export interface FormStepSchema {
|
|
112
|
+
id: string
|
|
113
|
+
label: string
|
|
114
|
+
description?: string
|
|
115
|
+
icon?: string
|
|
116
|
+
optional?: boolean
|
|
117
|
+
sections: FormSectionSchema[]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// Top-level form schema
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
export type FormSchema =
|
|
125
|
+
| {
|
|
126
|
+
sections: FormSectionSchema[]
|
|
127
|
+
steps?: never
|
|
128
|
+
submitLabel?: string
|
|
129
|
+
cancelLabel?: string
|
|
130
|
+
showCancel?: boolean
|
|
131
|
+
}
|
|
132
|
+
| {
|
|
133
|
+
sections?: never
|
|
134
|
+
steps: FormStepSchema[]
|
|
135
|
+
submitLabel?: string
|
|
136
|
+
cancelLabel?: string
|
|
137
|
+
showCancel?: boolean
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
// Enhancements (TS-only, NOT JSON-serializable)
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
export interface FieldEnhancement<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
145
|
+
/** Custom validator appended to the field's rules. */
|
|
146
|
+
validate?: (value: unknown, data: T) => string | undefined | null
|
|
147
|
+
/** Dynamic visibility (overrides schema condition if both present). */
|
|
148
|
+
visible?: (data: T) => boolean
|
|
149
|
+
/** Dynamic options for select/multiselect/radio fields. */
|
|
150
|
+
options?: (data: T) => { label: string; value: unknown }[]
|
|
151
|
+
/** Dynamic extra props merged into the component. */
|
|
152
|
+
props?: (data: T) => Record<string, unknown>
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface FormEnhancements<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
156
|
+
/** Per-field enhancements keyed by field name. */
|
|
157
|
+
fields?: Partial<Record<keyof T, FieldEnhancement<T>>>
|
|
158
|
+
/** Called on successful submit. */
|
|
159
|
+
onSubmit?: (data: T) => Promise<void> | void
|
|
160
|
+
/** Transform data before submit (return transformed copy). */
|
|
161
|
+
transform?: (data: T) => T | Record<string, unknown>
|
|
162
|
+
/** Called when any field value changes. */
|
|
163
|
+
onFieldChange?: (field: keyof T, value: unknown, data: T) => void
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
// useFormBuilder return type
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
export interface UseFormBuilderReturn<T extends Record<string, unknown>> {
|
|
171
|
+
/** Underlying useForm return. */
|
|
172
|
+
form: import('../composables/useForm').UseFormReturn<T>
|
|
173
|
+
/** Validation rules derived from schema + enhancements. */
|
|
174
|
+
rules: Partial<Record<keyof T, FieldRules>>
|
|
175
|
+
/** Whether a field is currently visible. */
|
|
176
|
+
isFieldVisible: (name: string) => boolean
|
|
177
|
+
/** Whether a section is currently visible. */
|
|
178
|
+
isSectionVisible: (id: string) => boolean
|
|
179
|
+
/** All flattened field schemas. */
|
|
180
|
+
fields: FormFieldSchema[]
|
|
181
|
+
/** Resolve final component props for a field. */
|
|
182
|
+
getResolvedFieldProps: (field: FormFieldSchema) => Record<string, unknown>
|
|
183
|
+
/** Get options for a select/radio/multiselect field. */
|
|
184
|
+
getFieldOptions: (name: string) => { label: string; value: unknown }[] | undefined
|
|
185
|
+
|
|
186
|
+
// Wizard-specific
|
|
187
|
+
currentStep: import('vue').Ref<number>
|
|
188
|
+
isCurrentStepValid: import('vue').ComputedRef<boolean>
|
|
189
|
+
goNext: () => boolean
|
|
190
|
+
goBack: () => void
|
|
191
|
+
goToStep: (index: number) => void
|
|
192
|
+
|
|
193
|
+
// Actions
|
|
194
|
+
validate: () => boolean
|
|
195
|
+
reset: (values?: Partial<T>) => void
|
|
196
|
+
submit: () => Promise<void>
|
|
197
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -132,6 +132,20 @@ export type {
|
|
|
132
132
|
TreeNode,
|
|
133
133
|
} from './components'
|
|
134
134
|
|
|
135
|
+
// FormBuilder types
|
|
136
|
+
export type {
|
|
137
|
+
FormFieldType,
|
|
138
|
+
FieldCondition,
|
|
139
|
+
FieldValidation,
|
|
140
|
+
FormFieldSchema,
|
|
141
|
+
FormSectionSchema,
|
|
142
|
+
FormStepSchema,
|
|
143
|
+
FormSchema,
|
|
144
|
+
FieldEnhancement,
|
|
145
|
+
FormEnhancements,
|
|
146
|
+
UseFormBuilderReturn,
|
|
147
|
+
} from './form-builder'
|
|
148
|
+
|
|
135
149
|
// Auth types
|
|
136
150
|
export type {
|
|
137
151
|
AuthConfig,
|