@bagelink/vue 0.0.1035 → 0.0.1041
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 +24 -0
- package/dist/components/BglComponent.vue.d.ts.map +1 -0
- package/dist/components/FieldSetVue.vue.d.ts +22 -0
- package/dist/components/FieldSetVue.vue.d.ts.map +1 -0
- package/dist/components/Pill.vue.d.ts +1 -0
- package/dist/components/Pill.vue.d.ts.map +1 -1
- package/dist/components/TableSchema.vue.d.ts.map +1 -1
- package/dist/components/form/BglField.vue.d.ts +8 -6
- package/dist/components/form/BglField.vue.d.ts.map +1 -1
- package/dist/components/form/BglForm.vue.d.ts +5 -4
- package/dist/components/form/BglForm.vue.d.ts.map +1 -1
- package/dist/components/form/BglMultiStepForm.vue.d.ts +2 -2
- package/dist/components/form/FieldArray.vue.d.ts +1 -0
- package/dist/components/form/FieldArray.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/NumberInput.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RadioGroup.vue.d.ts +1 -0
- package/dist/components/form/inputs/RadioGroup.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RangeInput.vue.d.ts +4 -3
- package/dist/components/form/inputs/RangeInput.vue.d.ts.map +1 -1
- package/dist/components/form/useBagelFormState.d.ts +11 -0
- package/dist/components/form/useBagelFormState.d.ts.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/index.cjs +7085 -9121
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +7091 -9127
- package/dist/style.css +504 -495
- package/dist/utils/BagelFormUtils.d.ts +31 -17
- package/dist/utils/BagelFormUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/BglComponent.vue +174 -0
- package/src/components/FieldSetVue.vue +23 -0
- package/src/components/ModalForm.vue +1 -1
- package/src/components/Pill.vue +3 -2
- package/src/components/TableSchema.vue +3 -2
- package/src/components/form/BglField.vue +50 -77
- package/src/components/form/BglForm.vue +44 -31
- package/src/components/form/FieldArray.vue +25 -19
- package/src/components/form/inputs/NumberInput.vue +7 -8
- package/src/components/form/inputs/RadioGroup.vue +2 -0
- package/src/components/form/inputs/RangeInput.vue +75 -42
- package/src/components/form/useBagelFormState.ts +87 -0
- package/src/components/index.ts +5 -2
- package/src/index.ts +3 -1
- package/src/utils/BagelFormUtils.ts +12 -1
- package/src/components/FieldSet.vue +0 -15
|
@@ -6,6 +6,7 @@ interface InputOptions {
|
|
|
6
6
|
defaultValue?: string;
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
helptext?: string;
|
|
9
|
+
vIf?: boolean | ((item: any, row: any) => boolean);
|
|
9
10
|
}
|
|
10
11
|
type DateOptions = InputOptions;
|
|
11
12
|
interface TextInputOptions extends InputOptions {
|
|
@@ -32,6 +33,7 @@ export declare function richText(id: string, label?: string, options?: RichTextO
|
|
|
32
33
|
required: boolean | undefined;
|
|
33
34
|
id: string;
|
|
34
35
|
label: string | undefined;
|
|
36
|
+
vIf: boolean | ((item: any, row: any) => boolean) | undefined;
|
|
35
37
|
placeholder: string | undefined;
|
|
36
38
|
attrs: {};
|
|
37
39
|
};
|
|
@@ -52,7 +54,17 @@ export declare function uploadField(id: string, label?: string, options?: Upload
|
|
|
52
54
|
$el: string;
|
|
53
55
|
id: string;
|
|
54
56
|
label: string | undefined;
|
|
55
|
-
|
|
57
|
+
vIf: boolean | ((item: any, row: any) => boolean) | undefined;
|
|
58
|
+
attrs: {
|
|
59
|
+
multiple?: boolean;
|
|
60
|
+
required?: boolean;
|
|
61
|
+
placeholder?: string;
|
|
62
|
+
class?: string;
|
|
63
|
+
defaultValue?: string;
|
|
64
|
+
disabled?: boolean;
|
|
65
|
+
helptext?: string;
|
|
66
|
+
vIf?: boolean | ((item: any, row: any) => boolean);
|
|
67
|
+
};
|
|
56
68
|
};
|
|
57
69
|
export declare function bglForm(idOrField?: string | Field, ...schema: Field[]): {
|
|
58
70
|
$el: import('vue').Raw<{
|
|
@@ -74,8 +86,8 @@ export declare function bglForm(idOrField?: string | Field, ...schema: Field[]):
|
|
|
74
86
|
submit: () => void;
|
|
75
87
|
validateForm: () => boolean;
|
|
76
88
|
deleteItem: () => void;
|
|
77
|
-
isDirty: import('
|
|
78
|
-
clearForm: () =>
|
|
89
|
+
isDirty: import('vue').Ref<boolean, boolean>;
|
|
90
|
+
clearForm: () => void;
|
|
79
91
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
80
92
|
submit: (...args: any[]) => void;
|
|
81
93
|
"update:modelValue": (...args: any[]) => void;
|
|
@@ -109,8 +121,8 @@ export declare function bglForm(idOrField?: string | Field, ...schema: Field[]):
|
|
|
109
121
|
submit: () => void;
|
|
110
122
|
validateForm: () => boolean;
|
|
111
123
|
deleteItem: () => void;
|
|
112
|
-
isDirty: import('
|
|
113
|
-
clearForm: () =>
|
|
124
|
+
isDirty: import('vue').Ref<boolean, boolean>;
|
|
125
|
+
clearForm: () => void;
|
|
114
126
|
}, {}, {}, {}, {
|
|
115
127
|
modelValue: {
|
|
116
128
|
[key: string]: any;
|
|
@@ -137,8 +149,8 @@ export declare function bglForm(idOrField?: string | Field, ...schema: Field[]):
|
|
|
137
149
|
submit: () => void;
|
|
138
150
|
validateForm: () => boolean;
|
|
139
151
|
deleteItem: () => void;
|
|
140
|
-
isDirty: import('
|
|
141
|
-
clearForm: () =>
|
|
152
|
+
isDirty: import('vue').Ref<boolean, boolean>;
|
|
153
|
+
clearForm: () => void;
|
|
142
154
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
143
155
|
submit: (...args: any[]) => void;
|
|
144
156
|
"update:modelValue": (...args: any[]) => void;
|
|
@@ -151,12 +163,12 @@ export declare function bglForm(idOrField?: string | Field, ...schema: Field[]):
|
|
|
151
163
|
$slots: {
|
|
152
164
|
submit?(_: {
|
|
153
165
|
submit: () => void;
|
|
154
|
-
isDirty:
|
|
166
|
+
isDirty: boolean;
|
|
155
167
|
validateForm: () => boolean;
|
|
156
168
|
}): any;
|
|
157
169
|
submit?(_: {
|
|
158
170
|
submit: () => void;
|
|
159
|
-
isDirty:
|
|
171
|
+
isDirty: boolean;
|
|
160
172
|
validateForm: () => boolean;
|
|
161
173
|
}): any;
|
|
162
174
|
success?(_: {}): any;
|
|
@@ -189,8 +201,8 @@ export declare function bglForm(idOrField?: string | Field, ...schema: Field[]):
|
|
|
189
201
|
submit: () => void;
|
|
190
202
|
validateForm: () => boolean;
|
|
191
203
|
deleteItem: () => void;
|
|
192
|
-
isDirty: import('
|
|
193
|
-
clearForm: () =>
|
|
204
|
+
isDirty: import('vue').Ref<boolean, boolean>;
|
|
205
|
+
clearForm: () => void;
|
|
194
206
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
195
207
|
submit: (...args: any[]) => void;
|
|
196
208
|
"update:modelValue": (...args: any[]) => void;
|
|
@@ -224,8 +236,8 @@ export declare function bglForm(idOrField?: string | Field, ...schema: Field[]):
|
|
|
224
236
|
submit: () => void;
|
|
225
237
|
validateForm: () => boolean;
|
|
226
238
|
deleteItem: () => void;
|
|
227
|
-
isDirty: import('
|
|
228
|
-
clearForm: () =>
|
|
239
|
+
isDirty: import('vue').Ref<boolean, boolean>;
|
|
240
|
+
clearForm: () => void;
|
|
229
241
|
}, {}, {}, {}, {
|
|
230
242
|
modelValue: {
|
|
231
243
|
[key: string]: any;
|
|
@@ -252,8 +264,8 @@ export declare function bglForm(idOrField?: string | Field, ...schema: Field[]):
|
|
|
252
264
|
submit: () => void;
|
|
253
265
|
validateForm: () => boolean;
|
|
254
266
|
deleteItem: () => void;
|
|
255
|
-
isDirty: import('
|
|
256
|
-
clearForm: () =>
|
|
267
|
+
isDirty: import('vue').Ref<boolean, boolean>;
|
|
268
|
+
clearForm: () => void;
|
|
257
269
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
258
270
|
submit: (...args: any[]) => void;
|
|
259
271
|
"update:modelValue": (...args: any[]) => void;
|
|
@@ -266,12 +278,12 @@ export declare function bglForm(idOrField?: string | Field, ...schema: Field[]):
|
|
|
266
278
|
$slots: {
|
|
267
279
|
submit?(_: {
|
|
268
280
|
submit: () => void;
|
|
269
|
-
isDirty:
|
|
281
|
+
isDirty: boolean;
|
|
270
282
|
validateForm: () => boolean;
|
|
271
283
|
}): any;
|
|
272
284
|
submit?(_: {
|
|
273
285
|
submit: () => void;
|
|
274
|
-
isDirty:
|
|
286
|
+
isDirty: boolean;
|
|
275
287
|
validateForm: () => boolean;
|
|
276
288
|
}): any;
|
|
277
289
|
success?(_: {}): any;
|
|
@@ -297,6 +309,7 @@ export declare function arrField(id: string, label: string, schema: BglFormSchem
|
|
|
297
309
|
label: string;
|
|
298
310
|
id: string;
|
|
299
311
|
$el: string;
|
|
312
|
+
vIf: boolean | ((item: any, row: any) => boolean) | undefined;
|
|
300
313
|
attrs: {
|
|
301
314
|
delete: boolean;
|
|
302
315
|
add: boolean;
|
|
@@ -306,6 +319,7 @@ export declare function arrField(id: string, label: string, schema: BglFormSchem
|
|
|
306
319
|
defaultValue?: string;
|
|
307
320
|
disabled?: boolean;
|
|
308
321
|
helptext?: string;
|
|
322
|
+
vIf?: boolean | ((item: any, row: any) => boolean);
|
|
309
323
|
schema: BglFormSchemaT;
|
|
310
324
|
};
|
|
311
325
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BagelFormUtils.d.ts","sourceRoot":"","sources":["../../src/utils/BagelFormUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,cAAc,EAAE,KAAK,KAAK,EAAE,KAAK,MAAM,EAAY,MAAM,eAAe,CAAA;AAGjG,UAAU,YAAY;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;I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E,cAAc,EAAE,OAAO,CAAC,EAAE,iBAAiB;;;;2BAjO9E,GAAG,OAAO,GAAG,KAAK,OAAO;;gBA6NxC,OAAO;aACV,OAAO;mBApOF,OAAO;sBACJ,MAAM;gBACZ,MAAM;uBACC,MAAM;mBACV,OAAO;mBACP,MAAM;cACX,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;;;EAyOlD"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T extends Record<string, any>">
|
|
2
|
+
import {
|
|
3
|
+
CheckInput,
|
|
4
|
+
DateInput,
|
|
5
|
+
FieldArray,
|
|
6
|
+
type Field,
|
|
7
|
+
FileUpload,
|
|
8
|
+
RichText,
|
|
9
|
+
SelectInput,
|
|
10
|
+
TextInput,
|
|
11
|
+
ToggleInput,
|
|
12
|
+
bindAttrs,
|
|
13
|
+
classify,
|
|
14
|
+
NumberInput,
|
|
15
|
+
UploadInput,
|
|
16
|
+
BglForm,
|
|
17
|
+
TabsNav,
|
|
18
|
+
} from '@bagelink/vue'
|
|
19
|
+
|
|
20
|
+
const props = defineProps<{
|
|
21
|
+
field: Field<T>
|
|
22
|
+
id?: string
|
|
23
|
+
modelValue?: any
|
|
24
|
+
parentPath?: string
|
|
25
|
+
}>()
|
|
26
|
+
|
|
27
|
+
const emit = defineEmits<{
|
|
28
|
+
'update:modelValue': [value: any]
|
|
29
|
+
}>()
|
|
30
|
+
|
|
31
|
+
const customAttrs = $ref<{ [key: string]: any }>({})
|
|
32
|
+
|
|
33
|
+
const is = $computed(() => {
|
|
34
|
+
if (props.field.$el === 'text') return TextInput
|
|
35
|
+
if (props.field.$el === 'textarea') {
|
|
36
|
+
customAttrs.multiline = true
|
|
37
|
+
return TextInput
|
|
38
|
+
}
|
|
39
|
+
if (props.field.$el === 'number') return NumberInput
|
|
40
|
+
if (props.field.$el === 'array') return FieldArray
|
|
41
|
+
if (props.field.$el === 'select') return SelectInput
|
|
42
|
+
if (props.field.$el === 'toggle') return ToggleInput
|
|
43
|
+
if (props.field.$el === 'check') return CheckInput
|
|
44
|
+
if (props.field.$el === 'richtext') return RichText
|
|
45
|
+
if (props.field.$el === 'upload') return UploadInput
|
|
46
|
+
if (props.field.$el === 'file') return FileUpload
|
|
47
|
+
if (props.field.$el === 'date') return DateInput
|
|
48
|
+
if (props.field.$el === 'tabs') return TabsNav
|
|
49
|
+
if (props.field.$el === 'form') return BglForm
|
|
50
|
+
return props.field.$el ?? 'div'
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
function getFieldData(path?: string) {
|
|
54
|
+
if (!path) return ''
|
|
55
|
+
const keys = path.split(/[.[]/)
|
|
56
|
+
let current = props.modelValue as any
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < keys.length; i++) {
|
|
59
|
+
const key = keys[i]
|
|
60
|
+
if (!current || typeof current !== 'object' || !(key in current)) {
|
|
61
|
+
return ''
|
|
62
|
+
}
|
|
63
|
+
current = current[key]
|
|
64
|
+
}
|
|
65
|
+
return current ?? ''
|
|
66
|
+
}
|
|
67
|
+
function safeClone(obj: any): any {
|
|
68
|
+
if (obj === null || typeof obj !== 'object') return obj
|
|
69
|
+
|
|
70
|
+
const seen = new WeakSet()
|
|
71
|
+
return JSON.parse(JSON.stringify(obj, (key, value) => {
|
|
72
|
+
if (typeof value === 'object' && value !== null) {
|
|
73
|
+
if (seen.has(value)) {
|
|
74
|
+
return undefined // Remove circular reference
|
|
75
|
+
}
|
|
76
|
+
seen.add(value)
|
|
77
|
+
}
|
|
78
|
+
return value
|
|
79
|
+
}))
|
|
80
|
+
}
|
|
81
|
+
function updateField(path: string, value: any) {
|
|
82
|
+
const keys = path.split(/[.[]/)
|
|
83
|
+
|
|
84
|
+
let current = props.modelValue ?? {} as any
|
|
85
|
+
|
|
86
|
+
// Build the path, ensuring each level is an object
|
|
87
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
88
|
+
const key = keys[i]
|
|
89
|
+
if (!(key in current) || typeof current[key] !== 'object' || current[key] === null) {
|
|
90
|
+
current[key] = {}
|
|
91
|
+
}
|
|
92
|
+
current = current[key]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Safely clone the value to remove circular references
|
|
96
|
+
const safeValue = safeClone(value)
|
|
97
|
+
current[keys[keys.length - 1]] = safeValue
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const fieldData = $computed({
|
|
101
|
+
get: () => {
|
|
102
|
+
if (!props.id) return props.modelValue ?? props.field.defaultValue ?? (props.field.$el === 'form' ? {} : '')
|
|
103
|
+
const value = getFieldData(props.id)
|
|
104
|
+
if (props.field.$el === 'form' && !value) return {}
|
|
105
|
+
return value ?? ''
|
|
106
|
+
},
|
|
107
|
+
set: (val: any) => {
|
|
108
|
+
if (!props.id) return
|
|
109
|
+
const currentValue = getFieldData(props.id)
|
|
110
|
+
if (JSON.stringify(val) === JSON.stringify(currentValue)) return
|
|
111
|
+
|
|
112
|
+
emit('update:modelValue', val)
|
|
113
|
+
if (props.field.onUpdate) {
|
|
114
|
+
props.field.onUpdate(val, currentValue)
|
|
115
|
+
}
|
|
116
|
+
updateField(props.id, val)
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
const vIf = $computed(() => {
|
|
121
|
+
if (props.field['v-if'] === undefined && props.field.vIf === undefined) return true
|
|
122
|
+
if (typeof props.field['v-if'] === 'boolean' || typeof props.field.vIf === 'boolean') return props.field['v-if']
|
|
123
|
+
if (typeof props.field['v-if'] === 'string' || typeof props.field.vIf === 'string') return true
|
|
124
|
+
if (typeof props.field['v-if'] === 'function') return props.field['v-if'](fieldData, props.modelValue as T)
|
|
125
|
+
if (typeof props.field.vIf === 'function') return props.field.vIf(fieldData, props.modelValue as T)
|
|
126
|
+
return true
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const computedOptions = $computed(
|
|
130
|
+
() => bindAttrs({ options: props.field.options }, fieldData, props.modelValue).options
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
const computedAttrs = $computed(() => {
|
|
134
|
+
const attrs = { ...customAttrs, ...props.field.attrs }
|
|
135
|
+
return bindAttrs(attrs, fieldData, props.modelValue)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
const computedClass = $computed(
|
|
139
|
+
() => classify(fieldData, props.modelValue, props.field.class, props.field.attrs?.class)
|
|
140
|
+
)
|
|
141
|
+
</script>
|
|
142
|
+
|
|
143
|
+
<template>
|
|
144
|
+
<component
|
|
145
|
+
v-bind="computedAttrs"
|
|
146
|
+
:is="is"
|
|
147
|
+
v-if="vIf"
|
|
148
|
+
:id="props.id"
|
|
149
|
+
v-model="fieldData"
|
|
150
|
+
:required="field.required"
|
|
151
|
+
:class="computedClass"
|
|
152
|
+
:label="field.label"
|
|
153
|
+
:placeholder="field.placeholder || field.label"
|
|
154
|
+
:defaultValue="field.defaultValue"
|
|
155
|
+
:disabled="field.disabled"
|
|
156
|
+
:options="computedOptions"
|
|
157
|
+
:helptext="field.helptext"
|
|
158
|
+
:schema="field.attrs?.schema ?? undefined"
|
|
159
|
+
>
|
|
160
|
+
<template v-if="field.$el === 'form'">
|
|
161
|
+
<slot />
|
|
162
|
+
</template>
|
|
163
|
+
<template v-else>
|
|
164
|
+
{{ fieldData }}
|
|
165
|
+
<BglComponent
|
|
166
|
+
v-for="(child, ii) in field.children"
|
|
167
|
+
:id="[props.id, child.id].filter(Boolean).join('.')"
|
|
168
|
+
:key="child.id || ii"
|
|
169
|
+
:field="child"
|
|
170
|
+
:parent-path="props.id"
|
|
171
|
+
/>
|
|
172
|
+
</template>
|
|
173
|
+
</component>
|
|
174
|
+
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
defineProps<{
|
|
3
|
+
label?: string
|
|
4
|
+
legend?: string
|
|
5
|
+
}>()
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<template>
|
|
9
|
+
<fieldset class="px-1 pt-025 pb-1">
|
|
10
|
+
<legend class="ms-1">
|
|
11
|
+
{{ legend || label }}
|
|
12
|
+
</legend>
|
|
13
|
+
<slot />
|
|
14
|
+
</fieldset>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<style scoped>
|
|
18
|
+
fieldset {
|
|
19
|
+
border: 1px solid var(--border-color);
|
|
20
|
+
border-radius: var(--card-border-radius);
|
|
21
|
+
padding: var(--space-md);
|
|
22
|
+
}
|
|
23
|
+
</style>
|
package/src/components/Pill.vue
CHANGED
|
@@ -20,6 +20,7 @@ const props = defineProps<{
|
|
|
20
20
|
outline?: boolean
|
|
21
21
|
loading?: boolean
|
|
22
22
|
value?: string
|
|
23
|
+
modelValue?: string
|
|
23
24
|
round?: boolean
|
|
24
25
|
btn?: BtnProp
|
|
25
26
|
btnEnd?: BtnProp
|
|
@@ -91,8 +92,8 @@ const computedBackgroundColor = $computed(
|
|
|
91
92
|
</div>
|
|
92
93
|
<MaterialIcon v-if="icon" :icon="icon" />
|
|
93
94
|
<slot />
|
|
94
|
-
<template v-if="!slots.default && value">
|
|
95
|
-
{{ value }}
|
|
95
|
+
<template v-if="!slots.default && (value)">
|
|
96
|
+
{{ value || modelValue }}
|
|
96
97
|
</template>
|
|
97
98
|
<MaterialIcon v-if="iconEnd" :icon="iconEnd" />
|
|
98
99
|
<div v-if="loading" class="loading" />
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T extends Record<string, any>">
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
BglComponent,
|
|
4
4
|
type BglFormSchemaT,
|
|
5
5
|
MaterialIcon,
|
|
6
6
|
isDate,
|
|
@@ -272,7 +272,8 @@ watch(
|
|
|
272
272
|
:field
|
|
273
273
|
/>
|
|
274
274
|
<div v-else>
|
|
275
|
-
<
|
|
275
|
+
<BglComponent
|
|
276
|
+
:id="field.id"
|
|
276
277
|
class="embedded-field"
|
|
277
278
|
:field
|
|
278
279
|
:modelValue="row"
|
|
@@ -11,23 +11,27 @@ import {
|
|
|
11
11
|
ToggleInput,
|
|
12
12
|
bindAttrs,
|
|
13
13
|
classify,
|
|
14
|
-
BagelForm,
|
|
15
14
|
NumberInput,
|
|
16
15
|
UploadInput,
|
|
16
|
+
type BagelFormState,
|
|
17
|
+
BglForm
|
|
17
18
|
} from '@bagelink/vue'
|
|
19
|
+
import { inject } from 'vue'
|
|
18
20
|
import TabsNav from '../layout/TabsNav.vue'
|
|
21
|
+
import { FORM_STATE_KEY } from './useBagelFormState'
|
|
19
22
|
|
|
20
|
-
const props =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const props = defineProps<{
|
|
24
|
+
field: Field<T>
|
|
25
|
+
id?: string
|
|
26
|
+
modelValue?: any
|
|
27
|
+
parentPath?: string
|
|
28
|
+
}>()
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits<{
|
|
31
|
+
'update:modelValue': [value: any]
|
|
32
|
+
}>()
|
|
29
33
|
|
|
30
|
-
const
|
|
34
|
+
const formState = inject<BagelFormState<T>>(FORM_STATE_KEY)
|
|
31
35
|
|
|
32
36
|
const customAttrs = $ref<{ [key: string]: any }>({})
|
|
33
37
|
|
|
@@ -47,90 +51,54 @@ const is = $computed(() => {
|
|
|
47
51
|
if (props.field.$el === 'file') return FileUpload
|
|
48
52
|
if (props.field.$el === 'date') return DateInput
|
|
49
53
|
if (props.field.$el === 'tabs') return TabsNav
|
|
50
|
-
if (props.field.$el === 'form') return
|
|
54
|
+
if (props.field.$el === 'form') return BglForm
|
|
51
55
|
return props.field.$el ?? 'div'
|
|
52
56
|
})
|
|
53
57
|
|
|
54
|
-
const
|
|
55
|
-
get: () =>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
const fieldData = $computed({
|
|
59
|
+
get: () => {
|
|
60
|
+
if (!props.id) return props.field.defaultValue ?? (props.field.$el === 'form' ? {} : '')
|
|
61
|
+
const value = formState?.getFieldData(props.id)
|
|
62
|
+
if (props.field.$el === 'form' && !value) return {}
|
|
63
|
+
return value ?? ''
|
|
58
64
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
function setFieldData(key: string, val: any) {
|
|
64
|
-
const data = { ...props.modelValue }
|
|
65
|
-
const keys = key.split(objPathRegex)
|
|
66
|
-
let temp = data
|
|
67
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
68
|
-
if (!temp[keys[i]]) {
|
|
69
|
-
temp[keys[i]] = {}
|
|
70
|
-
}
|
|
71
|
-
temp = temp[keys[i]]
|
|
72
|
-
}
|
|
73
|
-
temp[keys[keys.length - 1]] = val
|
|
74
|
-
return data
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const isForm = $computed(() => props.field.$el === 'form' || props.field.$el === BagelForm)
|
|
65
|
+
set: (val: any) => {
|
|
66
|
+
if (!props.id) return
|
|
67
|
+
const currentValue = formState?.getFieldData(props.id)
|
|
68
|
+
if (JSON.stringify(val) === JSON.stringify(currentValue)) return
|
|
78
69
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
let result = obj
|
|
83
|
-
for (const k of keys) {
|
|
84
|
-
if (result && k in result) {
|
|
85
|
-
result = result[k]
|
|
86
|
-
} else {
|
|
87
|
-
return undefined
|
|
70
|
+
emit('update:modelValue', val)
|
|
71
|
+
if (props.field.onUpdate) {
|
|
72
|
+
props.field.onUpdate(val, currentValue)
|
|
88
73
|
}
|
|
74
|
+
formState?.updateField(props.id, val)
|
|
89
75
|
}
|
|
90
|
-
return result
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const fieldData = $computed({
|
|
94
|
-
set: (val: any) => {
|
|
95
|
-
if (isForm) {
|
|
96
|
-
emit('update:modelValue', val)
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
if (!props.field.id) return
|
|
100
|
-
const data = setFieldData(props.field.id, val)
|
|
101
|
-
emit('update:modelValue', data)
|
|
102
|
-
},
|
|
103
|
-
get: () => {
|
|
104
|
-
if (props.field.id) return getFieldData(props.modelValue, props.field.id)
|
|
105
|
-
if (isForm) return props.modelValue
|
|
106
|
-
return props.field.defaultValue ?? ''
|
|
107
|
-
},
|
|
108
76
|
})
|
|
109
77
|
|
|
110
78
|
const vIf = $computed(() => {
|
|
111
79
|
if (props.field['v-if'] === undefined && props.field.vIf === undefined) return true
|
|
112
80
|
if (typeof props.field['v-if'] === 'boolean' || typeof props.field.vIf === 'boolean') return props.field['v-if']
|
|
113
81
|
if (typeof props.field['v-if'] === 'string' || typeof props.field.vIf === 'string') return true
|
|
114
|
-
if (typeof props.field['v-if'] === 'function') return props.field['v-if'](fieldData,
|
|
115
|
-
if (typeof props.field.vIf === 'function') return props.field.vIf(fieldData,
|
|
82
|
+
if (typeof props.field['v-if'] === 'function') return props.field['v-if'](fieldData, formState?.data.value as T)
|
|
83
|
+
if (typeof props.field.vIf === 'function') return props.field.vIf(fieldData, formState?.data.value as T)
|
|
116
84
|
return true
|
|
117
85
|
})
|
|
118
86
|
|
|
119
87
|
const computedFieldData = $computed(
|
|
120
|
-
() => props.field.transform?.(fieldData,
|
|
88
|
+
() => props.field.transform?.(fieldData, formState?.data.value as T) ?? fieldData
|
|
121
89
|
)
|
|
122
90
|
|
|
123
91
|
const computedOptions = $computed(
|
|
124
|
-
() => bindAttrs({ options: props.field.options }, fieldData,
|
|
92
|
+
() => bindAttrs({ options: props.field.options }, fieldData, formState?.data.value).options
|
|
125
93
|
)
|
|
126
94
|
|
|
127
95
|
const computedAttrs = $computed(() => {
|
|
128
96
|
const attrs = { ...customAttrs, ...props.field.attrs }
|
|
129
|
-
return bindAttrs(attrs, fieldData,
|
|
97
|
+
return bindAttrs(attrs, fieldData, formState?.data.value)
|
|
130
98
|
})
|
|
131
99
|
|
|
132
100
|
const computedClass = $computed(
|
|
133
|
-
() => classify(fieldData,
|
|
101
|
+
() => classify(fieldData, formState?.data.value, props.field.class, props.field.attrs?.class)
|
|
134
102
|
)
|
|
135
103
|
</script>
|
|
136
104
|
|
|
@@ -139,7 +107,7 @@ const computedClass = $computed(
|
|
|
139
107
|
v-bind="computedAttrs"
|
|
140
108
|
:is="is"
|
|
141
109
|
v-if="vIf"
|
|
142
|
-
:id="
|
|
110
|
+
:id="props.id"
|
|
143
111
|
v-model="fieldData"
|
|
144
112
|
:required="field.required"
|
|
145
113
|
:class="computedClass"
|
|
@@ -149,14 +117,19 @@ const computedClass = $computed(
|
|
|
149
117
|
:disabled="field.disabled"
|
|
150
118
|
:options="computedOptions"
|
|
151
119
|
:helptext="field.helptext"
|
|
152
|
-
|
|
120
|
+
:schema="field.attrs?.schema ?? undefined"
|
|
153
121
|
>
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
122
|
+
<template v-if="field.$el === 'form'">
|
|
123
|
+
<slot />
|
|
124
|
+
</template>
|
|
125
|
+
<template v-else>
|
|
126
|
+
<BglField
|
|
127
|
+
v-for="(child, ii) in field.children"
|
|
128
|
+
:id="[props.id, child.id].filter(Boolean).join('.')"
|
|
129
|
+
:key="child.id || ii"
|
|
130
|
+
:field="child"
|
|
131
|
+
:parent-path="props.id"
|
|
132
|
+
/>
|
|
133
|
+
</template>
|
|
161
134
|
</component>
|
|
162
135
|
</template>
|