codevdesign 1.0.46 → 1.0.48

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,102 +1,193 @@
1
- <template>
2
- <v-row
3
- dense
4
- class="align-center"
5
- >
6
- <!-- Texte + détails -->
7
- <v-col
8
- cols="10"
9
- xl="11"
10
- class="py-0"
11
- >
12
- <component
13
- :is="labelCliquable ? 'label' : 'div'"
14
- :for="labelCliquable ? switchId : undefined"
15
- class="labelSwitchSiSwitchApres"
16
- :class="{ 'label-cliquable': labelCliquable && !desactiver }"
17
- >
18
- <slot name="label">
19
- {{ texte }}
20
- </slot>
21
- </component>
22
-
23
- <div
24
- v-if="afficherDetails"
25
- class="details"
26
- >
27
- <slot name="details">
28
- <span v-html="texteDetaille"></span>
29
- </slot>
30
- </div>
31
- </v-col>
32
-
33
- <!-- Switch -->
34
- <v-col
35
- cols="2"
36
- xl="1"
37
- class="d-flex align-center justify-end py-0"
38
- >
39
- <v-switch
40
- :id="switchId"
41
- v-model="maValeur"
42
- class="switch-compact"
43
- :disabled="desactiver"
44
- :density="($attrs.density as any) ?? 'compact'"
45
- :inset="($attrs.inset as any) ?? true"
46
- v-bind="$attrs"
47
- hide-details
48
- />
49
- </v-col>
50
- </v-row>
51
- </template>
52
-
53
- <script setup lang="ts">
54
- import { computed, useSlots } from 'vue'
55
-
56
- const props = defineProps({
57
- valeurInverse: { type: Boolean, default: false },
58
- desactiver: { type: Boolean, default: false },
59
- modelValue: { type: Boolean, required: true },
60
- texte: { type: String, required: true },
61
- texteDetaille: { type: String, default: '' },
62
- labelCliquable: { type: Boolean, default: true },
63
- })
64
-
65
- const emit = defineEmits(['update:modelValue'])
66
- const slots = useSlots()
67
-
68
- const maValeur = computed<boolean>({
69
- get: () => (props.valeurInverse ? !props.modelValue : props.modelValue),
70
- set: v => emit('update:modelValue', props.valeurInverse ? !v : v),
71
- })
72
-
73
- const afficherDetails = computed(() => {
74
- const slotExiste = !!slots.details?.().length
75
- return slotExiste || props.texteDetaille.trim().length > 0
76
- })
77
-
78
- const switchId = `sw_${Math.random().toString(36).slice(2)}`
79
- </script>
80
-
81
- <style scoped>
82
- .labelSwitchSiSwitchApres {
83
- font-weight: bold;
84
- line-height: 1.2;
85
- }
86
-
87
- .label-cliquable {
88
- cursor: pointer;
89
- }
90
-
91
- .details {
92
- margin-top: 4px;
93
- }
94
-
95
- /* compact switch */
96
- :deep(.switch-compact.v-input) {
97
- margin: 0;
98
- }
99
- :deep(.switch-compact .v-selection-control) {
100
- margin: 0;
101
- }
102
- </style>
1
+ <template>
2
+ <v-row
3
+ dense
4
+ class="align-center"
5
+ >
6
+ <!-- Texte + détails -->
7
+ <v-col
8
+ cols="10"
9
+ xl="11"
10
+ class="py-0"
11
+ >
12
+ <component
13
+ :is="labelCliquable ? 'label' : 'div'"
14
+ :for="labelCliquable ? switchId : undefined"
15
+ class="labelSwitchSiSwitchApres"
16
+ :class="{ 'label-cliquable': labelCliquable && !desactiver }"
17
+ >
18
+ <slot name="label">
19
+ {{ texte }}
20
+ </slot>
21
+ </component>
22
+
23
+ <div
24
+ v-if="afficherDetails"
25
+ class="details"
26
+ >
27
+ <slot name="details">
28
+ <span v-html="texteDetaille"></span>
29
+ </slot>
30
+ </div>
31
+ </v-col>
32
+
33
+ <!-- Switch -->
34
+ <v-col
35
+ cols="2"
36
+ xl="1"
37
+ class="d-flex align-center justify-end py-0"
38
+ >
39
+ <span class="d-inline-flex">
40
+ <v-switch
41
+ :id="switchId"
42
+ class="switch-compact switch-tristate"
43
+ :class="{
44
+ 'is-null': maValeur === null,
45
+ 'is-true': maValeur === true,
46
+ 'is-false': maValeur === false,
47
+ }"
48
+ :disabled="desactiver"
49
+ hide-details
50
+ v-bind="$attrs"
51
+ :model-value="switchChecked"
52
+ :indeterminate="isIndeterminate"
53
+ indeterminate-icon="mdi-minus"
54
+ @click.prevent="onToggle"
55
+ @keydown.enter.prevent="onToggle"
56
+ @keydown.space.prevent="onToggle"
57
+ />
58
+
59
+ <v-tooltip
60
+ v-if="maValeur === null"
61
+ activator="parent"
62
+ >
63
+ {{ $t("csqc.csqcOptionSwitch.indeterminee") }}
64
+ </v-tooltip>
65
+ </span>
66
+ </v-col>
67
+ </v-row>
68
+ </template>
69
+
70
+ <script setup lang="ts">
71
+ import { computed, useSlots } from 'vue'
72
+
73
+ type TriBool = boolean | null
74
+
75
+ const props = defineProps({
76
+ valeurInverse: { type: Boolean, default: false },
77
+ desactiver: { type: Boolean, default: false },
78
+ modelValue: { type: [Boolean, null] as unknown as () => TriBool, default: false },
79
+ autoriserNull: { type: Boolean, default: false },
80
+ texte: { type: String, required: true },
81
+ texteDetaille: { type: String, default: '' },
82
+ labelCliquable: { type: Boolean, default: true },
83
+ })
84
+
85
+ const emit = defineEmits<{
86
+ (e: 'update:modelValue', v: TriBool): void
87
+ }>()
88
+ const isIndeterminate = computed(() => maValeur.value === null)
89
+
90
+
91
+ const slots = useSlots()
92
+
93
+ /**
94
+ * Valeur "logique" du composant (après inversion).
95
+ * Peut être true/false/null si allowNull=true.
96
+ */
97
+ const maValeur = computed<TriBool>({
98
+ get: () => (props.valeurInverse ? inverseTri(props.modelValue) : props.modelValue),
99
+ set: v => emit('update:modelValue', props.valeurInverse ? inverseTri(v) : v),
100
+ })
101
+
102
+ function inverseTri(v: TriBool): TriBool {
103
+ if (v === null) return null
104
+ return !v
105
+ }
106
+
107
+ /**
108
+ * v-switch attend un bool pour afficher ON/OFF.
109
+ * - null => on affiche OFF (false) visuellement
110
+ */
111
+ const switchChecked = computed(() => maValeur.value === true)
112
+
113
+ function onToggle() {
114
+ if (props.desactiver) return
115
+
116
+ // Mode tri-state
117
+ if (props.autoriserNull) {
118
+ // cycle: null -> true -> false -> null
119
+ const cur = maValeur.value
120
+ const next: TriBool = cur === null ? true : cur === true ? false : null
121
+ maValeur.value = next
122
+ return
123
+ }
124
+
125
+ // Mode classique (ne change rien vs avant)
126
+ maValeur.value = !switchChecked.value
127
+ }
128
+
129
+ const afficherDetails = computed(() => {
130
+ const slotExiste = !!slots.details?.().length
131
+ return slotExiste || props.texteDetaille.trim().length > 0
132
+ })
133
+
134
+ const switchId = `sw_${Math.random().toString(36).slice(2)}`
135
+ </script>
136
+
137
+ <style scoped>
138
+ /* OFF (false) */
139
+ :deep(.switch-tristate.is-false .v-switch__track) {
140
+ opacity: 0.22 !important;
141
+ }
142
+ :deep(.switch-tristate.is-false .v-switch__thumb) {
143
+ opacity: 0.65 !important;
144
+ }
145
+
146
+ /* NULL (centre + très distinct) */
147
+ :deep(.switch-tristate.is-null .v-switch__track) {
148
+ opacity: 1 !important;
149
+ background:
150
+ repeating-linear-gradient(
151
+ 45deg,
152
+ rgba(255, 255, 255, 0.22),
153
+ rgba(255, 255, 255, 0.22) 6px,
154
+ rgba(255, 255, 255, 0.05) 6px,
155
+ rgba(255, 255, 255, 0.05) 12px
156
+ ),
157
+ rgb(var(--v-theme-warning)) !important;
158
+ }
159
+
160
+ :deep(.switch-tristate.is-null .v-switch__thumb) {
161
+ transform: translateX(calc((100% - 20px) / 2)) !important;
162
+ background: white !important;
163
+ opacity: 1 !important;
164
+ box-shadow:
165
+ 0 0 0 2px rgba(var(--v-theme-warning), 0.55),
166
+ 0 2px 6px rgba(0, 0, 0, 0.18) !important;
167
+ }
168
+
169
+ /* Icône minus visible sur fond blanc */
170
+ :deep(.switch-tristate.is-null .v-selection-control__input-icon) {
171
+ color: rgb(var(--v-theme-warning)) !important;
172
+ }
173
+
174
+ /* Transition */
175
+ :deep(.switch-tristate .v-switch__thumb) {
176
+ transition:
177
+ transform 0.18s ease,
178
+ background 0.18s ease,
179
+ box-shadow 0.18s ease;
180
+ }
181
+ .labelSwitchSiSwitchApres {
182
+ font-weight: bold;
183
+ line-height: 1.2;
184
+ }
185
+
186
+ .label-cliquable {
187
+ cursor: pointer;
188
+ }
189
+
190
+ .details {
191
+ margin-top: 4px;
192
+ }
193
+ </style>
@@ -1,23 +1,34 @@
1
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
+ -->
2
8
  <v-snackbar
