@open-commune/web 0.2.17 → 0.2.18

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,28 +1,47 @@
1
1
  <template>
2
- <ul class="space-y-1 text-sm">
3
- <li v-for="row in rows" :key="row.name" class="relative flex h-7 items-center justify-between gap-3 px-2">
4
- <span
5
- class="absolute inset-y-0 left-0 rounded-md bg-primary/10"
6
- :style="{ width: `${Math.max(2, (row.value / max) * 100)}%` }"
7
- aria-hidden="true"
8
- />
9
- <NuxtLink v-if="row.link" :to="row.link" class="relative truncate text-default hover:text-highlighted hover:underline">
2
+ <ul class="space-y-2.5 text-sm">
3
+ <li v-for="row in rows" :key="row.name" class="flex min-w-0 items-center gap-3">
4
+ <NuxtLink
5
+ v-if="row.link"
6
+ :to="row.link"
7
+ class="truncate text-default hover:text-highlighted hover:underline"
8
+ :class="bars ? 'w-36 shrink-0' : 'min-w-0 flex-1'"
9
+ >
10
10
  {{ row.name }}
11
11
  </NuxtLink>
12
- <span v-else class="relative truncate text-default">{{ row.name }}</span>
13
- <span class="relative shrink-0 tabular-nums text-muted">{{ row.label ?? row.value }}</span>
12
+ <span
13
+ v-else
14
+ class="truncate text-default"
15
+ :class="[bars ? 'w-36 shrink-0' : 'min-w-0 flex-1', mono && 'font-mono text-[13px]']"
16
+ >
17
+ {{ row.name }}
18
+ </span>
19
+ <span v-if="bars" class="flex min-w-0 flex-1 items-center gap-2">
20
+ <span
21
+ class="h-1.5 shrink-0 rounded-full"
22
+ :class="row.accent ? 'bg-secondary' : 'bg-(--ui-text-dimmed)'"
23
+ :style="{ width: `${Math.max(3, (row.value / max) * 75)}%` }"
24
+ aria-hidden="true"
25
+ />
26
+ <span class="whitespace-nowrap tabular-nums text-dimmed">{{ row.label ?? row.value }}</span>
27
+ </span>
28
+ <span v-else class="shrink-0 whitespace-nowrap tabular-nums text-dimmed">{{ row.label ?? row.value }}</span>
14
29
  </li>
15
30
  </ul>
16
31
  </template>
17
32
 
18
33
  <script setup lang="ts">
19
34
  /**
20
- * A bar list: one row per item, a bar behind it as long as its share of the
21
- * longest row, the value on the right. The panels' sources, devices, reading
22
- * depth, most read pages and campaigns.
35
+ * A list of the panels: one row per item, its name and its value. With
36
+ * `bars`, a thin bar between them as long as its share of the longest row,
37
+ * the value right after it, and a row marked `accent` drawn in the accent
38
+ * colour. Without, the value is set flush right. `mono` sets the names in a
39
+ * fixed-width face, for the campaigns' codes.
23
40
  */
24
41
  const props = defineProps<{
25
- rows: { name: string; value: number; label?: string; link?: string }[];
42
+ rows: { name: string; value: number; label?: string; link?: string; accent?: boolean }[];
43
+ bars?: boolean;
44
+ mono?: boolean;
26
45
  }>();
27
46
 
28
47
  const max = computed(() => Math.max(1, ...props.rows.map((row) => row.value)));
@@ -1,16 +1,18 @@
1
1
  <template>
2
- <section v-if="visible && state !== 'hidden'" class="rounded-xl border border-default bg-default p-5" aria-label="Fréquentation">
3
- <header class="mb-4 flex flex-wrap items-center justify-between gap-2">
4
- <span class="text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">
5
- {{ heading }}
6
- </span>
7
- <span class="flex gap-1" role="group" aria-label="Période">
2
+ <section
3
+ v-if="visible && state !== 'hidden'"
4
+ class="rounded-lg bg-elevated p-6 shadow-card dark:shadow-none dark:ring dark:ring-[var(--ui-border)] plain:bg-default plain:ring plain:ring-default"
5
+ aria-label="Fréquentation"
6
+ >
7
+ <header class="flex flex-wrap items-center justify-between gap-2">
8
+ <span :class="LABEL">{{ heading }}</span>
9
+ <span class="flex gap-3" role="group" aria-label="Période">
8
10
  <button
