sv5ui 1.6.0 → 1.8.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.
Files changed (71) hide show
  1. package/dist/Banner/Banner.svelte +162 -0
  2. package/dist/Banner/Banner.svelte.d.ts +5 -0
  3. package/dist/Banner/banner.types.d.ts +148 -0
  4. package/dist/Banner/banner.types.js +1 -0
  5. package/dist/Banner/banner.variants.d.ts +293 -0
  6. package/dist/Banner/banner.variants.js +86 -0
  7. package/dist/Banner/index.d.ts +2 -0
  8. package/dist/Banner/index.js +1 -0
  9. package/dist/Calendar/Calendar.svelte +48 -6
  10. package/dist/Calendar/calendar.types.d.ts +19 -0
  11. package/dist/Calendar/calendar.variants.js +2 -1
  12. package/dist/Carousel/Carousel.svelte +279 -0
  13. package/dist/Carousel/Carousel.svelte.d.ts +26 -0
  14. package/dist/Carousel/carousel.types.d.ts +242 -0
  15. package/dist/Carousel/carousel.types.js +1 -0
  16. package/dist/Carousel/carousel.variants.d.ts +408 -0
  17. package/dist/Carousel/carousel.variants.js +88 -0
  18. package/dist/Carousel/index.d.ts +2 -0
  19. package/dist/Carousel/index.js +1 -0
  20. package/dist/Editor/Editor.svelte +738 -0
  21. package/dist/Editor/Editor.svelte.d.ts +6 -0
  22. package/dist/Editor/EditorUrlPrompt.svelte +111 -0
  23. package/dist/Editor/EditorUrlPrompt.svelte.d.ts +15 -0
  24. package/dist/Editor/SlashPopup.svelte +67 -0
  25. package/dist/Editor/SlashPopup.svelte.d.ts +9 -0
  26. package/dist/Editor/editor.extensions.d.ts +23 -0
  27. package/dist/Editor/editor.extensions.js +123 -0
  28. package/dist/Editor/editor.schemas.d.ts +4 -0
  29. package/dist/Editor/editor.schemas.js +3 -0
  30. package/dist/Editor/editor.slash.svelte.d.ts +34 -0
  31. package/dist/Editor/editor.slash.svelte.js +273 -0
  32. package/dist/Editor/editor.suggestion.d.ts +7 -0
  33. package/dist/Editor/editor.suggestion.js +142 -0
  34. package/dist/Editor/editor.toolbar.d.ts +11 -0
  35. package/dist/Editor/editor.toolbar.js +212 -0
  36. package/dist/Editor/editor.types.d.ts +347 -0
  37. package/dist/Editor/editor.types.js +1 -0
  38. package/dist/Editor/editor.variants.d.ts +308 -0
  39. package/dist/Editor/editor.variants.js +150 -0
  40. package/dist/Editor/index.d.ts +53 -0
  41. package/dist/Editor/index.js +52 -0
  42. package/dist/FileUpload/FileUpload.svelte +81 -10
  43. package/dist/FileUpload/file-upload.types.d.ts +39 -0
  44. package/dist/FileUpload/index.d.ts +1 -1
  45. package/dist/Modal/Modal.svelte +14 -3
  46. package/dist/Modal/modal.types.d.ts +15 -4
  47. package/dist/Modal/modal.variants.d.ts +110 -20
  48. package/dist/Modal/modal.variants.js +27 -9
  49. package/dist/PinInput/PinInput.svelte +18 -4
  50. package/dist/PinInput/pin-input.types.d.ts +11 -0
  51. package/dist/Select/Select.svelte +98 -28
  52. package/dist/Select/select.types.d.ts +44 -2
  53. package/dist/SelectMenu/SelectMenu.svelte +210 -25
  54. package/dist/SelectMenu/select-menu.types.d.ts +62 -1
  55. package/dist/SelectMenu/select-menu.variants.d.ts +26 -0
  56. package/dist/SelectMenu/select-menu.variants.js +34 -6
  57. package/dist/Slideover/Slideover.svelte +13 -2
  58. package/dist/Slideover/slideover.types.d.ts +14 -3
  59. package/dist/Slideover/slideover.variants.d.ts +85 -5
  60. package/dist/Slideover/slideover.variants.js +42 -12
  61. package/dist/Stepper/Stepper.svelte +292 -0
  62. package/dist/Stepper/Stepper.svelte.d.ts +5 -0
  63. package/dist/Stepper/index.d.ts +2 -0
  64. package/dist/Stepper/index.js +1 -0
  65. package/dist/Stepper/stepper.types.d.ts +223 -0
  66. package/dist/Stepper/stepper.types.js +1 -0
  67. package/dist/Stepper/stepper.variants.d.ts +428 -0
  68. package/dist/Stepper/stepper.variants.js +204 -0
  69. package/dist/index.d.ts +3 -0
  70. package/dist/index.js +3 -0
  71. package/package.json +102 -1
