@stsdti/auditing-vue 0.0.0-stage → 0.1.2

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.
@@ -0,0 +1,311 @@
1
+ <template>
2
+ <div :class="cn('laravel-auditing', ui?.root)" data-slot="audit-timeline">
3
+ <component
4
+ :is="bare ? 'div' : 'section'"
5
+ :data-slot="bare ? undefined : 'card'"
6
+ :class="cn(bare ? 'flex flex-col gap-4' : 'cn-card group/card flex flex-col', ui?.card)"
7
+ >
8
+ <div
9
+ v-if="!bare"
10
+ data-slot="card-header"
11
+ :class="cn('cn-card-header grid auto-rows-min items-start has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto]', ui?.header)"
12
+ >
13
+ <div class="flex min-w-0 flex-wrap items-center gap-2">
14
+ <h2 data-slot="card-title" class="cn-card-title cn-font-heading">
15
+ {{ title ?? texts.historyTitle }}
16
+ </h2>
17
+ <ui-badge v-if="subject" variant="secondary">
18
+ {{ subject }}
19
+ </ui-badge>
20
+ </div>
21
+ <p
22
+ v-if="description ?? texts.historyDescription"
23
+ data-slot="card-description"
24
+ class="cn-card-description"
25
+ >
26
+ {{ description ?? texts.historyDescription }}
27
+ </p>
28
+ <div
29
+ v-if="$slots.actions"
30
+ data-slot="card-action"
31
+ class="cn-card-action col-start-2 row-span-2 row-start-1 flex items-center gap-2 self-start justify-self-end"
32
+ >
33
+ <slot name="actions" />
34
+ </div>
35
+ </div>
36
+ <div v-else-if="$slots.actions" class="flex items-center justify-end gap-2">
37
+ <slot name="actions" />
38
+ </div>
39
+
40
+ <div :data-slot="bare ? undefined : 'card-content'" :class="cn(!bare && 'cn-card-content', ui?.content)">
41
+ <ui-loading-blur :loading="loading && audits.length > 0" :label="texts.loading">
42
+ <ol
43
+ v-if="loading && !audits.length"
44
+ class="flex flex-col gap-5"
45
+ :aria-label="texts.loading"
46
+ >
47
+ <li
48
+ v-for="index in 3"
49
+ :key="index"
50
+ class="flex gap-3"
51
+ >
52
+ <div data-slot="skeleton" class="cn-skeleton animate-pulse size-8 shrink-0 rounded-full" />
53
+ <div class="flex flex-1 flex-col gap-2 pt-1">
54
+ <div data-slot="skeleton" class="cn-skeleton animate-pulse h-4 w-48" />
55
+ <div data-slot="skeleton" class="cn-skeleton animate-pulse h-3 w-28" />
56
+ <div data-slot="skeleton" class="cn-skeleton animate-pulse h-12 w-full" />
57
+ </div>
58
+ </li>
59
+ </ol>
60
+
61
+ <div
62
+ v-else-if="error"
63
+ role="alert"
64
+ class="flex flex-col items-center gap-2 px-5 py-10 text-center text-muted-foreground"
65
+ >
66
+ <circle-alert-icon class="size-7 text-destructive" aria-hidden="true" />
67
+ <b class="text-sm font-semibold text-foreground">
68
+ {{ typeof error === 'string' ? error : texts.loadFailed }}
69
+ </b>
70
+ <ui-button
71
+ v-if="retry"
72
+ variant="outline"
73
+ size="sm"
74
+ @click="retry"
75
+ >
76
+ <rotate-ccw-icon data-icon="inline-start" aria-hidden="true" />
77
+ {{ texts.retry }}
78
+ </ui-button>
79
+ </div>
80
+
81
+ <slot v-else-if="!audits.length" name="empty">
82
+ <div data-slot="empty" class="cn-empty flex w-full min-w-0 flex-1 flex-col items-center justify-center text-center text-balance">
83
+ <div data-slot="empty-header" class="cn-empty-header flex max-w-sm flex-col items-center">
84
+ <div data-slot="empty-icon" class="cn-empty-media flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0 cn-empty-media-icon">
85
+ <history-icon aria-hidden="true" />
86
+ </div>
87
+ <div data-slot="empty-title" class="cn-empty-title cn-font-heading">
88
+ {{ texts.historyEmpty }}
89
+ </div>
90
+ </div>
91
+ </div>
92
+ </slot>
93
+
94
+ <ol
95
+ v-else
96
+ data-slot="timeline"
97
+ class="app-timeline flex min-w-0 flex-col text-sm"
98
+ >
99
+ <li
100
+ v-for="(entry, index) in entries"
101
+ :key="entry.audit.id"
102
+ :ref="(element) => registerEntry(entry.audit, element)"
103
+ data-slot="timeline-item"
104
+ :data-tone="entry.meta.tone"
105
+ :aria-current="entry.selected ? 'true' : undefined"
106
+ :class="cn('flex break-inside-avoid gap-3', ui?.item)"
107
+ >
108
+ <div class="flex flex-col items-center">
109
+ <span data-slot="timeline-marker" :class="cn('flex size-8 shrink-0 items-center justify-center rounded-full', toneMarker[entry.meta.tone], entry.selected && 'ring-2 ring-ring/60 ring-offset-2 ring-offset-background', ui?.marker)">
110
+ <component
111
+ :is="eventIcon(entry.meta.glyph)"
112
+ class="size-4"
113
+ aria-hidden="true"
114
+ />
115
+ </span>
116
+ <span
117
+ v-if="index < entries.length - 1"
118
+ data-slot="timeline-line"
119
+ class="my-2 w-px flex-1 bg-border"
120
+ />
121
+ </div>
122
+
123
+ <div
124
+ data-slot="timeline-content"
125
+ class="flex min-w-0 flex-1 flex-col gap-3 pb-8"
126
+ :class="[
127
+ index === entries.length - 1 && 'pb-0',
128
+ ]"
129
+ >
130
+ <div class="flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5">
131
+ <div class="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-1">
132
+ <span class="text-base font-semibold text-foreground">
133
+ {{ eventLabel(texts, entry.audit.event) }}
134
+ </span>
135
+ <span v-if="entry.fieldCount" class="text-muted-foreground">
136
+ {{ entry.fieldCount === 1 ? texts.fieldCountOne : formatMessage(texts.fieldCount, { count: entry.fieldCount }) }}
137
+ </span>
138
+ <span
139
+ v-if="showResource"
140
+ class="font-normal text-muted-foreground"
141
+ :title="entry.audit.auditable_type"
142
+ >
143
+ {{ typeLabel(entry.audit.auditable_type) }} <span class="tabular-nums">
144
+ #{{ entry.audit.auditable_id }}
145
+ </span>
146
+ </span>
147
+ <ui-badge
148
+ v-if="entry.batchSize > 1"
149
+ variant="outline"
150
+ :title="entry.audit.batch"
151
+ >
152
+ <layers-icon data-icon="inline-start" aria-hidden="true" />
153
+ {{ formatMessage(texts.sameBatch, { count: entry.batchSize }) }}
154
+ </ui-badge>
155
+ <ui-badge v-if="entry.selected" variant="secondary">
156
+ <target-icon data-icon="inline-start" aria-hidden="true" />
157
+ {{ texts.selectedRecord }}
158
+ </ui-badge>
159
+ </div>
160
+ </div>
161
+
162
+ <div data-slot="timeline-meta" class="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-muted-foreground">
163
+ <span
164
+ data-slot="avatar"
165
+ class="flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-full bg-muted text-muted-foreground"
166
+ aria-hidden="true"
167
+ >
168
+ <cpu-icon v-if="!entry.audit.user" class="size-3" />
169
+ <img
170
+ v-else-if="avatarOf(entry.audit)"
171
+ :src="avatarOf(entry.audit)"
172
+ alt=""
173
+ loading="lazy"
174
+ draggable="false"
175
+ class="size-full object-cover object-top"
176
+ @error="failAvatar(avatarOf(entry.audit))"
177
+ >
178
+ <user-round-icon v-else class="size-3.5" />
179
+ </span>
180
+ <span class="truncate" :class="[entry.audit.user && 'text-foreground/80']">
181
+ {{ authorName(entry.audit) }}
182
+ </span>
183
+ <span aria-hidden="true">
184
+ ·
185
+ </span>
186
+ <time :datetime="entry.audit.created_at" class="font-mono text-xs tabular-nums">
187
+ {{ formatDateTime(entry.audit.created_at) }}
188
+ </time>
189
+ </div>
190
+
191
+ <audit-changes
192
+ :value="entry.audit"
193
+ :limit="expanded.has(entry.audit.id) ? null : changesLimit"
194
+ :format-value="formatValue"
195
+ :field-label="fieldLabel"
196
+ :messages="messages"
197
+ @expand="expand"
198
+ >
199
+ <template v-if="$slots['change-value']" #value="scope">
200
+ <slot name="change-value" v-bind="scope" />
201
+ </template>
202
+ </audit-changes>
203
+
204
+ <div v-if="$slots['entry-actions']" class="flex flex-wrap items-center gap-2">
205
+ <slot name="entry-actions" :audit="entry.audit" />
206
+ </div>
207
+ </div>
208
+ </li>
209
+ </ol>
210
+ </ui-loading-blur>
211
+ </div>
212
+ </component>
213
+ </div>
214
+ </template>
215
+
216
+ <script setup>
217
+ import { CircleAlertIcon, CpuIcon, HistoryIcon, LayersIcon, RotateCcwIcon, TargetIcon, UserRoundIcon } from '@lucide/vue'
218
+ import {
219
+ auditEvent,
220
+ formatValue as defaultFormatValue,
221
+ eventLabel,
222
+ formatDateTime,
223
+ formatMessage,
224
+ groupByBatch,
225
+ shortClassName,
226
+ userName
227
+ } from '@stsdti/auditing-core'
228
+ import { computed, nextTick, shallowRef, watch } from 'vue'
229
+ import { cn, eventIcon, toneMarker, UiBadge, UiButton, useMessages } from '../../shared.js'
230
+ import UiLoadingBlur from '../ui/UiLoadingBlur.vue'
231
+ import AuditChanges from './AuditChanges.vue'
232
+
233
+ const props = defineProps({
234
+ audits: { type: Array, default: () => [] },
235
+ loading: { type: Boolean, default: false },
236
+ error: { type: [Boolean, String], default: false },
237
+ retry: { type: Function, default: null },
238
+ highlight: { type: [String, Number], default: null },
239
+ groupBatches: { type: Boolean, default: true },
240
+ showResource: { type: Boolean, default: true },
241
+ bare: { type: Boolean, default: false },
242
+ changesLimit: { type: Number, default: null },
243
+ typeLabel: { type: Function, default: shortClassName },
244
+ userLabel: { type: [String, Function], default: 'name' },
245
+ userAvatar: { type: Function, default: null },
246
+ formatValue: { type: Function, default: defaultFormatValue },
247
+ fieldLabel: { type: Function, default: (field) => field },
248
+ title: { type: String, default: null },
249
+ description: { type: String, default: null },
250
+ subject: { type: String, default: null },
251
+ messages: { type: Object, default: null },
252
+ ui: { type: Object, default: null }
253
+ })
254
+
255
+ const emits = defineEmits(['expand'])
256
+
257
+ const texts = useMessages(props.messages)
258
+
259
+ const entries = computed(() => {
260
+ const sizes = new Map()
261
+ if (props.groupBatches) {
262
+ for (const group of groupByBatch(props.audits)) {
263
+ if (group.audits.length > 1) {
264
+ sizes.set(group.audits[0].id, group.audits.length)
265
+ }
266
+ }
267
+ }
268
+
269
+ return props.audits.map((audit) => ({
270
+ audit,
271
+ meta: auditEvent(audit.event),
272
+ batchSize: sizes.get(audit.id) ?? 0,
273
+ fieldCount: new Set([...Object.keys(audit.old_values ?? {}), ...Object.keys(audit.new_values ?? {})]).size,
274
+ selected: props.highlight !== null && String(audit.id) === String(props.highlight)
275
+ }))
276
+ })
277
+
278
+ const expanded = shallowRef(new Set())
279
+ function expand(audit) {
280
+ expanded.value = new Set(expanded.value).add(audit.id)
281
+ emits('expand', audit)
282
+ }
283
+
284
+ const authorName = (audit) => (audit.user ? userName(audit.user, props.userLabel) : texts.system)
285
+
286
+ const failedAvatars = shallowRef(new Set())
287
+ function avatarOf(audit) {
288
+ const url = props.userAvatar?.(audit.user) ?? null
289
+ return url && !failedAvatars.value.has(url) ? url : null
290
+ }
291
+ function failAvatar(url) {
292
+ failedAvatars.value = new Set(failedAvatars.value).add(url)
293
+ }
294
+
295
+ const elements = new Map()
296
+ function registerEntry(audit, element) {
297
+ if (element) {
298
+ elements.set(String(audit.id), element)
299
+ } else {
300
+ elements.delete(String(audit.id))
301
+ }
302
+ }
303
+
304
+ watch(() => [props.highlight, props.audits.length], async () => {
305
+ if (props.highlight === null) {
306
+ return
307
+ }
308
+ await nextTick()
309
+ elements.get(String(props.highlight))?.scrollIntoView?.({ block: 'center', behavior: 'smooth' })
310
+ }, { immediate: true })
311
+ </script>
@@ -0,0 +1,166 @@
1
+ <template>
2
+ <teleport to="body">
3
+ <div v-if="open" class="laravel-auditing">
4
+ <div
5
+ :data-slot="drawer ? 'sheet-overlay' : 'dialog-overlay'"
6
+ data-state="open"
7
+ :class="cn(drawer ? 'cn-sheet-overlay fixed inset-0 z-50 animate-in fade-in-0 duration-200' : 'cn-dialog-overlay fixed inset-0 isolate z-50', ui?.overlay)"
8
+ @click="open = false"
9
+ />
10
+ <div
11
+ ref="panel"
12
+ role="dialog"
13
+ aria-modal="true"
14
+ tabindex="-1"
15
+ :aria-labelledby="titleId"
16
+ :aria-describedby="hasDescription ? descriptionId : undefined"
17
+ :data-slot="drawer ? 'sheet-content' : 'dialog-content'"
18
+ data-state="open"
19
+ :data-side="drawer ? 'right' : undefined"
20
+ :class="cn(
21
+ drawer
22
+ ? 'cn-sheet-content gap-0 outline-none animate-in fade-in-0 slide-in-from-right-10 sm:max-w-sm'
23
+ : 'cn-dialog-content fixed top-1/2 left-1/2 z-50 flex max-h-[90vh] w-full max-w-[calc(100%-2*var(--overlay-margin))] -translate-x-1/2 -translate-y-1/2 flex-col gap-0 overflow-hidden p-0 outline-none',
24
+ !drawer && width,
25
+ ui?.content,
26
+ )"
27
+ >
28
+ <div
29
+ :data-slot="drawer ? 'drawer-header' : 'modal-header'"
30
+ :class="cn('flex shrink-0 items-center gap-2 border-b px-(--layout-gap) py-3 pr-12', ui?.header)"
31
+ >
32
+ <div class="flex min-w-0 flex-col gap-0.5">
33
+ <h2
34
+ :id="titleId"
35
+ data-slot="dialog-title"
36
+ :class="cn('cn-font-heading text-base font-medium text-foreground', ui?.title)"
37
+ >
38
+ <slot name="title">
39
+ {{ title }}
40
+ </slot>
41
+ </h2>
42
+ <div
43
+ v-if="hasDescription"
44
+ :id="descriptionId"
45
+ data-slot="dialog-description"
46
+ :class="cn('text-sm text-muted-foreground', ui?.description)"
47
+ >
48
+ <slot name="description">
49
+ {{ description }}
50
+ </slot>
51
+ </div>
52
+ </div>
53
+ <div
54
+ v-if="$slots.actions"
55
+ data-slot="modal-header-actions"
56
+ class="ml-auto flex shrink-0 items-center gap-1"
57
+ >
58
+ <slot name="actions" />
59
+ </div>
60
+ </div>
61
+
62
+ <div :data-slot="drawer ? 'drawer-body' : 'modal-body'" :class="cn('flex min-h-0 flex-1 flex-col gap-(--form-gap) overflow-y-auto p-(--layout-gap)', ui?.body)">
63
+ <slot />
64
+ </div>
65
+
66
+ <div
67
+ v-if="$slots.footer"
68
+ :data-slot="drawer ? 'drawer-footer' : 'modal-footer'"
69
+ :class="cn('flex shrink-0 flex-col-reverse gap-2 border-t px-(--layout-gap) py-3 sm:flex-row sm:justify-end', ui?.footer)"
70
+ >
71
+ <slot name="footer" />
72
+ </div>
73
+
74
+ <ui-button
75
+ variant="ghost"
76
+ size="icon-sm"
77
+ :class="cn(drawer ? 'cn-sheet-close' : 'cn-dialog-close', 'top-2.5 right-2.5', ui?.close)"
78
+ :aria-label="closeLabel"
79
+ @click="open = false"
80
+ >
81
+ <x-icon aria-hidden="true" />
82
+ </ui-button>
83
+ </div>
84
+ </div>
85
+ </teleport>
86
+ </template>
87
+
88
+ <script setup>
89
+ import { XIcon } from '@lucide/vue'
90
+ import { computed, nextTick, onBeforeUnmount, ref, useId, useSlots, watch } from 'vue'
91
+ import { cn, UiButton } from '../../shared.js'
92
+
93
+ const props = defineProps({
94
+ variant: { type: String, default: 'dialog' },
95
+ title: { type: String, default: '' },
96
+ description: { type: String, default: '' },
97
+ width: { type: String, default: 'sm:max-w-lg' },
98
+ closeLabel: { type: String, default: 'Închide' },
99
+ ui: { type: Object, default: null }
100
+ })
101
+
102
+ const open = defineModel('open', { type: Boolean, default: false })
103
+
104
+ const slots = useSlots()
105
+ const panel = ref(null)
106
+ const titleId = useId()
107
+ const descriptionId = useId()
108
+ const drawer = computed(() => props.variant === 'drawer')
109
+ const hasDescription = computed(() => Boolean(props.description || slots.description))
110
+
111
+ let previousFocus = null
112
+ let previousOverflow = ''
113
+ let locked = false
114
+
115
+ function onKeydown(event) {
116
+ if (!open.value) {
117
+ return
118
+ }
119
+ if (event.key === 'Escape') {
120
+ event.stopPropagation()
121
+ open.value = false
122
+ } else if (event.key === 'Tab' && panel.value) {
123
+ const focusable = [...panel.value.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')]
124
+ if (!focusable.length) {
125
+ return
126
+ }
127
+ const first = focusable[0]
128
+ const last = focusable.at(-1)
129
+ const inside = panel.value.contains(document.activeElement)
130
+ if (event.shiftKey && (!inside || document.activeElement === first || document.activeElement === panel.value)) {
131
+ event.preventDefault()
132
+ last.focus()
133
+ } else if (!event.shiftKey && (!inside || document.activeElement === last)) {
134
+ event.preventDefault()
135
+ first.focus()
136
+ }
137
+ }
138
+ }
139
+
140
+ watch(open, async (isOpen) => {
141
+ if (typeof document === 'undefined') {
142
+ return
143
+ }
144
+ if (isOpen && !locked) {
145
+ locked = true
146
+ previousFocus = document.activeElement
147
+ previousOverflow = document.documentElement.style.overflow
148
+ document.documentElement.style.overflow = 'hidden'
149
+ document.addEventListener('keydown', onKeydown)
150
+ await nextTick()
151
+ panel.value?.focus()
152
+ } else if (!isOpen && locked) {
153
+ locked = false
154
+ document.documentElement.style.overflow = previousOverflow
155
+ document.removeEventListener('keydown', onKeydown)
156
+ previousFocus?.focus?.()
157
+ }
158
+ }, { immediate: true })
159
+
160
+ onBeforeUnmount(() => {
161
+ if (locked && typeof document !== 'undefined') {
162
+ document.documentElement.style.overflow = previousOverflow
163
+ document.removeEventListener('keydown', onKeydown)
164
+ }
165
+ })
166
+ </script>
@@ -0,0 +1,29 @@
1
+ <template>
2
+ <div data-slot="loading-blur" :class="cn('relative', ui?.root)">
3
+ <div
4
+ v-if="loading"
5
+ role="status"
6
+ :class="cn('pointer-events-none absolute top-[min(22%,--spacing(21))] left-1/2 z-10 inline-flex -translate-x-1/2 animate-in items-center gap-2 rounded-full bg-foreground px-3.5 py-2 text-sm font-medium whitespace-nowrap text-background shadow-lg duration-300 fade-in slide-in-from-top-2 motion-reduce:animate-none', ui?.label)"
7
+ >
8
+ <loader-circle-icon class="size-4 animate-spin opacity-85 motion-reduce:animate-none" aria-hidden="true" />
9
+ {{ label }}
10
+ </div>
11
+ <div
12
+ :class="cn('transition-[opacity,filter] duration-200 motion-reduce:transition-none', loading && 'pointer-events-none opacity-55 blur-2xs', ui?.content)"
13
+ :aria-busy="loading"
14
+ >
15
+ <slot />
16
+ </div>
17
+ </div>
18
+ </template>
19
+
20
+ <script setup>
21
+ import { LoaderCircleIcon } from '@lucide/vue'
22
+ import { cn } from '../../shared.js'
23
+
24
+ defineProps({
25
+ loading: { type: Boolean, default: false },
26
+ label: { type: String, default: '' },
27
+ ui: { type: Object, default: null }
28
+ })
29
+ </script>
package/src/index.js ADDED
@@ -0,0 +1,61 @@
1
+ import AuditChanges from './components/audit/AuditChanges.vue'
2
+ import AuditChangesDialog from './components/audit/AuditChangesDialog.vue'
3
+ import AuditEventBadge from './components/audit/AuditEventBadge.vue'
4
+ import AuditFilters from './components/audit/AuditFilters.vue'
5
+ import AuditFilterSelect from './components/audit/AuditFilterSelect.vue'
6
+ import AuditHistory from './components/audit/AuditHistory.vue'
7
+ import AuditHistoryButton from './components/audit/AuditHistoryButton.vue'
8
+ import AuditTable from './components/audit/AuditTable.vue'
9
+ import AuditTimeline from './components/audit/AuditTimeline.vue'
10
+
11
+ import { AUDITING_MESSAGES, useMessages } from './shared.js'
12
+
13
+ export {
14
+ AuditChanges,
15
+ AuditChangesDialog,
16
+ AuditEventBadge,
17
+ AuditFilters,
18
+ AuditFilterSelect,
19
+ AuditHistory,
20
+ AuditHistoryButton,
21
+ AuditTable,
22
+ AuditTimeline
23
+ }
24
+
25
+ export { AUDITING_MESSAGES, useMessages }
26
+
27
+ export {
28
+ AUDIT_EVENTS,
29
+ DEFAULT_MESSAGES,
30
+ emptyFilters,
31
+ setAuditingColorScheme,
32
+ setAuditingDateFormatter,
33
+ shortClassName,
34
+ toParams
35
+ } from '@stsdti/auditing-core'
36
+
37
+ const components = {
38
+ AuditTable,
39
+ AuditFilters,
40
+ AuditFilterSelect,
41
+ AuditTimeline,
42
+ AuditHistory,
43
+ AuditHistoryButton,
44
+ AuditChanges,
45
+ AuditChangesDialog,
46
+ AuditEventBadge
47
+ }
48
+
49
+ export default {
50
+ install(app, { messages = null, register = true } = {}) {
51
+ if (messages) {
52
+ app.provide(AUDITING_MESSAGES, messages)
53
+ }
54
+
55
+ if (register) {
56
+ for (const [name, component] of Object.entries(components)) {
57
+ app.component(name, component)
58
+ }
59
+ }
60
+ }
61
+ }
package/src/shared.js ADDED
@@ -0,0 +1,95 @@
1
+ import { CircleSmallIcon, LinkIcon, PencilIcon, PlusIcon, RotateCcwIcon, TrashIcon, UnlinkIcon } from '@lucide/vue'
2
+ import { mergeMessages } from '@stsdti/auditing-core'
3
+ import { clsx } from 'clsx'
4
+ import { extendTailwindMerge } from 'tailwind-merge'
5
+ import { h, inject } from 'vue'
6
+
7
+ export const AUDITING_MESSAGES = Symbol('auditing.messages')
8
+
9
+ export function useMessages(overrides = null) {
10
+ return mergeMessages(inject(AUDITING_MESSAGES, null), overrides)
11
+ }
12
+
13
+ const twMerge = extendTailwindMerge({
14
+ extend: {
15
+ theme: {
16
+ radius: ['surface', 'control', 'item']
17
+ }
18
+ }
19
+ })
20
+
21
+ export function cn(...inputs) {
22
+ return twMerge(clsx(inputs))
23
+ }
24
+
25
+ export const eventIcons = {
26
+ plus: PlusIcon,
27
+ pencil: PencilIcon,
28
+ trash: TrashIcon,
29
+ restore: RotateCcwIcon,
30
+ link: LinkIcon,
31
+ unlink: UnlinkIcon,
32
+ dot: CircleSmallIcon
33
+ }
34
+
35
+ export const eventIcon = (glyph) => eventIcons[glyph] ?? CircleSmallIcon
36
+
37
+ export const buttonVariants = ({ variant = 'default', size = 'default' } = {}) => cn(
38
+ 'cn-button group/button inline-flex shrink-0 items-center justify-center whitespace-nowrap transition-all outline-none select-none disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0',
39
+ `cn-button-variant-${variant}`,
40
+ `cn-button-size-${size}`
41
+ )
42
+
43
+ export const badgeVariants = ({ variant = 'default' } = {}) => cn(
44
+ 'cn-badge group/badge inline-flex w-fit shrink-0 items-center justify-center overflow-hidden whitespace-nowrap focus-visible:border-ring focus-ring aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none',
45
+ `cn-badge-variant-${variant}`
46
+ )
47
+
48
+ export const inputClasses = 'cn-input w-full min-w-0 outline-none file:inline-flex file:border-0 file:bg-transparent file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50'
49
+
50
+ export const buttonGroupClasses = 'cn-button-group flex w-fit items-stretch *:focus-visible:relative *:focus-visible:z-10 [&>input]:flex-1 cn-button-group-orientation-horizontal [&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none'
51
+
52
+ export const fieldClasses = 'cn-field group/field flex w-full cn-field-orientation-vertical flex-col *:w-full [&>.sr-only]:w-auto'
53
+ export const fieldGroupClasses = 'cn-field-group group/field-group @container/field-group flex w-full flex-col gap-(--form-gap)'
54
+ export const fieldLabelClasses = 'cn-label flex items-center select-none group-data-[disabled=true]:pointer-events-none peer-disabled:cursor-not-allowed cn-field-label group/field-label peer/field-label w-fit leading-snug'
55
+
56
+ export const rowActionClasses = 'bg-card text-muted-foreground hover:text-foreground'
57
+
58
+ export const toneVariant = {
59
+ success: 'success',
60
+ info: 'info',
61
+ danger: 'destructive',
62
+ warning: 'warning',
63
+ accent: 'outline',
64
+ neutral: 'secondary'
65
+ }
66
+
67
+ export const toneMarker = {
68
+ success: 'bg-success/10 text-success dark:bg-success/20',
69
+ info: 'bg-info/10 text-info dark:bg-info/20',
70
+ danger: 'bg-destructive/10 text-destructive dark:bg-destructive/20',
71
+ warning: 'bg-warning/10 text-warning dark:bg-warning/20',
72
+ accent: 'bg-primary/10 text-primary dark:bg-primary/20',
73
+ neutral: 'bg-muted text-muted-foreground'
74
+ }
75
+
76
+ export const UiButton = ({ as, type, variant, size }, { slots }) => h(as, {
77
+ 'type': as === 'button' ? type : undefined,
78
+ 'data-slot': 'button',
79
+ 'data-variant': variant,
80
+ 'data-size': size,
81
+ 'class': buttonVariants({ variant, size })
82
+ }, slots.default?.())
83
+ UiButton.props = {
84
+ as: { type: [String, Object], default: 'button' },
85
+ type: { type: String, default: 'button' },
86
+ variant: { type: String, default: 'default' },
87
+ size: { type: String, default: 'default' }
88
+ }
89
+
90
+ export const UiBadge = ({ variant }, { slots }) => h('span', {
91
+ 'data-slot': 'badge',
92
+ 'data-variant': variant,
93
+ 'class': badgeVariants({ variant })
94
+ }, slots.default?.())
95
+ UiBadge.props = { variant: { type: String, default: 'default' } }