3
- v-model="snackbar"
4
- v-bind="$attrs"
5
- :timeout="tempsFinal"
6
- :style="styleCss"
7
- color="success"
9
+ :model-value="snackbar"
10
+ v-bind="attrsAffiches"
11
+ :timeout="-1"
12
+ :style="props.styleCss"
13
+ :color="colorAffiche"
14
+ :location="locationAffiche"
8
15
  multi-line
9
- @update:model-value="fermer"
16
+ @update:model-value="
17
+ v => {
18
+ if (!v) fermer()
19
+ }
20
+ "
10
21
  >
11
- <template v-if="props.titre || props.message">
12
- <b style="font-size: 12pt">{{ props.titre }}</b>
13
- <br v-if="props.titre" />
14
- <b>{{ props.message }}</b>
22
+ <template v-if="titreAffiche || messageAffiche">
23
+ <b style="font-size: 12pt">{{ titreAffiche }}</b>
24
+ <br v-if="titreAffiche" />
25
+ <b>{{ messageAffiche }}</b>
15
26
  </template>
16
27
 
17
28
  <template #actions>
18
- <!-- on affiche tjrs si c'est -1 car on ne pourra pas fermer le snack -->
29
+ <!-- Toujours afficher la fermeture si timeout = -1 -->
19
30
  <v-icon
