codevdesign 1.0.55 → 1.0.56

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,125 +1,125 @@
1
- <template>
2
- <div>
3
- <v-btn
4
- color="success"
5
- variant="outlined"
6
- :loading="chargement"
7
- class="elevation-0"
8
- @click="importCsv"
9
- >
10
- {{ boutonTexte }}
11
- <template #append>
12
- <v-icon icon="mdi-microsoft-excel"></v-icon>
13
- </template>
14
- </v-btn>
15
-
16
- <input
17
- ref="fileInput"
18
- type="file"
19
- accept=".csv"
20
- style="display: none"
21
- @change="handleFileUpload"
22
- />
23
- </div>
24
- </template>
25
-
26
- <script setup lang="ts">
27
- import { ref, computed } from 'vue'
28
- import { useI18n } from 'vue-i18n'
29
-
30
- // Props
31
- const props = withDefaults(
32
- defineProps<{
33
- boutonTexte?: string
34
- erreurTexte?: string
35
- chargement?: boolean
36
- }>(),
37
- {
38
- chargement: false, // défaut
39
- },
40
- )
41
- const emit = defineEmits(['import', 'import-erreur'])
42
-
43
- const { t } = useI18n()
44
-
45
- const boutonTexte = computed(() => props.boutonTexte ?? t('csqc.bouton.importer'))
46
- const erreurTexte = computed(() => props.erreurTexte ?? t('csqc.csqcImportCSV.erreur.lectureFichier'))
47
-
48
- // Références
49
- const fileInput = ref<HTMLInputElement | null>(null)
50
- const csvFile = ref<File | null>(null)
51
-
52
- // Méthodes
53
- function importCsv() {
54
- fileInput.value?.click()
55
- }
56
-
57
- function handleFileUpload(event: Event) {
58
- const target = event.target as HTMLInputElement
59
- const file = target.files?.[0]
60
-
61
- if (file?.name.toLowerCase().endsWith('.csv')) {
62
- csvFile.value = file
63
-
64
- const reader = new FileReader()
65
-
66
- reader.onload = () => {
67
- try {
68
- let text = reader.result as string
69
-
70
- // Supprime BOM UTF-8 si présent
71
- if (text.charCodeAt(0) === 0xfeff) {
72
- text = text.slice(1)
73
- }
74
-
75
- const lignes = text
76
- .trim()
77
- .split(/\r?\n/)
78
- .filter(row => row.trim() !== '') // ignore lignes vides
79
-
80
- if (lignes.length === 0) {
81
- emit('import-erreur', 'Le fichier CSV est vide.')
82
- return
83
- }
84
-
85
- // Détection automatique du séparateur
86
- const separateur = detecterSeparateur(lignes[0]!)
87
-
88
- // Découpage des lignes
89
- const data: string[][] = lignes.map(row => row.split(separateur).map(cell => cell.trim()))
90
-
91
- emit('import', data)
92
- } catch (error) {
93
- emit('import-erreur', erreurTexte || t('csqc.csqcImportCSV.erreur.lectureFichier'))
94
- }
95
- }
96
-
97
- reader.onerror = () => {
98
- emit('import-erreur', t('csqc.csqcImportCSV.erreur.lectureFichier'))
99
- }
100
-
101
- reader.readAsText(file)
102
- } else {
103
- const message = erreurTexte || t('csqc.csqcImportCSV.erreur.erreur')
104
- emit('import-erreur', message)
105
- csvFile.value = null
106
- }
107
- }
108
-
109
- // Fonction pour détecter le séparateur le plus probable
110
- function detecterSeparateur(ligne: string): string {
111
- const separateursTestés = [',', ';', '\t', '|']
112
- let meilleurSeparateur = ','
113
- let maxColonnes = 0
114
-
115
- for (const sep of separateursTestés) {
116
- const nb = ligne.split(sep).length
117
- if (nb > maxColonnes) {
118
- maxColonnes = nb
119
- meilleurSeparateur = sep
120
- }
121
- }
122
-
123
- return meilleurSeparateur
124
- }
125
- </script>
1
+ <template>
2
+ <div>
3
+ <v-btn
4
+ color="success"
5
+ variant="outlined"
6
+ :loading="chargement"
7
+ class="elevation-0"
8
+ @click="importCsv"
9
+ >
10
+ {{ boutonTexte }}
11
+ <template #append>
12
+ <v-icon icon="mdi-microsoft-excel"></v-icon>
13
+ </template>
14
+ </v-btn>
15
+
16
+ <input
17
+ ref="fileInput"
18
+ type="file"
19
+ accept=".csv"
20
+ style="display: none"
21
+ @change="handleFileUpload"
22
+ />
23
+ </div>
24
+ </template>
25
+
26
+ <script setup lang="ts">
27
+ import { ref, computed } from 'vue'
28
+ import { useI18n } from 'vue-i18n'
29
+
30
+ // Props
31
+ const props = withDefaults(
32
+ defineProps<{
33
+ boutonTexte?: string
34
+ erreurTexte?: string
35
+ chargement?: boolean
36
+ }>(),
37
+ {
38
+ chargement: false, // défaut
39
+ },
40
+ )
41
+ const emit = defineEmits(['import', 'import-erreur'])
42
+
43
+ const { t } = useI18n()
44
+
45
+ const boutonTexte = computed(() => props.boutonTexte ?? t('csqc.bouton.importer'))
46
+ const erreurTexte = computed(() => props.erreurTexte ?? t('csqc.csqcImportCSV.erreur.lectureFichier'))
47
+
48
+ // Références
49
+ const fileInput = ref<HTMLInputElement | null>(null)
50
+ const csvFile = ref<File | null>(null)
51
+
52
+ // Méthodes
53
+ function importCsv() {
54
+ fileInput.value?.click()
55
+ }
56
+
57
+ function handleFileUpload(event: Event) {
58
+ const target = event.target as HTMLInputElement
59
+ const file = target.files?.[0]
60
+
61
+ if (file?.name.toLowerCase().endsWith('.csv')) {
62
+ csvFile.value = file
63
+
64
+ const reader = new FileReader()
65
+
66
+ reader.onload = () => {
67
+ try {
68
+ let text = reader.result as string
69
+
70
+ // Supprime BOM UTF-8 si présent
71
+ if (text.charCodeAt(0) === 0xfeff) {
72
+ text = text.slice(1)
73
+ }
74
+
75
+ const lignes = text
76
+ .trim()
77
+ .split(/\r?\n/)
78
+ .filter(row => row.trim() !== '') // ignore lignes vides
79
+
80
+ if (lignes.length === 0) {
81
+ emit('import-erreur', 'Le fichier CSV est vide.')
82
+ return
83
+ }
84
+
85
+ // Détection automatique du séparateur
86
+ const separateur = detecterSeparateur(lignes[0]!)
87
+
88
+ // Découpage des lignes
89
+ const data: string[][] = lignes.map(row => row.split(separateur).map(cell => cell.trim()))
90
+
91
+ emit('import', data)
92
+ } catch (error) {
93
+ emit('import-erreur', erreurTexte || t('csqc.csqcImportCSV.erreur.lectureFichier'))
94
+ }
95
+ }
96
+
97
+ reader.onerror = () => {
98
+ emit('import-erreur', t('csqc.csqcImportCSV.erreur.lectureFichier'))
99
+ }
100
+
101
+ reader.readAsText(file)
102
+ } else {
103
+ const message = erreurTexte || t('csqc.csqcImportCSV.erreur.erreur')
104
+ emit('import-erreur', message)
105
+ csvFile.value = null
106
+ }
107
+ }
108
+
109
+ // Fonction pour détecter le séparateur le plus probable
110
+ function detecterSeparateur(ligne: string): string {
111
+ const separateursTestés = [',', ';', '\t', '|']
112
+ let meilleurSeparateur = ','
113
+ let maxColonnes = 0
114
+
115
+ for (const sep of separateursTestés) {
116
+ const nb = ligne.split(sep).length
117
+ if (nb > maxColonnes) {
118
+ maxColonnes = nb
119
+ meilleurSeparateur = sep
120
+ }
121
+ }
122
+
123
+ return meilleurSeparateur
124
+ }
125
+ </script>
@@ -1,207 +1,207 @@
1
- <template>
2
- <!--
3
- FIFO Snackbar
4
- - On affiche 1 snackbar à la fois.
5
- - Les demandes suivantes sont mises en file (FIFO) et s’affichent après fermeture.
6
- - color/location sont figées par item via props (pas via $attrs) pour éviter les changements live.
7
- -->
8
- <v-snackbar
9
- :model-value="snackbar"
10
- v-bind="attrsAffiches"
11
- :timeout="-1"
12
- :style="props.styleCss"
13
- :color="colorAffiche"
14
- :location="locationAffiche"
15
- multi-line
16
- @update:model-value="
17
- v => {
18
- if (!v) fermer()
19
- }
20
- "
21
- >
22
- <template v-if="titreAffiche || messageAffiche">
23
- <b style="font-size: 12pt">{{ titreAffiche }}</b>
24
- <br v-if="titreAffiche" />
25
- <b>{{ messageAffiche }}</b>
26
- </template>
27
-
28
- <template #actions>
29
- <!-- Toujours afficher la fermeture si timeout = -1 -->
30
- <v-icon
31
- v-if="props.btnFermer || timeoutAffiche === -1"
32
- color="white"
33
- style="cursor: pointer"
34
- @click.stop="fermer"
35
- >
36
- mdi-close
37
- </v-icon>
38
- </template>
39
- </v-snackbar>
40
- </template>
41
-
42
- <script setup lang="ts">
43
- import { computed, ref, watch, useAttrs, toRaw } from 'vue'
44
-
45
- // - color/location sont en props (et non via $attrs) pour être snapshottées proprement.
46
- const props = defineProps({
47
- styleCss: { type: String, required: false },
48
-
49
- // Durée d’affichage (ms). -1 = ne ferme jamais automatiquement
50
- temps: { type: Number, required: false, default: 4000 },
51
-
52
- // Déclencheur : à chaque changement non-vide, on queue un item
53
- message: { type: String, required: true },
54
- titre: { type: String, required: false },
55
-
56
- btnFermer: { type: Boolean, required: false, default: true },
57
-
58
- // en props pour éviter le "live update" via $attrs
59
- color: { type: String, required: false, default: 'success' },
60
- location: { type: [String, Array, Object] as any, required: false },
61
- })
62
-
63
- const emit = defineEmits(['fermer:snackbar'])
64
-
65
- /**
66
- * ============================================================================
67
- * $attrs : on forward tout sauf color/location (qui sont gérés par props & snapshot)
68
- * ============================================================================
69
- */
70
- const attrs = useAttrs()
71
-
72
- const attrsSansCouleur = computed(() => {
73
- const { color, location, ...rest } = attrs as any
74
- return rest
75
- })
76
-
77
- /**
78
- * ============================================================================
79
- * FIFO Queue (snapshot par item)
80
- * ============================================================================
81
- */
82
- type ItemSnack = {
83
- message: string
84
- titre?: string
85
- color: string
86
- location?: any
87
- attrs: Record<string, any>
88
- timeout: number // -1 = manuel
89
- }
90
-
91
- const file = ref<ItemSnack[]>([])
92
- const enCours = ref<ItemSnack | null>(null)
93
-
94
- /**
95
- * ============================================================================
96
- * État UI
97
- * ============================================================================
98
- */
99
- const snackbar = ref(false)
100
-
101
- /**
102
- * ============================================================================
103
- * Computeds d’affichage (basés sur l’item en cours)
104
- * ============================================================================
105
- */
106
- const attrsAffiches = computed(() => {
107
- // On évite de forward color/location par attrs (même s’ils y étaient)
108
- const a = (enCours.value?.attrs ?? {}) as any
109
- const { color, location, ...rest } = a
110
- return rest
111
- })
112
-
113
- const messageAffiche = computed(() => enCours.value?.message ?? '')
114
- const titreAffiche = computed(() => enCours.value?.titre ?? '')
115
- const colorAffiche = computed(() => enCours.value?.color ?? 'success')
116
- const locationAffiche = computed(() => enCours.value?.location)
117
- const timeoutAffiche = computed(() => enCours.value?.timeout ?? props.temps)
118
-
119
- /**
120
- * ============================================================================
121
- * Timer (auto-close géré par nous, puisque v-snackbar est timeout=-1)
122
- * ============================================================================
123
- */
124
- let timer: number | null = null
125
-
126
- function clearTimer() {
127
- if (timer != null) {
128
- window.clearTimeout(timer)
129
- timer = null
130
- }
131
- }
132
-
133
- function scheduleAutoClose() {
134
- clearTimer()
135
-
136
- const t = timeoutAffiche.value
137
- if (t === -1) return
138
-
139
- // 1 seconde minimum, sinon on ne la voit pas
140
- const ms = Math.max(1000, t)
141
-
142
- timer = window.setTimeout(() => {
143
- fermer()
144
- }, ms)
145
- }
146
-
147
- /**
148
- * ============================================================================
149
- * Navigation FIFO
150
- * ============================================================================
151
- */
152
- function afficherProchain() {
153
- // Un seul snackbar à la fois
154
- if (snackbar.value) return
155
- if (enCours.value) return
156
-
157
- const next = file.value.shift()
158
- if (!next) return
159
-
160
- enCours.value = next
161
- snackbar.value = true
162
- scheduleAutoClose()
163
- }
164
-
165
- function fermer() {
166
- clearTimer()
167
- snackbar.value = false
168
- emit('fermer:snackbar')
169
-
170
- // On attend un tick pour éviter les glitches (transition/DOM)
171
- setTimeout(() => {
172
- enCours.value = null
173
- afficherProchain()
174
- }, 0)
175
- }
176
-
177
- /**
178
- * ============================================================================
179
- * queue (snapshot) à chaque nouveau message
180
- * ============================================================================
181
- */
182
- watch(
183
- () => props.message,
184
- nouveau => {
185
- if (!nouveau) return
186
-
187
- // Normalisation timeout
188
- const timeout = props.temps < -1 ? -1 : props.temps >= 0 && props.temps < 1000 ? 1000 : props.temps
189
-
190
- file.value.push({
191
- message: String(nouveau),
192
- titre: props.titre ? String(props.titre) : undefined,
193
-
194
- // ✅ Primitives + props => stable (pas de "live update")
195
- color: String(props.color ?? 'success'),
196
- location: props.location,
197
-
198
- // On forward les autres attrs (snapshot) : variant, rounded, etc.
199
- attrs: structuredClone(toRaw(attrsSansCouleur.value)),
200
-
201
- timeout,
202
- })
203
-
204
- afficherProchain()
205
- },
206
- )
207
- </script>
1
+ <template>
2
+ <!--
3
+ FIFO Snackbar
4
+ - On affiche 1 snackbar à la fois.
5
+ - Les demandes suivantes sont mises en file (FIFO) et s’affichent après fermeture.
6
+ - color/location sont figées par item via props (pas via $attrs) pour éviter les changements live.
7
+ -->
8
+ <v-snackbar
9
+ :model-value="snackbar"
10
+ v-bind="attrsAffiches"
11
+ :timeout="-1"
12
+ :style="props.styleCss"
13
+ :color="colorAffiche"
14
+ :location="locationAffiche"
15
+ multi-line
16
+ @update:model-value="
17
+ v => {
18
+ if (!v) fermer()
19
+ }
20
+ "
21
+ >
22
+ <template v-if="titreAffiche || messageAffiche">
23
+ <b style="font-size: 12pt">{{ titreAffiche }}</b>
24
+ <br v-if="titreAffiche" />
25
+ <b>{{ messageAffiche }}</b>
26
+ </template>
27
+
28
+ <template #actions>
29
+ <!-- Toujours afficher la fermeture si timeout = -1 -->
30
+ <v-icon
31
+ v-if="props.btnFermer || timeoutAffiche === -1"
32
+ color="white"
33
+ style="cursor: pointer"
34
+ @click.stop="fermer"
35
+ >
36
+ mdi-close
37
+ </v-icon>
38
+ </template>
39
+ </v-snackbar>
40
+ </template>
41
+
42
+ <script setup lang="ts">
43
+ import { computed, ref, watch, useAttrs, toRaw } from 'vue'
44
+
45
+ // - color/location sont en props (et non via $attrs) pour être snapshottées proprement.
46
+ const props = defineProps({
47
+ styleCss: { type: String, required: false },
48
+
49
+ // Durée d’affichage (ms). -1 = ne ferme jamais automatiquement
50
+ temps: { type: Number, required: false, default: 4000 },
51
+
52
+ // Déclencheur : à chaque changement non-vide, on queue un item
53
+ message: { type: String, required: true },
54
+ titre: { type: String, required: false },
55
+
56
+ btnFermer: { type: Boolean, required: false, default: true },
57
+
58
+ // en props pour éviter le "live update" via $attrs
59
+ color: { type: String, required: false, default: 'success' },
60
+ location: { type: [String, Array, Object] as any, required: false },
61
+ })
62
+
63
+ const emit = defineEmits(['fermer:snackbar'])
64
+
65
+ /**
66
+ * ============================================================================
67
+ * $attrs : on forward tout sauf color/location (qui sont gérés par props & snapshot)
68
+ * ============================================================================
69
+ */
70
+ const attrs = useAttrs()
71
+
72
+ const attrsSansCouleur = computed(() => {
73
+ const { color, location, ...rest } = attrs as any
74
+ return rest
75
+ })
76
+
77
+ /**
78
+ * ============================================================================
79
+ * FIFO Queue (snapshot par item)
80
+ * ============================================================================
81
+ */
82
+ type ItemSnack = {
83
+ message: string
84
+ titre?: string
85
+ color: string
86
+ location?: any
87
+ attrs: Record<string, any>
88
+ timeout: number // -1 = manuel
89
+ }
90
+
91
+ const file = ref<ItemSnack[]>([])
92
+ const enCours = ref<ItemSnack | null>(null)
93
+
94
+ /**
95
+ * ============================================================================
96
+ * État UI
97
+ * ============================================================================
98
+ */
99
+ const snackbar = ref(false)
100
+
101
+ /**
102
+ * ============================================================================
103
+ * Computeds d’affichage (basés sur l’item en cours)
104
+ * ============================================================================
105
+ */
106
+ const attrsAffiches = computed(() => {
107
+ // On évite de forward color/location par attrs (même s’ils y étaient)
108
+ const a = (enCours.value?.attrs ?? {}) as any
109
+ const { color, location, ...rest } = a
110
+ return rest
111
+ })
112
+
113
+ const messageAffiche = computed(() => enCours.value?.message ?? '')
114
+ const titreAffiche = computed(() => enCours.value?.titre ?? '')
115
+ const colorAffiche = computed(() => enCours.value?.color ?? 'success')
116
+ const locationAffiche = computed(() => enCours.value?.location)
117
+ const timeoutAffiche = computed(() => enCours.value?.timeout ?? props.temps)
118
+
119
+ /**
120
+ * ============================================================================
121
+ * Timer (auto-close géré par nous, puisque v-snackbar est timeout=-1)
122
+ * ============================================================================
123
+ */
124
+ let timer: number | null = null
125
+
126
+ function clearTimer() {
127
+ if (timer != null) {
128
+ window.clearTimeout(timer)
129
+ timer = null
130
+ }
131
+ }
132
+
133
+ function scheduleAutoClose() {
134
+ clearTimer()
135
+
136
+ const t = timeoutAffiche.value
137
+ if (t === -1) return
138
+
139
+ // 1 seconde minimum, sinon on ne la voit pas
140
+ const ms = Math.max(1000, t)
141
+
142
+ timer = window.setTimeout(() => {
143
+ fermer()
144
+ }, ms)
145
+ }
146
+
147
+ /**
148
+ * ============================================================================
149
+ * Navigation FIFO
150
+ * ============================================================================
151
+ */
152
+ function afficherProchain() {
153
+ // Un seul snackbar à la fois
154
+ if (snackbar.value) return
155
+ if (enCours.value) return
156
+
157
+ const next = file.value.shift()
158
+ if (!next) return
159
+
160
+ enCours.value = next
161
+ snackbar.value = true
162
+ scheduleAutoClose()
163
+ }
164
+
165
+ function fermer() {
166
+ clearTimer()
167
+ snackbar.value = false
168
+ emit('fermer:snackbar')
169
+
170
+ // On attend un tick pour éviter les glitches (transition/DOM)
171
+ setTimeout(() => {
172
+ enCours.value = null
173
+ afficherProchain()
174
+ }, 0)
175
+ }
176
+
177
+ /**
178
+ * ============================================================================
179
+ * queue (snapshot) à chaque nouveau message
180
+ * ============================================================================
181
+ */
182
+ watch(
183
+ () => props.message,
184
+ nouveau => {
185
+ if (!nouveau) return
186
+
187
+ // Normalisation timeout
188
+ const timeout = props.temps < -1 ? -1 : props.temps >= 0 && props.temps < 1000 ? 1000 : props.temps
189
+
190
+ file.value.push({
191
+ message: String(nouveau),
192
+ titre: props.titre ? String(props.titre) : undefined,
193
+
194
+ // ✅ Primitives + props => stable (pas de "live update")
195
+ color: String(props.color ?? 'success'),
196
+ location: props.location,
197
+
198
+ // On forward les autres attrs (snapshot) : variant, rounded, etc.
199
+ attrs: structuredClone(toRaw(attrsSansCouleur.value)),
200
+
201
+ timeout,
202
+ })
203
+
204
+ afficherProchain()
205
+ },
206
+ )
207
+ </script>