@tekkare/romulus 0.1.284 → 0.1.285
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/module.json
CHANGED
|
@@ -54,11 +54,16 @@
|
|
|
54
54
|
<div v-if="textBlocks.length > 0" class="am_texts">
|
|
55
55
|
<div v-for="block in textBlocks" :key="block.key" class="oip_list gap-4">
|
|
56
56
|
<p class="oip_label">{{ block.label }}</p>
|
|
57
|
-
<p
|
|
57
|
+
<p
|
|
58
|
+
:id="`${blockId}-${block.key}`"
|
|
59
|
+
:ref="(el) => watchOverflow(block.key, el as HTMLElement | null)"
|
|
60
|
+
class="am_text"
|
|
61
|
+
:class="{ 'am_text--clamped': !expanded[block.key] }"
|
|
62
|
+
>
|
|
58
63
|
<template v-for="(seg, si) in block.segments" :key="si"><mark v-if="seg.hit">{{ seg.text }}</mark><template v-else>{{ seg.text }}</template></template>
|
|
59
64
|
</p>
|
|
60
65
|
<button
|
|
61
|
-
v-if="block.
|
|
66
|
+
v-if="overflowing[block.key]"
|
|
62
67
|
type="button"
|
|
63
68
|
class="am_toggle"
|
|
64
69
|
:aria-expanded="!!expanded[block.key]"
|
|
@@ -103,7 +108,7 @@
|
|
|
103
108
|
</template>
|
|
104
109
|
|
|
105
110
|
<script lang="ts" setup>
|
|
106
|
-
import { useId } from "vue";
|
|
111
|
+
import { nextTick, onBeforeUnmount, useId, watch } from "vue";
|
|
107
112
|
import { AMENDMENT_FIELDS, amendmentDiscussed } from "../../../../oip-drugs/utils/associationFields";
|
|
108
113
|
import { highlightSegments } from "../../../../oip-drugs/utils/esHighlight";
|
|
109
114
|
import { drugsAssociationPath } from "../../../../oip-drugs/kinds";
|
|
@@ -204,9 +209,6 @@ const associations = computed<string[]>(() => {
|
|
|
204
209
|
.sort((a, b) => a.localeCompare(b, "fr"));
|
|
205
210
|
});
|
|
206
211
|
|
|
207
|
-
/** Au-dela, le texte se replie sur quatre lignes. */
|
|
208
|
-
const LONG_TEXT = 320;
|
|
209
|
-
|
|
210
212
|
/** Dispositif puis expose, surlignes quand le moteur l'a fait. */
|
|
211
213
|
const textBlocks = computed(() =>
|
|
212
214
|
(
|
|
@@ -221,7 +223,6 @@ const textBlocks = computed(() =>
|
|
|
221
223
|
return {
|
|
222
224
|
key,
|
|
223
225
|
label: t(`oipDrugs.heart.associations.nationalAssembly.amendments.card.${key}`),
|
|
224
|
-
long: plain.length > LONG_TEXT,
|
|
225
226
|
segments: highlighted ? highlightSegments(highlighted) : [{ text: plain, hit: false }],
|
|
226
227
|
plain,
|
|
227
228
|
};
|
|
@@ -231,6 +232,35 @@ const textBlocks = computed(() =>
|
|
|
231
232
|
|
|
232
233
|
const expanded = reactive<Record<string, boolean>>({});
|
|
233
234
|
|
|
235
|
+
/**
|
|
236
|
+
* « Afficher tout » ne vaut que si le texte deborde vraiment ses quatre
|
|
237
|
+
* lignes. Un seuil en caracteres se trompe selon la largeur de la carte :
|
|
238
|
+
* on mesure le paragraphe replie, et on garde la reponse une fois deplie
|
|
239
|
+
* pour pouvoir le replier.
|
|
240
|
+
*/
|
|
241
|
+
const overflowing = reactive<Record<string, boolean>>({});
|
|
242
|
+
const observed = new Map<string, HTMLElement>();
|
|
243
|
+
function measure() {
|
|
244
|
+
for (const [key, el] of observed) {
|
|
245
|
+
if (!expanded[key]) overflowing[key] = el.scrollHeight > el.clientHeight + 1;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const resizeObserver = import.meta.client ? new ResizeObserver(measure) : null;
|
|
249
|
+
// Un nouveau surlignage peut changer le texte sans changer la hauteur repliee.
|
|
250
|
+
watch(textBlocks, () => nextTick(measure));
|
|
251
|
+
|
|
252
|
+
function watchOverflow(key: string, el: HTMLElement | null) {
|
|
253
|
+
const previous = observed.get(key);
|
|
254
|
+
if (previous === el) return;
|
|
255
|
+
if (previous) resizeObserver?.unobserve(previous);
|
|
256
|
+
if (el) {
|
|
257
|
+
observed.set(key, el);
|
|
258
|
+
resizeObserver?.observe(el);
|
|
259
|
+
} else observed.delete(key);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
onBeforeUnmount(() => resizeObserver?.disconnect());
|
|
263
|
+
|
|
234
264
|
function openLink(url: string) {
|
|
235
265
|
if (url) window.open(url, "_blank");
|
|
236
266
|
}
|