@open-commune/web 0.2.14 → 0.2.16

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.
Files changed (69) hide show
  1. package/app.config.ts +7 -0
  2. package/components/audience/audience-bar-list.vue +29 -0
  3. package/components/audience/audience-panel.vue +230 -0
  4. package/components/data/lists/data-table.vue +203 -0
  5. package/components/data/lists/row-actions.vue +41 -0
  6. package/components/elements/badges/status-badge.vue +23 -0
  7. package/components/elements/media/media-image.vue +26 -0
  8. package/components/forms/fields/input-files-media.vue +87 -0
  9. package/components/forms/{inputs → fields}/input-filter-status.vue +2 -2
  10. package/components/forms/{inputs → fields}/input-search.vue +8 -2
  11. package/components/forms/fields/input-text-area.vue +86 -0
  12. package/components/forms/fields/input-text.vue +47 -0
  13. package/components/forms/fields/select-enum.vue +69 -0
  14. package/components/forms/handlers/handler-collections.vue +100 -170
  15. package/components/forms/handlers/handler-list.vue +187 -0
  16. package/components/forms/handlers/handler-members.vue +171 -0
  17. package/components/forms/handlers/handler-password-reset.vue +45 -0
  18. package/components/forms/handlers/handler-roles.vue +28 -166
  19. package/components/forms/handlers/handler-sessions.vue +77 -0
  20. package/components/forms/handlers/handler-tokens.vue +54 -69
  21. package/components/forms/layouts/form-default.vue +99 -0
  22. package/components/forms/layouts/form.vue +4 -0
  23. package/components/forms/layouts/forms-layout.vue +236 -0
  24. package/components/forms/layouts/forms-section.vue +186 -0
  25. package/components/forms/layouts/layout.vue +4 -0
  26. package/components/forms/layouts/modal.vue +4 -0
  27. package/components/forms/layouts/section.vue +4 -0
  28. package/components/layout/shell/shell-account-menu.vue +10 -2
  29. package/composables/core/domains/use-api-tokens.ts +80 -0
  30. package/composables/core/domains/use-audience.ts +26 -0
  31. package/composables/core/domains/use-auth.ts +56 -2
  32. package/composables/core/domains/use-definitions.ts +18 -5
  33. package/composables/core/domains/use-entries.ts +125 -3
  34. package/composables/core/domains/use-media.ts +24 -1
  35. package/composables/core/domains/use-members.ts +68 -0
  36. package/composables/core/domains/use-organization.ts +53 -0
  37. package/composables/use-models.js +1 -7
  38. package/constants/errors.ts +29 -0
  39. package/constants/forms/account.ts +62 -0
  40. package/constants/forms/collections.ts +39 -0
  41. package/constants/forms/members.ts +40 -0
  42. package/constants/forms/organization.ts +188 -0
  43. package/constants/forms/tokens.ts +15 -0
  44. package/constants/roles.ts +57 -0
  45. package/constants/settings.ts +26 -0
  46. package/constants/statuses.ts +8 -5
  47. package/nuxt.config.ts +4 -1
  48. package/package.json +4 -3
  49. package/pages/[collection]/[record]/index.vue +7 -0
  50. package/pages/[collection]/index.vue +117 -97
  51. package/pages/account.vue +40 -0
  52. package/pages/overview.vue +106 -2
  53. package/pages/settings.vue +26 -181
  54. package/plugins/01.validation.client.ts +23 -0
  55. package/store/layout/workspace.js +4 -28
  56. package/utils/colors.ts +26 -0
  57. package/utils/errors.ts +13 -0
  58. package/utils/forms.ts +67 -0
  59. package/utils/list-columns.ts +90 -0
  60. package/utils/settings.ts +38 -0
  61. package/utils/statuses.ts +4 -0
  62. package/models/role.js +0 -66
  63. package/models/token.js +0 -56
  64. package/models/user.js +0 -97
  65. package/pages/management/index.vue +0 -15
  66. package/pages/management/members.vue +0 -176
  67. package/pages/management/organizations.vue +0 -192
  68. package/pages/management/roles.vue +0 -183
  69. /package/components/forms/{inputs → fields}/input-filter.vue +0 -0