@@ -0,0 +1,150 @@
1
+ import { tv } from 'tailwind-variants';
2
+ export const editorVariants = tv({
3
+ slots: {
4
+ root: [
5
+ 'relative w-full rounded-lg border border-outline-variant bg-surface',
6
+ 'transition-shadow',
7
+ 'focus-within:ring-2 focus-within:ring-offset-0',
8
+ 'data-[disabled=true]:opacity-60 data-[disabled=true]:pointer-events-none'
9
+ ],
10
+ toolbar: [
11
+ 'flex flex-wrap items-center gap-0.5',
12
+ 'border-b border-outline-variant',
13
+ 'bg-surface-container-low',
14
+ 'rounded-t-lg p-1.5'
15
+ ],
16
+ toolbarGroup: 'flex items-center gap-0.5',
17
+ toolbarButton: [
18
+ 'inline-flex items-center justify-center rounded text-on-surface-variant',
19
+ 'hover:bg-surface-container-high hover:text-on-surface',
20
+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary',
21
+ 'data-[active=true]:bg-primary-container data-[active=true]:text-on-primary-container',
22
+ 'disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent',
23
+ 'transition-colors'
24
+ ],
25
+ toolbarSeparator: 'mx-1 h-5 w-px shrink-0 bg-outline-variant',
26
+ content: [
27
+ 'text-on-surface',
28
+ // ----- Inner ProseMirror element (the actual contenteditable) -----
29
+ '[&_.ProseMirror]:outline-none',
30
+ '[&_.ProseMirror]:focus:outline-none',
31
+ '[&_.ProseMirror]:focus-visible:outline-none',
32
+ '[&_.ProseMirror]:p-4',
33
+ '[&_.ProseMirror]:min-h-32',
34
+ '[&_.ProseMirror]:whitespace-pre-wrap',
35
+ '[&_.ProseMirror]:break-words',
36
+ // ----- Placeholder (when editor is empty) -----
37
+ '[&_.is-editor-empty]:before:content-[attr(data-placeholder)]',
38
+ '[&_.is-editor-empty]:before:text-on-surface-variant/60',
39
+ '[&_.is-editor-empty]:before:pointer-events-none',
40
+ '[&_.is-editor-empty]:before:float-left',
41
+ '[&_.is-editor-empty]:before:h-0',
42
+ // ----- Content typography (lightweight in-house prose) -----
43
+ '[&_p]:my-2 [&_p:first-child]:mt-0 [&_p:last-child]:mb-0',
44
+ '[&_h1]:text-2xl [&_h1]:font-bold [&_h1]:my-3',
45
+ '[&_h2]:text-xl [&_h2]:font-bold [&_h2]:my-3',
46
+ '[&_h3]:text-lg [&_h3]:font-semibold [&_h3]:my-2',
47
+ '[&_ul]:list-disc [&_ul]:ps-6 [&_ul]:my-2',
48
+ '[&_ol]:list-decimal [&_ol]:ps-6 [&_ol]:my-2',
49
+ '[&_li>p]:my-0',
50
+ '[&_blockquote]:border-l-4 [&_blockquote]:border-outline-variant [&_blockquote]:ps-3 [&_blockquote]:italic [&_blockquote]:text-on-surface-variant [&_blockquote]:my-3',
51
+ '[&_code]:rounded [&_code]:bg-surface-container-highest [&_code]:px-1 [&_code]:py-0.5 [&_code]:text-sm [&_code]:font-mono',
52
+ '[&_pre]:rounded-md [&_pre]:bg-surface-container-highest [&_pre]:p-3 [&_pre]:my-3 [&_pre]:overflow-x-auto',
53
+ '[&_pre_code]:bg-transparent [&_pre_code]:p-0',
54
+ '[&_a]:text-primary [&_a]:underline [&_a]:underline-offset-2',
55
+ '[&_a:hover]:text-primary/80',
56
+ '[&_hr]:border-outline-variant [&_hr]:my-4',
57
+ '[&_strong]:font-semibold',
58
+ '[&_em]:italic',
59
+ // ----- Image -----
60
+ '[&_img]:max-w-full [&_img]:h-auto [&_img]:rounded-md [&_img]:my-2',
61
+ // ----- YouTube embed (responsive 16:9) -----
62
+ '[&_iframe[src*="youtube"]]:aspect-video [&_iframe[src*="youtube"]]:w-full [&_iframe[src*="youtube"]]:rounded-md [&_iframe[src*="youtube"]]:my-3 [&_iframe[src*="youtube"]]:border-0',
63
+ // ----- Mention chip -----
64
+ '[&_.sv5ui-editor-mention]:inline-flex [&_.sv5ui-editor-mention]:items-center',
65
+ '[&_.sv5ui-editor-mention]:rounded [&_.sv5ui-editor-mention]:bg-primary-container/60',
66
+ '[&_.sv5ui-editor-mention]:text-on-primary-container',
67
+ '[&_.sv5ui-editor-mention]:px-1.5 [&_.sv5ui-editor-mention]:py-0.5',
68
+ '[&_.sv5ui-editor-mention]:text-sm [&_.sv5ui-editor-mention]:font-medium',
69
+ // ----- Table -----
70
+ '[&_.tableWrapper]:my-3 [&_.tableWrapper]:overflow-x-auto',
71
+ '[&_table]:w-full [&_table]:border-collapse [&_table]:table-fixed',
72
+ '[&_table]:border [&_table]:border-outline-variant [&_table]:rounded-md',
73
+ '[&_th]:border [&_th]:border-outline-variant',
74
+ '[&_th]:bg-surface-container-low [&_th]:px-2 [&_th]:py-1.5',
75
+ '[&_th]:font-semibold [&_th]:text-start [&_th]:align-top',
76
+ '[&_th]:relative [&_th]:min-w-16',
77
+ '[&_td]:border [&_td]:border-outline-variant',
78
+ '[&_td]:px-2 [&_td]:py-1.5 [&_td]:align-top',
79
+ '[&_td]:relative [&_td]:min-w-16',
80
+ // Tiptap selectedCell highlight + column resize handle
81
+ '[&_.selectedCell]:bg-primary/10',
82
+ '[&_.column-resize-handle]:absolute [&_.column-resize-handle]:top-0 [&_.column-resize-handle]:bottom-[-2px]',
83
+ '[&_.column-resize-handle]:-right-0.5 [&_.column-resize-handle]:w-1',
84
+ '[&_.column-resize-handle]:bg-primary/40 [&_.column-resize-handle]:pointer-events-none',
85
+ // ----- Selection styling -----
86
+ '[&_::selection]:bg-primary/20'
87
+ ],
88
+ footer: [
89
+ 'flex items-center justify-between gap-2',
90
+ 'border-t border-outline-variant',
91
+ 'bg-surface-container-low',
92
+ 'px-3 py-1.5 rounded-b-lg',
93
+ 'text-xs text-on-surface-variant'
94
+ ],
95
+ countLabel: 'tabular-nums',
96
+ bubbleMenu: [
97
+ // ⚠️ Tiptap's BubbleMenu only sets `visibility:hidden` initially,
98
+ // leaving the element in normal flow (taking up space below the editor)
99
+ // until the user first selects text. Setting `position:absolute` upfront
100
+ // keeps it out of flow from mount — extension's Floating UI positioning
101
+ // then overrides left/top inline on selection.
102
+ 'absolute top-0 left-0 z-50 invisible',
103
+ 'flex items-center gap-0.5 p-1',
104
+ 'rounded-lg border border-outline-variant bg-surface',
105
+ 'shadow-md'
106
+ ]
107
+ },
108
+ variants: {
109
+ size: {
110
+ sm: {
111
+ toolbarButton: 'size-7 *:size-3.5',
112
+ content: 'text-sm [&_.ProseMirror]:p-3 [&_.ProseMirror]:min-h-24',
113
+ footer: 'text-[11px]'
114
+ },
115
+ md: {
116
+ toolbarButton: 'size-8 *:size-4',
117
+ content: 'text-sm',
118
+ footer: ''
119
+ },
120
+ lg: {
121
+ toolbarButton: 'size-9 *:size-5',
122
+ content: 'text-base [&_.ProseMirror]:p-5 [&_.ProseMirror]:min-h-40',
123
+ footer: ''
124
+ }
125
+ },
126
+ color: {
127
+ primary: { root: 'focus-within:ring-primary' },
128
+ secondary: { root: 'focus-within:ring-secondary' },
129
+ tertiary: { root: 'focus-within:ring-tertiary' },
130
+ success: { root: 'focus-within:ring-success' },
131
+ warning: { root: 'focus-within:ring-warning' },
132
+ error: { root: 'focus-within:ring-error' },
133
+ info: { root: 'focus-within:ring-info' },
134
+ surface: { root: 'focus-within:ring-outline' }
135
+ },
136
+ sticky: {
137
+ true: { toolbar: 'sticky top-0 z-10 backdrop-blur-sm' },
138
+ false: ''
139
+ }
140
+ },
141
+ defaultVariants: {
142
+ size: 'md',
143
+ color: 'primary',
144
+ sticky: false
145
+ }
146
+ });
147
+ export const editorDefaults = {
148
+ defaultVariants: editorVariants.defaultVariants,
149
+ slots: {}
150
+ };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * SV5UI Editor — rich-text WYSIWYG built on Tiptap v3 + ProseMirror.
3
+ *
4
+ * ## Installation
5
+ *
6
+ * Tiptap is declared as an optional peer dependency of sv5ui, so consumers
7
+ * who don't use `<Editor>` pay zero install/bundle cost. When you do use it,
8
+ * install Tiptap alongside sv5ui:
9
+ *
10
+ * ```bash
11
+ * pnpm add sv5ui \
12
+ * @tiptap/core @tiptap/pm @tiptap/starter-kit \
13
+ * @tiptap/extension-bubble-menu \
14
+ * @tiptap/extension-character-count \
15
+ * @tiptap/extension-drag-handle \
16
+ * @tiptap/extension-image \
17
+ * @tiptap/extension-mention \
18
+ * @tiptap/extension-placeholder \
19
+ * @tiptap/extension-table \
20
+ * @tiptap/extension-table-cell \
21
+ * @tiptap/extension-table-header \
22
+ * @tiptap/extension-table-row \
23
+ * @tiptap/extension-text-align \
24
+ * @tiptap/extension-typography \
25
+ * @tiptap/extension-youtube \
26
+ * @tiptap/suggestion \
27
+ * tiptap-markdown
28
+ * ```
29
+ *
30
+ * (`npm add` / `yarn add` work equally well.)
31
+ *
32
+ * All 18 packages are required, even if you only enable a subset of
33
+ * features. Editor imports every extension at module load so toggling
34
+ * `image`, `tables`, `youtube`, etc. via props doesn't trigger a dynamic
35
+ * import. Missing peers fail at runtime with module-resolution errors.
36
+ *
37
+ * ## Usage
38
+ *
39
+ * ```svelte
40
+ * <script lang="ts">
41
+ * import { Editor, type EditorApi } from 'sv5ui/editor'
42
+ * let value = $state('<p>Hello</p>')
43
+ * let api = $state<EditorApi>()
44
+ * </script>
45
+ *
46
+ * <Editor bind:value bind:api placeholder="Write something…" />
47
+ * ```
48
+ *
49
+ * See {@link EditorProps} for every option.
50
+ */
51
+ export { default as Editor } from './Editor.svelte';
52
+ export { buildDefaultSlashCommands } from './editor.slash.svelte.js';
53
+ export type { EditorProps, EditorApi, EditorJSON, EditorReactiveState, MentionItem, SlashCommand, ToolbarAction } from './editor.types.js';
@@ -0,0 +1,52 @@
1
+ /**
2
+ * SV5UI Editor — rich-text WYSIWYG built on Tiptap v3 + ProseMirror.
3
+ *
4
+ * ## Installation
5
+ *
6
+ * Tiptap is declared as an optional peer dependency of sv5ui, so consumers
7
+ * who don't use `<Editor>` pay zero install/bundle cost. When you do use it,
8
+ * install Tiptap alongside sv5ui:
9
+ *
10
+ * ```bash
11
+ * pnpm add sv5ui \
12
+ * @tiptap/core @tiptap/pm @tiptap/starter-kit \
13
+ * @tiptap/extension-bubble-menu \
14
+ * @tiptap/extension-character-count \
15
+ * @tiptap/extension-drag-handle \
16
+ * @tiptap/extension-image \
17
+ * @tiptap/extension-mention \
18
+ * @tiptap/extension-placeholder \
19
+ * @tiptap/extension-table \
20
+ * @tiptap/extension-table-cell \
21
+ * @tiptap/extension-table-header \
22
+ * @tiptap/extension-table-row \
23
+ * @tiptap/extension-text-align \
24
+ * @tiptap/extension-typography \
25
+ * @tiptap/extension-youtube \
26
+ * @tiptap/suggestion \
27
+ * tiptap-markdown
28
+ * ```
29
+ *
30
+ * (`npm add` / `yarn add` work equally well.)
31
+ *
32
+ * All 18 packages are required, even if you only enable a subset of
33
+ * features. Editor imports every extension at module load so toggling
34
+ * `image`, `tables`, `youtube`, etc. via props doesn't trigger a dynamic
35
+ * import. Missing peers fail at runtime with module-resolution errors.
36
+ *
37
+ * ## Usage
38
+ *
39
+ * ```svelte
40
+ * <script lang="ts">
41
+ * import { Editor, type EditorApi } from 'sv5ui/editor'
42
+ * let value = $state('<p>Hello</p>')
43
+ * let api = $state<EditorApi>()
44
+ * </script>
45
+ *
46
+ * <Editor bind:value bind:api placeholder="Write something…" />
47
+ * ```
48
+ *
49
+ * See {@link EditorProps} for every option.
50
+ */
51
+ export { default as Editor } from './Editor.svelte';
52
+ export { buildDefaultSlashCommands } from './editor.slash.svelte.js';
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" module>
2
- import type { FileUploadProps } from './file-upload.types.js'
2
+ import type { FileUploadProps, FileUploadRejection } from './file-upload.types.js'
3
3
 
