reburn-ui 0.2.1 → 0.3.1

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 (133) hide show
  1. package/dist/core/MantineProvider/color-functions/get-contrast-color.svelte.js +1 -1
  2. package/dist/core/MantineProvider/color-functions/index.d.ts +1 -1
  3. package/dist/core/MantineProvider/color-functions/index.js +1 -1
  4. package/dist/core/MantineProvider/color-functions/parse-theme-color.svelte.js +1 -1
  5. package/dist/core/MantineProvider/theme.svelte.js +1 -1
  6. package/dist/core/MantineProvider/theme.types.d.ts +5 -6
  7. package/dist/core/charts/ChartRoot/ChartContext.svelte.d.ts +64 -0
  8. package/dist/core/charts/ChartRoot/ChartContext.svelte.js +56 -0
  9. package/dist/core/charts/ChartRoot/ChartRoot.svelte +238 -0
  10. package/dist/core/charts/ChartRoot/ChartRoot.svelte.d.ts +87 -0
  11. package/dist/core/charts/ChartRoot/ChartXGrid.svelte +32 -0
  12. package/dist/core/charts/ChartRoot/ChartXGrid.svelte.d.ts +18 -0
  13. package/dist/core/charts/ChartRoot/ChartXLabels.svelte +26 -0
  14. package/dist/core/charts/ChartRoot/ChartXLabels.svelte.d.ts +18 -0
  15. package/dist/core/charts/ChartRoot/ChartYGrid.svelte +32 -0
  16. package/dist/core/charts/ChartRoot/ChartYGrid.svelte.d.ts +18 -0
  17. package/dist/core/charts/ChartRoot/ChartYLabels.svelte +31 -0
  18. package/dist/core/charts/ChartRoot/ChartYLabels.svelte.d.ts +18 -0
  19. package/dist/core/charts/ChartRoot/tickLabels.d.ts +8 -0
  20. package/dist/core/charts/ChartRoot/tickLabels.js +21 -0
  21. package/dist/core/charts/ChartTooltip/ChartTooltip.svelte +260 -0
  22. package/dist/core/charts/ChartTooltip/ChartTooltip.svelte.d.ts +34 -0
  23. package/dist/core/charts/ChartTooltip/ChartTooltipData.svelte +47 -0
  24. package/dist/core/charts/ChartTooltip/ChartTooltipData.svelte.d.ts +29 -0
  25. package/dist/core/charts/ChartTooltip/utils/findClosestElement.d.ts +2 -0
  26. package/dist/core/charts/ChartTooltip/utils/findClosestElement.js +21 -0
  27. package/dist/core/charts/ChartTooltip/utils/getTooltipPosition.d.ts +9 -0
  28. package/dist/core/charts/ChartTooltip/utils/getTooltipPosition.js +6 -0
  29. package/dist/core/charts/CompositeChart/CompositeChart.svelte +82 -0
  30. package/dist/core/charts/CompositeChart/CompositeChart.svelte.d.ts +60 -0
  31. package/dist/core/charts/LineChart/LineChart.svelte +30 -321
  32. package/dist/core/charts/LineChart/LineChart.svelte.d.ts +16 -64
  33. package/dist/core/charts/LineChart/LineChartInner.svelte +66 -0
  34. package/dist/core/charts/LineChart/LineChartInner.svelte.d.ts +34 -0
  35. package/dist/core/charts/ScatterChart/ScatterChart.svelte +33 -0
  36. package/dist/core/charts/ScatterChart/ScatterChart.svelte.d.ts +39 -0
  37. package/dist/core/charts/ScatterChart/ScatterChartInner.svelte +67 -0
  38. package/dist/core/charts/ScatterChart/ScatterChartInner.svelte.d.ts +32 -0
  39. package/dist/core/charts/d3/array/tick.d.ts +1 -0
  40. package/dist/core/charts/d3/array/tick.js +66 -0
  41. package/dist/core/charts/d3/scale/scaleLinear.d.ts +4 -0
  42. package/dist/core/charts/d3/scale/scaleLinear.js +14 -0
  43. package/dist/core/charts/d3/shape/curve/curveLinear.d.ts +2 -0
  44. package/dist/core/charts/d3/shape/curve/curveLinear.js +16 -0
  45. package/dist/core/charts/d3/shape/line.d.ts +7 -0
  46. package/dist/core/charts/d3/shape/line.js +6 -0
  47. package/dist/core/charts/d3/shape/toFixed.d.ts +1 -0
  48. package/dist/core/charts/d3/shape/toFixed.js +7 -0
  49. package/dist/core/charts/d3/shape/withPath.d.ts +1 -0
  50. package/dist/core/charts/d3/shape/withPath.js +18 -0
  51. package/dist/core/charts/index.d.ts +5 -0
  52. package/dist/core/charts/index.js +5 -0
  53. package/dist/core/charts/types.d.ts +10 -0
  54. package/dist/core/charts/utils/minMaxObject.d.ts +6 -0
  55. package/dist/core/charts/utils/minMaxObject.js +26 -0
  56. package/dist/core/components/Badge/Badge.svelte +1 -1
  57. package/dist/core/components/Burger/Burger.svelte +1 -1
  58. package/dist/core/components/Checkbox/Checkbox.svelte +1 -1
  59. package/dist/core/components/Checkbox/CheckboxCard/CheckboxCard.svelte +8 -6
  60. package/dist/core/components/Checkbox/CheckboxIndicator.svelte +4 -1
  61. package/dist/core/components/ColorPicker/ColorSlider.svelte +10 -14
  62. package/dist/core/components/ColorPicker/Saturation.svelte +8 -4
  63. package/dist/core/components/ColorPicker/converters/index.d.ts +2 -2
  64. package/dist/core/components/ColorPicker/converters/index.js +2 -2
  65. package/dist/core/components/Combobox/ComboboxChevron.svelte +4 -3
  66. package/dist/core/components/Combobox/ComboboxDropdown.svelte +0 -3
  67. package/dist/core/components/Dropzone/Dropzone.svelte +396 -0
  68. package/dist/core/components/Dropzone/Dropzone.svelte.d.ts +104 -0
  69. package/dist/core/components/Dropzone/DropzoneContext.svelte.js +3 -0
  70. package/dist/core/components/Dropzone/index.d.ts +3 -0
  71. package/dist/core/components/Dropzone/index.js +2 -0
  72. package/dist/core/components/Dropzone/mime-types.d.ts +30 -0
  73. package/dist/core/components/Dropzone/mime-types.js +41 -0
  74. package/dist/core/components/Dropzone/utils/acceptPropAsAccaptAttr.d.ts +5 -0
  75. package/dist/core/components/Dropzone/utils/acceptPropAsAccaptAttr.js +21 -0
  76. package/dist/core/components/Dropzone/utils/fromEvent.d.ts +6 -0
  77. package/dist/core/components/Dropzone/utils/fromEvent.js +45 -0
  78. package/dist/core/components/Dropzone/utils/getAllFilesAccepted.d.ts +35 -0
  79. package/dist/core/components/Dropzone/utils/getAllFilesAccepted.js +69 -0
  80. package/dist/core/components/Dropzone/utils/isEvtWithFiles.d.ts +1 -0
  81. package/dist/core/components/Dropzone/utils/isEvtWithFiles.js +8 -0
  82. package/dist/core/components/Dropzone/utils/isExt.d.ts +4 -0
  83. package/dist/core/components/Dropzone/utils/isExt.js +6 -0
  84. package/dist/core/components/Dropzone/utils/isMIMEType.d.ts +6 -0
  85. package/dist/core/components/Dropzone/utils/isMIMEType.js +8 -0
  86. package/dist/core/components/Dropzone/utils/isPropagationStopped.d.ts +1 -0
  87. package/dist/core/components/Dropzone/utils/isPropagationStopped.js +12 -0
  88. package/dist/core/components/Fieldset/Fieldset.svelte +76 -0
  89. package/dist/core/components/Fieldset/Fieldset.svelte.d.ts +15 -0
  90. package/dist/core/components/Floating/CreateFloating.svelte.js +0 -5
  91. package/dist/core/components/Group/Group.svelte +4 -9
  92. package/dist/core/components/Input/Input.svelte.d.ts +2 -2
  93. package/dist/core/components/InputBase/InputBase.svelte.d.ts +2 -2
  94. package/dist/core/components/Loader/Loader.svelte +1 -1
  95. package/dist/core/components/LoadingOverlay/LoadingOverlay.svelte +72 -0
  96. package/dist/core/components/LoadingOverlay/LoadingOverlay.svelte.d.ts +19 -0
  97. package/dist/core/components/Modal/ModalContent.svelte +4 -2
  98. package/dist/core/components/NavLink/NavLink.svelte +4 -3
  99. package/dist/core/components/Notification/Notification.svelte +5 -4
  100. package/dist/core/components/Pill/Pill.svelte +172 -0
  101. package/dist/core/components/Pill/Pill.svelte.d.ts +23 -0
  102. package/dist/core/components/Pill/PillGroup.svelte +47 -0
  103. package/dist/core/components/Pill/PillGroup.svelte.d.ts +13 -0
  104. package/dist/core/components/Pill/PillGroupContext.svelte.d.ts +15 -0
  105. package/dist/core/components/Pill/PillGroupContext.svelte.js +13 -0
  106. package/dist/core/components/Pill/index.d.ts +8 -0
  107. package/dist/core/components/Pill/index.js +5 -0
  108. package/dist/core/components/Progress/ProgressSection.svelte +3 -1
  109. package/dist/core/components/SegmentedControl/SegmentedControl.svelte +18 -7
  110. package/dist/core/components/Select/Select.svelte.d.ts +1 -1
  111. package/dist/core/components/Slider/SliderRoot.svelte +5 -1
  112. package/dist/core/components/Slider/Thumb.svelte +5 -1
  113. package/dist/core/components/Slider/Track.svelte +16 -6
  114. package/dist/core/components/Switch/Switch.svelte +1 -1
  115. package/dist/core/components/Table/Table.svelte +10 -12
  116. package/dist/core/components/Table/Table.svelte.d.ts +4 -1
  117. package/dist/core/components/Table/TableContext.svelte.d.ts +2 -0
  118. package/dist/core/components/Table/TableContext.svelte.js +1 -0
  119. package/dist/core/components/Table/TableTh.svelte +10 -1
  120. package/dist/core/components/Table/getTableDataAttr.d.ts +1 -0
  121. package/dist/core/components/Table/getTableDataAttr.js +3 -0
  122. package/dist/core/components/index.d.ts +4 -0
  123. package/dist/core/components/index.js +4 -0
  124. package/dist/core/hooks/use-id.d.ts +1 -0
  125. package/dist/core/hooks/use-id.js +4 -0
  126. package/dist/core/utils/get-default-z-index.d.ts +1 -1
  127. package/package.json +11 -9
  128. package/dist/core/charts/LineChart/LineChart.types.js +0 -1
  129. package/dist/core/charts/LineChart/types.d.ts +0 -68
  130. /package/dist/core/MantineProvider/color-functions/{get-primary-shade.d.ts → get-primary-shade.svelte.d.ts} +0 -0
  131. /package/dist/core/MantineProvider/color-functions/{get-primary-shade.js → get-primary-shade.svelte.js} +0 -0
  132. /package/dist/core/charts/{LineChart/types.js → types.js} +0 -0
  133. /package/dist/core/{charts/LineChart/LineChart.types.d.ts → components/Dropzone/DropzoneContext.svelte.d.ts} +0 -0
