@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.
Files changed (102) hide show
  1. package/dist/components/Alert.vue.d.ts.map +1 -1
  2. package/dist/components/Badge.vue.d.ts.map +1 -1
  3. package/dist/components/Btn.vue.d.ts.map +1 -1
  4. package/dist/components/Dropdown.vue.d.ts.map +1 -1
  5. package/dist/components/Image.vue.d.ts.map +1 -1
  6. package/dist/components/ListItem.vue.d.ts.map +1 -1
  7. package/dist/components/MapEmbed/Index.vue.d.ts.map +1 -1
  8. package/dist/components/Pagination.vue.d.ts.map +1 -1
  9. package/dist/components/Swiper.vue.d.ts.map +1 -1
  10. package/dist/components/Toast.vue.d.ts.map +1 -1
  11. package/dist/components/form/index.d.ts.map +1 -1
  12. package/dist/components/form/inputs/SelectInput.vue.d.ts.map +1 -1
  13. package/dist/components/index.d.ts.map +1 -1
  14. package/dist/components/layout/AppContent.vue.d.ts.map +1 -1
  15. package/dist/components/layout/AppLayout.vue.d.ts.map +1 -1
  16. package/dist/components/layout/AppSidebar.vue.d.ts.map +1 -1
  17. package/dist/components/layout/Panel.vue.d.ts.map +1 -1
  18. package/dist/components/layout/Resizable.vue.d.ts.map +1 -1
  19. package/dist/components/layout/TabsNav.vue.d.ts.map +1 -1
  20. package/dist/components/layout/appLayoutContext.d.ts +24 -0
  21. package/dist/components/layout/appLayoutContext.d.ts.map +1 -0
  22. package/dist/components/layout/index.d.ts.map +1 -1
  23. package/dist/components/lightbox/Lightbox.vue.d.ts.map +1 -1
  24. package/dist/composables/index.d.ts.map +1 -1
  25. package/dist/composables/useDevice.d.ts.map +1 -1
  26. package/dist/composables/useEscapeKey.d.ts +12 -0
  27. package/dist/composables/useEscapeKey.d.ts.map +1 -0
  28. package/dist/composables/useSchemaField.d.ts.map +1 -1
  29. package/dist/composables/useTheme.d.ts.map +1 -1
  30. package/dist/form-flow/FormFlow.vue.d.ts.map +1 -1
  31. package/dist/form-flow/form-flow.d.ts.map +1 -1
  32. package/dist/index.cjs +203 -207
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.mjs +25819 -28870
  35. package/dist/style.css +1 -1
  36. package/dist/types/BagelForm.d.ts.map +1 -1
  37. package/dist/types/BtnOptions.d.ts.map +1 -1
  38. package/dist/utils/constants.d.ts.map +1 -1
  39. package/dist/utils/index.d.ts.map +1 -1
  40. package/package.json +3 -6
  41. package/src/components/Alert.vue +34 -14
  42. package/src/components/Badge.vue +145 -22
  43. package/src/components/Btn.vue +43 -31
  44. package/src/components/Dropdown.vue +5 -12
  45. package/src/components/FilterQuery.vue +1 -1
  46. package/src/components/Image.vue +3 -2
  47. package/src/components/JSONSchema.vue +2 -2
  48. package/src/components/JsonBuilder.vue +1 -1
  49. package/src/components/ListItem.vue +1 -3
  50. package/src/components/MapEmbed/Index.vue +10 -9
  51. package/src/components/NavBar.vue +2 -2
  52. package/src/components/Spreadsheet/Index.vue +1 -1
  53. package/src/components/Swiper.vue +3 -1
  54. package/src/components/Toast.vue +23 -8
  55. package/src/components/calendar/Index.vue +4 -4
  56. package/src/components/calendar/views/MonthView.vue +3 -3
  57. package/src/components/form/index.ts +0 -4
  58. package/src/components/form/inputs/EmailInput.vue +1 -1
  59. package/src/components/form/inputs/NumberInput.vue +1 -1
  60. package/src/components/form/inputs/OTP.vue +2 -2
  61. package/src/components/form/inputs/SelectInput.vue +3 -3
  62. package/src/components/form/inputs/TelInput.vue +2 -2
  63. package/src/components/form/inputs/TextInput.vue +1 -1
  64. package/src/components/form/inputs/Upload/upload.css +2 -2
  65. package/src/components/index.ts +2 -6
  66. package/src/components/layout/AppContent.vue +5 -19
  67. package/src/components/layout/AppLayout.vue +47 -18
  68. package/src/components/layout/AppSidebar.vue +16 -33
  69. package/src/components/layout/Resizable.vue +5 -2
  70. package/src/components/layout/TabsNav.vue +5 -5
  71. package/src/components/layout/appLayoutContext.ts +44 -0
  72. package/src/components/layout/index.ts +2 -0
  73. package/src/components/lightbox/Lightbox.vue +3 -9
  74. package/src/composables/index.ts +1 -0
  75. package/src/composables/useDevice.ts +2 -1
  76. package/src/composables/useEscapeKey.ts +56 -0
  77. package/src/composables/useSchemaField.ts +2 -17
  78. package/src/composables/useTheme.ts +23 -19
  79. package/src/form-flow/FormFlow.vue +2 -0
  80. package/src/form-flow/form-flow.ts +7 -0
  81. package/src/index.ts +0 -2
  82. package/src/styles/inputs.css +1 -1
  83. package/src/types/BagelForm.ts +46 -151
  84. package/src/types/BtnOptions.ts +5 -3
  85. package/src/utils/constants.ts +7 -0
  86. package/src/utils/index.ts +19 -3
  87. package/src/utils/sizeParsing.ts +5 -5
  88. package/vite.config.ts +5 -1
  89. package/src/components/Carousel.vue +0 -724
  90. package/src/components/ImportData.vue +0 -1749
  91. package/src/components/Pill.vue +0 -150
  92. package/src/components/Slider.vue +0 -1446
  93. package/src/components/Title.vue +0 -23
  94. package/src/components/ToolBar.vue +0 -9
  95. package/src/components/form/BagelForm.vue +0 -219
  96. package/src/components/form/BglFieldSet.vue +0 -14
  97. package/src/components/form/BglMultiStepForm.vue +0 -469
  98. package/src/components/form/FieldArray.vue +0 -422
  99. package/src/components/form/useBagelFormState.ts +0 -76
  100. package/src/composables/useFormField.ts +0 -38
  101. package/src/dialog/DialogOLD.vue +0 -358
  102. package/src/utils/BagelFormUtils.ts +0 -684
@@ -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,9 +0,0 @@
1
- <script lang="ts" setup>
2
-
3
- </script>
4
-
5
- <template>
6
- <div class="bg-red">
7
- 123
8
- </div>
9
- </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>