4
4
  export type Props = FileUploadProps
5
5
  </script>
@@ -12,6 +12,7 @@
12
12
  import Icon from '../Icon/Icon.svelte'
13
13
  import Button from '../Button/Button.svelte'
14
14
  import Modal from '../Modal/Modal.svelte'
15
+ import { useFormField, useFormFieldEmit } from '../hooks/useFormField.svelte.js'
15
16
 
16
17
  const config = getComponentConfig('fileUpload', fileUploadDefaults)
17
18
  const icons = getComponentConfig('icons', iconsDefaults)
@@ -22,6 +23,9 @@
22
23
  onValueChange,
23
24
  multiple = false,
24
25
  accept,
26
+ maxSize,
27
+ maxFiles,
28
+ onReject,
25
29
  dropzone = true,
26
30
  interactive = true,
27
31
  label = 'Drop files here or click to upload',
@@ -39,6 +43,7 @@
39
43
  required = false,
40
44
  fileIcon = icons.file,
41
45
  imagePreview = true,
46
+ id,
42
47
  name,
43
48
  leadingSlot,
44
49
  labelSlot,
@@ -59,6 +64,9 @@
59
64
  let previewOpen = $state(false)
60
65
  let previewFile = $state<File | null>(null)
61
66
 
67
+ const formFieldContext = useFormField()
68
+ const emit = useFormFieldEmit()
69
+
62
70
  // Stable file identity key with separator to avoid collisions
