@altafusion/fugue-ui 0.0.0-stage → 0.2.0
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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +46 -2
- package/components/AccentSectionCard.vue +243 -0
- package/components/CopyToClipboard.vue +105 -0
- package/components/FileDropzone.vue +223 -0
- package/components/FugueAppHeader.vue +66 -0
- package/components/FugueAppHeaderDefault.vue +74 -0
- package/components/FugueAppHeaderLanding.vue +85 -0
- package/components/PresenceOrb.vue +55 -0
- package/components/TileGroupSection.vue +65 -0
- package/components/TileHintTooltip.vue +37 -0
- package/components/TileSelector.vue +174 -0
- package/components/TileSelectorLabel.vue +110 -0
- package/components/TileSelectorMultiple.vue +114 -0
- package/components/accentSectionCard.shared.ts +293 -0
- package/components/fileDropzone.shared.ts +140 -0
- package/components/fugue-app-header-types.ts +6 -0
- package/components/tileGroupSection.shared.ts +60 -0
- package/components/tileSelector.shared.ts +491 -0
- package/composables/useFugueAppHeaderChrome.ts +33 -0
- package/eslint.config.mjs +4 -0
- package/lib/fugue-header-visual-style.ts +8 -0
- package/nuxt.config.ts +17 -0
- package/package.json +46 -3
- package/utils/brandTheme.ts +42 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T extends CheckboxGroupItem[], VK extends GetItemKeys<T> = 'value'">
|
|
2
|
+
import type { CheckboxGroupItem, GetItemKeys, GetModelValue } from '@nuxt/ui'
|
|
3
|
+
import type { TileSelectorMultipleProps } from './tileSelector.shared'
|
|
4
|
+
import {
|
|
5
|
+
applyHiddenIndicatorUi,
|
|
6
|
+
hasTileExtras,
|
|
7
|
+
mergeTileUi,
|
|
8
|
+
normalizeTileItems,
|
|
9
|
+
resolveNuxtTileVariant,
|
|
10
|
+
resolveTileDescription,
|
|
11
|
+
resolveTileLabel,
|
|
12
|
+
resolveTileLabelItem,
|
|
13
|
+
splitTileUi,
|
|
14
|
+
usesInlineTileLabel,
|
|
15
|
+
} from './tileSelector.shared'
|
|
16
|
+
import TileSelectorLabel from './TileSelectorLabel.vue'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Multi-select tile picker on {@link UCheckboxGroup}.
|
|
20
|
+
* Same item shapes and layout fixes as {@link TileSelector}.
|
|
21
|
+
*/
|
|
22
|
+
const props = withDefaults(defineProps<TileSelectorMultipleProps<T, VK>>(), {
|
|
23
|
+
variant: 'card',
|
|
24
|
+
color: 'primary',
|
|
25
|
+
size: 'md',
|
|
26
|
+
indicator: 'hidden',
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
defineSlots<{
|
|
30
|
+
legend?: () => unknown
|
|
31
|
+
label?: (_slotProps: { item: CheckboxGroupItem & { id: string } }) => unknown
|
|
32
|
+
}>()
|
|
33
|
+
|
|
34
|
+
const model = defineModel<GetModelValue<T, VK, true>>()
|
|
35
|
+
|
|
36
|
+
const mergedUi = computed(() => mergeTileUi(props.variant ?? 'card', props.ui))
|
|
37
|
+
const splitUi = computed(() => splitTileUi(mergedUi.value))
|
|
38
|
+
const labelUi = computed(() => splitUi.value.labelUi)
|
|
39
|
+
|
|
40
|
+
const groupUi = computed(() => {
|
|
41
|
+
const base = splitUi.value.groupUi
|
|
42
|
+
return props.indicator === 'hidden'
|
|
43
|
+
? applyHiddenIndicatorUi(base)
|
|
44
|
+
: base
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const visibleItems = computed(() =>
|
|
48
|
+
props.items
|
|
49
|
+
? normalizeTileItems(props.items)
|
|
50
|
+
: undefined,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
const nuxtVariant = computed(() => resolveNuxtTileVariant(props.variant))
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<template>
|
|
57
|
+
<UFormField
|
|
58
|
+
:error="error"
|
|
59
|
+
:required="required"
|
|
60
|
+
:name="name"
|
|
61
|
+
:class="props.class"
|
|
62
|
+
>
|
|
63
|
+
<UCheckboxGroup
|
|
64
|
+
v-model="model"
|
|
65
|
+
:name="name"
|
|
66
|
+
:legend="legend"
|
|
67
|
+
:items="visibleItems"
|
|
68
|
+
:default-value="defaultValue"
|
|
69
|
+
:required="required"
|
|
70
|
+
:disabled="disabled"
|
|
71
|
+
:loop="loop"
|
|
72
|
+
:color="color"
|
|
73
|
+
:size="size"
|
|
74
|
+
:orientation="orientation"
|
|
75
|
+
:value-key="valueKey"
|
|
76
|
+
:label-key="labelKey"
|
|
77
|
+
:description-key="descriptionKey"
|
|
78
|
+
:indicator="indicator"
|
|
79
|
+
:highlight="highlight"
|
|
80
|
+
:icon="icon"
|
|
81
|
+
:variant="nuxtVariant"
|
|
82
|
+
:ui="groupUi"
|
|
83
|
+
>
|
|
84
|
+
<template v-if="$slots.legend" #legend>
|
|
85
|
+
<slot name="legend" />
|
|
86
|
+
</template>
|
|
87
|
+
|
|
88
|
+
<template #label="slotProps">
|
|
89
|
+
<slot name="label" v-bind="slotProps">
|
|
90
|
+
<TileSelectorLabel
|
|
91
|
+
v-if="usesInlineTileLabel(variant)"
|
|
92
|
+
:layout="variant === 'feature' ? 'feature' : 'row'"
|
|
93
|
+
:item="resolveTileLabelItem(slotProps.item, labelKey)"
|
|
94
|
+
:description="resolveTileDescription(slotProps.item, descriptionKey)"
|
|
95
|
+
:ui="labelUi"
|
|
96
|
+
/>
|
|
97
|
+
<TileSelectorLabel
|
|
98
|
+
v-else-if="hasTileExtras(slotProps.item) || resolveTileDescription(slotProps.item, descriptionKey)"
|
|
99
|
+
:item="resolveTileLabelItem(slotProps.item, labelKey)"
|
|
100
|
+
:description="resolveTileDescription(slotProps.item, descriptionKey)"
|
|
101
|
+
/>
|
|
102
|
+
<span
|
|
103
|
+
v-else
|
|
104
|
+
class="font-medium text-default"
|
|
105
|
+
>
|
|
106
|
+
{{ resolveTileLabel(slotProps.item, labelKey) }}
|
|
107
|
+
</span>
|
|
108
|
+
</slot>
|
|
109
|
+
</template>
|
|
110
|
+
|
|
111
|
+
<template #description />
|
|
112
|
+
</UCheckboxGroup>
|
|
113
|
+
</UFormField>
|
|
114
|
+
</template>
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import type { ButtonProps, CardProps } from '@nuxt/ui'
|
|
2
|
+
import type { ClassNameValue } from 'tailwind-merge'
|
|
3
|
+
import type { HTMLAttributes } from 'vue'
|
|
4
|
+
import { twMerge } from 'tailwind-merge'
|
|
5
|
+
|
|
6
|
+
/** Nuxt UI semantic role for the left accent stripe only (not {@link UCard} `variant`). */
|
|
7
|
+
export type AccentSectionCardColor
|
|
8
|
+
= | 'primary'
|
|
9
|
+
| 'success'
|
|
10
|
+
| 'info'
|
|
11
|
+
| 'warning'
|
|
12
|
+
| 'error'
|
|
13
|
+
| 'neutral'
|
|
14
|
+
|
|
15
|
+
/** Named composer palette keys (hex parity with UI React `AccentSectionCardVisualStyle`). */
|
|
16
|
+
export type AccentSectionCardVisualStyle
|
|
17
|
+
= | 'amber'
|
|
18
|
+
| 'blue'
|
|
19
|
+
| 'cyan'
|
|
20
|
+
| 'emerald'
|
|
21
|
+
| 'fuchsia'
|
|
22
|
+
| 'gray'
|
|
23
|
+
| 'red'
|
|
24
|
+
| 'sky'
|
|
25
|
+
| 'violet'
|
|
26
|
+
|
|
27
|
+
/** Hex swatch for each {@link AccentSectionCardVisualStyle} — matches UI React palette. */
|
|
28
|
+
export const ACCENT_SECTION_CARD_VISUAL_STYLE_COLORS: Record<AccentSectionCardVisualStyle, string> = {
|
|
29
|
+
blue: '#60a5fa',
|
|
30
|
+
fuchsia: '#e879f9',
|
|
31
|
+
violet: '#a78bfa',
|
|
32
|
+
gray: '#d1d5db',
|
|
33
|
+
emerald: '#34d399',
|
|
34
|
+
cyan: '#22d3ee',
|
|
35
|
+
sky: '#7dd3fc',
|
|
36
|
+
amber: '#ffb900',
|
|
37
|
+
red: '#fb2c36',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** {@link UButton} props for {@link AccentSectionCard} `close` (icon comes from `closeIcon`). */
|
|
41
|
+
export type AccentSectionCardCloseConfig = Omit<
|
|
42
|
+
ButtonProps,
|
|
43
|
+
'icon' | 'leadingIcon' | 'trailingIcon'
|
|
44
|
+
> & {
|
|
45
|
+
'aria-label'?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type AccentSectionCardCardUi = NonNullable<CardProps['ui']>
|
|
49
|
+
|
|
50
|
+
type CardUiSlot = NonNullable<AccentSectionCardCardUi['root']>
|
|
51
|
+
|
|
52
|
+
function asCardUiSlot(value: AccentSectionCardCardUi['root'] | SlotClass | undefined): CardUiSlot | undefined {
|
|
53
|
+
if (value === null || value === undefined)
|
|
54
|
+
return undefined
|
|
55
|
+
return value as CardUiSlot
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface AccentSectionCardUi {
|
|
59
|
+
root?: HTMLAttributes['class']
|
|
60
|
+
card?: AccentSectionCardCardUi
|
|
61
|
+
titleRow?: HTMLAttributes['class']
|
|
62
|
+
title?: HTMLAttributes['class']
|
|
63
|
+
icon?: HTMLAttributes['class']
|
|
64
|
+
/** Region below the title row (named `#header` slot). */
|
|
65
|
+
headerSlot?: HTMLAttributes['class']
|
|
66
|
+
body?: HTMLAttributes['class']
|
|
67
|
+
closeButton?: HTMLAttributes['class']
|
|
68
|
+
overlay?: HTMLAttributes['class']
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type SlotClass = HTMLAttributes['class']
|
|
72
|
+
|
|
73
|
+
function isSlotClassReplacer(value: unknown): boolean {
|
|
74
|
+
if (value === undefined || value === null)
|
|
75
|
+
return false
|
|
76
|
+
if (typeof value === 'function')
|
|
77
|
+
return true
|
|
78
|
+
return typeof value === 'object' && !Array.isArray(value)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function asClassNameValue(value: SlotClass): ClassNameValue {
|
|
82
|
+
return value as ClassNameValue
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function mergeUiSlot(base: SlotClass | undefined, extra: SlotClass | undefined): SlotClass | undefined {
|
|
86
|
+
if (base === undefined)
|
|
87
|
+
return extra
|
|
88
|
+
if (extra === undefined)
|
|
89
|
+
return base
|
|
90
|
+
if (isSlotClassReplacer(base) || isSlotClassReplacer(extra))
|
|
91
|
+
return extra
|
|
92
|
+
return twMerge(asClassNameValue(base), asClassNameValue(extra))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function mergeCardSlot(base: CardUiSlot | undefined, extra: CardUiSlot | undefined): CardUiSlot | undefined {
|
|
96
|
+
if (base === undefined)
|
|
97
|
+
return extra
|
|
98
|
+
if (extra === undefined)
|
|
99
|
+
return base
|
|
100
|
+
if (isSlotClassReplacer(base) || isSlotClassReplacer(extra))
|
|
101
|
+
return extra
|
|
102
|
+
return twMerge(asClassNameValue(base as SlotClass), asClassNameValue(extra as SlotClass)) as CardUiSlot
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function mergeCardUi(
|
|
106
|
+
base: AccentSectionCardCardUi | undefined,
|
|
107
|
+
extra: AccentSectionCardCardUi | undefined,
|
|
108
|
+
): AccentSectionCardCardUi | undefined {
|
|
109
|
+
if (!base)
|
|
110
|
+
return extra
|
|
111
|
+
if (!extra)
|
|
112
|
+
return base
|
|
113
|
+
const merged: AccentSectionCardCardUi = {
|
|
114
|
+
...base,
|
|
115
|
+
...extra,
|
|
116
|
+
}
|
|
117
|
+
const keys = new Set([
|
|
118
|
+
...Object.keys(base),
|
|
119
|
+
...Object.keys(extra),
|
|
120
|
+
]) as Set<keyof AccentSectionCardCardUi>
|
|
121
|
+
for (const key of keys)
|
|
122
|
+
merged[key] = mergeCardSlot(asCardUiSlot(base[key]), asCardUiSlot(extra[key]))
|
|
123
|
+
|
|
124
|
+
return merged
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const ACCENT_SECTION_CARD_DEFAULT_UI: AccentSectionCardUi = {
|
|
128
|
+
root: 'relative w-full',
|
|
129
|
+
card: {
|
|
130
|
+
root: 'w-full min-w-0 overflow-hidden border-2 border-default bg-default shadow-sm transition-shadow duration-300 border-s-4 hover:shadow-md',
|
|
131
|
+
header:
|
|
132
|
+
'border-b border-default py-[var(--accent-section-header-py)] px-[var(--accent-section-header-px)]',
|
|
133
|
+
body: 'px-6 pt-4 pb-5',
|
|
134
|
+
},
|
|
135
|
+
titleRow: 'accent-section-title-row min-w-0 flex-1 flex items-center gap-2',
|
|
136
|
+
title: 'accent-section-title',
|
|
137
|
+
icon: 'accent-section-icon',
|
|
138
|
+
headerSlot: 'space-y-4',
|
|
139
|
+
closeButton: 'shrink-0',
|
|
140
|
+
overlay: 'absolute inset-0 z-[5] cursor-not-allowed bg-default/50',
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const ACCENT_BORDER_CLASS: Record<AccentSectionCardColor, string> = {
|
|
144
|
+
primary: 'border-s-primary',
|
|
145
|
+
success: 'border-s-success',
|
|
146
|
+
info: 'border-s-info',
|
|
147
|
+
warning: 'border-s-warning',
|
|
148
|
+
error: 'border-s-error',
|
|
149
|
+
neutral: 'border-s-neutral',
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Left accent stripe class for `color` (muted when disabled). */
|
|
153
|
+
export function accentSectionCardBorderAccentClass(
|
|
154
|
+
color: AccentSectionCardColor,
|
|
155
|
+
disabled: boolean,
|
|
156
|
+
): string {
|
|
157
|
+
if (disabled)
|
|
158
|
+
return 'border-s-neutral'
|
|
159
|
+
return ACCENT_BORDER_CLASS[color]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface ResolveAccentSectionCardAccentInput {
|
|
163
|
+
/** Any CSS color for the left stripe (highest precedence). */
|
|
164
|
+
accentColor?: string
|
|
165
|
+
/** Named composer palette key (hex from {@link ACCENT_SECTION_CARD_VISUAL_STYLE_COLORS}). */
|
|
166
|
+
palette?: AccentSectionCardVisualStyle
|
|
167
|
+
/** Nuxt UI semantic stripe color (default `primary`); not {@link UCard} `variant`. */
|
|
168
|
+
color?: AccentSectionCardColor
|
|
169
|
+
disabled?: boolean
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export type ResolvedAccentSectionCardAccent
|
|
173
|
+
= | { mode: 'semantic', borderClass: string }
|
|
174
|
+
| { mode: 'custom', borderClass: string, style: Record<string, string> }
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Resolves the left accent stripe for {@link AccentSectionCard}.
|
|
178
|
+
*
|
|
179
|
+
* **Precedence** (highest first):
|
|
180
|
+
* 1. `accentColor` — any CSS color
|
|
181
|
+
* 2. `palette` — named key from {@link ACCENT_SECTION_CARD_VISUAL_STYLE_COLORS} (React composer palette parity)
|
|
182
|
+
* 3. `color` — Nuxt UI semantic role (default `primary`)
|
|
183
|
+
*
|
|
184
|
+
* When `disabled` is true, custom accents are ignored: muted neutral stripe (same as
|
|
185
|
+
* semantic disabled), neutral border, and no inline hex on the card root.
|
|
186
|
+
*/
|
|
187
|
+
export function resolveAccentSectionCardAccent(
|
|
188
|
+
input: ResolveAccentSectionCardAccentInput,
|
|
189
|
+
): ResolvedAccentSectionCardAccent {
|
|
190
|
+
const color = input.color ?? 'primary'
|
|
191
|
+
const disabled = input.disabled ?? false
|
|
192
|
+
|
|
193
|
+
if (disabled) {
|
|
194
|
+
return {
|
|
195
|
+
mode: 'semantic',
|
|
196
|
+
borderClass: accentSectionCardBorderAccentClass(color, true),
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (input.accentColor !== undefined && input.accentColor !== '') {
|
|
201
|
+
return {
|
|
202
|
+
mode: 'custom',
|
|
203
|
+
borderClass: 'border-s-4',
|
|
204
|
+
style: { borderInlineStartColor: input.accentColor },
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (input.palette !== undefined) {
|
|
209
|
+
return {
|
|
210
|
+
mode: 'custom',
|
|
211
|
+
borderClass: 'border-s-4',
|
|
212
|
+
style: { borderInlineStartColor: ACCENT_SECTION_CARD_VISUAL_STYLE_COLORS[input.palette] },
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
mode: 'semantic',
|
|
218
|
+
borderClass: accentSectionCardBorderAccentClass(color, false),
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const ACCENT_SECTION_CARD_DEFAULT_CLOSE_BUTTON = {
|
|
223
|
+
'type': 'button' as const,
|
|
224
|
+
'color': 'neutral' as const,
|
|
225
|
+
'variant': 'ghost' as const,
|
|
226
|
+
'size': 'xs' as const,
|
|
227
|
+
'square': true,
|
|
228
|
+
'aria-label': 'Close',
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Modal-style `close` prop → {@link UButton} bindings (hidden when falsy). */
|
|
232
|
+
export function resolveAccentSectionCardClose(
|
|
233
|
+
close: boolean | AccentSectionCardCloseConfig | undefined,
|
|
234
|
+
): { show: boolean, buttonProps: Record<string, unknown> } {
|
|
235
|
+
if (!close)
|
|
236
|
+
return { show: false, buttonProps: {} }
|
|
237
|
+
|
|
238
|
+
if (close === true) {
|
|
239
|
+
return {
|
|
240
|
+
show: true,
|
|
241
|
+
buttonProps: { ...ACCENT_SECTION_CARD_DEFAULT_CLOSE_BUTTON },
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
show: true,
|
|
247
|
+
buttonProps: {
|
|
248
|
+
...ACCENT_SECTION_CARD_DEFAULT_CLOSE_BUTTON,
|
|
249
|
+
...close,
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Merge default presets with optional per-slot `ui` overrides. */
|
|
255
|
+
export function mergeAccentSectionCardUi(ui?: AccentSectionCardUi): AccentSectionCardUi {
|
|
256
|
+
const preset = ACCENT_SECTION_CARD_DEFAULT_UI
|
|
257
|
+
if (!ui)
|
|
258
|
+
return preset
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
root: mergeUiSlot(preset.root, ui.root),
|
|
262
|
+
card: mergeCardUi(preset.card, ui.card),
|
|
263
|
+
titleRow: mergeUiSlot(preset.titleRow, ui.titleRow),
|
|
264
|
+
title: mergeUiSlot(preset.title, ui.title),
|
|
265
|
+
icon: mergeUiSlot(preset.icon, ui.icon),
|
|
266
|
+
headerSlot: mergeUiSlot(preset.headerSlot, ui.headerSlot),
|
|
267
|
+
body: mergeUiSlot(preset.body, ui.body),
|
|
268
|
+
closeButton: mergeUiSlot(preset.closeButton, ui.closeButton),
|
|
269
|
+
overlay: mergeUiSlot(preset.overlay, ui.overlay),
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Build `:ui` for {@link UCard} including accent border and shell `root` classes on `root`. Inline hex is bound on {@link UCard} via `:style` in the component. */
|
|
274
|
+
export function buildAccentSectionCardUCardUi(
|
|
275
|
+
merged: AccentSectionCardUi,
|
|
276
|
+
accentClass: string,
|
|
277
|
+
disabled: boolean,
|
|
278
|
+
): AccentSectionCardCardUi {
|
|
279
|
+
const card = merged.card ?? {}
|
|
280
|
+
const rootExtra = disabled ? 'border-muted' : undefined
|
|
281
|
+
const accentSlot = accentClass
|
|
282
|
+
? asCardUiSlot(accentClass)
|
|
283
|
+
: undefined
|
|
284
|
+
return {
|
|
285
|
+
...card,
|
|
286
|
+
root: mergeCardSlot(
|
|
287
|
+
asCardUiSlot(card.root),
|
|
288
|
+
mergeCardSlot(asCardUiSlot(rootExtra), accentSlot),
|
|
289
|
+
),
|
|
290
|
+
header: asCardUiSlot(card.header),
|
|
291
|
+
body: mergeCardSlot(asCardUiSlot(card.body), asCardUiSlot(merged.body)),
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export type FileRejectionReason = 'extension' | 'empty' | 'size'
|
|
2
|
+
|
|
3
|
+
export interface FileRejection {
|
|
4
|
+
file: File
|
|
5
|
+
reason: FileRejectionReason
|
|
6
|
+
/** Echoed back so the consumer can build its own message. */
|
|
7
|
+
accept?: string[]
|
|
8
|
+
maxSize?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface FileConstraints {
|
|
12
|
+
/**
|
|
13
|
+
* Permitted file **extensions**, with or without the leading dot (`.zip`, `zip`).
|
|
14
|
+
* Media types are not accepted here: `image/png` would be normalized to
|
|
15
|
+
* `.image/png` and match no file name. Add media-type matching against
|
|
16
|
+
* `file.type` if a consumer ever needs it — no caller does today.
|
|
17
|
+
*/
|
|
18
|
+
accept?: string[]
|
|
19
|
+
maxSize?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function normalizeExtension(ext: string): string {
|
|
23
|
+
const lower = ext.toLowerCase()
|
|
24
|
+
return lower.startsWith('.')
|
|
25
|
+
? lower
|
|
26
|
+
: `.${lower}`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function hasAcceptedExtension(fileName: string, accept?: string[]): boolean {
|
|
30
|
+
if (!accept || accept.length === 0)
|
|
31
|
+
return true
|
|
32
|
+
|
|
33
|
+
const lowerName = fileName.toLowerCase()
|
|
34
|
+
return accept.some(ext => lowerName.endsWith(normalizeExtension(ext)))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function isWithinMaxSize(sizeBytes: number, maxSize?: number): boolean {
|
|
38
|
+
if (maxSize === undefined || maxSize <= 0)
|
|
39
|
+
return true
|
|
40
|
+
|
|
41
|
+
return sizeBytes <= maxSize
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function validateFile(file: File, constraints: FileConstraints): FileRejection | null {
|
|
45
|
+
if (!hasAcceptedExtension(file.name, constraints.accept)) {
|
|
46
|
+
return {
|
|
47
|
+
file,
|
|
48
|
+
reason: 'extension',
|
|
49
|
+
accept: constraints.accept,
|
|
50
|
+
maxSize: constraints.maxSize,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Zero bytes is never something to send, and it is also how browsers report a
|
|
55
|
+
// dropped folder — which would otherwise look like a valid pick until the server
|
|
56
|
+
// turned it away.
|
|
57
|
+
if (file.size === 0) {
|
|
58
|
+
return {
|
|
59
|
+
file,
|
|
60
|
+
reason: 'empty',
|
|
61
|
+
accept: constraints.accept,
|
|
62
|
+
maxSize: constraints.maxSize,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!isWithinMaxSize(file.size, constraints.maxSize)) {
|
|
67
|
+
return {
|
|
68
|
+
file,
|
|
69
|
+
reason: 'size',
|
|
70
|
+
accept: constraints.accept,
|
|
71
|
+
maxSize: constraints.maxSize,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function formatFileSize(bytes: number): string {
|
|
79
|
+
if (bytes === 0)
|
|
80
|
+
return '0 B'
|
|
81
|
+
|
|
82
|
+
const units = ['B', 'KB', 'MB', 'GB'] as const
|
|
83
|
+
const base = 1024
|
|
84
|
+
let value = bytes
|
|
85
|
+
let unitIndex = 0
|
|
86
|
+
|
|
87
|
+
while (value >= base && unitIndex < units.length - 1) {
|
|
88
|
+
value /= base
|
|
89
|
+
unitIndex++
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const formatted = unitIndex === 0
|
|
93
|
+
? String(value)
|
|
94
|
+
: value.toFixed(1).replace(/\.0$/, '')
|
|
95
|
+
|
|
96
|
+
return `${formatted} ${units[unitIndex]}`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Media types to offer the picker alongside an extension, keyed by extension.
|
|
101
|
+
*
|
|
102
|
+
* Some platforms match `accept` against the file's reported type rather than its
|
|
103
|
+
* name, where an extension token alone leaves the file greyed out. Only archive
|
|
104
|
+
* formats are listed; an unmapped extension simply contributes its own token.
|
|
105
|
+
*/
|
|
106
|
+
const MEDIA_TYPES_BY_EXTENSION: Record<string, readonly string[]> = {
|
|
107
|
+
'.zip': ['application/zip', 'application/x-zip-compressed'],
|
|
108
|
+
'.tar': ['application/x-tar'],
|
|
109
|
+
'.gz': ['application/gzip', 'application/x-gzip'],
|
|
110
|
+
'.tgz': ['application/gzip', 'application/x-gzip'],
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* `accept` for the native file dialog, deliberately wider than the validation list.
|
|
115
|
+
*
|
|
116
|
+
* Browsers match `accept` on the final extension segment only, so `.tar.gz` on its
|
|
117
|
+
* own leaves `app.tar.gz` unselectable in the picker. Emitting `.gz` and the media
|
|
118
|
+
* types alongside it makes the file selectable; `validateFile` still turns away a
|
|
119
|
+
* bare `.gz`, so the widening never loosens what is actually accepted.
|
|
120
|
+
*/
|
|
121
|
+
export function toAcceptAttribute(accept?: string[]): string | undefined {
|
|
122
|
+
if (!accept || accept.length === 0)
|
|
123
|
+
return undefined
|
|
124
|
+
|
|
125
|
+
const tokens = new Set<string>()
|
|
126
|
+
|
|
127
|
+
for (const entry of accept) {
|
|
128
|
+
const extension = normalizeExtension(entry)
|
|
129
|
+
tokens.add(extension)
|
|
130
|
+
|
|
131
|
+
const finalSegment = extension.slice(extension.lastIndexOf('.'))
|
|
132
|
+
if (finalSegment !== extension)
|
|
133
|
+
tokens.add(finalSegment)
|
|
134
|
+
|
|
135
|
+
for (const mediaType of MEDIA_TYPES_BY_EXTENSION[finalSegment] ?? [])
|
|
136
|
+
tokens.add(mediaType)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return [...tokens].join(',')
|
|
140
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'vue'
|
|
2
|
+
|
|
3
|
+
export type TileGroupSectionVariant = 'field' | 'category'
|
|
4
|
+
|
|
5
|
+
export interface TileGroupSectionUi {
|
|
6
|
+
root?: HTMLAttributes['class']
|
|
7
|
+
title?: HTMLAttributes['class']
|
|
8
|
+
note?: HTMLAttributes['class']
|
|
9
|
+
required?: HTMLAttributes['class']
|
|
10
|
+
optional?: HTMLAttributes['class']
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type SlotClass = HTMLAttributes['class']
|
|
14
|
+
|
|
15
|
+
function mergeUiSlot(base: SlotClass | undefined, extra: SlotClass | undefined): SlotClass | undefined {
|
|
16
|
+
if (base === undefined)
|
|
17
|
+
return extra
|
|
18
|
+
if (extra === undefined)
|
|
19
|
+
return base
|
|
20
|
+
return [base, extra] as SlotClass
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const TILE_GROUP_SECTION_COMMON_UI: TileGroupSectionUi = {
|
|
24
|
+
note: 'text-sm text-muted',
|
|
25
|
+
required: 'text-error',
|
|
26
|
+
optional: 'text-muted',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const TILE_GROUP_SECTION_VARIANT_UI: Record<TileGroupSectionVariant, TileGroupSectionUi> = {
|
|
30
|
+
field: {
|
|
31
|
+
...TILE_GROUP_SECTION_COMMON_UI,
|
|
32
|
+
title: 'm-0 text-sm font-medium text-muted',
|
|
33
|
+
},
|
|
34
|
+
category: {
|
|
35
|
+
...TILE_GROUP_SECTION_COMMON_UI,
|
|
36
|
+
title: 'm-0 text-sm font-medium uppercase tracking-wide text-muted',
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Merge variant presets with optional per-slot `ui` overrides (strings / class arrays). */
|
|
41
|
+
export function mergeTileGroupSectionUi(
|
|
42
|
+
variant: TileGroupSectionVariant,
|
|
43
|
+
ui?: TileGroupSectionUi,
|
|
44
|
+
): TileGroupSectionUi {
|
|
45
|
+
const preset = TILE_GROUP_SECTION_VARIANT_UI[variant] ?? TILE_GROUP_SECTION_VARIANT_UI.field
|
|
46
|
+
if (!ui)
|
|
47
|
+
return preset
|
|
48
|
+
|
|
49
|
+
const keys = new Set([
|
|
50
|
+
...Object.keys(preset),
|
|
51
|
+
...Object.keys(ui),
|
|
52
|
+
])
|
|
53
|
+
|
|
54
|
+
const merged: TileGroupSectionUi = {}
|
|
55
|
+
for (const key of keys) {
|
|
56
|
+
const slot = key as keyof TileGroupSectionUi
|
|
57
|
+
merged[slot] = mergeUiSlot(preset[slot], ui[slot])
|
|
58
|
+
}
|
|
59
|
+
return merged
|
|
60
|
+
}
|