@bagelink/vue 0.0.1045 → 0.0.1054
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/components/BglComponent.vue.d.ts.map +1 -1
- package/dist/components/TableSchema.vue.d.ts.map +1 -1
- package/dist/components/form/BglField.vue.d.ts +2 -4
- package/dist/components/form/BglField.vue.d.ts.map +1 -1
- package/dist/components/form/BglForm.vue.d.ts +3 -1
- package/dist/components/form/BglForm.vue.d.ts.map +1 -1
- package/dist/components/form/BglMultiStepForm.vue.d.ts +2 -1
- package/dist/components/form/BglMultiStepForm.vue.d.ts.map +1 -1
- package/dist/index.cjs +82 -67
- package/dist/index.mjs +82 -67
- package/dist/style.css +56 -56
- package/dist/types/BagelForm.d.ts +1 -1
- package/dist/types/BagelForm.d.ts.map +1 -1
- package/dist/utils/BagelFormUtils.d.ts +2 -216
- package/dist/utils/BagelFormUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/BglComponent.vue +16 -7
- package/src/components/TableSchema.vue +0 -1
- package/src/components/form/BglField.vue +15 -16
- package/src/components/form/BglForm.vue +8 -6
- package/src/components/form/inputs/RangeInput.vue +4 -4
- package/src/types/BagelForm.ts +1 -1
- package/src/utils/BagelFormUtils.ts +4 -4
|
@@ -22,7 +22,7 @@ import { FORM_STATE_KEY } from './useBagelFormState'
|
|
|
22
22
|
|
|
23
23
|
const props = defineProps<{
|
|
24
24
|
field: Field<T>
|
|
25
|
-
|
|
25
|
+
fieldID?: string
|
|
26
26
|
modelValue?: any
|
|
27
27
|
parentPath?: string
|
|
28
28
|
}>()
|
|
@@ -51,27 +51,27 @@ const is = $computed(() => {
|
|
|
51
51
|
if (props.field.$el === 'file') return FileUpload
|
|
52
52
|
if (props.field.$el === 'date') return DateInput
|
|
53
53
|
if (props.field.$el === 'tabs') return TabsNav
|
|
54
|
-
if (props.field.$el === '
|
|
54
|
+
if (props.field.$el === 'bglform') return BglForm
|
|
55
55
|
return props.field.$el ?? 'div'
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
const fieldData = $computed({
|
|
59
59
|
get: () => {
|
|
60
|
-
if (!props.
|
|
61
|
-
const value = formState?.getFieldData(props.
|
|
60
|
+
if (!props.fieldID) return props.field.defaultValue ?? (props.field.$el === 'form' ? {} : '')
|
|
61
|
+
const value = formState?.getFieldData(props.fieldID)
|
|
62
62
|
if (props.field.$el === 'form' && !value) return {}
|
|
63
63
|
return value ?? ''
|
|
64
64
|
},
|
|
65
65
|
set: (val: any) => {
|
|
66
|
-
if (!props.
|
|
67
|
-
const currentValue = formState?.getFieldData(props.
|
|
66
|
+
if (!props.fieldID) return
|
|
67
|
+
const currentValue = formState?.getFieldData(props.fieldID)
|
|
68
68
|
if (JSON.stringify(val) === JSON.stringify(currentValue)) return
|
|
69
69
|
|
|
70
70
|
emit('update:modelValue', val)
|
|
71
71
|
if (props.field.onUpdate) {
|
|
72
72
|
props.field.onUpdate(val, currentValue)
|
|
73
73
|
}
|
|
74
|
-
formState?.updateField(props.
|
|
74
|
+
formState?.updateField(props.fieldID, val)
|
|
75
75
|
}
|
|
76
76
|
})
|
|
77
77
|
|
|
@@ -94,6 +94,7 @@ const computedOptions = $computed(
|
|
|
94
94
|
|
|
95
95
|
const computedAttrs = $computed(() => {
|
|
96
96
|
const attrs = { ...customAttrs, ...props.field.attrs }
|
|
97
|
+
delete attrs.schema
|
|
97
98
|
return bindAttrs(attrs, fieldData, formState?.data.value)
|
|
98
99
|
})
|
|
99
100
|
|
|
@@ -107,8 +108,8 @@ const computedClass = $computed(
|
|
|
107
108
|
v-bind="computedAttrs"
|
|
108
109
|
:is="is"
|
|
109
110
|
v-if="vIf"
|
|
110
|
-
:id="props.id"
|
|
111
111
|
v-model="fieldData"
|
|
112
|
+
:fieldID="props.fieldID"
|
|
112
113
|
:required="field.required"
|
|
113
114
|
:class="computedClass"
|
|
114
115
|
:label="field.label"
|
|
@@ -119,17 +120,15 @@ const computedClass = $computed(
|
|
|
119
120
|
:helptext="field.helptext"
|
|
120
121
|
:schema="field.attrs?.schema ?? undefined"
|
|
121
122
|
>
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
</template>
|
|
125
|
-
<template v-else>
|
|
123
|
+
{{ computedFieldData }}
|
|
124
|
+
<template v-for="(child, ii) in field.children" :key="ii">
|
|
126
125
|
<BglField
|
|
127
|
-
v-
|
|
128
|
-
:
|
|
129
|
-
:key="child.id || ii"
|
|
126
|
+
v-if="(typeof child !== 'string')"
|
|
127
|
+
:fieldID="[props.fieldID, child.id].filter(Boolean).join('.')"
|
|
130
128
|
:field="child"
|
|
131
|
-
:parent-path="props.
|
|
129
|
+
:parent-path="props.fieldID"
|
|
132
130
|
/>
|
|
131
|
+
<span v-else>{{ child }}</span>
|
|
133
132
|
</template>
|
|
134
133
|
</component>
|
|
135
134
|
</template>
|
|
@@ -8,28 +8,30 @@ export type FormStatus = 'idle' | 'loading' | 'success' | 'error'
|
|
|
8
8
|
const props = withDefaults(
|
|
9
9
|
defineProps<{
|
|
10
10
|
label?: string
|
|
11
|
-
|
|
11
|
+
fieldID?: string
|
|
12
12
|
schema: BglFormSchemaFnT<any>
|
|
13
13
|
modelValue?: { [key: string]: any }
|
|
14
14
|
onDelete?: (id: string) => void
|
|
15
15
|
onSubmit?: (data: any) => void
|
|
16
16
|
status?: FormStatus
|
|
17
|
+
tag?: 'template' | 'form'
|
|
17
18
|
}>(),
|
|
18
19
|
{
|
|
19
20
|
modelValue: () => ({}),
|
|
21
|
+
tag: 'form',
|
|
20
22
|
},
|
|
21
23
|
)
|
|
22
24
|
|
|
23
25
|
const emit = defineEmits(['update:modelValue', 'submit', 'dirty'])
|
|
24
26
|
|
|
25
|
-
const slots = useSlots()
|
|
27
|
+
const slots = useSlots() as any
|
|
26
28
|
const { showModal } = useModal()
|
|
27
29
|
const instAt = new Date()
|
|
28
30
|
const timeSinceInst = () => Date.now() - instAt.getTime()
|
|
29
31
|
|
|
30
32
|
// Check if we're a nested form
|
|
31
33
|
const existingFormState = inject<BagelFormState | undefined>(FORM_STATE_KEY)
|
|
32
|
-
const isNested = Boolean(existingFormState && props.
|
|
34
|
+
const isNested = Boolean(existingFormState && props.fieldID)
|
|
33
35
|
|
|
34
36
|
// Only provide new form state if we're not nested
|
|
35
37
|
const { data, isDirty } = isNested
|
|
@@ -119,11 +121,11 @@ defineExpose({
|
|
|
119
121
|
</script>
|
|
120
122
|
|
|
121
123
|
<template>
|
|
122
|
-
<template v-if="
|
|
124
|
+
<template v-if="tag === 'template'">
|
|
123
125
|
<BglField
|
|
124
126
|
v-for="(field, i) in computedSchema"
|
|
125
|
-
:id="[id, field.id].filter(Boolean).join('.')"
|
|
126
127
|
:key="field.id || `${i}p`"
|
|
128
|
+
:fieldID="field.id"
|
|
127
129
|
:field="field"
|
|
128
130
|
/>
|
|
129
131
|
<slot name="submit" :submit="runSubmit" :isDirty="isDirty" :validateForm="validateForm" />
|
|
@@ -136,8 +138,8 @@ defineExpose({
|
|
|
136
138
|
<Title v-if="label" tag="h4" :label="label" />
|
|
137
139
|
<BglField
|
|
138
140
|
v-for="(field, i) in computedSchema"
|
|
139
|
-
:id="field.id"
|
|
140
141
|
:key="field.id || `${i}p`"
|
|
142
|
+
:fieldID="field.id"
|
|
141
143
|
:field="field"
|
|
142
144
|
/>
|
|
143
145
|
<slot name="submit" :submit="runSubmit" :isDirty="isDirty" :validateForm="validateForm" />
|
|
@@ -41,8 +41,8 @@ const toPercentage = $computed(() => ((validTo - min) / (max - min)) * 100)
|
|
|
41
41
|
|
|
42
42
|
watch(() => props.modelValue, (newVal) => {
|
|
43
43
|
if (Array.isArray(newVal) && multiRange) {
|
|
44
|
-
from = newVal[0]
|
|
45
|
-
to = newVal[1]
|
|
44
|
+
from = newVal[0] ?? min
|
|
45
|
+
to = newVal[1] ?? max
|
|
46
46
|
} else if (!Array.isArray(newVal)) {
|
|
47
47
|
from = newVal ?? min
|
|
48
48
|
to = max
|
|
@@ -84,7 +84,7 @@ const displayTo = $computed(() => formatValue(validTo))
|
|
|
84
84
|
class="from"
|
|
85
85
|
type="range"
|
|
86
86
|
:min="min"
|
|
87
|
-
:max="
|
|
87
|
+
:max="max"
|
|
88
88
|
:step="step"
|
|
89
89
|
:required="required"
|
|
90
90
|
:disabled="disabled"
|
|
@@ -96,7 +96,7 @@ const displayTo = $computed(() => formatValue(validTo))
|
|
|
96
96
|
:value="validTo"
|
|
97
97
|
class="to"
|
|
98
98
|
type="range"
|
|
99
|
-
:min="
|
|
99
|
+
:min="min"
|
|
100
100
|
:max="max"
|
|
101
101
|
:step="step"
|
|
102
102
|
:required="required"
|
package/src/types/BagelForm.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface BaseBagelField<T = { [key: string]: any }> {
|
|
|
29
29
|
'id'?: string
|
|
30
30
|
'label'?: string
|
|
31
31
|
'placeholder'?: string
|
|
32
|
-
'children'?: Field<T>[]
|
|
32
|
+
'children'?: (Field<T> | string)[]
|
|
33
33
|
'class'?: AttributeValue | AttributeFn<T>
|
|
34
34
|
'attrs'?: Attributes<T>
|
|
35
35
|
'required'?: boolean
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type BglFormSchemaT, type Field, type Option, TelInput } from '@bagelink/vue'
|
|
2
2
|
import { markRaw } from 'vue'
|
|
3
3
|
|
|
4
4
|
interface InputOptions {
|
|
@@ -192,7 +192,7 @@ export function uploadField(id: string, label?: string, options?: UploadOptions)
|
|
|
192
192
|
export function bglForm(idOrField?: string | Field, ...schema: Field[]) {
|
|
193
193
|
if (typeof idOrField === 'string') {
|
|
194
194
|
return {
|
|
195
|
-
$el:
|
|
195
|
+
$el: 'bagelform',
|
|
196
196
|
id: idOrField,
|
|
197
197
|
attrs: {
|
|
198
198
|
schema: [idOrField, ...schema],
|
|
@@ -200,7 +200,7 @@ export function bglForm(idOrField?: string | Field, ...schema: Field[]) {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
return {
|
|
203
|
-
$el:
|
|
203
|
+
$el: 'bagelform',
|
|
204
204
|
attrs: {
|
|
205
205
|
schema: [idOrField, ...schema]
|
|
206
206
|
},
|
|
@@ -221,7 +221,7 @@ export function findBglFieldById(id: string, _schema: BglFormSchemaT): Field | u
|
|
|
221
221
|
for (const field of _schema) {
|
|
222
222
|
if (field.id === id) return field
|
|
223
223
|
if (field.children && Number(field.children.length) > 0) {
|
|
224
|
-
const child = findBglFieldById(id, field.children)
|
|
224
|
+
const child = findBglFieldById(id, field.children.filter(c => typeof c !== 'string'))
|
|
225
225
|
if (child) return child
|
|
226
226
|
}
|
|
227
227
|
}
|