63
71
  const fileKey = (f: File) => `${f.name}:${f.size}:${f.lastModified}`
64
72
 
@@ -67,8 +75,23 @@
67
75
  // eslint-disable-next-line svelte/prefer-svelte-reactivity
68
76
  const urlCache = new Map<string, string>()
69
77
 
78
+ const hasError = $derived(
79
+ formFieldContext?.error !== undefined && formFieldContext?.error !== false
80
+ )
81
+ const resolvedHighlight = $derived(highlight || hasError)
82
+ const resolvedId = $derived(id ?? formFieldContext?.ariaId)
83
+ const resolvedName = $derived(name ?? formFieldContext?.name)
84
+ const ariaDescribedBy = $derived(
85
+ !formFieldContext
86
+ ? undefined
87
+ : hasError
88
+ ? `${formFieldContext.ariaId}-error`
89
+ : `${formFieldContext.ariaId}-description ${formFieldContext.ariaId}-help`
90
+ )
91
+
70
92
  const isDisabled = $derived(disabled || loading)
71
93
  const isDragging = $derived(dragCounter > 0)
94
+ const isFull = $derived(maxFiles !== undefined && value.length >= maxFiles)
72
95
  const showFilesInside = $derived(
73
96
  layout === 'grid' && !multiple && value.length > 0 && preview && variant === 'area'
74
97
  )
