@bagelink/vue 1.14.15 → 1.15.0
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/Alert.vue.d.ts.map +1 -1
- package/dist/components/Badge.vue.d.ts.map +1 -1
- package/dist/components/Btn.vue.d.ts.map +1 -1
- package/dist/components/Dropdown.vue.d.ts.map +1 -1
- package/dist/components/Image.vue.d.ts.map +1 -1
- package/dist/components/ListItem.vue.d.ts.map +1 -1
- package/dist/components/MapEmbed/Index.vue.d.ts.map +1 -1
- package/dist/components/Pagination.vue.d.ts.map +1 -1
- package/dist/components/Swiper.vue.d.ts.map +1 -1
- package/dist/components/Toast.vue.d.ts.map +1 -1
- package/dist/components/form/index.d.ts.map +1 -1
- package/dist/components/form/inputs/SelectInput.vue.d.ts.map +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/layout/AppContent.vue.d.ts.map +1 -1
- package/dist/components/layout/AppLayout.vue.d.ts.map +1 -1
- package/dist/components/layout/AppSidebar.vue.d.ts.map +1 -1
- package/dist/components/layout/Panel.vue.d.ts.map +1 -1
- package/dist/components/layout/Resizable.vue.d.ts.map +1 -1
- package/dist/components/layout/TabsNav.vue.d.ts.map +1 -1
- package/dist/components/layout/appLayoutContext.d.ts +24 -0
- package/dist/components/layout/appLayoutContext.d.ts.map +1 -0
- package/dist/components/layout/index.d.ts.map +1 -1
- package/dist/components/lightbox/Lightbox.vue.d.ts.map +1 -1
- package/dist/composables/index.d.ts.map +1 -1
- package/dist/composables/useDevice.d.ts.map +1 -1
- package/dist/composables/useEscapeKey.d.ts +12 -0
- package/dist/composables/useEscapeKey.d.ts.map +1 -0
- package/dist/composables/useSchemaField.d.ts.map +1 -1
- package/dist/composables/useTheme.d.ts.map +1 -1
- package/dist/form-flow/FormFlow.vue.d.ts.map +1 -1
- package/dist/form-flow/form-flow.d.ts.map +1 -1
- package/dist/index.cjs +203 -207
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +25819 -28870
- package/dist/style.css +1 -1
- package/dist/types/BagelForm.d.ts.map +1 -1
- package/dist/types/BtnOptions.d.ts.map +1 -1
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +3 -6
- package/src/components/Alert.vue +34 -14
- package/src/components/Badge.vue +145 -22
- package/src/components/Btn.vue +43 -31
- package/src/components/Dropdown.vue +5 -12
- package/src/components/FilterQuery.vue +1 -1
- package/src/components/Image.vue +3 -2
- package/src/components/JSONSchema.vue +2 -2
- package/src/components/JsonBuilder.vue +1 -1
- package/src/components/ListItem.vue +1 -3
- package/src/components/MapEmbed/Index.vue +10 -9
- package/src/components/NavBar.vue +2 -2
- package/src/components/Spreadsheet/Index.vue +1 -1
- package/src/components/Swiper.vue +3 -1
- package/src/components/Toast.vue +23 -8
- package/src/components/calendar/Index.vue +4 -4
- package/src/components/calendar/views/MonthView.vue +3 -3
- package/src/components/form/index.ts +0 -4
- package/src/components/form/inputs/EmailInput.vue +1 -1
- package/src/components/form/inputs/NumberInput.vue +1 -1
- package/src/components/form/inputs/OTP.vue +2 -2
- package/src/components/form/inputs/SelectInput.vue +3 -3
- package/src/components/form/inputs/TelInput.vue +2 -2
- package/src/components/form/inputs/TextInput.vue +1 -1
- package/src/components/form/inputs/Upload/upload.css +2 -2
- package/src/components/index.ts +2 -6
- package/src/components/layout/AppContent.vue +5 -19
- package/src/components/layout/AppLayout.vue +47 -18
- package/src/components/layout/AppSidebar.vue +16 -33
- package/src/components/layout/Resizable.vue +5 -2
- package/src/components/layout/TabsNav.vue +5 -5
- package/src/components/layout/appLayoutContext.ts +44 -0
- package/src/components/layout/index.ts +2 -0
- package/src/components/lightbox/Lightbox.vue +3 -9
- package/src/composables/index.ts +1 -0
- package/src/composables/useDevice.ts +2 -1
- package/src/composables/useEscapeKey.ts +56 -0
- package/src/composables/useSchemaField.ts +2 -17
- package/src/composables/useTheme.ts +23 -19
- package/src/form-flow/FormFlow.vue +2 -0
- package/src/form-flow/form-flow.ts +7 -0
- package/src/index.ts +0 -2
- package/src/styles/inputs.css +1 -1
- package/src/types/BagelForm.ts +46 -151
- package/src/types/BtnOptions.ts +5 -3
- package/src/utils/constants.ts +7 -0
- package/src/utils/index.ts +19 -3
- package/src/utils/sizeParsing.ts +5 -5
- package/vite.config.ts +5 -1
- package/src/components/Carousel.vue +0 -724
- package/src/components/ImportData.vue +0 -1749
- package/src/components/Pill.vue +0 -150
- package/src/components/Slider.vue +0 -1446
- package/src/components/Title.vue +0 -23
- package/src/components/ToolBar.vue +0 -9
- package/src/components/form/BagelForm.vue +0 -219
- package/src/components/form/BglFieldSet.vue +0 -14
- package/src/components/form/BglMultiStepForm.vue +0 -469
- package/src/components/form/FieldArray.vue +0 -422
- package/src/components/form/useBagelFormState.ts +0 -76
- package/src/composables/useFormField.ts +0 -38
- package/src/dialog/DialogOLD.vue +0 -358
- package/src/utils/BagelFormUtils.ts +0 -684
package/src/components/Title.vue
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
defineProps({
|
|
3
|
-
value: {
|
|
4
|
-
type: String,
|
|
5
|
-
default: '',
|
|
6
|
-
},
|
|
7
|
-
label: {
|
|
8
|
-
type: String,
|
|
9
|
-
default: '',
|
|
10
|
-
},
|
|
11
|
-
tag: {
|
|
12
|
-
type: String,
|
|
13
|
-
default: 'h1',
|
|
14
|
-
},
|
|
15
|
-
})
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
<template>
|
|
19
|
-
<component :is="tag">
|
|
20
|
-
{{ label || value }}
|
|
21
|
-
<slot />
|
|
22
|
-
</component>
|
|
23
|
-
</template>
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts" generic="T extends {[key:string]:any}, P extends Path<T>">
|
|
2
|
-
import type { BglFormSchemaT, Path, BaseBagelField } from '@bagelink/vue'
|
|
3
|
-
import type { MaybeRefOrGetter } from 'vue'
|
|
4
|
-
import { onMounted, watch, ref, computed, toValue } from 'vue'
|
|
5
|
-
import { useSchemaField } from '../../composables/useSchemaField'
|
|
6
|
-
import { getNestedValue } from '../../utils'
|
|
7
|
-
|
|
8
|
-
const props = withDefaults(defineProps<{
|
|
9
|
-
modelValue?: T
|
|
10
|
-
schema?: MaybeRefOrGetter<BglFormSchemaT<T>>
|
|
11
|
-
tag?: 'form' | 'template'
|
|
12
|
-
class?: string
|
|
13
|
-
onSubmit?: (data: T) => Promise<unknown> | unknown
|
|
14
|
-
}>(), {
|
|
15
|
-
modelValue: undefined,
|
|
16
|
-
schema: undefined,
|
|
17
|
-
tag: 'form',
|
|
18
|
-
class: ''
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
const emit = defineEmits<{
|
|
22
|
-
(e: 'update:modelValue', value: T): void
|
|
23
|
-
}>()
|
|
24
|
-
|
|
25
|
-
// Clone helper
|
|
26
|
-
const clone = <T>(obj: T): T => !obj ? obj : JSON.parse(JSON.stringify(obj))
|
|
27
|
-
|
|
28
|
-
// Form state
|
|
29
|
-
const form = ref<HTMLFormElement>()
|
|
30
|
-
const formData = ref<T>(clone(props.modelValue ?? {}) as T)
|
|
31
|
-
const initialFormData = ref<T>(clone(props.modelValue ?? {}) as T)
|
|
32
|
-
const formState = ref<'success' | 'error' | 'idle' | 'submitting'>('idle')
|
|
33
|
-
const resolvedSchema = computed(() => toValue(props.schema))
|
|
34
|
-
|
|
35
|
-
const isDirty = computed(() => {
|
|
36
|
-
try {
|
|
37
|
-
return JSON.stringify(formData.value) !== JSON.stringify(initialFormData.value)
|
|
38
|
-
} catch {
|
|
39
|
-
return false
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
// Initialize on mount
|
|
44
|
-
onMounted(() => {
|
|
45
|
-
if (props.modelValue) {
|
|
46
|
-
initialFormData.value = clone(props.modelValue)
|
|
47
|
-
// Ensure formData is properly initialized with the model value
|
|
48
|
-
if (Object.keys(formData.value).length === 0 && Object.keys(props.modelValue).length > 0) {
|
|
49
|
-
formData.value = clone(props.modelValue)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
// Apply defaults after ensuring model value is set
|
|
53
|
-
setTimeout(() => {
|
|
54
|
-
applyDefaultValues()
|
|
55
|
-
}, 10)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
// Watch for model changes
|
|
59
|
-
watch(() => props.modelValue, (val) => {
|
|
60
|
-
if (val !== undefined) { formData.value = clone(val) }
|
|
61
|
-
}, { immediate: true, deep: true })
|
|
62
|
-
|
|
63
|
-
let isApplyingDefaults = false
|
|
64
|
-
|
|
65
|
-
function applyDefaultValues() {
|
|
66
|
-
if (isApplyingDefaults) { return }
|
|
67
|
-
isApplyingDefaults = true
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
const schema = resolvedSchema.value as unknown as Array<BaseBagelField<T, any>> | undefined
|
|
71
|
-
if (!schema) { return }
|
|
72
|
-
|
|
73
|
-
const walk = (nodes: any[]) => {
|
|
74
|
-
for (const node of nodes) {
|
|
75
|
-
if (!node || typeof node !== 'object') { continue }
|
|
76
|
-
const hasId = typeof node.id === 'string' && node.id.length > 0
|
|
77
|
-
const hasDefault = Object.hasOwn(node, 'defaultValue') && node.defaultValue !== undefined
|
|
78
|
-
if (hasId && hasDefault) {
|
|
79
|
-
const current = getNestedValue(formData.value as any, node.id as string, undefined)
|
|
80
|
-
|
|
81
|
-
// Skip arrays completely - let FieldArray manage its own defaults
|
|
82
|
-
if (node.$el === 'array' || node.type === 'array') {
|
|
83
|
-
// Don't apply any defaults to arrays - let FieldArray handle it
|
|
84
|
-
continue
|
|
85
|
-
} else {
|
|
86
|
-
// Don't restore defaultValue for regular inputs - let user control their content
|
|
87
|
-
// Only apply defaultValue on initial load when truly undefined/null
|
|
88
|
-
if (current === undefined || current === null) {
|
|
89
|
-
updateFormData({ fieldId: node.id, value: node.defaultValue })
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (Array.isArray(node.children) && node.children.length) { walk(node.children) }
|
|
94
|
-
// Also check nested fields in array/object configurations
|
|
95
|
-
if (Array.isArray(node.fields) && node.fields.length) { walk(node.fields) }
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
walk(schema as any[])
|
|
99
|
-
} finally {
|
|
100
|
-
// Reset the flag after a short delay to allow for multiple synchronous calls
|
|
101
|
-
setTimeout(() => {
|
|
102
|
-
isApplyingDefaults = false
|
|
103
|
-
}, 0)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Use a more conservative watch that doesn't trigger on every change
|
|
108
|
-
const schemaVersion = ref(0)
|
|
109
|
-
watch(resolvedSchema, () => {
|
|
110
|
-
// Increment version to track schema changes
|
|
111
|
-
schemaVersion.value++
|
|
112
|
-
// Only apply defaults after a small delay to avoid rapid firing
|
|
113
|
-
setTimeout(() => {
|
|
114
|
-
if (!isApplyingDefaults) {
|
|
115
|
-
applyDefaultValues()
|
|
116
|
-
}
|
|
117
|
-
}, 10)
|
|
118
|
-
}, { immediate: false })
|
|
119
|
-
|
|
120
|
-
// Update form data
|
|
121
|
-
function updateFormData({ fieldId, value }: { fieldId?: string, value: any }) {
|
|
122
|
-
const keys = fieldId?.split('.') || []
|
|
123
|
-
const newData = clone(formData.value) as { [key: string]: any }
|
|
124
|
-
let current = newData
|
|
125
|
-
|
|
126
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
127
|
-
const key = keys[i]
|
|
128
|
-
if (!current[key] || typeof current[key] !== 'object') { current[key] = {} }
|
|
129
|
-
current = current[key]
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
current[keys[keys.length - 1]] = value
|
|
133
|
-
formData.value = newData as T
|
|
134
|
-
emit('update:modelValue', formData.value)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Form validation
|
|
138
|
-
const validateForm = () => form.value?.reportValidity() ?? false
|
|
139
|
-
const checkValidity = () => form.value?.checkValidity() ?? false
|
|
140
|
-
const formError = ref<Error>()
|
|
141
|
-
// Form submission
|
|
142
|
-
async function handleSubmit() {
|
|
143
|
-
try {
|
|
144
|
-
const valid = validateForm()
|
|
145
|
-
if (!valid) { return }
|
|
146
|
-
if (formState.value === 'submitting') { return }
|
|
147
|
-
formState.value = 'submitting'
|
|
148
|
-
await props.onSubmit?.(formData.value)
|
|
149
|
-
initialFormData.value = clone(formData.value)
|
|
150
|
-
formState.value = 'success'
|
|
151
|
-
window.parent.postMessage({ type: 'BAGEL_FORM_SUCCESS', data: JSON.stringify(formData.value) }, '*')
|
|
152
|
-
} catch (error) {
|
|
153
|
-
formState.value = 'error'
|
|
154
|
-
formError.value = error as Error
|
|
155
|
-
console.error('Submit error:', formError.value)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Field renderingks
|
|
160
|
-
const { renderField } = useSchemaField<T>({
|
|
161
|
-
mode: 'form',
|
|
162
|
-
getFormData: () => formData.value,
|
|
163
|
-
onUpdateModelValue: (field, value) => {
|
|
164
|
-
if (!field.id) { return }
|
|
165
|
-
|
|
166
|
-
updateFormData({ fieldId: field.id, value })
|
|
167
|
-
field.onUpdate?.(value, formData.value)
|
|
168
|
-
}
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
const renderSchemaField = (field: any) => renderField(field as BaseBagelField<T, Path<T>>)
|
|
172
|
-
|
|
173
|
-
// Add new method to handle slot input changes
|
|
174
|
-
function handleSlotInputChange(event: Event) {
|
|
175
|
-
const input = event.target as HTMLInputElement
|
|
176
|
-
if (input.name) {
|
|
177
|
-
const value = input.type === 'checkbox' ? input.checked : input.value
|
|
178
|
-
updateFormData({ fieldId: input.name, value })
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
defineExpose({ form, isDirty, validateForm, checkValidity })
|
|
183
|
-
</script>
|
|
184
|
-
|
|
185
|
-
<template>
|
|
186
|
-
<template v-if="formState !== 'success' || !$slots.success">
|
|
187
|
-
<form
|
|
188
|
-
v-if="props.tag === 'form'" ref="form" :class="props.class" @submit.prevent="handleSubmit"
|
|
189
|
-
@input="handleSlotInputChange"
|
|
190
|
-
>
|
|
191
|
-
<!-- Render fields -->
|
|
192
|
-
<template v-if="resolvedSchema">
|
|
193
|
-
<Component :is="renderSchemaField(field as any)" v-for="field in resolvedSchema" :key="field.id" />
|
|
194
|
-
</template>
|
|
195
|
-
|
|
196
|
-
<!-- Default slot -->
|
|
197
|
-
<slot v-else />
|
|
198
|
-
<!-- Submit slot -->
|
|
199
|
-
<slot
|
|
200
|
-
name="submit" :submit="handleSubmit" :isDirty="isDirty" :validateForm="validateForm"
|
|
201
|
-
:formState="formState"
|
|
202
|
-
/>
|
|
203
|
-
</form>
|
|
204
|
-
|
|
205
|
-
<!-- Template mode -->
|
|
206
|
-
<template v-else>
|
|
207
|
-
<template v-if="resolvedSchema">
|
|
208
|
-
<component
|
|
209
|
-
:is="renderSchemaField(field as any)" v-for="field in resolvedSchema" :key="field.id"
|
|
210
|
-
:class="props.class"
|
|
211
|
-
/>
|
|
212
|
-
</template>
|
|
213
|
-
</template>
|
|
214
|
-
</template>
|
|
215
|
-
|
|
216
|
-
<!-- Success/error slots -->
|
|
217
|
-
<slot v-if="formState === 'success'" name="success" />
|
|
218
|
-
<slot v-if="formState === 'error'" name="error" :error="formError" />
|
|
219
|
-
</template>
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { ref } from 'vue'
|
|
3
|
-
|
|
4
|
-
const fieldSet = ref<HTMLFieldSetElement | undefined>()
|
|
5
|
-
const isDirty = ref(false)
|
|
6
|
-
const validateForm = () => fieldSet.value?.reportValidity()
|
|
7
|
-
defineExpose({ validateForm, isDirty })
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<template>
|
|
11
|
-
<fieldset ref="fieldSet">
|
|
12
|
-
<slot />
|
|
13
|
-
</fieldset>
|
|
14
|
-
</template>
|