@@ -0,0 +1,396 @@
1
+ <script lang="ts" module>
2
+ import type { DivElement } from '../../element-types.js';
3
+ import { theme } from '../../MantineProvider/theme.svelte.js';
4
+ import type { MantineColor, MantineRadius } from '../../MantineProvider/theme.types.js';
5
+ import { getRadius } from '../../utils/get-size.js';
6
+ import type { Snippet } from 'svelte';
7
+ import type { HTMLInputAttributes } from 'svelte/elements';
8
+ import type { LoaderProps } from '../Loader/Loader.svelte';
9
+ import LoadingOverlay from '../LoadingOverlay/LoadingOverlay.svelte';
10
+ import { acceptPropAsAcceptAttr } from './utils/acceptPropAsAccaptAttr.js';
11
+ import { fromEvent } from './utils/fromEvent.js';
12
+ import { allFilesAccepted, fileAccepted, fileMatchSize, TOO_MANY_FILES_REJECTION } from './utils/getAllFilesAccepted.js';
13
+ import { isEvtWithFiles } from './utils/isEvtWithFiles.js';
14
+
15
+ export interface FileWithPath extends File {
16
+ readonly path?: string;
17
+ readonly handle?: FileSystemFileHandle;
18
+ readonly relativePath?: string;
19
+ }
20
+
21
+ export type DropzoneStatus = 'accept' | 'reject' | 'idle';
22
+
23
+ const errorCodes = {
24
+ FileInvalidType: 'file-invalid-type',
25
+ FileTooLarge: 'file-too-large',
26
+ FileTooSmall: 'file-too-small',
27
+ TooManyFiles: 'too-many-files',
28
+ } as const;
29
+
30
+ export interface FileRejection {
31
+ file: FileWithPath;
32
+ errors: readonly FileError[];
33
+ }
34
+
35
+ export interface FileError {
36
+ message: string;
37
+ code: keyof typeof errorCodes | string;
38
+ }
39
+ export type DropEvent = DragEvent | Event | Array<FileSystemFileHandle>;
40
+
41
+ export interface Accept {
42
+ [key: string]: readonly string[];
43
+ }
44
+
45
+ export type DropzoneVariant = 'filled' | 'light';
46
+
47
+ export interface DropzoneProps extends Omit<DivElement, 'ondrop' | 'children'> {
48
+ /** Key of `theme.colors` or any valid CSS color to set colors of `Dropzone.Accept`, `theme.primaryColor` by default */
49
+ acceptColor?: MantineColor;
50
+
51
+ /** Key of `theme.colors` or any valid CSS color to set colors of `Dropzone.Reject`, `'red'` by default */
52
+ rejectColor?: MantineColor;
53
+
54
+ /** Key of `theme.radius` or any valid CSS value to set `border-radius`, numbers are converted to rem, `theme.defaultRadius` by default */
55
+ radius?: MantineRadius;
56
+
57
+ /** Determines whether files capturing should be disabled, `false` by default */
58
+ disabled?: boolean;
59
+
60
+ /** Called when any files are dropped to the dropzone */
61
+ ondropany?: (files: FileWithPath[], fileRejections: FileRejection[]) => void;
62
+
63
+ /** Called when valid files are dropped to the dropzone */
64
+ ondrop: (files: FileWithPath[]) => void;
65
+
66
+ /** Called when dropped files do not meet file restrictions */
67
+ onreject?: (fileRejections: FileRejection[]) => void;
68
+
69
+ /** Determines whether a loading overlay should be displayed over the dropzone, `false` by default */
70
+ loading?: boolean;
71
+
72
+ /** Mime types of the files that dropzone can accepts. By default, dropzone accepts all file types. */
73
+ accept?: Accept | string[];
74
+
75
+ /** A ref function which when called opens the file system file picker */
76
+ openRef?: React.ForwardedRef<() => void | undefined>;
77
+
78
+ /** Determines whether multiple files can be dropped to the dropzone or selected from file system picker, `true` by default */
79
+ multiple?: boolean;
80
+
81
+ /** Minimum file size in bytes */
82
+ minSize?: number;
83
+
84
+ /** Maximum file size in bytes */
85
+ maxSize?: number;
86
+
87
+ /** Name of the form control. Submitted with the form as part of a name/value pair. */
88
+ name?: string;
89
+
90
+ /** Maximum number of files that can be picked at once */
91
+ maxFiles?: number;
92
+
93
+ /** Set to autofocus the root element */
94
+ autoFocus?: boolean;
95
+
96
+ /** If `false`, disables click to open the native file selection dialog */
97
+ activateOnClick?: boolean;
98
+
99
+ /** If `false`, disables drag 'n' drop */
100
+ activateOnDrag?: boolean;
101
+
102
+ /** If `false`, disables Space/Enter to open the native file selection dialog. Note that it also stops tracking the focus state. */
103
+ activateOnKeyboard?: boolean;
104
+
105
+ /** If `false`, stops drag event propagation to parents */
106
+ dragEventsBubbling?: boolean;
107
+
108
+ /** Called when the `dragenter` event occurs */
109
+ ondragenter?: (event: DragEvent) => void;
110
+
111
+ /** Called when the `dragleave` event occurs */
112
+ ondragleave?: (event: DragEvent) => void;
113
+
114
+ /** Called when the `dragover` event occurs */
115
+ ondragover?: (event: DragEvent) => void;
116
+
117
+ /** Called when user closes the file selection dialog with no selection */
118
+ onfiledialogcancel?: () => void;
119
+
120
+ /** Called when user opens the file selection dialog */
121
+ onfiledialogopen?: () => void;
122
+
123
+ /** If `false`, allow dropped items to take over the current browser window */
124
+ preventDropOnDocument?: boolean;
125
+
126
+ /** Set to true to use the File System Access API to open the file picker instead of using an <input type="file"> click event, defaults to true */
127
+ useFsAccessApi?: boolean;
128
+
129
+ /** Use this to provide a custom file aggregator */
130
+ getFilesFromEvent?: (event: DropEvent) => Promise<Array<File | DataTransferItem>>;
131
+
132
+ /** Custom validation function. It must return null if there's no errors. */
133
+ validator?: <T extends File>(file: T) => FileError | FileError[] | null;
134
+
135
+ /** Determines whether pointer events should be enabled on the inner element, `false` by default */
136
+ enablePointerEvents?: boolean;
137
+
138
+ /** Props passed down to the Loader component */
139
+ loaderProps?: LoaderProps;
140
+
141
+ /** Props passed down to the internal Input component */
142
+ inputProps?: HTMLInputAttributes;
143
+
144
+ /** Dropzone variant */
145
+ variant?: DropzoneVariant;
146
+
147
+ /** Dropzone children */
148
+ children?: Snippet<[status: DropzoneStatus]>;
149
+
150
+ value?: FileList | null;
151
+ }
152
+ </script>
153
+
154
+ <script lang="ts">
155
+ let {
156
+ multiple = true,
157
+ minSize = 0,
158
+ maxSize = Infinity,
159
+ activateOnClick = true,
160
+ activateOnDrag = true,
161
+ dragEventsBubbling = true,
162
+ activateOnKeyboard = true,
163
+ useFsAccessApi = true,
164
+ variant = 'light',
165
+ rejectColor = 'red',
166
+ acceptColor = theme.primaryColor,
167
+ loading,
168
+ disabled,
169
+ radius,
170
+ loaderProps,
171
+ children,
172
+ name,
173
+ ondragenter,
174
+ ondragover,
175
+ ondragleave,
176
+ getFilesFromEvent = fromEvent,
177
+ accept,
178
+ maxFiles = multiple ? Infinity : 1,
179
+ validator = () => null,
180
+ value = $bindable(),
181
+ ondropany,
182
+ ondrop,
183
+ onreject,
184
+ ...props
185
+ }: DropzoneProps = $props();
186
+
187
+ const acceptColors = $derived(theme.variantColorResolver({ color: acceptColor, variant }));
188
+ const rejectColors = $derived(theme.variantColorResolver({ color: rejectColor, variant }));
189
+
190
+ let isAccepted = $state(false);
191
+ let isRejected = $state(false);
192
+ let isDragActive = $state(false);
193
+
194
+ const isIdle = $derived(!isAccepted && !isRejected);
195
+
196
+ const status = $derived(isAccepted ? 'accept' : isRejected ? 'reject' : 'idle');
197
+
198
+ const acceptAttr = $derived(accept ? acceptPropAsAcceptAttr(accept) : '');
199
+
200
+ function handleDragEnter(event: DragEvent & { currentTarget: EventTarget & HTMLDivElement }) {
201
+ event.preventDefault();
202
+ ondragenter?.(event);
203
+
204
+ getFilesFromEvent(event)
205
+ .then((files) => {
206
+ const fileCount = files.length;
207
+ const isDragAccept =
208
+ fileCount > 0 &&
209
+ allFilesAccepted({
210
+ files,
211
+ accept: acceptAttr,
212
+ minSize,
213
+ maxSize,
214
+ multiple,
215
+ maxFiles,
216
+ validator,
217
+ });
218
+
219
+ isAccepted = isDragAccept;
220
+ isRejected = fileCount > 0 && !isDragAccept;
221
+ isDragActive = true;
222
+ })
223
+ .catch();
224
+ }
225
+
226
+ function handleDragOver(event: DragEvent & { currentTarget: EventTarget & HTMLDivElement }) {
227
+ event.preventDefault();
228
+ const hasFiles = isEvtWithFiles(event);
229
+
230
+ if (hasFiles && event.dataTransfer) {
231
+ try {
232
+ event.dataTransfer.dropEffect = 'copy';
233
+ } catch (error) {}
234
+ }
235
+
236
+ if (hasFiles && ondragover) {
237
+ ondragover(event);
238
+ }
239
+ }
240
+
241
+ function handleDragLeave(event: DragEvent & { currentTarget: EventTarget & HTMLDivElement }) {
242
+ event.preventDefault();
243
+
244
+ const isOutside = !event.relatedTarget || !event.currentTarget.contains(event.relatedTarget as Node);
245
+
246
+ if (!isOutside) return;
247
+ ondragleave?.(event);
248
+
249
+ isAccepted = false;
250
+ isRejected = false;
251
+ isDragActive = false;
252
+ }
253
+
254
+ function setFiles(files: File[], event: DragEvent & { currentTarget: EventTarget & HTMLDivElement }) {
255
+ const acceptedFiles: File[] = [];
256
+ const fileRejections: FileRejection[] = [];
257
+
258
+ files.forEach((file) => {
259
+ const [accepted, acceptError] = fileAccepted(file, acceptAttr || '');
260
+ const [sizeMatch, sizeError] = fileMatchSize(file, minSize, maxSize);
261
+ const customErrors = validator ? validator(file) : null;
262
+
263
+ if (accepted && sizeMatch && !customErrors) {
264
+ acceptedFiles.push(file);
265
+ } else {
266
+ let errors = [acceptError, sizeError];
267
+
268
+ if (customErrors) {
269
+ errors = errors.concat(customErrors);
270
+ }
271
+
272
+ fileRejections.push({ file, errors: errors.filter((e) => e) });
273
+ }
274
+ });
275
+
276
+ if ((!multiple && acceptedFiles.length > 1) || (multiple && maxFiles >= 1 && acceptedFiles.length > maxFiles)) {
277
+ // Reject everything and empty accepted files
278
+ acceptedFiles.forEach((file) => {
279
+ fileRejections.push({ file, errors: [TOO_MANY_FILES_REJECTION] });
280
+ });
281
+ acceptedFiles.splice(0);
282
+ }
283
+
284
+ value = acceptedFiles;
285
+
286
+ ondropany?.(acceptedFiles, fileRejections, event);
287
+ if (acceptedFiles.length > 0) ondrop?.(acceptedFiles, event);
288
+ if (fileRejections.length > 0) onreject?.(fileRejections, event);
289
+
290
+ isAccepted = false;
291
+ isRejected = false;
292
+ isDragActive = false;
293
+ }
294
+
295
+ function handleDrop(event: DragEvent & { currentTarget: EventTarget & HTMLDivElement }) {
296
+ event.preventDefault();
297
+ event.stopPropagation();
298
+
299
+ const hasFiles = isEvtWithFiles(event);
300
+
301
+ if (!hasFiles) return;
302
+
303
+ getFilesFromEvent(event).then((files) => {
304
+ setFiles(files, event);
305
+ });
306
+ }
307
+ </script>
308
+
309
+ <div
310
+ {...props}
311
+ ondragenter={handleDragEnter}
312
+ ondragover={handleDragOver}
313
+ ondragleave={handleDragLeave}
314
+ ondrop={handleDrop}
315
+ class="root"
316
+ style:--dropzone-radius={getRadius(radius)}
317
+ style:--dropzone-accept-color={acceptColors.color}
318
+ style:--dropzone-accept-bg={acceptColors.background}
319
+ style:--dropzone-reject-color={rejectColors.color}
320
+ style:--dropzone-reject-bg={rejectColors.background}
321
+ data-accept={isAccepted || undefined}
322
+ data-reject={isRejected || undefined}
323
+ data-idle={isIdle || undefined}
324
+ data-disabled={disabled || undefined}
325
+ data-loading={loading || undefined}
326
+ data-activate-on-click={activateOnClick || undefined}
327
+ >
328
+ <LoadingOverlay visible={loading} overlayProps={{ radius }} {loaderProps} />
329
+
330
+ <input class="input" type="file" {name} {multiple} tabindex={-1} bind:value />
331
+
332
+ <div class="inner">
333
+ {@render children?.(status)}
334
+ </div>
335
+ </div>
336
+
337
+ <style>.root {
338
+ position: relative;
339
+ border: 1px dashed;
340
+ color: var(--mantine-color-text);
341
+ padding: var(--mantine-spacing-md);
342
+ border-radius: var(--dropzone-radius);
343
+ cursor: pointer;
344
+ user-select: none;
345
+ transition: background-color 100ms ease, border-color 100ms ease;
346
+ }
347
+ .root:where([data-loading]), .root:where(:not([data-activate-on-click])) {
348
+ cursor: default;
349
+ }
350
+ :global(:where([data-mantine-color-scheme="light"])) .root {
351
+ background-color: var(--mantine-color-white);
352
+ border-color: var(--mantine-color-gray-4);
353
+ }
354
+ :global(:where([data-mantine-color-scheme="dark"])) .root {
355
+ background-color: var(--mantine-color-dark-6);
356
+ border-color: var(--mantine-color-dark-4);
357
+ }
358
+ @media (hover: hover) {
359
+ :global(:where([data-mantine-color-scheme="light"])) .root:hover:where([data-activate-on-click]:not([data-loading])) {
360
+ background-color: var(--mantine-color-gray-0);
361
+ }
362
+ :global(:where([data-mantine-color-scheme="dark"])) .root:hover:where([data-activate-on-click]:not([data-loading])) {
363
+ background-color: var(--mantine-color-dark-5);
364
+ }
365
+ }
366
+ @media (hover: none) {
367
+ :global(:where([data-mantine-color-scheme="light"])) .root:active:where([data-activate-on-click]:not([data-loading])) {
368
+ background-color: var(--mantine-color-gray-0);
369
+ }
370
+ :global(:where([data-mantine-color-scheme="dark"])) .root:active:where([data-activate-on-click]:not([data-loading])) {
371
+ background-color: var(--mantine-color-dark-5);
372
+ }
373
+ }
374
+ .root:where([data-accept]) {
375
+ background-color: var(--dropzone-accept-bg);
376
+ border-color: var(--dropzone-accept-bg);
377
+ color: var(--dropzone-accept-color);
378
+ }
379
+ .root:where([data-reject]) {
380
+ background-color: var(--dropzone-reject-bg);
381
+ border-color: var(--dropzone-reject-bg);
382
+ color: var(--dropzone-reject-color);
383
+ }
384
+
385
+ .input {
386
+ border: 0px;
387
+ clip: rect(0px, 0px, 0px, 0px);
388
+ clip-path: inset(50%);
389
+ height: 1px;
390
+ margin: 0px -1px -1px 0px;
391
+ overflow: hidden;
392
+ padding: 0px;
393
+ position: absolute;
394
+ width: 1px;
395
+ white-space: nowrap;
396
+ }</style>
@@ -0,0 +1,104 @@
1
+ import type { DivElement } from '../../element-types.js';
2
+ import type { MantineColor, MantineRadius } from '../../MantineProvider/theme.types.js';
3
+ import type { Snippet } from 'svelte';
4
+ import type { HTMLInputAttributes } from 'svelte/elements';
5
+ import type { LoaderProps } from '../Loader/Loader.svelte';
6
+ export interface FileWithPath extends File {
7
+ readonly path?: string;
8
+ readonly handle?: FileSystemFileHandle;
9
+ readonly relativePath?: string;
10
+ }
11
+ export type DropzoneStatus = 'accept' | 'reject' | 'idle';
12
+ declare const errorCodes: {
13
+ readonly FileInvalidType: "file-invalid-type";
14
+ readonly FileTooLarge: "file-too-large";
15
+ readonly FileTooSmall: "file-too-small";
16
+ readonly TooManyFiles: "too-many-files";
17
+ };
18
+ export interface FileRejection {
19
+ file: FileWithPath;
20
+ errors: readonly FileError[];
21
+ }
22
+ export interface FileError {
23
+ message: string;
24
+ code: keyof typeof errorCodes | string;
25
+ }
26
+ export type DropEvent = DragEvent | Event | Array<FileSystemFileHandle>;
27
+ export interface Accept {
28
+ [key: string]: readonly string[];
29
+ }
30
+ export type DropzoneVariant = 'filled' | 'light';
31
+ export interface DropzoneProps extends Omit<DivElement, 'ondrop' | 'children'> {
32
+ /** Key of `theme.colors` or any valid CSS color to set colors of `Dropzone.Accept`, `theme.primaryColor` by default */
33
+ acceptColor?: MantineColor;
34
+ /** Key of `theme.colors` or any valid CSS color to set colors of `Dropzone.Reject`, `'red'` by default */
35
+ rejectColor?: MantineColor;
36
+ /** Key of `theme.radius` or any valid CSS value to set `border-radius`, numbers are converted to rem, `theme.defaultRadius` by default */
37
+ radius?: MantineRadius;
38
+ /** Determines whether files capturing should be disabled, `false` by default */
39
+ disabled?: boolean;
40
+ /** Called when any files are dropped to the dropzone */
41
+ ondropany?: (files: FileWithPath[], fileRejections: FileRejection[]) => void;
42
+ /** Called when valid files are dropped to the dropzone */
43
+ ondrop: (files: FileWithPath[]) => void;
44
+ /** Called when dropped files do not meet file restrictions */
45
+ onreject?: (fileRejections: FileRejection[]) => void;
46
+ /** Determines whether a loading overlay should be displayed over the dropzone, `false` by default */
47
+ loading?: boolean;
48
+ /** Mime types of the files that dropzone can accepts. By default, dropzone accepts all file types. */
49
+ accept?: Accept | string[];
50
+ /** A ref function which when called opens the file system file picker */
51
+ openRef?: React.ForwardedRef<() => void | undefined>;
52
+ /** Determines whether multiple files can be dropped to the dropzone or selected from file system picker, `true` by default */
53
+ multiple?: boolean;
54
+ /** Minimum file size in bytes */
55
+ minSize?: number;
56
+ /** Maximum file size in bytes */
57
+ maxSize?: number;
58
+ /** Name of the form control. Submitted with the form as part of a name/value pair. */
59
+ name?: string;
60
+ /** Maximum number of files that can be picked at once */
61
+ maxFiles?: number;
62
+ /** Set to autofocus the root element */
63
+ autoFocus?: boolean;
64
+ /** If `false`, disables click to open the native file selection dialog */
65
+ activateOnClick?: boolean;
66
+ /** If `false`, disables drag 'n' drop */
67
+ activateOnDrag?: boolean;
68
+ /** If `false`, disables Space/Enter to open the native file selection dialog. Note that it also stops tracking the focus state. */
69
+ activateOnKeyboard?: boolean;
70
+ /** If `false`, stops drag event propagation to parents */
71
+ dragEventsBubbling?: boolean;
72
+ /** Called when the `dragenter` event occurs */
73
+ ondragenter?: (event: DragEvent) => void;
74
+ /** Called when the `dragleave` event occurs */
75
+ ondragleave?: (event: DragEvent) => void;
76
+ /** Called when the `dragover` event occurs */
77
+ ondragover?: (event: DragEvent) => void;
78
+ /** Called when user closes the file selection dialog with no selection */
79
+ onfiledialogcancel?: () => void;
80
+ /** Called when user opens the file selection dialog */
81
+ onfiledialogopen?: () => void;
82
+ /** If `false`, allow dropped items to take over the current browser window */
83
+ preventDropOnDocument?: boolean;
84
+ /** Set to true to use the File System Access API to open the file picker instead of using an <input type="file"> click event, defaults to true */
85
+ useFsAccessApi?: boolean;
86
+ /** Use this to provide a custom file aggregator */
87
+ getFilesFromEvent?: (event: DropEvent) => Promise<Array<File | DataTransferItem>>;
88
+ /** Custom validation function. It must return null if there's no errors. */
89
+ validator?: <T extends File>(file: T) => FileError | FileError[] | null;
90
+ /** Determines whether pointer events should be enabled on the inner element, `false` by default */
91
+ enablePointerEvents?: boolean;
92
+ /** Props passed down to the Loader component */
93
+ loaderProps?: LoaderProps;
94
+ /** Props passed down to the internal Input component */
95
+ inputProps?: HTMLInputAttributes;
96
+ /** Dropzone variant */
97
+ variant?: DropzoneVariant;
98
+ /** Dropzone children */
99
+ children?: Snippet<[status: DropzoneStatus]>;
100
+ value?: FileList | null;
101
+ }
102
+ declare const Dropzone: import("svelte").Component<DropzoneProps, {}, "value">;
103
+ type Dropzone = ReturnType<typeof Dropzone>;
104
+ export default Dropzone;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ class DropzoneContext {
3
+ }
@@ -0,0 +1,3 @@
1
+ export { default as Dropzone } from './Dropzone.svelte';
2
+ export type { DropzoneStatus } from './Dropzone.svelte';
3
+ export { MIME_TYPES } from './mime-types.js';
@@ -0,0 +1,2 @@
1
+ export { default as Dropzone } from './Dropzone.svelte';
2
+ export { MIME_TYPES } from './mime-types.js';
@@ -0,0 +1,30 @@
1
+ export declare const MIME_TYPES: {
2
+ readonly png: "image/png";
3
+ readonly gif: "image/gif";
4
+ readonly jpeg: "image/jpeg";
5
+ readonly svg: "image/svg+xml";
6
+ readonly webp: "image/webp";
7
+ readonly avif: "image/avif";
8
+ readonly heic: "image/heic";
9
+ readonly heif: "image/heif";
10
+ readonly mp4: "video/mp4";
11
+ readonly zip: "application/zip";
12
+ readonly rar: "application/x-rar";
13
+ readonly '7z': "application/x-7z-compressed";
14
+ readonly csv: "text/csv";
15
+ readonly pdf: "application/pdf";
16
+ readonly doc: "application/msword";
17
+ readonly docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
18
+ readonly xls: "application/vnd.ms-excel";
19
+ readonly xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
20
+ readonly ppt: "application/vnd.ms-powerpoint";
21
+ readonly pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation";
22
+ readonly exe: "application/vnd.microsoft.portable-executable";
23
+ readonly tsv: "text/tab-separated-values";
24
+ };
25
+ export declare const IMAGE_MIME_TYPE: ("image/png" | "image/gif" | "image/jpeg" | "image/svg+xml" | "image/webp" | "image/avif" | "image/heic" | "image/heif")[];
26
+ export declare const PDF_MIME_TYPE: "application/pdf"[];
27
+ export declare const MS_WORD_MIME_TYPE: ("application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document")[];
28
+ export declare const MS_EXCEL_MIME_TYPE: ("application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")[];
29
+ export declare const MS_POWERPOINT_MIME_TYPE: ("application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation")[];
30
+ export declare const EXE_MIME_TYPE: "application/vnd.microsoft.portable-executable"[];
@@ -0,0 +1,41 @@
1
+ export const MIME_TYPES = {
2
+ // Images
3
+ png: 'image/png',
4
+ gif: 'image/gif',
5
+ jpeg: 'image/jpeg',
6
+ svg: 'image/svg+xml',
7
+ webp: 'image/webp',
8
+ avif: 'image/avif',
9
+ heic: 'image/heic',
10
+ heif: 'image/heif',
11
+ // Documents
12
+ mp4: 'video/mp4',
13
+ zip: 'application/zip',
14
+ rar: 'application/x-rar',
15
+ '7z': 'application/x-7z-compressed',
16
+ csv: 'text/csv',
17
+ pdf: 'application/pdf',
18
+ doc: 'application/msword',
19
+ docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
20
+ xls: 'application/vnd.ms-excel',
21
+ xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
22
+ ppt: 'application/vnd.ms-powerpoint',
23
+ pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
24
+ exe: 'application/vnd.microsoft.portable-executable',
25
+ tsv: 'text/tab-separated-values',
26
+ };
27
+ export const IMAGE_MIME_TYPE = [
28
+ MIME_TYPES.png,
29
+ MIME_TYPES.gif,
30
+ MIME_TYPES.jpeg,
31
+ MIME_TYPES.svg,
32
+ MIME_TYPES.webp,
33
+ MIME_TYPES.avif,
34
+ MIME_TYPES.heic,
35
+ MIME_TYPES.heif,
36
+ ];
37
+ export const PDF_MIME_TYPE = [MIME_TYPES.pdf];
38
+ export const MS_WORD_MIME_TYPE = [MIME_TYPES.doc, MIME_TYPES.docx];
39
+ export const MS_EXCEL_MIME_TYPE = [MIME_TYPES.xls, MIME_TYPES.xlsx];
40
+ export const MS_POWERPOINT_MIME_TYPE = [MIME_TYPES.ppt, MIME_TYPES.pptx];
41
+ export const EXE_MIME_TYPE = [MIME_TYPES.exe];
@@ -0,0 +1,5 @@
1
+ import type { Accept } from '../Dropzone.svelte';
2
+ /**
3
+ * Convert the `{accept}` dropzone prop to an array of MIME types/extensions.
4
+ */
5
+ export declare function acceptPropAsAcceptAttr(accept: Accept): string | undefined;
@@ -0,0 +1,21 @@
1
+ import { isExt } from './isExt.js';
2
+ import { isMIMEType } from './isMIMEType.js';
3
+ /**
4
+ * Convert the `{accept}` dropzone prop to an array of MIME types/extensions.
5
+ */
6
+ export function acceptPropAsAcceptAttr(accept) {
7
+ if (!accept)
8
+ return;
9
+ const acceptSet = [];
10
+ for (const [mimeType, ext] of Object.entries(accept)) {
11
+ if (isMIMEType(mimeType)) {
12
+ acceptSet.push(mimeType);
13
+ }
14
+ for (let i = 0; i < ext.length; i++) {
15
+ if (isExt(ext[i])) {
16
+ acceptSet.push(ext[i]);
17
+ }
18
+ }
19
+ }
20
+ return acceptSet.join(',');
21
+ }
@@ -0,0 +1,6 @@
1
+ export interface FileWithPath extends File {
2
+ readonly path?: string;
3
+ readonly handle?: FileSystemFileHandle;
4
+ readonly relativePath?: string;
5
+ }
6
+ export declare function fromEvent(evt: Event | any): Promise<(FileWithPath | DataTransferItem)[]>;
@@ -0,0 +1,45 @@
1
+ export async function fromEvent(evt) {
2
+ if (isDragEvent(evt) && evt.dataTransfer) {
3
+ return getDataTransferFiles(evt.dataTransfer, evt.type);
4
+ }
5
+ else if (isChangeEvent(evt)) {
6
+ return getInputFiles(evt);
7
+ }
8
+ else if (Array.isArray(evt) && evt.every((item) => 'getFile' in item)) {
9
+ return getFsHandleFiles(evt);
10
+ }
11
+ return [];
12
+ }
13
+ function isDragEvent(evt) {
14
+ return evt && typeof evt === 'object' && 'dataTransfer' in evt;
15
+ }
16
+ function isChangeEvent(evt) {
17
+ return evt && typeof evt === 'object' && evt.type === 'change' && 'target' in evt;
18
+ }
19
+ async function getDataTransferFiles(dt, type) {
20
+ const items = Array.from(dt.items).filter((item) => item.kind === 'file');
21
+ if (type !== 'drop') {
22
+ return items;
23
+ }
24
+ const files = await Promise.all(items.map(async (item) => {
25
+ if (item.kind === 'file') {
26
+ const file = item.getAsFile();
27
+ return file ? [file] : [];
28
+ }
29
+ return [];
30
+ }));
31
+ return files.flat();
32
+ }
33
+ function getInputFiles(evt) {
34
+ const target = evt.target;
35
+ if (!target.files)
36
+ return [];
37
+ return Array.from(target.files).map((file) => file);
38
+ }
39
+ async function getFsHandleFiles(handles) {
40
+ const files = await Promise.all(handles.map(async (handle) => {
41
+ const file = await handle.getFile();
42
+ return file;
43
+ }));
44
+ return files;
45
+ }