@@ -76,13 +99,13 @@
76
99
  // Pass booleans directly so compound variants with `false` values match correctly
77
100
  const slots = $derived(
78
101
  fileUploadVariants({
79
- color,
102
+ color: hasError ? 'error' : color,
80
103
  size,
81
104
  variant,
82
105
  layout,
83
106
  dropzone,
84
107
  interactive: interactive && !isDisabled,
85
- highlight,
108
+ highlight: resolvedHighlight,
86
109
  multiple,
87
110
  disabled: isDisabled
88
111
  })
@@ -150,17 +173,53 @@
150
173
  })
151
174
  }
152
175
 
176
+ function validateIngress(file: File): FileUploadRejection['reason'] | null {
177
+ if (accept && !isFileAccepted(file)) return 'accept'
178
+ if (maxSize !== undefined && file.size > maxSize) return 'maxSize'
179
+ return null
180
+ }
181
+
182
+ function applyMaxFiles(candidates: File[]): {
183
+ accepted: File[]
184
+ rejected: FileUploadRejection[]
185
+ } {
186
+ if (maxFiles === undefined) return { accepted: candidates, rejected: [] }
187
+ const remaining = Math.max(0, maxFiles - value.length)
188
+ if (candidates.length <= remaining) return { accepted: candidates, rejected: [] }
189
+ return {
190
+ accepted: candidates.slice(0, remaining),
191
+ rejected: candidates.slice(remaining).map((file) => ({ file, reason: 'maxFiles' }))
192
+ }
193
+ }
194
+
153
195
  function addFiles(newFiles: File[]) {
154
196
  if (isDisabled) return
155
- const filtered = accept ? newFiles.filter(isFileAccepted) : newFiles
156
- if (!filtered.length) return
197
+
198
+ const rejected: FileUploadRejection[] = []
199
+ const passed: File[] = []
200
+ for (const file of newFiles) {
201
+ const reason = validateIngress(file)
202
+ if (reason) rejected.push({ file, reason })
203
+ else passed.push(file)
204
+ }
205
+
206
+ let accepted: File[]
157
207
  if (!multiple) {
158
- value = [filtered[0]]
208
+ accepted = passed.slice(0, 1)
159
209
  } else {
160
210
  const existing = new Set(value.map(fileKey))
161
- value = [...value, ...filtered.filter((f) => !existing.has(fileKey(f)))]
211
+ const deduped = passed.filter((f) => !existing.has(fileKey(f)))
212
+ const result = applyMaxFiles(deduped)
213
+ accepted = result.accepted
214
+ rejected.push(...result.rejected)
162
215
  }
163
- onValueChange?.(value)
216
+
217
+ if (accepted.length) {
218
+ value = multiple ? [...value, ...accepted] : accepted
219
+ onValueChange?.(value)
220
+ emit.onChange()
221
+ }
222
+ if (rejected.length) onReject?.(rejected)
164
223
  }
