codevdesign 1.0.54 → 1.0.55

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.
@@ -1,79 +1,79 @@
1
- <template>
2
- <v-date-input
3
- v-model="dateInterne"
4
- v-bind="$attrs"
5
- input-format="yyyy-MM-dd"
6
- variant="outlined"
7
- prepend-icon=""
8
- prepend-inner-icon="$calendar"
9
- density="comfortable"
10
- @update:model-value="choixUtilisateur"
11
- />
12
- </template>
13
-
14
- <script setup lang="ts">
15
- import { computed } from 'vue'
16
- import { VDateInput } from 'vuetify/labs/VDateInput'
17
-
18
- type Model = string | Date | null
19
-
20
- const props = defineProps<{ modelValue: Model }>()
21
-
22
- const emit = defineEmits<{
23
- (e: 'update:model-value', v: string | null): void
24
- (e: 'change', v: string | null): void
25
- }>()
26
-
27
- // Normalisation, TOUJOURS "YYYY-MM-DD" ou null
28
- const normalizeToYmd = (v: Date | string | null | undefined): string | null => {
29
- if (v == null || v === '') return null
30
-
31
- if (v instanceof Date) {
32
- if (isNaN(v.getTime())) return null
33
- const yyyy = v.getFullYear()
34
- const mm = String(v.getMonth() + 1).padStart(2, '0')
35
- const dd = String(v.getDate()).padStart(2, '0')
36
- return `${yyyy}-${mm}-${dd}`
37
- }
38
-
39
- const s = String(v).trim()
40
-
41
- // si ça commence par YYYY-MM-DD, on prend les 10 premiers chars
42
- const m = s.match(/^(\d{4}-\d{2}-\d{2})/)
43
- if (m) return m[1]
44
-
45
- // Sinon, on tente un fallback
46
- const d = new Date(s)
47
- if (isNaN(d.getTime())) return null
48
- const yyyy = d.getFullYear()
49
- const mm = String(d.getMonth() + 1).padStart(2, '0')
50
- const dd = String(d.getDate()).padStart(2, '0')
51
- return `${yyyy}-${mm}-${dd}`
52
- }
53
-
54
- // UI: VDateInput stable avec Date|null
55
- const dateInterne = computed<Date | null>({
56
- get() {
57
- const ymd = normalizeToYmd(props.modelValue as any)
58
- if (!ymd) return null
59
-
60
- // Construire une Date locale sans décalage timezone (évite UTC shift)
61
- const [y, m, d] = ymd.split('-').map(Number)
62
- return new Date(y, m - 1, d)
63
- },
64
- set() {
65
- // rien: on émet seulement dans choixUtilisateur
66
- },
67
- })
68
-
69
- const choixUtilisateur = (v: Date | string | null) => {
70
- const next = normalizeToYmd(v)
71
- const current = normalizeToYmd(props.modelValue as any)
72
-
73
- // Bloque la 2e émission au blur (même si type diffère Date/string)
74
- if (next === current) return
75
-
76
- emit('update:model-value', next)
77
- emit('change', next)
78
- }
79
- </script>
1
+ <template>
2
+ <v-date-input
3
+ :model-value="dateInterne"
4
+ v-bind="$attrs"
5
+ input-format="yyyy-MM-dd"
6
+ variant="outlined"
7
+ prepend-icon=""
8
+ prepend-inner-icon="$calendar"
9
+ density="comfortable"
10
+ @update:model-value="choixUtilisateur"
11
+ />
12
+ </template>
13
+
14
+ <script setup lang="ts">
15
+ import { computed, ref } from 'vue'
16
+ import { VDateInput } from 'vuetify/labs/VDateInput'
17
+
18
+ type Model = string | Date | null
19
+
20
+ const props = defineProps<{ modelValue: Model }>()
21
+
22
+ const emit = defineEmits<{
23
+ (e: 'update:modelValue', v: string | null): void
24
+ (e: 'change', v: string | null): void
25
+ }>()
26
+
27
+ // Normalisation, TOUJOURS "YYYY-MM-DD" ou null
28
+ const normalizeToYmd = (v: Date | string | null | undefined): string | null => {
29
+ if (v == null || v === '') return null
30
+
31
+ // Date -> YYYY-MM-DD (local)
32
+ if (v instanceof Date) {
33
+ if (isNaN(v.getTime())) return null
34
+ const yyyy = v.getFullYear()
35
+ const mm = String(v.getMonth() + 1).padStart(2, '0')
36
+ const dd = String(v.getDate()).padStart(2, '0')
37
+ return `${yyyy}-${mm}-${dd}`
38
+ }
39
+
40
+ // String -> accepte seulement YYYY-MM-DD
41
+ const s = String(v).trim()
42
+ const m = s.match(/^(\d{4})-(\d{2})-(\d{2})$/)
43
+ if (!m) return null
44
+
45
+ // Optionnel: validation simple (évite 2026-99-99)
46
+ const y = Number(m[1]),
47
+ mo = Number(m[2]),
48
+ d = Number(m[3])
49
+ if (mo < 1 || mo > 12 || d < 1 || d > 31) return null
50
+
51
+ return `${m[1]}-${m[2]}-${m[3]}`
52
+ }
53
+
54
+ // UI: VDateInput stable avec Date|null
55
+ const dateInterne = computed<Date | null>(() => {
56
+ const ymd = normalizeToYmd(props.modelValue as any)
57
+ if (!ymd) return null
58
+ const [y, m, d] = ymd.split('-').map(Number)
59
+ return new Date(y, m - 1, d) // local, stable
60
+ })
61
+
62
+ const prevBeforeEmit = ref<string | null>(null)
63
+
64
+ const choixUtilisateur = (v: Date | string | null) => {
65
+ const next = normalizeToYmd(v)
66
+ const current = normalizeToYmd(props.modelValue as any)
67
+
68
+ // rollback: on reçoit l'ancienne valeur (celle qu'on avait avant)
69
+ if (prevBeforeEmit.value && next === prevBeforeEmit.value && current !== prevBeforeEmit.value) {
70
+ return
71
+ }
72
+
73
+ if (next === current) return
74
+
75
+ prevBeforeEmit.value = current
76
+ emit('update:modelValue', next)
77
+ emit('change', next)
78
+ }
79
+ </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codevdesign",
3
- "version": "1.0.54",
3
+ "version": "1.0.55",
4
4
  "description": "Composants Vuetify 3 pour les projets Codev",
5
5
  "files": [
6
6
  "./**/*.vue",