package/app.config.ts CHANGED
@@ -1,4 +1,11 @@
1
+ import type { LayerSettingsSection } from '~/types';
2
+
1
3
  export default defineAppConfig({
4
+ // Sections a Nuxt layer adds to the settings, after the product's own. A
5
+ // layer declares them in its own `app.config.ts` (see `LayerSettingsSection`).
6
+ settings: {
7
+ sections: [] as LayerSettingsSection[],
8
+ },
2
9
  ui: {
3
10
  colors: {
4
11
  // Sober palette while the visual identity settles; final palette is a
@@ -0,0 +1,29 @@
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">
10
+ {{ row.name }}
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>
14
+ </li>
15
+ </ul>
16
+ </template>
17
+
18
+ <script setup lang="ts">
19
+ /**
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.
23
+ */
24
+ const props = defineProps<{
25
+ rows: { name: string; value: number; label?: string; link?: string }[];
26
+ }>();
27
+
28
+ const max = computed(() => Math.max(1, ...props.rows.map((row) => row.value)));
29
+ </script>
@@ -0,0 +1,230 @@
1
+ <template>
2
+ <section v-if="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">
8
+ <button
9
+ v-for="option in PERIODS"
10
+ :key="option"
11
+ 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
+ :aria-pressed="option === period"
15
+ @click="period = option"
16
+ >
17
+ {{ option }} jours
18
+ </button>
19
+ </span>
20
+ </header>
21
+
22
+ <div v-if="state === 'loading' && !audience" class="space-y-3">
23
+ <USkeleton class="h-10 w-2/3" />
24
+ <USkeleton class="h-24 w-full" />
25
+ </div>
26
+
27
+ <template v-else-if="audience">
28
+ <div class="flex flex-wrap items-baseline gap-x-6 gap-y-2">
29
+ <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>
33
+ </div>
34
+ <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>
37
+ </div>
38
+ <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>
41
+ </div>
42
+ <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>
45
+ </div>
46
+ <div v-if="audience.rightNow != null" class="ml-auto text-xs text-muted">
47
+ <span class="mr-1.5 inline-block size-1.5 rounded-full bg-success align-middle" aria-hidden="true" />
48
+ <b class="text-highlighted">{{ audience.rightNow }}</b>
49
+ {{ audience.rightNow > 1 ? 'visiteurs' : 'visiteur' }} en ce moment
50
+ </div>
51
+ </div>
52
+
53
+ <div
54
+ class="mt-4"
55
+ role="img"
56
+ :aria-label="`${collection ? 'Pages vues' : 'Visites'} par jour, du ${day(audience.period.from)} au ${day(audience.period.to)}`"
57
+ >
58
+ <AreaChart
59
+ :data="audience.daily"
60
+ :categories="series"
61
+ :height="140"
62
+ 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
+ :tooltip-title-formatter="(row: { day: string }) => day(row.day)"
68
+ curve-type="monotoneX"
69
+ :padding="{ top: 4, right: 24, bottom: 0, left: 0 }"
70
+ :gradient-stops="[
71
+ { offset: '0%', stopOpacity: 0.12 },
72
+ { offset: '100%', stopOpacity: 0 },
73
+ ]"
74
+ hide-legend
75
+ />
76
+ </div>
77
+
78
+ <div v-if="open" class="mt-5 grid gap-6 border-t border-default pt-5 sm:grid-cols-3">
79
+ <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)" />
82
+ </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)" />
86
+ </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>
89
+ <audience-bar-list :rows="topPages" />
90
+ </div>
91
+ <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)" />
94
+ </div>
95
+ <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" />
98
+ </div>
99
+ <p class="flex gap-2 rounded-lg bg-elevated/50 p-3 text-xs leading-relaxed text-muted sm:col-span-3">
100
+ <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>
102
+ </p>
103
+ </div>
104
+
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">
107
+ {{ open ? 'Replier ⌃' : 'Plus de détails ⌄' }}
108
+ </button>
109
+ </div>
110
+ </template>
111
+ </section>
112
+ </template>
113
+
114
+ <script setup lang="ts">
115
+ /**
116
+ * An audience panel: the site's, a collection's or an entry's, read from the
117
+ * instance's `audience.summary`, which asks the configured audience source.
118
+ * A refusal means no source is configured, this user is not among its viewers,
119
+ * or the source did not answer: the panel then renders nothing at all. Every
120
+ * block the source leaves out is left out here too.
121
+ */
122
+ import { AUDIENCE_PERIODS } from '@open-commune/core/dtos';
123
+ import AudienceBarList from './audience-bar-list.vue';
124
+
125
+ type Share = { name: string; share: number };
126
+
127
+ /**
128
+ * Without props, the site's panel; with `collection`, that collection's; with
129
+ * `collection` and `entry` (the entry's id), that entry's.
130
+ */
131
+ const props = defineProps<{ collection?: { id: string; slug: string }; entry?: string }>();
132
+
133
+ const heading = computed(() =>
134
+ props.entry
135
+ ? 'Fréquentation de la fiche'
136
+ : props.collection
137
+ ? 'Fréquentation de la collection'
138
+ : 'Fréquentation du site',
139
+ );
140
+
141
+ const PERIODS = AUDIENCE_PERIODS;
142
+ const DEVICES: Record<string, string> = {
143
+ phone: 'Téléphone',
144
+ computer: 'Ordinateur',
145
+ tablet: 'Tablette',
146
+ };
147
+
148
+ const period = ref<(typeof PERIODS)[number]>(30);
149
+ const open = ref(false);
150
+ const { data, isPending, isError } = useAudience().summary(
151
+ computed(() => ({
152
+ period: period.value,
153
+ collection: props.collection?.slug,
154
+ entry: props.collection ? props.entry : undefined,
155
+ })),
156
+ );
157
+ const audience = computed(() => (isError.value ? null : (data.value ?? null)));
158
+ const state = computed(() =>
159
+ isError.value ? 'hidden' : isPending.value && !data.value ? 'loading' : 'ready',
160
+ );
161
+
162
+ const trend = computed(() => {
163
+ const a = audience.value;
164
+ if (!a?.visitsPrevious) return null;
165
+ const change = Math.round(((a.visits - a.visitsPrevious) / a.visitsPrevious) * 100);
166
+ return { up: change >= 0, label: `${change >= 0 ? '+' : '−'}${Math.abs(change)} %` };
167
+ });
168
+
169
+ /** How far the readers of an entry went down the page. */
170
+ const depth = computed(() => {
171
+ const d = audience.value?.depth;
172
+ if (!d) return [];
173
+ return [
174
+ { name: 'Un quart', share: d.reached25 },
175
+ { name: 'La moitié', share: d.reached50 },
176
+ { name: "Jusqu'au bout", share: d.reachedEnd },
177
+ ];
178
+ });
179
+
180
+ const devices = computed(() =>
181
+ (audience.value?.devices ?? []).map((row) => ({ ...row, name: DEVICES[row.name] ?? row.name })),
182
+ );
183
+
184
+ /** The daily curve's one series, named the way the headline counts. */
185
+ const series = computed(() => ({
186
+ visits: { name: props.collection ? 'Pages vues' : 'Visites', color: 'var(--ui-text-highlighted)' },
187
+ }));
188
+
189
+ /** The most read pages, named after their entry and opening it in the admin. */
190
+ const topPages = computed(() =>
191
+ (audience.value?.top ?? []).map((page) => {
192
+ const slug = page.collection ?? props.collection?.slug;
193
+ return {
194
+ name: page.title,
195
+ value: page.visits,
196
+ label: count(page.visits),
197
+ link: slug ? (page.entryId ? `/${slug}/${page.entryId}` : `/${slug}`) : undefined,
198
+ };
199
+ }),
200
+ );
201
+
202
+ const campaigns = computed(() =>
203
+ (audience.value?.campaigns ?? []).map((campaign) => ({
204
+ name: campaign.name,
205
+ value: campaign.visits,
206
+ label: `${count(campaign.visits)} visites`,
207
+ })),
208
+ );
209
+
210
+ /** Shares, as rows of a bar list. */
211
+ const shares = (rows: Share[]) =>
212
+ rows.map((row) => ({ name: row.name, value: row.share, label: `${row.share} %` }));
213
+
214
+ const count = (value: number) => value.toLocaleString('fr-FR');
215
+ const decimal = (value: number) => value.toLocaleString('fr-FR', { maximumFractionDigits: 1 });
216
+ const duration = (ms: number) => {
217
+ const seconds = Math.round(ms / 1000);
218
+ return seconds < 60
219
+ ? `${seconds} s`
220
+ : `${Math.floor(seconds / 60)} min ${String(seconds % 60).padStart(2, '0')}`;
221
+ };
222
+ const day = (iso: string) =>
223
+ new Date(`${iso}T12:00:00Z`).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' });
224
+ /** An x tick of the curve: an index into the days, or the day itself. */
225
+ const dayTick = (tick: number | Date) => {
226
+ const iso = typeof tick === 'number' ? audience.value?.daily[tick]?.day : String(tick);
227
+ return iso ? day(iso) : '';
228
+ };
229
+
230
+ </script>
@@ -0,0 +1,203 @@
1
+ <template>
2
+ <UTable
3
+ :data="items"
4
+ :columns="columns"
5
+ :loading="loading"
6
+ :ui="UI"
7
+ :on-select="onSelect"
8
+ >
9
+ <!-- THE row of every listing, written once. A caller does not say what a
10
+ cell renders, only which key holds what. -->
11
+ <template #summary-cell="{ row }">
12
+ <div class="flex w-full items-center gap-4 py-1 text-sm" :class="onSelect ? 'cursor-pointer' : ''">
13
+ <!-- 16/9, the ratio the public themes use: an editor sees what an
14
+ inhabitant will see. The box is held even without a cover, so
15
+ titles stay aligned down the column. Today's look never had it. -->
16
+ <div
17
+ v-if="coverKey"
18
+ class="hidden aspect-video w-48 shrink-0 overflow-hidden rounded-md bg-muted sm:block plain:sm:hidden"
19
+ >
20
+ <media-image v-if="_coverOf(row.original)" :media-id="_coverOf(row.original)" class="size-full object-cover" />
21
+ <!-- With no cover the box SAYS it is empty: a plain fill read as an
22
+ image failing to load. -->
23
+ <div v-else class="flex size-full items-center justify-center">
24
+ <UIcon name="i-lucide-image" class="size-6 text-dimmed" />
25
+ </div>
26
+ </div>
27
+
28
+ <!-- Bounded: without a cap the title and the description dictated the
29
+ column's width and left nothing to the others. -->
30
+ <div class="flex min-w-0 max-w-2xl flex-1 flex-col items-start justify-center space-y-1">
31
+ <status-badge :status="row.original.status" class="sm:hidden" />
32
+ <div class="flex w-full min-w-0 items-center space-x-2">
33
+ <p class="min-w-0 truncate text-base font-semibold text-highlighted plain:text-sm plain:font-normal plain:text-default">
34
+ {{ row.original[titleKey] }}
35
+ </p>
36
+ <status-badge :status="row.original.status" class="hidden sm:inline-flex" />
37
+ </div>
38
+ <!-- One line, cut with an ellipsis: the description places the entry,
39
+ it is not read here, and a fixed line keeps rows of equal height. -->
40
+ <p class="hidden w-full truncate text-[13px] font-normal text-muted sm:block plain:line-clamp-2 plain:whitespace-normal plain:text-sm plain:font-light">
41
+ {{ row.original[descriptionKey] }}
42
+ </p>
43
+ </div>
44
+ </div>
45
+ </template>
46
+
47
+ <!-- The linked entries, as pills. Editors pick their colours freely and
48
+ they carry no meaning: repeated on every row they shouted louder than
49
+ the publication status, which does, so the pills are neutral. Today's
50
+ look keeps the colours its users know. Never wider than the cell:
51
+ beyond it the pills wrap. -->
52
+ <template #labels-cell="{ row }">
53
+ <div class="flex max-w-full flex-wrap justify-end gap-1.5">
54
+ <UBadge
55
+ v-for="label in _labelsOf(row.original)"
56
+ :key="label.id"
57
+ color="neutral"
58
+ variant="soft"
59
+ size="md"
60
+ :icon="label.data?.icon || undefined"
61
+ :label="label.title"
62
+ class="max-w-full truncate rounded-full bg-default text-default plain:font-light"
63
+ :style="plain ? swatchOf(label.data?.color) : undefined"
64
+ :ui="{ leadingIcon: plain ? '' : 'text-muted' }"
65
+ />
66
+ </div>
67
+ </template>
68
+
69
+ <!-- Who, and when. Mirrored: the disc sits at the right edge, where it
70
+ lines up from one row to the next, and the text ranges against it. -->
71
+ <template #update-cell="{ row }">
72
+ <UUser
73
+ :name="_authorOf(row.original)"
74
+ :description="_fromNow(row.original.updatedAt)"
75
+ :avatar="{ alt: _authorOf(row.original), ui: { root: 'bg-muted ring ring-default', fallback: 'text-muted' } }"
76
+ size="sm"
77
+ :ui="{ root: 'flex-row-reverse plain:flex-row plain:justify-end', wrapper: 'text-right plain:text-left', name: 'font-normal' }"
78
+ />
79
+ </template>
80
+
81
+ <template #actions-cell="{ row }">
82
+ <row-actions :actions="actions" @action="$emitters($event, row.original)" />
83
+ </template>
84
+ </UTable>
85
+ </template>
86
+
87
+ <script setup>
88
+ /**
89
+ * A table of entries, all drawn the same way: a summary, and the optional
90
+ * cells the caller asks for. `UTable` holds the table and its keyboard, and
91
+ * the cells are Nuxt UI's own pieces (`UBadge`, `UUser`) filled in here.
92
+ */
93
+ import { DateTime } from 'luxon'
94
+ import rowActions from '~/components/data/lists/row-actions'
95
+ import statusBadge from '~/components/elements/badges/status-badge'
96
+ import mediaImage from '~/components/elements/media/media-image'
97
+ import { swatchOf } from '~/utils/colors'
98
+
99
+ // Prepare props
100
+ const $props = defineProps({
101
+ items: {
102
+ type: Array,
103
+ default: () => []
104
+ },
105
+ // Which key of a row holds what the row shows.
106
+ titleKey: {
107
+ type: String,
108
+ default: 'title'
109
+ },
110
+ descriptionKey: {
111
+ type: String,
112
+ default: 'description'
113
+ },
114
+ // Empty: no thumbnail box at all. A media field may hold one id or several,
115
+ // the cover is the first.
116
+ coverKey: {
117
+ type: String,
118
+ default: ''
119
+ },
120
+ // Empty: no column of linked entries.
121
+ labelsKey: {
122
+ type: String,
123
+ default: ''
124
+ },
125
+ // Offered on every row. Empty: no overflow menu.
126
+ actions: {
127
+ type: Array,
128
+ default: () => []
129
+ },
130
+ loading: {
131
+ type: Boolean,
132
+ default: false
133
+ },
134
+ // Given a row, opens it. Without it the rows are not clickable.
135
+ onSelect: {
136
+ type: Function,
137
+ default: undefined
138
+ }
139
+ })
140
+
141
+ // Prepare emitters
142
+ const $emitters = defineEmits(['update', 'remove'])
143
+
144
+ // Prepare composables
145
+ const { public: { appearance } } = useRuntimeConfig()
146
+ const plain = appearance === 'plain'
147
+ const $entries = useEntries()
148
+ const $members = useMembers()
149
+
150
+ // Fetch data
151
+ // What a row only holds an id of is looked up HERE, once for the table: the
152
+ // members' directory, and the entries the rows link to.
153
+ const { data: members } = $members.directory()
154
+ // An id shared by several rows is asked for once.
155
+ const linked = $entries.getMany(() => ($props.labelsKey ? [...new Set($props.items.flatMap(item => item[$props.labelsKey] ?? []))] : []))
156
+
157
+ // Prepare constants
158
+ /**
159
+ * Rows detached, each on its own rounded surface. Still a table: only the
160
+ * spacing changes, and the corners move to the outer cells since a `tr`
161
+ * cannot be rounded once the borders are separated. Under today's look the
162
+ * rows join back into one white sheet ruled by hairlines.
163
+ */
164
+ const UI = {
165
+ // `table-fixed` + `w-full`: the columns share the frame's width instead of
166
+ // dictating it from their content, so a long description truncates rather
167
+ // than pushing the card off screen.
168
+ base: 'w-full table-fixed border-separate border-spacing-y-2 plain:border-spacing-y-0',
169
+ tr: 'group drop-shadow-xs plain:drop-shadow-none',
170
+ // No listing shows its headings: the row says what it holds.
171
+ thead: 'hidden',
172
+ td: 'bg-elevated py-3 first:rounded-l-lg last:rounded-r-lg plain:first:rounded-none plain:last:rounded-none plain:border-b plain:border-default plain:bg-default plain:group-last:border-b-0 plain:group-hover:bg-elevated',
173
+ tbody: '',
174
+ }
175
+
176
+ // Prepare computed
177
+ /**
178
+ * The frozen order of the row. The width is the one thing a fixed table
179
+ * cannot work out for itself: a column is exactly as wide as it is told, and
180
+ * the summary, which says nothing, takes what the others leave.
181
+ */
182
+ const columns = computed(() => {
183
+ const width = value => ({ class: { td: value } })
184
+ return [
185
+ { id: 'summary', header: '', meta: {} },
186
+ ...($props.labelsKey ? [{ id: 'labels', header: '', meta: width('w-64 hidden lg:table-cell') }] : []),
187
+ { id: 'update', header: '', meta: width('w-48 hidden sm:table-cell') },
188
+ ...($props.actions.length ? [{ id: 'actions', header: '', meta: width('w-12') }] : []),
189
+ ]
190
+ })
191
+
192
+ const linkedById = computed(() => new Map(linked.value.map(entry => [entry.id, entry])))
193
+
194
+ // Prepare methods
195
+ const _labelsOf = item => [item[$props.labelsKey] ?? []].flat().map(id => linkedById.value.get(id)).filter(Boolean)
196
+ const _authorOf = item => members.value?.find(({ id }) => id === item.updatedBy)?.name ?? ''
197
+ const _fromNow = value => (value ? DateTime.fromISO(value).setLocale('fr').toRelative() : '')
198
+ /** A media field may hold one id or several; the cover is the first. */
199
+ const _coverOf = (item) => {
200
+ const value = item[$props.coverKey]
201
+ return (Array.isArray(value) ? value[0] : value) ?? ''
202
+ }
203
+ </script>
@@ -0,0 +1,41 @@
1
+ <template>
2
+ <UDropdownMenu :items="items" :content="{ align: 'end' }">
3
+ <UButton
4
+ icon="i-lucide-ellipsis"
5
+ color="neutral"
6
+ variant="ghost"
7
+ size="xs"
8
+ aria-label="Actions sur cette ligne"
9
+ @click.stop
10
+ />
11
+ </UDropdownMenu>
12
+ </template>
13
+
14
+ <script setup>
15
+ /**
16
+ * The actions of a row. Callers name them either way the admin ever did — a
17
+ * bare verb, or a label and its verb — and get the same menu.
18
+ */
19
+ // Prepare props
20
+ const $props = defineProps({
21
+ actions: {
22
+ type: Array,
23
+ default: () => []
24
+ }
25
+ })
26
+
27
+ // Prepare emitters
28
+ const $emitters = defineEmits(['action'])
29
+
30
+ // Prepare constants
31
+ const LABELS = { read: 'Voir', update: 'Modifier', remove: 'Supprimer' }
32
+
33
+ // Prepare computed
34
+ const items = computed(() =>
35
+ $props.actions.map((action) =>
36
+ typeof action === 'string'
37
+ ? { label: LABELS[action] ?? action, onSelect: () => $emitters('action', action) }
38
+ : { label: action.label, onSelect: () => $emitters('action', action.action) }
39
+ )
40
+ )
41
+ </script>
@@ -0,0 +1,23 @@
1
+ <template>
2
+ <UBadge v-if="status" :color="status.ui" variant="subtle" size="sm" class="gap-1.5 plain:rounded-full plain:font-normal">
3
+ <span class="size-1.5 rounded-full bg-current" />
4
+ {{ status.label }}
5
+ </UBadge>
6
+ </template>
7
+
8
+ <script setup>
9
+ // A publication status: label and colour come from constants/statuses, which
10
+ // derives the lifecycle itself from the core.
11
+ import { statusOf } from '~/utils/statuses'
12
+
13
+ // Prepare props
14
+ const $props = defineProps({
15
+ status: {
16
+ type: String,
17
+ default: ''
18
+ }
19
+ })
20
+
21
+ // Prepare computed
22
+ const status = computed(() => statusOf($props.status))
23
+ </script>
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <img v-if="src && !failed" :src="src" :alt="title" @error="failed = true">
3
+ </template>
4
+
5
+ <script setup>
6
+ // Prepare props
7
+ const $props = defineProps({
8
+ mediaId: {
9
+ type: String,
10
+ default: ''
11
+ }
12
+ })
13
+
14
+ // Prepare composables
15
+ const $media = useMedia()
16
+
17
+ // Prepare reactive
18
+ const id = toRef($props, 'mediaId')
19
+ const failed = ref(false)
20
+
21
+ // Fetch data
22
+ const { src, title } = $media.asset(id)
23
+
24
+ // Prepare watchers
25
+ watch(src, () => { failed.value = false })
26
+ </script>
@@ -0,0 +1,87 @@
1
+ <template>
2
+ <!-- No field of its own: `form-default` puts the label around it. -->
3
+ <div class="flex flex-col gap-2">
4
+ <!-- The dropzone PREVIEWS nothing: what it receives goes straight to
5
+ storage, and the thumbnails below show the stored media, not the
6
+ local files. -->
7
+ <UFileUpload
8
+ v-if="!readOnly && (limit === 0 || currentMedia.length < limit)"
9
+ :multiple="limit !== 1"
10
+ :preview="false"
11
+ :disabled="loading"
12
+ accept="image/*,application/pdf"
13
+ icon="i-lucide-image-up"
14
+ label="Déposez un fichier ici"
15
+ :description="loading ? 'Envoi en cours…' : 'ou cliquez pour le choisir — PNG, JPG, GIF, PDF jusqu\'à 10 Mo'"
16
+ class="w-full"
17
+ :ui="{
18
+ // A panel rather than a line: an area one AIMS at to drop a file must
19
+ // offer itself as a target. Dressed like a `UEmpty` — icon, title,
20
+ // hint, in a column — but still a `UFileUpload`: only it carries the
21
+ // drag and drop, the `accept` and the file picker.
22
+ wrapper: 'flex-col items-center justify-center gap-1 px-4 py-10',
23
+ label: 'text-sm font-medium text-highlighted',
24
+ description: 'mt-0.5 text-[13px]',
25
+ icon: 'size-6 text-dimmed',
26
+ }"
27
+ @update:model-value="_handlePicked"
28
+ />
29
+
30
+ <ul v-if="currentMedia.length" role="list" :class="limit === 1 ? '' : 'grid grid-cols-2 gap-2'">
31
+ <media-editor
32
+ v-for="_id in currentMedia"
33
+ :key="_id"
34
+ :value="_id"
35
+ :read-only="readOnly"
36
+ @remove="_removeMedia(_id)"
37
+ />
38
+ </ul>
39
+ </div>
40
+ </template>
41
+
42
+ <script setup>
43
+ // The media card is still the older one; it moves with the record page (A6).
44
+ import mediaEditor from '~/components/forms/inputs/media-section/media-editor'
45
+ // Prepare props
46
+ defineProps({
47
+ readOnly: {
48
+ type: Boolean,
49
+ default: false
50
+ },
51
+ limit: {
52
+ type: Number,
53
+ default: 0
54
+ }
55
+ })
56
+
57
+ // Prepare composables
58
+ const $media = useMedia()
59
+
60
+ // Prepare reactive
61
+ // A media field holds one id or several; the form's state is the only copy.
62
+ const model = defineModel({ type: [Array, String], default: () => [] })
63
+ const loading = ref(false)
64
+
65
+ // Prepare computed
66
+ const currentMedia = computed(() => (Array.isArray(model.value) ? model.value : (model.value ? [model.value] : [])))
67
+
68
+ // Prepare methods
69
+ const _removeMedia = (idToRemove) => {
70
+ model.value = currentMedia.value.filter(_id => _id !== idToRemove)
71
+ }
72
+
73
+ const _handlePicked = async (picked) => {
74
+ const files = (Array.isArray(picked) ? picked : [picked]).filter(Boolean)
75
+ if (!files.length) return
76
+ loading.value = true
77
+ try {
78
+ // Files go one after another: in parallel, a handful of heavy images would
79
+ // saturate a town hall's uplink.
80
+ const created = []
81
+ for (const file of files) created.push(await $media.upload(file))
82
+ model.value = [...currentMedia.value, ...created.map(({ id }) => id)]
83
+ } finally {
84
+ loading.value = false
85
+ }
86
+ }
87
+ </script>
@@ -39,8 +39,8 @@
39
39
  * The publication statuses a listing keeps. It owns nothing but the choice —
40
40
  * the screen holds them and decides what to do with them.
41
41
  */
42
- import inputFilter from '~/components/forms/inputs/input-filter'
43
- import { ALL_STATUSES, STATUSES } from '../../../constants/statuses'
42
+ import inputFilter from '~/components/forms/fields/input-filter'
43
+ import { ALL_STATUSES, STATUSES } from '~/constants/statuses'
44
44
 
45
45
  // Prepare props
46
46
  const $props = defineProps({