9
11
  v-for="option in PERIODS"
10
12
  :key="option"
11
13
  type="button"
12
- class="border-b-2 px-1.5 py-0.5 text-xs"
13
- :class="option === period ? 'border-primary font-semibold text-highlighted' : 'border-transparent text-dimmed hover:text-highlighted'"
14
+ class="border-b-2 py-0.5 text-sm"
15
+ :class="option === period ? 'border-primary font-semibold text-highlighted' : 'border-transparent text-muted hover:text-highlighted'"
14
16
  :aria-pressed="option === period"
15
17
  @click="period = option"
16
18
  >
@@ -19,31 +21,30 @@
19
21
  </span>
20
22
  </header>
21
23
 
22
- <div v-if="state === 'loading' && !audience" class="space-y-3">
24
+ <div v-if="state === 'loading' && !audience" class="mt-5 space-y-3">
23
25
  <USkeleton class="h-10 w-2/3" />
24
26
  <USkeleton class="h-24 w-full" />
25
27
  </div>
26
28
 
27
29
  <template v-else-if="audience">
28
- <div class="flex flex-wrap items-baseline gap-x-6 gap-y-2">
30
+ <div class="mt-5 flex flex-wrap items-baseline gap-x-9 gap-y-2">
29
31
  <div>
30
- <span class="font-serif text-3xl font-semibold text-highlighted">{{ count(audience.visits) }}</span>
31
- <span class="ml-1 text-xs text-dimmed">{{ collection ? 'pages vues' : 'visites' }}</span>
32
- <span v-if="trend" class="ml-2 text-xs font-medium" :class="trend.up ? 'text-success' : 'text-error'">{{ trend.label }}</span>
32
+ <span class="font-serif text-[2.125rem] leading-none font-semibold text-highlighted">{{ count(audience.visits) }}</span>
33
+ <span class="ml-1.5 text-sm text-dimmed">{{ collection ? 'pages vues' : 'visites' }}</span>
33
34
  </div>
34
35
  <div v-if="audience.visitors != null">
35
- <span class="font-serif text-lg text-highlighted">{{ count(audience.visitors) }}</span>
36
- <span class="ml-1 text-xs text-dimmed">visiteurs</span>
36
+ <span class="font-serif text-xl text-highlighted">{{ count(audience.visitors) }}</span>
37
+ <span class="ml-1.5 text-sm text-dimmed">visiteurs</span>
37
38
  </div>
38
39
  <div v-if="audience.viewsPerVisit != null">
39
- <span class="font-serif text-lg text-highlighted">{{ decimal(audience.viewsPerVisit) }}</span>
40
- <span class="ml-1 text-xs text-dimmed">pages / visite</span>
40
+ <span class="font-serif text-xl text-highlighted">{{ decimal(audience.viewsPerVisit) }}</span>
41
+ <span class="ml-1.5 text-sm text-dimmed">pages / visite</span>
41
42
  </div>
42
43
  <div v-if="audience.readingMs != null">
43
- <span class="font-serif text-lg text-highlighted">{{ duration(audience.readingMs) }}</span>
44
- <span class="ml-1 text-xs text-dimmed">durée moyenne</span>
44
+ <span class="font-serif text-xl text-highlighted">{{ duration(audience.readingMs) }}</span>
45
+ <span class="ml-1.5 text-sm text-dimmed">durée moyenne</span>
45
46
  </div>
46
- <div v-if="audience.rightNow != null" class="ml-auto text-xs text-muted">
47
+ <div v-if="audience.rightNow != null" class="ml-auto text-sm whitespace-nowrap text-muted">
47
48
  <span class="mr-1.5 inline-block size-1.5 rounded-full bg-success align-middle" aria-hidden="true" />
48
49
  <b class="text-highlighted">{{ audience.rightNow }}</b>
