@open-commune/web 0.2.14 → 0.2.15
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/app.config.ts +7 -0
- package/components/data/lists/data-table.vue +203 -0
- package/components/data/lists/row-actions.vue +41 -0
- package/components/elements/badges/status-badge.vue +23 -0
- package/components/elements/media/media-image.vue +26 -0
- package/components/forms/fields/input-files-media.vue +87 -0
- package/components/forms/{inputs → fields}/input-filter-status.vue +2 -2
- package/components/forms/{inputs → fields}/input-search.vue +8 -2
- package/components/forms/fields/input-text-area.vue +86 -0
- package/components/forms/fields/input-text.vue +47 -0
- package/components/forms/fields/select-enum.vue +69 -0
- package/components/forms/handlers/handler-collections.vue +100 -170
- package/components/forms/handlers/handler-list.vue +187 -0
- package/components/forms/handlers/handler-members.vue +171 -0
- package/components/forms/handlers/handler-password-reset.vue +45 -0
- package/components/forms/handlers/handler-roles.vue +28 -166
- package/components/forms/handlers/handler-sessions.vue +77 -0
- package/components/forms/handlers/handler-tokens.vue +54 -69
- package/components/forms/layouts/form-default.vue +99 -0
- package/components/forms/layouts/form.vue +4 -0
- package/components/forms/layouts/forms-layout.vue +236 -0
- package/components/forms/layouts/forms-section.vue +186 -0
- package/components/forms/layouts/layout.vue +4 -0
- package/components/forms/layouts/modal.vue +4 -0
- package/components/forms/layouts/section.vue +4 -0
- package/components/layout/shell/shell-account-menu.vue +10 -2
- package/composables/core/domains/use-api-tokens.ts +80 -0
- package/composables/core/domains/use-auth.ts +56 -2
- package/composables/core/domains/use-definitions.ts +18 -5
- package/composables/core/domains/use-entries.ts +113 -3
- package/composables/core/domains/use-media.ts +24 -1
- package/composables/core/domains/use-members.ts +68 -0
- package/composables/core/domains/use-organization.ts +53 -0
- package/composables/use-models.js +1 -7
- package/constants/errors.ts +28 -0
- package/constants/forms/account.ts +62 -0
- package/constants/forms/collections.ts +39 -0
- package/constants/forms/members.ts +40 -0
- package/constants/forms/organization.ts +188 -0
- package/constants/forms/tokens.ts +15 -0
- package/constants/roles.ts +57 -0
- package/constants/settings.ts +26 -0
- package/constants/statuses.ts +8 -5
- package/package.json +3 -3
- package/pages/[collection]/index.vue +92 -79
- package/pages/account.vue +40 -0
- package/pages/settings.vue +26 -181
- package/plugins/01.validation.client.ts +23 -0
- package/store/layout/workspace.js +4 -28
- package/utils/colors.ts +26 -0
- package/utils/errors.ts +13 -0
- package/utils/forms.ts +67 -0
- package/utils/list-columns.ts +90 -0
- package/utils/settings.ts +38 -0
- package/utils/statuses.ts +4 -0
- package/models/role.js +0 -66
- package/models/token.js +0 -56
- package/models/user.js +0 -97
- package/pages/management/index.vue +0 -15
- package/pages/management/members.vue +0 -176
- package/pages/management/organizations.vue +0 -192
- package/pages/management/roles.vue +0 -183
- /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,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/
|
|
43
|
-
import { ALL_STATUSES, STATUSES } from '
|
|
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({
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
and the box stayed at 48px instead of 36. -->
|
|
5
5
|
<div
|
|
6
6
|
class="transition-[width] duration-200"
|
|
7
|
-
:class="expanded ?
|
|
7
|
+
:class="expanded ? openClass : 'w-9'"
|
|
8
8
|
@mouseenter="hovered = true"
|
|
9
9
|
@mouseleave="hovered = false"
|
|
10
10
|
>
|
|
@@ -28,12 +28,18 @@
|
|
|
28
28
|
</template>
|
|
29
29
|
|
|
30
30
|
<script setup>
|
|
31
|
+
// The collapsible search: a magnifier that opens on hover or focus, and stays
|
|
32
|
+
// open while it holds text. The collection list and the settings rail share it.
|
|
31
33
|
import { refDebounced } from '@vueuse/core'
|
|
32
34
|
|
|
33
35
|
// Prepare props
|
|
34
36
|
const $props = defineProps({
|
|
35
37
|
modelValue: { type: String, default: '' },
|
|
36
38
|
placeholder: { type: String, default: 'Rechercher' },
|
|
39
|
+
/** Width once open: the collection list's fixed width, or the rail's own. */
|
|
40
|
+
openClass: { type: String, default: 'w-64' },
|
|
41
|
+
/** A request per keystroke is too many; a filter in the page wants none. */
|
|
42
|
+
debounce: { type: Number, default: 350 },
|
|
37
43
|
})
|
|
38
44
|
|
|
39
45
|
// Prepare emitters
|
|
@@ -45,7 +51,7 @@ const hovered = ref(false)
|
|
|
45
51
|
const focused = ref(false)
|
|
46
52
|
|
|
47
53
|
// A keystroke must not fire a request.
|
|
48
|
-
const debounced = refDebounced(term,
|
|
54
|
+
const debounced = refDebounced(term, $props.debounce)
|
|
49
55
|
|
|
50
56
|
// Prepare computed
|
|
51
57
|
const expanded = computed(() => hovered.value || focused.value || Boolean(term.value))
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- No field of its own: `form-default` puts the label and the name around
|
|
3
|
+
it, and the textarea reads them from there. -->
|
|
4
|
+
<UTextarea
|
|
5
|
+
v-model="text"
|
|
6
|
+
:placeholder="placeHolder"
|
|
7
|
+
:disabled="readOnly"
|
|
8
|
+
:rows="format === 'json' ? 8 : 3"
|
|
9
|
+
class="w-full"
|
|
10
|
+
:ui="format === 'json' ? { base: 'font-mono text-xs' } : {}"
|
|
11
|
+
/>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script setup>
|
|
15
|
+
// Prepare props
|
|
16
|
+
const $props = defineProps({
|
|
17
|
+
placeHolder: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: ''
|
|
20
|
+
},
|
|
21
|
+
/**
|
|
22
|
+
* `json`: the value is an object or an array, shown as indented JSON and
|
|
23
|
+
* given back parsed. Half-typed JSON is not an error, it is a moment: nothing
|
|
24
|
+
* is given back until the text reads again.
|
|
25
|
+
*/
|
|
26
|
+
format: {
|
|
27
|
+
type: String,
|
|
28
|
+
default: 'text'
|
|
29
|
+
},
|
|
30
|
+
readOnly: {
|
|
31
|
+
type: Boolean,
|
|
32
|
+
default: false
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// Prepare reactive
|
|
37
|
+
const model = defineModel({ type: [String, Object, Array], default: '' })
|
|
38
|
+
const text = ref('')
|
|
39
|
+
|
|
40
|
+
// Prepare methods
|
|
41
|
+
const _blank = value => value === undefined || value === null || value === ''
|
|
42
|
+
|
|
43
|
+
function _sameJson(written, value) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.stringify(JSON.parse(written)) === JSON.stringify(value)
|
|
46
|
+
} catch {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Prepare watchers
|
|
52
|
+
watch(
|
|
53
|
+
model,
|
|
54
|
+
(value) => {
|
|
55
|
+
if ($props.format !== 'json') {
|
|
56
|
+
text.value = value ?? ''
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
// Typing must not be rewritten under the cursor: the text is replaced only
|
|
60
|
+
// when the value it describes changed.
|
|
61
|
+
// Nothing yet is an empty box, not the text of an empty value.
|
|
62
|
+
if (_blank(value)) {
|
|
63
|
+
if (text.value.trim()) text.value = ''
|
|
64
|
+
} else if (!_sameJson(text.value, value)) {
|
|
65
|
+
text.value = JSON.stringify(value, null, 2)
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
{ immediate: true }
|
|
69
|
+
)
|
|
70
|
+
watch(text, (written) => {
|
|
71
|
+
if ($props.format !== 'json') {
|
|
72
|
+
model.value = written
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
if (!written.trim()) {
|
|
76
|
+
if (!_blank(model.value)) model.value = undefined
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const parsed = JSON.parse(written)
|
|
81
|
+
if (!_sameJson(written, model.value)) model.value = parsed
|
|
82
|
+
} catch {
|
|
83
|
+
// Nothing given back: the form keeps the last value that read.
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
</script>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- No field of its own: `form-default` puts the label and the name around
|
|
3
|
+
it, and the input reads them from there. -->
|
|
4
|
+
<UInput
|
|
5
|
+
v-model="model"
|
|
6
|
+
:autocomplete="autoComplete"
|
|
7
|
+
:placeholder="placeHolder"
|
|
8
|
+
:icon="icon || undefined"
|
|
9
|
+
:type="type"
|
|
10
|
+
:required="required"
|
|
11
|
+
:disabled="readOnly"
|
|
12
|
+
class="w-full"
|
|
13
|
+
/>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script setup>
|
|
17
|
+
// Prepare props
|
|
18
|
+
defineProps({
|
|
19
|
+
autoComplete: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: 'given-name'
|
|
22
|
+
},
|
|
23
|
+
type: {
|
|
24
|
+
type: String,
|
|
25
|
+
default: 'text'
|
|
26
|
+
},
|
|
27
|
+
icon: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: ''
|
|
30
|
+
},
|
|
31
|
+
placeHolder: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: ''
|
|
34
|
+
},
|
|
35
|
+
readOnly: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
default: false
|
|
38
|
+
},
|
|
39
|
+
required: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: false
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Prepare reactive
|
|
46
|
+
const model = defineModel({ type: String, default: '' })
|
|
47
|
+
</script>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- No field of its own: `form-default` puts the label and the name around
|
|
3
|
+
it. -->
|
|
4
|
+
<USelectMenu
|
|
5
|
+
v-model="model"
|
|
6
|
+
:items="options"
|
|
7
|
+
:multiple="enableMultiple"
|
|
8
|
+
:disabled="readOnly"
|
|
9
|
+
:placeholder="placeHolder"
|
|
10
|
+
value-key="value"
|
|
11
|
+
class="w-full"
|
|
12
|
+
/>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup>
|
|
16
|
+
// Prepare props
|
|
17
|
+
const $props = defineProps({
|
|
18
|
+
filter: {
|
|
19
|
+
type: Function,
|
|
20
|
+
default: () => () => true
|
|
21
|
+
},
|
|
22
|
+
items: {
|
|
23
|
+
type: Array,
|
|
24
|
+
default: () => []
|
|
25
|
+
},
|
|
26
|
+
itemKey: {
|
|
27
|
+
type: String,
|
|
28
|
+
default: 'name'
|
|
29
|
+
},
|
|
30
|
+
itemValue: {
|
|
31
|
+
type: String,
|
|
32
|
+
default: '_id'
|
|
33
|
+
},
|
|
34
|
+
enableMultiple: {
|
|
35
|
+
type: Boolean,
|
|
36
|
+
default: false
|
|
37
|
+
},
|
|
38
|
+
object: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
default: true
|
|
41
|
+
},
|
|
42
|
+
placeHolder: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: 'Sélectionnez'
|
|
45
|
+
},
|
|
46
|
+
readOnly: {
|
|
47
|
+
type: Boolean,
|
|
48
|
+
default: false
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// Prepare reactive
|
|
53
|
+
// A choice is not always a string: APIDAE-fed fields carry numeric ids.
|
|
54
|
+
const model = defineModel({ type: [String, Number, Array], default: undefined })
|
|
55
|
+
|
|
56
|
+
// Prepare computed
|
|
57
|
+
/**
|
|
58
|
+
* The choices in the ONE shape the menu reads: a label to show, a value to
|
|
59
|
+
* emit. `object: false` describes a list of plain scalars, where the choice IS
|
|
60
|
+
* the value.
|
|
61
|
+
*/
|
|
62
|
+
const options = computed(() =>
|
|
63
|
+
$props.items
|
|
64
|
+
.filter($props.filter)
|
|
65
|
+
.map(item => ($props.object
|
|
66
|
+
? { label: item?.[$props.itemKey], value: item?.[$props.itemValue] }
|
|
67
|
+
: { label: item, value: item }))
|
|
68
|
+
)
|
|
69
|
+
</script>
|