@bagelink/vue 1.0.38 → 1.0.41

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/style.css CHANGED
@@ -3079,16 +3079,16 @@ to {
3079
3079
  }
3080
3080
 
3081
3081
  /* Bar Theme */
3082
- .lds-bar[data-v-2e27b3c1] {
3082
+ .lds-bar[data-v-221a3053] {
3083
3083
  height: 4px;
3084
3084
  width: 100%;
3085
3085
  max-width: 130px;
3086
3086
  --c: no-repeat linear-gradient(currentColor 0 0);
3087
3087
  background: var(--c), var(--c), #ddd;
3088
3088
  background-size: 60% 100%;
3089
- animation: bar-animation-2e27b3c1 3s infinite ease-in-out;
3089
+ animation: bar-animation-221a3053 3s infinite ease-in-out;
3090
3090
  }
3091
- @keyframes bar-animation-2e27b3c1 {
3091
+ @keyframes bar-animation-221a3053 {
3092
3092
  0% { background-position: -150% 0, -150% 0
3093
3093
  }
3094
3094
  66% { background-position: 250% 0, -150% 0
@@ -3096,17 +3096,17 @@ to {
3096
3096
  100% { background-position: 250% 0, 250% 0
3097
3097
  }
3098
3098
  }
3099
- .lds-ring[data-v-2e27b3c1],
3100
- .lds-ring div[data-v-2e27b3c1] {
3099
+ .lds-ring[data-v-221a3053],
3100
+ .lds-ring div[data-v-221a3053] {
3101
3101
  box-sizing: border-box;
3102
3102
  }
3103
- .lds-ring[data-v-2e27b3c1] {
3103
+ .lds-ring[data-v-221a3053] {
3104
3104
  position: relative;
3105
3105
  width: var(--size);
3106
3106
  height: var(--size);
3107
3107
  transform: translate(calc(var(--thickness) * -1), calc(var(--thickness) * -1));
3108
3108
  }
3109
- .lds-ring div[data-v-2e27b3c1] {
3109
+ .lds-ring div[data-v-221a3053] {
3110
3110
  box-sizing: border-box;
3111
3111
  display: block;
3112
3112
  position: absolute;
@@ -3115,19 +3115,19 @@ to {
3115
3115
  margin: var(--thickness);
3116
3116
  border: var(--thickness) solid currentColor;
3117
3117
  border-radius: 50%;
3118
- animation: lds-ring-2e27b3c1 var(--animation-duration) cubic-bezier(0.5, 0, 0.5, 1) infinite;
3118
+ animation: lds-ring-221a3053 var(--animation-duration) cubic-bezier(0.5, 0, 0.5, 1) infinite;
3119
3119
  border-color: currentColor transparent transparent transparent;
3120
3120
  }
3121
- .lds-ring div[data-v-2e27b3c1]:nth-child(1) {
3121
+ .lds-ring div[data-v-221a3053]:nth-child(1) {
3122
3122
  animation-delay: calc(var(--animation-duration) * -0.38);
3123
3123
  }
3124
- .lds-ring div[data-v-2e27b3c1]:nth-child(2) {
3124
+ .lds-ring div[data-v-221a3053]:nth-child(2) {
3125
3125
  animation-delay: calc(var(--animation-duration) / -4);
3126
3126
  }
3127
- .lds-ring div[data-v-2e27b3c1]:nth-child(3) {
3127
+ .lds-ring div[data-v-221a3053]:nth-child(3) {
3128
3128
  animation-delay: calc(var(--animation-duration) / -8);
3129
3129
  }
3130
- @keyframes lds-ring-2e27b3c1 {
3130
+ @keyframes lds-ring-221a3053 {
3131
3131
  0% {
3132
3132
  transform: rotate(0deg);
3133
3133
  }
@@ -3135,17 +3135,17 @@ to {
3135
3135
  transform: rotate(360deg);
3136
3136
  }
3137
3137
  }
3138
- .lds-ellipsis[data-v-2e27b3c1],
3139
- .lds-ellipsis div[data-v-2e27b3c1] {
3138
+ .lds-ellipsis[data-v-221a3053],
3139
+ .lds-ellipsis div[data-v-221a3053] {
3140
3140
  box-sizing: border-box;
3141
3141
  }
3142
- .lds-ellipsis[data-v-2e27b3c1] {
3142
+ .lds-ellipsis[data-v-221a3053] {
3143
3143
  display: inline-block;
3144
3144
  position: relative;
3145
3145
  width: var(--size);
3146
3146
  height: var(--size);
3147
3147
  }
3148
- .lds-ellipsis div[data-v-2e27b3c1] {
3148
+ .lds-ellipsis div[data-v-221a3053] {
3149
3149
  position: absolute;
3150
3150
  top: calc(var(--size) - 40%);
3151
3151
  width: calc(var(--size) / 5);
@@ -3154,23 +3154,23 @@ to {
3154
3154
  background: currentColor;
3155
3155
  animation-timing-function: cubic-bezier(0, 1, 1, 0);
3156
3156
  }
3157
- .lds-ellipsis div[data-v-2e27b3c1]:nth-child(1) {
3157
+ .lds-ellipsis div[data-v-221a3053]:nth-child(1) {
3158
3158
  left: calc(var(--size) / 10);
3159
- animation: lds-ellipsis1-2e27b3c1 0.6s infinite;
3159
+ animation: lds-ellipsis1-221a3053 0.6s infinite;
3160
3160
  }
3161
- .lds-ellipsis div[data-v-2e27b3c1]:nth-child(2) {
3161
+ .lds-ellipsis div[data-v-221a3053]:nth-child(2) {
3162
3162
  left: calc(var(--size) / 10);
3163
- animation: lds-ellipsis2-2e27b3c1 0.6s infinite;
3163
+ animation: lds-ellipsis2-221a3053 0.6s infinite;
3164
3164
  }
3165
- .lds-ellipsis div[data-v-2e27b3c1]:nth-child(3) {
3165
+ .lds-ellipsis div[data-v-221a3053]:nth-child(3) {
3166
3166
  left: calc(var(--size) / 2.5);
3167
- animation: lds-ellipsis2-2e27b3c1 0.6s infinite;
3167
+ animation: lds-ellipsis2-221a3053 0.6s infinite;
3168
3168
  }
3169
- .lds-ellipsis div[data-v-2e27b3c1]:nth-child(4) {
3169
+ .lds-ellipsis div[data-v-221a3053]:nth-child(4) {
3170
3170
  left: calc(var(--size) / 1.42);
3171
- animation: lds-ellipsis3-2e27b3c1 0.6s infinite;
3171
+ animation: lds-ellipsis3-221a3053 0.6s infinite;
3172
3172
  }
3173
- @keyframes lds-ellipsis1-2e27b3c1 {
3173
+ @keyframes lds-ellipsis1-221a3053 {
3174
3174
  0% {
3175
3175
  transform: scale(0);
3176
3176
  }
@@ -3178,7 +3178,7 @@ to {
3178
3178
  transform: scale(1);
3179
3179
  }
3180
3180
  }
3181
- @keyframes lds-ellipsis3-2e27b3c1 {
3181
+ @keyframes lds-ellipsis3-221a3053 {
3182
3182
  0% {
3183
3183
  transform: scale(1);
3184
3184
  }
@@ -3186,7 +3186,7 @@ to {
3186
3186
  transform: scale(0);
3187
3187
  }
3188
3188
  }
3189
- @keyframes lds-ellipsis2-2e27b3c1 {
3189
+ @keyframes lds-ellipsis2-221a3053 {
3190
3190
  0% {
3191
3191
  transform: translate(0, 0);
3192
3192
  }
@@ -64,6 +64,6 @@ export type BglFormSchemaT<T = {
64
64
  }> = Field<T>[];
65
65
  export type BglFormSchemaFnT<T = {
66
66
  [key: string]: any;
67
- }> = (() => BglFormSchemaT<T>) | BglFormSchemaT<T>;
67
+ }> = (() => BglFormSchemaT<T>) | BglFormSchemaT<T> | (() => Promise<BglFormSchemaT<T>>) | Promise<BglFormSchemaT<T>>;
68
68
  export {};
69
69
  //# sourceMappingURL=BagelForm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BagelForm.d.ts","sourceRoot":"","sources":["../../src/types/BagelForm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAEhC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAA;AAEvG,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,cAAc,CAAA;AAE5F,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,GAAG;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;CAC9C;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,IAAI,CAC3D,MAAM,GACJ,CACD;IACC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,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AC5G,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,IAAI,KAAK,CAAC,CAAC,CAAC,CAAA;AAE5D,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;AAEnE,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,IAAI,CAAC,MAAM,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.0.38",
4
+ "version": "1.0.41",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  type LoadingType = 'ring' | 'ellipsis' | 'bar'
3
3
 
4
- const { type: theme = 'ring', size = 64, thickness, duration = 1.2, color } = defineProps<{
4
+ const { type: theme = 'ring', size = 50, thickness, duration = 1.2, color } = defineProps<{
5
5
  size?: number | string
6
6
  thickness?: number | string
7
7
  duration?: number | string
@@ -21,7 +21,7 @@ const animationDuration = $computed(() => `${duration}s`)
21
21
 
22
22
  // Border size for ring theme (defaults to 1/8th of the size)
23
23
  const computedBorder = $computed(() => {
24
- const borderValue = thickness ?? Number.parseInt(computedSize) / 7
24
+ const borderValue = thickness ?? Math.max(Number.parseInt(computedSize) / 9, 2)
25
25
  return standardSize(borderValue)
26
26
  })
27
27
  </script>
@@ -1,19 +1,18 @@
1
1
  <script setup lang="ts" generic="T extends {[key:string]:any}">
2
- import type { BglFormSchemaFnT, Field } from '@bagelink/vue'
2
+ import type { BglFormSchemaFnT, Field, BglFormSchemaT } from '@bagelink/vue'
3
3
  import type { VNode } from 'vue'
4
- import { onMounted, watch, ref } from 'vue'
4
+ import { Loading } from '@bagelink/vue'
5
+ import { onMounted, watch, ref, toRef, computed } from 'vue'
5
6
  import { useSchemaField } from '../../composables/useSchemaField'
6
7
  import { getNestedValue } from '../../utils'
7
8
 
8
- export interface BagelFormProps<_T> {
9
- modelValue?: _T
10
- schema?: BglFormSchemaFnT<_T>
9
+ const props = withDefaults(defineProps<{
10
+ modelValue?: T
11
+ schema?: BglFormSchemaFnT<T>
11
12
  tag?: 'form' | 'template'
12
13
  class?: string
13
- onSubmit?: (data: _T) => Promise<void> | void
14
- }
15
-
16
- const props = withDefaults(defineProps<BagelFormProps<T>>(), {
14
+ onSubmit?: (data: T) => Promise<void> | void
15
+ }>(), {
17
16
  modelValue: undefined,
18
17
  schema: undefined,
19
18
  tag: 'form',
@@ -24,131 +23,192 @@ const emit = defineEmits<{
24
23
  (e: 'update:modelValue', value: T): void
25
24
  }>()
26
25
 
27
- function safeClone<T>(obj: T): T {
28
- if (!obj) return obj
29
- try {
30
- return JSON.parse(JSON.stringify(obj))
31
- } catch (e) {
32
- console.warn('Failed to clone object:', e)
33
- return obj
34
- }
35
- }
26
+ // Clone helper
27
+ const clone = <T>(obj: T): T => !obj ? obj : JSON.parse(JSON.stringify(obj))
36
28
 
29
+ // Form state
37
30
  const form = ref<HTMLFormElement>()
38
- const formData = ref<T>(safeClone(props.modelValue ?? {}) as T)
39
- const initialFormData = ref<T>(safeClone(props.modelValue ?? {}) as T)
40
-
41
- onMounted(() => {
42
- if (props.modelValue) {
43
- initialFormData.value = safeClone(props.modelValue)
31
+ const formData = ref<T>(clone(props.modelValue ?? {}) as T)
32
+ const initialFormData = ref<T>(clone(props.modelValue ?? {}) as T)
33
+ const formState = ref<'success' | 'error' | 'idle' | 'submitting'>('idle')
34
+ const schemaState = ref<'loading' | 'loaded' | 'error'>('loaded')
35
+ const resolvedSchemaData = ref<BglFormSchemaT<T>>()
36
+ const schemaRef = toRef(props, 'schema')
37
+ const resolvedSchema = computed(() => resolvedSchemaData.value)
38
+ const isDirty = computed(() => {
39
+ try {
40
+ return JSON.stringify(formData.value) !== JSON.stringify(initialFormData.value)
41
+ } catch {
42
+ return false
44
43
  }
45
44
  })
46
45
 
47
- const formState = ref<'success' | 'error' | 'idle' | 'submitting'>('idle')
46
+ // Initialize on mount
47
+ onMounted(() => {
48
+ if (props.modelValue) initialFormData.value = clone(props.modelValue)
49
+ refreshSchema()
50
+ })
48
51
 
49
- watch(() => props.modelValue, (newValue) => {
50
- if (newValue !== undefined) {
51
- formData.value = safeClone(newValue)
52
- }
52
+ // Watch for model changes
53
+ watch(() => props.modelValue, (val) => {
54
+ if (val !== undefined) formData.value = clone(val)
53
55
  }, { immediate: true, deep: true })
54
56
 
55
- const resolvedSchema = $computed<BglFormSchemaFnT<T> | undefined>(() => {
56
- if (!props.schema) return undefined
57
- return typeof props.schema === 'function' ? props.schema() : props.schema
58
- })
57
+ // Schema resolution
58
+ async function resolveSchema(schema?: BglFormSchemaFnT<T>) {
59
+ if (!schema) {
60
+ resolvedSchemaData.value = undefined
61
+ schemaState.value = 'loaded'
62
+ return
63
+ }
59
64
 
60
- const isDirty = $computed(() => {
61
65
  try {
62
- const current = JSON.stringify(formData.value)
63
- const initial = JSON.stringify(initialFormData.value)
64
- return current !== initial
65
- } catch (e) {
66
- console.warn('Failed to compare form data:', e)
67
- return false
66
+ schemaState.value = 'loading'
67
+ const isPromise = (obj: any) => obj && typeof obj.then === 'function'
68
+
69
+ let result: any
70
+ if (typeof schema === 'function') {
71
+ result = schema()
72
+ result = isPromise(result) ? await result : result
73
+ } else {
74
+ result = isPromise(schema) ? await schema : schema
75
+ }
76
+
77
+ resolvedSchemaData.value = result
78
+ schemaState.value = 'loaded'
79
+ } catch (error) {
80
+ console.error('Schema error:', error)
81
+ schemaState.value = 'error'
82
+ resolvedSchemaData.value = undefined
68
83
  }
69
- })
84
+ }
85
+
86
+ // Public refresh method
87
+ async function refreshSchema() {
88
+ await resolveSchema(props.schema)
89
+ return resolvedSchemaData.value
90
+ }
91
+
92
+ // Watch schema changes
93
+ watch(schemaRef, resolveSchema, { immediate: true, deep: true })
70
94
 
95
+ // Update form data
71
96
  function updateFormData(fieldId: string, value: any) {
72
97
  const keys = fieldId.split('.')
73
- const newData = safeClone(formData.value) as Record<string, any>
98
+ const newData = clone(formData.value) as Record<string, any>
74
99
  let current = newData
75
100
 
76
- // Traverse the object, creating nested objects as needed
77
101
  for (let i = 0; i < keys.length - 1; i++) {
78
102
  const key = keys[i]
79
- // Initialize as empty object if current[key] is null/undefined or not an object
80
- if (!current[key] || typeof current[key] !== 'object') {
81
- current[key] = {}
82
- }
103
+ if (!current[key] || typeof current[key] !== 'object') current[key] = {}
83
104
  current = current[key]
84
105
  }
85
106
 
86
- // Set the value at the final key
87
107
  current[keys[keys.length - 1]] = value
88
108
  formData.value = newData as T
89
109
  emit('update:modelValue', formData.value)
90
110
  }
91
111
 
112
+ // Form submission
92
113
  async function handleSubmit() {
93
114
  try {
94
115
  if (formState.value === 'submitting') return
95
116
  formState.value = 'submitting'
96
117
  await props.onSubmit?.(formData.value)
97
- initialFormData.value = safeClone(formData.value)
118
+ initialFormData.value = clone(formData.value)
98
119
  formState.value = 'success'
99
- // Notify parent window of successful submission
100
120
  window.parent.postMessage({ type: 'BAGEL_FORM_SUCCESS', data: JSON.stringify(formData.value) }, '*')
101
121
  } catch (error) {
102
- console.error('Form submission error:', error)
122
+ console.error('Submit error:', error)
103
123
  formState.value = 'error'
104
124
  }
105
125
  }
106
126
 
107
- function validateForm() {
108
- if (!form.value) return false
109
- return form.value.reportValidity()
110
- }
127
+ // Form validation
128
+ const validateForm = () => form.value?.reportValidity() ?? false
111
129
 
130
+ // Field rendering
112
131
  const { renderField } = useSchemaField<T>({
113
132
  mode: 'form',
114
- getRowData: () => {
115
- return {
116
- ...formData.value,
117
- // Add a special getter to handle nested paths
118
- get: (path: string) => getNestedValue(formData.value, path, '')
119
- }
120
- },
133
+ getRowData: () => ({
134
+ ...formData.value,
135
+ get: (path: string) => getNestedValue(formData.value, path, '')
136
+ }),
121
137
  onUpdate: (field, value) => {
122
- if (!field.id) return
123
- updateFormData(field.id, value)
124
- field.onUpdate?.(value, formData.value)
138
+ if (field.id) {
139
+ updateFormData(field.id, value)
140
+ field.onUpdate?.(value, formData.value)
141
+ }
125
142
  }
126
143
  })
127
144
 
128
- function renderSchemaField(field: Field): VNode | null {
129
- return renderField(field)
130
- }
145
+ const renderSchemaField = (field: Field<T>): VNode | null => renderField(field)
131
146
 
132
- defineExpose({ form, isDirty, validateForm })
147
+ defineExpose({ form, isDirty, validateForm, resolveSchema, refreshSchema })
133
148
  </script>
134
149
 
135
150
  <template>
136
151
  <template v-if="formState !== 'success' || !$slots.success">
137
152
  <form v-if="props.tag === 'form'" ref="form" :class="props.class" @submit.prevent="handleSubmit">
138
- <template v-if="resolvedSchema">
139
- <template v-for="field in (resolvedSchema as Field[])" :key="field.id">
140
- <component :is="renderSchemaField(field)" />
141
- </template>
142
- </template>
153
+ <!-- Loading state -->
154
+ <slot v-if="schemaState === 'loading'" name="loading">
155
+ <div class="flex-center h-300px">
156
+ <Loading />
157
+ </div>
158
+ </slot>
159
+
160
+ <!-- Error state -->
161
+ <slot v-else-if="schemaState === 'error'" name="schema-error">
162
+ <div class="flex-center h-300px txt-red">
163
+ Error loading form
164
+ </div>
165
+ </slot>
166
+
167
+ <!-- Render fields -->
168
+ <component
169
+ :is="renderSchemaField(field)"
170
+ v-for="field in resolvedSchema"
171
+ v-else-if="resolvedSchema"
172
+ :key="field.id"
173
+ />
174
+
175
+ <!-- Default slot -->
143
176
  <slot v-else />
144
- <slot name="submit" :submit="handleSubmit" :isDirty="isDirty" :validateForm="validateForm" :formState="formState" />
177
+
178
+ <!-- Submit slot -->
179
+ <slot
180
+ name="submit"
181
+ :submit="handleSubmit"
182
+ :isDirty="isDirty"
183
+ :validateForm="validateForm"
184
+ :formState="formState"
185
+ :schemaState="schemaState"
186
+ />
145
187
  </form>
188
+
189
+ <!-- Template mode -->
146
190
  <template v-else>
147
- <template v-for="field in (resolvedSchema as Field[])" :key="field.id">
148
- <component :is="renderSchemaField(field)" :class="props.class" />
149
- </template>
191
+ <slot v-if="schemaState === 'loading'" name="loading">
192
+ <Loading />
193
+ </slot>
194
+
195
+ <slot v-else-if="schemaState === 'error'" name="schema-error">
196
+ <div class="flex-center h-300px txt-red">
197
+ Error loading form
198
+ </div>
199
+ </slot>
200
+
201
+ <component
202
+ :is="renderSchemaField(field)"
203
+ v-for="field in resolvedSchema"
204
+ v-else-if="resolvedSchema"
205
+ :key="field.id"
206
+ :class="props.class"
207
+ />
150
208
  </template>
151
209
  </template>
210
+
211
+ <!-- Success/error slots -->
152
212
  <slot v-if="formState === 'success'" name="success" />
153
213
  <slot v-if="formState === 'error'" name="error" />
154
214
  </template>