165
224
 
166
225
  function removeFile(index: number) {
@@ -176,6 +235,7 @@
176
235
  }
177
236
  value = value.filter((_, i) => i !== index)
178
237
  onValueChange?.(value)
238
+ emit.onChange()
179
239
  }
180
240
 
181
241
  export function clearAll() {
@@ -185,6 +245,7 @@
185
245
  urlCache.clear()
186
246
  value = []
187
247
  onValueChange?.(value)
248
+ emit.onChange()
188
249
  }
189
250
 
190
251
  function handleInputChange(e: Event) {
@@ -254,13 +315,13 @@
254
315
  }
255
316
  </script>
256
317
 
257
- <div {...restProps} bind:this={ref} class={classes.root}>
318
+ <div {...restProps} bind:this={ref} class={classes.root} data-full={isFull ? '' : undefined}>
258
319
  <!-- Hidden file input — uses auto-generated id internally -->
259
320
  <input
260
321
  bind:this={inputRef}
261
322
  type="file"
262
323
  id={autoId}
263
- {name}
324
+ name={resolvedName}
264
325
  {accept}
265
326
  {multiple}
266
327
  {required}
@@ -275,18 +336,23 @@
275
336
  <!-- Area / Dropzone -->
276
337
  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
277
338
  <div
339
+ id={resolvedId}
278
340
  class={classes.base}