20
- v-if="props.btnFermer || props.temps === -1"
31
+ v-if="props.btnFermer || timeoutAffiche === -1"
21
32
  color="white"
22
33
  style="cursor: pointer"
23
34
  @click.stop="fermer"
@@ -27,62 +38,170 @@
27
38
  </template>
28
39
  </v-snackbar>
29
40
  </template>
30
- <script lang="ts" setup>
31
- import { computed, ref, watch, type PropType } from 'vue'
32
41
 
33
- // Définir les props avec les types
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.
34
46
  const props = defineProps({
35
- styleCss: {
36
- type: String,
37
- required: false,
38
- },
39
- temps: {
40
- type: Number,
41
- required: false,
42
- default: 4000,
43
- validator(value: number) {
44
- // Si la valeur est inférieure à -1, on la remplace par -1
45
- if (value < -1) {
46
- return false // Laisser échouer la validation pour gérer ça dans une logique personnalisée
47
- }
48
- // Validation que la valeur soit comprise entre -1 et Number.MAX_VALUE
49
- return value <= Number.MAX_VALUE
50
- },
51
- },
52
- message: {
53
- type: String,
54
- required: true,
55
- },
56
- titre: {
57
- type: String,
58
- required: false,
59
- },
60
- btnFermer: {
61
- type: Boolean,
62
- required: false,
63
- default: true,
64
- },
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 },
65
61
  })
62
+
66
63
  const emit = defineEmits(['fermer:snackbar'])
67
- const fermer = (): void => {
68
- snackbar.value = false
69
- emit('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
70
89
  }
71
- // Déclarer l'état réactif pour snackbar
90
+
91
+ const file = ref<ItemSnack[]>([])
92
+ const enCours = ref<ItemSnack | null>(null)
93
+
94
+ /**
95
+ * ============================================================================
96
+ * État UI
97
+ * ============================================================================
98
+ */
72
99
  const snackbar = ref(false)
73
- const message = computed(() => props.message)
74
- const tempsFinal = computed(() => {
75
- if (props.temps < -1) {
76
- return -1 // Si la valeur est inférieure à -1, on la met à -1
77
- }
78
- if (props.temps >= 0 && props.temps < 1000) return 1000 // on met 1 seconde minimum sinon one ne la voit pas
79
100
 
80
- return props.temps // Sinon, on retourne la valeur de la prop
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
81
111
  })
82
112
 
83
- watch(message, nouveau => {
84
- if (nouveau != null && nouveau !== '') {
85
- snackbar.value = true
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
86
130
  }
87
- })
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
+ )
88
207
  </script>