49
50
  {{ audience.rightNow > 1 ? 'visiteurs' : 'visiteur' }} en ce moment
@@ -60,50 +61,55 @@
60
61
  :categories="series"
61
62
  :height="140"
62
63
  x-axis="day"
63
- :x-formatter="dayTick"
64
- :x-num-ticks="4"
65
- :y-num-ticks="3"
66
- :y-axes="{ 0: { formatter: (value: number) => count(value) } }"
67
64
  :tooltip-title-formatter="(row: { day: string }) => day(row.day)"
68
- curve-type="monotoneX"
69
- :padding="{ top: 4, right: 24, bottom: 0, left: 0 }"
65
+ curve-type="basis"
66
+ :padding="{ top: 4, right: 0, bottom: 0, left: 0 }"
70
67
  :gradient-stops="[
71
- { offset: '0%', stopOpacity: 0.12 },
68
+ { offset: '0%', stopOpacity: 0.08 },
72
69
  { offset: '100%', stopOpacity: 0 },
73
70
  ]"
71
+ hide-x-axis
72
+ hide-y-axis
74
73
  hide-legend
75
74
  />
76
75
  </div>
77
76
 
78
- <div v-if="open" class="mt-5 grid gap-6 border-t border-default pt-5 sm:grid-cols-3">
77
+ <div v-if="open" class="mt-5 grid gap-x-8 gap-y-8 border-t border-default pt-6 sm:grid-cols-3">
79
78
  <div v-if="audience.sources?.length">
80
- <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Sources</h3>
81
- <audience-bar-list :rows="shares(audience.sources)" />
79
+ <h3 :class="[LABEL, 'mb-3']">Sources</h3>
80
+ <audience-bar-list :rows="sources" bars />
82
81
  </div>
83
- <div v-if="audience.depth">
84
- <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Lecture</h3>
85
- <audience-bar-list :rows="shares(depth)" />
82
+ <div v-if="entry && audience.depth">
83
+ <h3 :class="[LABEL, 'mb-3']">Lecture</h3>
84
+ <audience-bar-list :rows="shares(depth)" bars />
86
85
  </div>
87
- <div v-else-if="!entry && audience.top.length">
88
- <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Pages les plus vues</h3>
86
+ <div v-if="!entry && audience.top.length">
87
+ <h3 :class="[LABEL, 'mb-3']">Pages les plus vues</h3>
89
88
  <audience-bar-list :rows="topPages" />
90
89
  </div>
91
90
  <div v-if="audience.devices?.length">
92
- <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Appareils</h3>
93
- <audience-bar-list :rows="shares(devices)" />
91
+ <h3 :class="[LABEL, 'mb-3']">Appareils</h3>
92
+ <audience-bar-list :rows="shares(devices)" bars />
93
+ </div>
94
+ <div v-if="audience.places?.length">
95
+ <h3 :class="[LABEL, 'mb-3']">Provenance géographique</h3>
96
+ <audience-bar-list :rows="shares(audience.places)" />
94
97
  </div>
95
98
  <div v-if="audience.campaigns?.length">
96
- <h3 class="mb-2 text-[10.5px] font-semibold uppercase tracking-[.14em] text-dimmed">Campagnes (UTM)</h3>
97
- <audience-bar-list :rows="campaigns" />
99
+ <h3 :class="[LABEL, 'mb-3']">Campagnes (UTM)</h3>
100
+ <audience-bar-list :rows="campaigns" mono />
98
101
  </div>
99
- <p class="flex gap-2 rounded-lg bg-elevated/50 p-3 text-xs leading-relaxed text-muted sm:col-span-3">
102
+ <p class="flex gap-3 rounded-lg border border-default bg-default p-4 text-sm leading-relaxed text-muted sm:col-span-3">
100
103
  <svg class="mt-0.5 size-4 shrink-0 text-success" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" /><path d="m9 12 2 2 4-4" /></svg>
101
- <span><b class="text-default">Conforme RGPD</b> — mesure anonyme et agrégée, sans cookie ni bandeau de consentement.</span>
104
+ <span>
105
+ <b class="font-semibold text-highlighted">Conforme RGPD</b> — mesure anonyme et agrégée, sans cookie ni bandeau de consentement.
106
+ <template v-if="audience.places?.length">La provenance géographique est une estimation, agrégée par commune.</template>
107
+ </span>
102
108
  </p>