279
341
  data-dragging={isDragging ? '' : undefined}
280
342
  role={interactive ? 'button' : undefined}
281
343
  tabindex={interactive && !isDisabled ? 0 : undefined}
282
344
  aria-disabled={isDisabled || undefined}
283
345
  aria-label={interactive ? label : undefined}
346
+ aria-invalid={resolvedHighlight ? true : undefined}
347
+ aria-describedby={ariaDescribedBy}
284
348
  onclick={handleAreaClick}
285
349
  ondragenter={handleDragEnter}
286
350
  ondragover={handleDragOver}
287
351
  ondragleave={handleDragLeave}
288
352
  ondrop={handleDrop}
289
353
  onkeydown={handleKeydown}
354
+ onfocus={() => emit.onFocus()}
355
+ onblur={() => emit.onBlur()}
290
356
  >
291
357
  {#if showFilesInside}
292
358
  <!-- Grid single: file fills the area as overlay -->
@@ -390,6 +456,7 @@
390
456
  {:else}
391
457
  <!-- Button variant -->
392
458
  <Button
459
+ id={resolvedId}
393
460
  {color}
394
461
  {size}
395
462
  disabled={isDisabled}
@@ -397,7 +464,11 @@
397
464
  {loadingIcon}
398
465
  leadingIcon={loading ? undefined : icon}
399
466
  {label}
467
+ aria-invalid={resolvedHighlight ? true : undefined}
468
+ aria-describedby={ariaDescribedBy}
400
469
  onclick={handleAreaClick}
470
+ onfocus={() => emit.onFocus()}
471
+ onblur={() => emit.onBlur()}
401
472
  />
402
473
  {/if}
403
474
 
@@ -2,6 +2,21 @@ import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
3
  import type { ClassNameValue } from 'tailwind-merge';
4
4
  import type { FileUploadVariantProps, FileUploadSlots } from './file-upload.variants.js';
5
+ /**
6
+ * Reason a file was rejected by FileUpload.
7
+ *
8
+ * - `accept`: file did not match the `accept` MIME/extension filter
9
+ * - `maxSize`: file exceeded the `maxSize` byte limit
10
+ * - `maxFiles`: file would have pushed the selection past `maxFiles`
11
+ */
12
+ export type FileUploadRejectionReason = 'accept' | 'maxSize' | 'maxFiles';
13
+ /**
14
+ * A single rejected file along with the reason it was rejected.
15
+ */
16
+ export interface FileUploadRejection {
17
+ file: File;
18
+ reason: FileUploadRejectionReason;
19
+ }
5
20
  export type FileUploadProps = Omit<HTMLAttributes<HTMLElement>, 'class' | 'children'> & {
6
21
  /**
7
22
  * Bindable reference to the root DOM element.
@@ -25,6 +40,30 @@ export type FileUploadProps = Omit<HTMLAttributes<HTMLElement>, 'class' | 'child
25
40
  * Accepted file types as MIME types or extensions (e.g. "image/*,.pdf").
26
41
  */
27
42
  accept?: string;
43
+ /**
44
+ * Maximum allowed size per file, in bytes. Files exceeding this are
45
+ * rejected and reported through `onReject`.
46
+ *
47
+ * @example
48
+ * ```svelte
49
+ * <FileUpload maxSize={5 * 1024 * 1024} /> <!-- 5 MB -->
50
+ * ```
51
+ */
52
+ maxSize?: number;
53
+ /**
54
+ * Maximum number of files that can be selected. When the current
55
+ * selection plus the incoming files would exceed this, the excess
56
+ * files are rejected and reported through `onReject`. The root element
57
+ * exposes a `data-full` attribute when the limit is reached, so the
58
+ * upload area can be styled accordingly.
59
+ */
60
+ maxFiles?: number;
61
+ /**
62
+ * Called when one or more incoming files are rejected by `accept`,
63
+ * `maxSize`, or `maxFiles`. Receives the full rejection list for a
64
+ * single user action (one drop or one input change).
65
+ */
66
+ onReject?: (rejected: FileUploadRejection[]) => void;
28
67
  /**
29
68
  * Enable drag-and-drop file upload.
30
69
  * @default true
@@ -1,2 +1,2 @@
1
1
  export { default as FileUpload } from './FileUpload.svelte';
2
- export type { FileUploadProps } from './file-upload.types.js';
2
+ export type { FileUploadProps, FileUploadRejection, FileUploadRejectionReason } from './file-upload.types.js';
@@ -28,8 +28,9 @@
28
28
  description,
29
29
  overlay: showOverlay = config.defaultVariants.overlay ?? true,
30
30
  scrollable = config.defaultVariants.scrollable ?? false,
31
- transition = config.defaultVariants.transition ?? true,
32
- fullscreen = config.defaultVariants.fullscreen ?? false,
31
+ transition = config.defaultVariants.transition ?? 'scale',
32
+ size = config.defaultVariants.size ?? 'md',
33
+ fullscreen = false,
33
34
  portal = true,
34
35
  close: closeProp = true,
35
36
  dismissible = true,
@@ -46,6 +47,11 @@
46
47
  closeSlot
47
48
  }: Props = $props()
48
49
 
50
+ const resolvedSize = $derived(fullscreen ? 'full' : size)
51
+ const resolvedTransition = $derived(
52
+ transition === false ? 'none' : transition === true ? 'scale' : transition
53
+ )
54
+
49
55
  const showClose = $derived(!!closeProp)
50
56
  const closeProps = $derived(typeof closeProp === 'object' ? closeProp : {})
51
57
 
@@ -57,7 +63,12 @@
57
63
  )
58
64
 
59
65
  const variantSlots = $derived(
60
- modalVariants({ transition, fullscreen, overlay: showOverlay, scrollable })
66
+ modalVariants({
67
+ transition: resolvedTransition,
68
+ size: resolvedSize,
69
+ overlay: showOverlay,
70
+ scrollable
71
+ })
61
72
  )
62
73
 
63
74
  const classes = $derived({
@@ -43,15 +43,26 @@ export interface ModalProps extends RootProps, ContentProps {
43
43
  */
44
44
  scrollable?: ModalVariantProps['scrollable'];
45
45
  /**
46
- * Animate the modal on open and close.
47
- * @default true
46
+ * Controls the entrance/exit animation.
47
+ * - `'none'` / `false`: no animation
48
+ * - `'fade'`: overlay + content fade
49
+ * - `'slide'`: overlay fade + content slide-in from top
50
+ * - `'scale'` / `true`: overlay fade + content scale-in (default)
51
+ * @default 'scale'
52
+ */
53
+ transition?: ModalVariantProps['transition'] | boolean;
54
+ /**
55
+ * Controls the modal width. The `'full'` value expands to fill the
56
+ * entire viewport (replaces the deprecated `fullscreen` prop).
57
+ * @default 'md'
48
58
  */
49
- transition?: ModalVariantProps['transition'];
59
+ size?: ModalVariantProps['size'];
50
60
  /**
51
61
  * Expand the modal to fill the entire viewport.
62
+ * @deprecated Use `size="full"` instead. Retained as an alias for backward compatibility.
52
63
  * @default false
53
64
  */
54
- fullscreen?: ModalVariantProps['fullscreen'];
65
+ fullscreen?: boolean;
55
66
  /**
56
67
  * Render the modal content in a portal appended to `<body>`.
57
68
  * @default true