@bagelink/vue 1.4.50 → 1.4.54

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.4.50",
4
+ "version": "1.4.54",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -11,7 +11,7 @@ const props = withDefaults(
11
11
  bagelFormProps?: Omit<
12
12
  ComponentProps<typeof BagelForm<T, P>>,
13
13
  (
14
- 'schema' | `${string}modelValue` | `ref${string}` | `onVnode${string}` | 'onSubmit'
14
+ 'schema' | `${string}modelValue` | `ref${string}` | `onVnode${string}` | 'onSubmit'
15
15
  )
16
16
  >
17
17
  schema?: MaybeRefOrGetter<BglFormSchemaT<T>>
@@ -174,22 +174,46 @@ async function nextStep() {
174
174
  checkCurrentStepValidity()
175
175
  }
176
176
 
177
- function goToStep(stepIndex: number) {
177
+ async function goToStep(stepIndex: number) {
178
178
  // Can always go back, or to already validated steps
179
179
  if (stepIndex < currentStep.value || validatedSteps.value.includes(stepIndex)) {
180
180
  currentStep.value = stepIndex
181
181
  return true
182
182
  }
183
183
 
184
- // For forward navigation to non-validated steps, validate current step first if needed
185
- // This will show validation errors to the user
186
- if (props.validateOnSteps && reportValidity() === false) {
187
- return false
188
- }
184
+ // For forward navigation, validate each step sequentially until target or invalid step
185
+ if (stepIndex > currentStep.value) {
186
+ // Validate current step first
187
+ if (props.validateOnSteps && reportValidity() === false) {
188
+ return false
189
+ }
190
+
191
+ // Move forward step by step, validating each one
192
+ for (let step = currentStep.value + 1; step <= stepIndex; step++) {
193
+ // Move to the next step
194
+ currentStep.value = step
195
+
196
+ // Wait for the form to update with new step's fields
197
+ await nextTick()
198
+ await sleep(100) // Give time for form to render
199
+
200
+ // Validate this step if validation is enabled
201
+ if (props.validateOnSteps) {
202
+ // Check if the step is valid without showing validation errors for intermediate steps
203
+ const isValid = formRef.value?.checkValidity() ?? false
204
+
205
+ if (!isValid) {
206
+ // If this step is invalid, stop here
207
+ return false
208
+ } else {
209
+ // Mark this step as validated
210
+ if (!validatedSteps.value.includes(step)) {
211
+ validatedSteps.value.push(step)
212
+ }
213
+ }
214
+ }
215
+ }
189
216
 
190
- // Can only move one step forward at a time (prevent skipping)
191
- if (stepIndex === currentStep.value + 1) {
192
- currentStep.value = stepIndex
193
217
  return true
194
218
  }
195
219
 
@@ -247,14 +271,11 @@ defineExpose({
247
271
  >
248
272
  <div class="bgl-steps-indicator">
249
273
  <div
250
- v-for="(_, index) in numberOfSteps"
251
- :key="index"
252
- class="bgl-step-indicator" :class="[
274
+ v-for="(_, index) in numberOfSteps" :key="index" class="bgl-step-indicator" :class="[
253
275
  { active: index === currentStep },
254
276
  { completed: index < currentStep || isStepValidated(index) },
255
277
  { clickable: props.allowStepNavigation },
256
- ]"
257
- @click="props.allowStepNavigation && goToStep(index)"
278
+ ]" @click="props.allowStepNavigation && goToStep(index)"
258
279
  >
259
280
  <span>{{ index + 1 }}</span>
260
281
  <span v-if="props.stepLabels && props.stepLabels[index]" class="bgl-step-label">
@@ -266,17 +287,9 @@ defineExpose({
266
287
  </div>
267
288
 
268
289
  <div class="bgl-form-wrapper">
269
- <transition
270
- :name="slideDirection === 'right' ? 'slide-right' : 'slide-left'"
271
- mode="out-in"
272
- >
290
+ <transition :name="slideDirection === 'right' ? 'slide-right' : 'slide-left'" mode="out-in">
273
291
  <div :key="currentStep" ref="formContainer" class="bgl-form-container">
274
- <BagelForm
275
- ref="formRef"
276
- v-model="formData"
277
- :schema="currentStepSchema"
278
- v-bind="bagelFormProps"
279
- >
292
+ <BagelForm ref="formRef" v-model="formData" :schema="currentStepSchema" v-bind="bagelFormProps">
280
293
  <template v-if="$slots.success" #success>
281
294
  <slot name="success" />
282
295
  </template>
@@ -302,9 +315,7 @@ defineExpose({
302
315
  >
303
316
  <Btn v-if="currentStep !== 0" color="gray" icon="arrow_back" @click="prevStep" />
304
317
  <Btn
305
- v-if="!isLastStep"
306
- icon="arrow_forward"
307
- :disabled="props.validateOnSteps && !isStepValid"
318
+ v-if="!isLastStep" icon="arrow_forward" :disabled="props.validateOnSteps && !isStepValid"
308
319
  @click="nextStep"
309
320
  />
310
321
  <Btn v-else value="Submit" @click="handleSubmit" />
@@ -356,7 +367,7 @@ defineExpose({
356
367
  display: none;
357
368
  }
358
369
 
359
- .bgl-step-indicator > span:first-child {
370
+ .bgl-step-indicator>span:first-child {
360
371
  width: 30px;
361
372
  height: 30px;
362
373
  border-radius: 50%;
@@ -368,12 +379,12 @@ defineExpose({
368
379
  margin-bottom: 0.5rem;
369
380
  }
370
381
 
371
- .bgl-step-indicator.active > span:first-child {
382
+ .bgl-step-indicator.active>span:first-child {
372
383
  background: var(--primary-color, #4CAF50);
373
384
  color: white;
374
385
  }
375
386
 
376
- .bgl-step-indicator.completed > span:first-child {
387
+ .bgl-step-indicator.completed>span:first-child {
377
388
  background: var(--success-color, #8BC34A);
378
389
  color: white;
379
390
  }
@@ -396,7 +407,7 @@ defineExpose({
396
407
  interpolate-size: allow-keywords;
397
408
  }
398
409
 
399
- .bgl-form-wrapper > div {
410
+ .bgl-form-wrapper>div {
400
411
  grid-area: 1 / 1;
401
412
 
402
413
  }
@@ -418,12 +429,12 @@ defineExpose({
418
429
  /* Slide Left Animation (going forward) */
419
430
  .slide-left-enter-active {
420
431
  transition: opacity var(--transition-duration) var(--ease-in),
421
- transform var(--transition-duration) var(--ease-in);
432
+ transform var(--transition-duration) var(--ease-in);
422
433
  }
423
434
 
424
435
  .slide-left-leave-active {
425
436
  transition: opacity var(--transition-duration) var(--ease-out),
426
- transform var(--transition-duration) var(--ease-out);
437
+ transform var(--transition-duration) var(--ease-out);
427
438
  }
428
439
 
429
440
  .slide-left-enter-from {
@@ -439,12 +450,12 @@ defineExpose({
439
450
  /* Slide Right Animation (going back) */
440
451
  .slide-right-enter-active {
441
452
  transition: opacity var(--transition-duration) var(--ease-in),
442
- transform var(--transition-duration) var(--ease-in);
453
+ transform var(--transition-duration) var(--ease-in);
443
454
  }
444
455
 
445
456
  .slide-right-leave-active {
446
457
  transition: opacity var(--transition-duration) var(--ease-out),
447
- transform var(--transition-duration) var(--ease-out);
458
+ transform var(--transition-duration) var(--ease-out);
448
459
  }
449
460
 
450
461
  .slide-right-enter-from {
@@ -65,7 +65,21 @@ function selectCountry(country: Country) {
65
65
  activeCountry = country
66
66
  open = false
67
67
  search = ''
68
- if (!phoneNumber) phoneNumber = `+${activeCountry.dialCode}`
68
+
69
+ if (!phoneNumber) {
70
+ phoneNumber = `+${activeCountry.dialCode}`
71
+ } else if (phoneNumber.startsWith('+')) {
72
+ // Replace existing country code with the new one
73
+ const existingCountry = countries.find(c => phoneNumber.startsWith(`+${c.dialCode}`))
74
+ if (existingCountry && existingCountry !== country) {
75
+ // Remove the old country code and replace with new one
76
+ const nationalPart = phoneNumber.substring(`+${existingCountry.dialCode}`.length).trim()
77
+ phoneNumber = `+${activeCountry.dialCode}${nationalPart ? ` ${nationalPart}` : ''}`
78
+ }
79
+ } else {
80
+ // Phone number doesn't start with +, prepend the country code
81
+ phoneNumber = `+${activeCountry.dialCode} ${phoneNumber.replace(/^0+/, '')}`
82
+ }
69
83
  }
70
84
 
71
85
  async function getIp() {