103
109
  </div>
104
110
 
105
- <div class="mt-3 text-center">
106
- <button type="button" class="text-xs text-dimmed hover:text-highlighted" :aria-expanded="open" @click="open = !open">
111
+ <div class="mt-4 text-center">
112
+ <button type="button" class="text-sm text-muted hover:text-highlighted" :aria-expanded="open" @click="open = !open">
107
113
  {{ open ? 'Replier ⌃' : 'Plus de détails ⌄' }}
108
114
  </button>
109
115
  </div>
@@ -119,7 +125,8 @@
119
125
  * if not, nothing renders and nothing is asked. A refusal still means no
120
126
  * source is configured, this user is not among its viewers, or the source did
121
127
  * not answer: the panel then renders nothing at all. Every block the source
122
- * leaves out is left out here too.
128
+ * leaves out is left out here too. The most read pages are the site's and a
129
+ * collection's; the reading depth, an entry's.
123
130
  */
124
131
  import { AUDIENCE_PERIODS } from '@open-commune/core/dtos';
125
132
  import AudienceBarList from './audience-bar-list.vue';
@@ -162,12 +169,15 @@ const state = computed(() =>
162
169
  isError.value ? 'hidden' : isPending.value && !data.value ? 'loading' : 'ready',
163
170
  );
164
171
 
165
- const trend = computed(() => {
166
- const a = audience.value;
167
- if (!a?.visitsPrevious) return null;
168
- const change = Math.round(((a.visits - a.visitsPrevious) / a.visitsPrevious) * 100);
169
- return { up: change >= 0, label: `${change >= 0 ? '+' : '−'}${Math.abs(change)} %` };
170
- });
172
+ /** A section's title, and the panel's own. */
173
+ const LABEL = 'text-xs font-semibold tracking-[.14em] text-muted uppercase';
174
+
175
+ /** The social networks, whose share the sources draw in the accent colour. */
176
+ const SOCIAL = /(^|\.)(facebook|instagram|linkedin|twitter|x|t|youtube|tiktok|whatsapp|bsky|threads|mastodon)\.[a-z]+$|^réseaux sociaux$/i;
177
+
178
+ const sources = computed(() =>
179
+ shares(audience.value?.sources ?? []).map((row) => ({ ...row, accent: SOCIAL.test(row.name) })),
180
+ );
171
181
 
172
182
  /** How far the readers of an entry went down the page. */
173
183
  const depth = computed(() => {
@@ -224,10 +234,5 @@ const duration = (ms: number) => {
224
234
  };
225
235
  const day = (iso: string) =>
226
236
  new Date(`${iso}T12:00:00Z`).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' });
227
- /** An x tick of the curve: an index into the days, or the day itself. */
228
- const dayTick = (tick: number | Date) => {
229
- const iso = typeof tick === 'number' ? audience.value?.daily[tick]?.day : String(tick);
230
- return iso ? day(iso) : '';
231
- };
232
237
 
233
238
  </script>
package/package.json CHANGED
@@ -19,8 +19,8 @@
19
19
  "@iconify/vue": "^5.0.3",
20
20
  "@nuxt/kit": "^4.6.1",
21
21
  "@nuxt/ui": "^4.12.0",
22
- "@open-commune/core": "^0.2.17",
23
- "@open-commune/editor": "^0.2.17",
22
+ "@open-commune/core": "^0.2.18",
23
+ "@open-commune/editor": "^0.2.18",
24
24
  "@pinia-orm/nuxt": "^2.0.0",
25
25
  "@pinia/nuxt": "^1.0.3",
26
26
  "@tanstack/vue-query": "^5.104.3",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "description": "The Open Commune application: the admin interface and the server, on a single origin.",
45
45
  "license": "AGPL-3.0-or-later",
46
- "version": "0.2.17",
46
+ "version": "0.2.18",
47
47
  "type": "module",
48
48
  "main": "./nuxt.config.ts",
49
49
  "files": [