@mantine-vue/dropzone 1.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.
package/cjs/index.cjs ADDED
@@ -0,0 +1,941 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let vue = require("vue");
3
+ let _mantine_vue_hooks = require("@mantine-vue/hooks");
4
+ let _mantine_vue_core = require("@mantine-vue/core");
5
+ //#region src/Dropzone.context.ts
6
+ var [provideDropzoneContext, useDropzoneContext] = (0, _mantine_vue_core.createSafeContext)("Dropzone component was not found in tree");
7
+ //#endregion
8
+ //#region src/DropzoneStatus.ts
9
+ function upperFirst(value) {
10
+ return value.charAt(0).toUpperCase() + value.slice(1);
11
+ }
12
+ function createDropzoneStatus(status) {
13
+ return (0, vue.defineComponent)({
14
+ name: `Dropzone${upperFirst(status)}`,
15
+ setup(_, { slots, attrs }) {
16
+ const ctx = useDropzoneContext();
17
+ return () => {
18
+ if (!ctx[status]) return null;
19
+ const children = slots.default?.();
20
+ const child = children && children.length === 1 ? children[0] : children;
21
+ if ((0, vue.isVNode)(child) && !Array.isArray(child)) return (0, vue.cloneVNode)(child, attrs);
22
+ return (0, vue.h)("span", attrs, children);
23
+ };
24
+ }
25
+ });
26
+ }
27
+ var DropzoneAccept = createDropzoneStatus("accept");
28
+ var DropzoneReject = createDropzoneStatus("reject");
29
+ var DropzoneIdle = createDropzoneStatus("idle");
30
+ //#endregion
31
+ //#region src/get-files-from-event.ts
32
+ function toFileWithPath(file, path) {
33
+ const fileWithPath = file;
34
+ const relativePath = path || file.webkitRelativePath || file.name;
35
+ if (fileWithPath.path === void 0) try {
36
+ Object.defineProperty(fileWithPath, "path", {
37
+ value: relativePath,
38
+ writable: false,
39
+ configurable: true,
40
+ enumerable: true
41
+ });
42
+ } catch {}
43
+ return fileWithPath;
44
+ }
45
+ async function fromDataTransferItem(item) {
46
+ const entry = item.webkitGetAsEntry?.();
47
+ if (entry?.isDirectory) return fromDirectoryEntry(entry);
48
+ const file = item.getAsFile();
49
+ return file ? [toFileWithPath(file)] : [];
50
+ }
51
+ function fromDirectoryEntry(dirEntry, path = "") {
52
+ const reader = dirEntry.createReader();
53
+ return new Promise((resolve) => {
54
+ const entries = [];
55
+ const readEntries = () => {
56
+ reader.readEntries(async (batch) => {
57
+ if (batch.length === 0) {
58
+ resolve((await Promise.all(entries.map((entry) => entry.isDirectory ? fromDirectoryEntry(entry, `${path}${dirEntry.name}/`) : new Promise((res) => {
59
+ entry.file((file) => res([toFileWithPath(file, `${path}${dirEntry.name}/${file.name}`)]));
60
+ })))).flat());
61
+ return;
62
+ }
63
+ entries.push(...batch);
64
+ readEntries();
65
+ }, () => resolve([]));
66
+ };
67
+ readEntries();
68
+ });
69
+ }
70
+ async function fromDataTransfer(dataTransfer) {
71
+ if (dataTransfer.items && dataTransfer.items.length > 0) {
72
+ const items = Array.from(dataTransfer.items).filter((item) => item.kind === "file");
73
+ return (await Promise.all(items.map(fromDataTransferItem))).flat();
74
+ }
75
+ return Array.from(dataTransfer.files || []).map((file) => toFileWithPath(file));
76
+ }
77
+ async function getFilesFromEvent(event) {
78
+ if (Array.isArray(event)) return (await Promise.all(event.map((handle) => handle.getFile()))).map((file) => toFileWithPath(file));
79
+ const dragEvent = event;
80
+ if (dragEvent.dataTransfer) return fromDataTransfer(dragEvent.dataTransfer);
81
+ const target = event.target;
82
+ if (target?.files) return Array.from(target.files).map((file) => toFileWithPath(file));
83
+ return [];
84
+ }
85
+ //#endregion
86
+ //#region src/utils.ts
87
+ var FILE_INVALID_TYPE = "file-invalid-type";
88
+ var FILE_TOO_LARGE = "file-too-large";
89
+ var FILE_TOO_SMALL = "file-too-small";
90
+ var TOO_MANY_FILES = "too-many-files";
91
+ var ErrorCode = {
92
+ FileInvalidType: FILE_INVALID_TYPE,
93
+ FileTooLarge: FILE_TOO_LARGE,
94
+ FileTooSmall: FILE_TOO_SMALL,
95
+ TooManyFiles: TOO_MANY_FILES
96
+ };
97
+ var getInvalidTypeRejectionErr = (accept = "") => {
98
+ const acceptArr = accept.split(",");
99
+ return {
100
+ code: FILE_INVALID_TYPE,
101
+ message: `File type must be ${acceptArr.length > 1 ? `one of ${acceptArr.join(", ")}` : acceptArr[0]}`
102
+ };
103
+ };
104
+ var getTooLargeRejectionErr = (maxSize) => ({
105
+ code: FILE_TOO_LARGE,
106
+ message: `File is larger than ${maxSize} ${maxSize === 1 ? "byte" : "bytes"}`
107
+ });
108
+ var getTooSmallRejectionErr = (minSize) => ({
109
+ code: FILE_TOO_SMALL,
110
+ message: `File is smaller than ${minSize} ${minSize === 1 ? "byte" : "bytes"}`
111
+ });
112
+ var TOO_MANY_FILES_REJECTION = {
113
+ code: TOO_MANY_FILES,
114
+ message: "Too many files"
115
+ };
116
+ function isDefined(value) {
117
+ return value !== void 0 && value !== null;
118
+ }
119
+ function attrAccept(file, acceptedFiles) {
120
+ if (!acceptedFiles) return true;
121
+ const fileName = file.name || "";
122
+ const mimeType = (file.type || "").toLowerCase();
123
+ const baseMimeType = mimeType.replace(/\/.*$/, "");
124
+ return acceptedFiles.split(",").map((type) => type.trim().toLowerCase()).some((type) => {
125
+ if (type.startsWith(".")) return fileName.toLowerCase().endsWith(type);
126
+ if (type.endsWith("/*")) return baseMimeType === type.replace(/\/.*$/, "");
127
+ return mimeType === type;
128
+ });
129
+ }
130
+ /**
131
+ * Check if the given file is a DataTransferItem with an empty type. During drag events some
132
+ * browsers report an empty MIME type on DataTransferItem for certain file extensions even though
133
+ * the type is correctly set once the file is actually dropped, so we accept those provisionally.
134
+ */
135
+ function isDataTransferItemWithEmptyType(file) {
136
+ return file.type === "" && typeof file.getAsFile === "function";
137
+ }
138
+ function fileAccepted(file, accept) {
139
+ const isAcceptable = file.type === "application/x-moz-file" || attrAccept(file, accept) || isDataTransferItemWithEmptyType(file);
140
+ return [isAcceptable, isAcceptable ? null : getInvalidTypeRejectionErr(accept)];
141
+ }
142
+ function fileMatchSize(file, minSize, maxSize) {
143
+ if (isDefined(file.size)) {
144
+ if (isDefined(minSize) && isDefined(maxSize)) {
145
+ if (file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];
146
+ if (file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];
147
+ } else if (isDefined(minSize) && file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];
148
+ else if (isDefined(maxSize) && file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];
149
+ }
150
+ return [true, null];
151
+ }
152
+ function allFilesAccepted({ files, accept, minSize, maxSize, multiple, maxFiles, validator }) {
153
+ if (!multiple && files.length > 1 || multiple && (maxFiles ?? 0) >= 1 && files.length > maxFiles) return false;
154
+ return files.every((file) => {
155
+ const [accepted] = fileAccepted(file, accept);
156
+ const [sizeMatch] = fileMatchSize(file, minSize, maxSize);
157
+ const customErrors = validator ? validator(file) : null;
158
+ return accepted && sizeMatch && !customErrors;
159
+ });
160
+ }
161
+ function isEvtWithFiles(event) {
162
+ const dataTransfer = event.dataTransfer;
163
+ if (!dataTransfer) {
164
+ const target = event.target;
165
+ return !!target && !!target.files;
166
+ }
167
+ return Array.prototype.some.call(dataTransfer.types || [], (type) => type === "Files" || type === "application/x-moz-file");
168
+ }
169
+ function canUseFileSystemAccessAPI() {
170
+ return typeof window !== "undefined" && "showOpenFilePicker" in window;
171
+ }
172
+ /** Convert the `accept` prop into the `{types}` option for `window.showOpenFilePicker`. */
173
+ function pickerOptionsFromAccept(accept) {
174
+ if (!isDefined(accept)) return;
175
+ return [{
176
+ description: "Files",
177
+ accept: Object.entries(accept).filter(([mimeType, ext]) => isMIMEType(mimeType) && Array.isArray(ext) && ext.every(isExt)).reduce((agg, [mimeType, ext]) => ({
178
+ ...agg,
179
+ [mimeType]: ext
180
+ }), {})
181
+ }];
182
+ }
183
+ /** Convert the `accept` prop into a comma-separated string suitable for `<input accept>`. */
184
+ function acceptPropAsAcceptAttr(accept) {
185
+ if (!isDefined(accept)) return;
186
+ return Object.entries(accept).reduce((acc, [mimeType, ext]) => [
187
+ ...acc,
188
+ mimeType,
189
+ ...ext
190
+ ], []).filter((v) => isMIMEType(v) || isExt(v)).join(",");
191
+ }
192
+ function isAbort(v) {
193
+ return v instanceof DOMException && (v.name === "AbortError" || v.code === v.ABORT_ERR);
194
+ }
195
+ function isSecurityError(v) {
196
+ return v instanceof DOMException && (v.name === "SecurityError" || v.code === v.SECURITY_ERR);
197
+ }
198
+ function isMIMEType(v) {
199
+ return v === "audio/*" || v === "video/*" || v === "image/*" || v === "text/*" || v === "application/*" || /\w+\/[-+.\w]+/g.test(v);
200
+ }
201
+ function isExt(v) {
202
+ return /^.*\.[\w]+$/.test(v);
203
+ }
204
+ //#endregion
205
+ //#region src/use-dropzone.ts
206
+ function useDropzone(options) {
207
+ const rootRef = (0, vue.ref)(null);
208
+ const inputRef = (0, vue.ref)(null);
209
+ const state = (0, vue.reactive)({
210
+ isFocused: false,
211
+ isFileDialogActive: false,
212
+ isDragActive: false,
213
+ isDragAccept: false,
214
+ isDragReject: false
215
+ });
216
+ let dragTargets = [];
217
+ const fsAccessApiWorks = typeof window !== "undefined" && window.isSecureContext && !!options.useFsAccessApi?.() && canUseFileSystemAccessAPI();
218
+ const acceptAttr = (0, vue.computed)(() => acceptPropAsAcceptAttr(options.accept?.()));
219
+ const pickerTypes = (0, vue.computed)(() => pickerOptionsFromAccept(options.accept?.()));
220
+ const getFilesFromEvent$1 = (event) => (options.getFilesFromEvent?.() ?? getFilesFromEvent)(event);
221
+ const onErr = (error) => {
222
+ if (options.onError) options.onError(error);
223
+ else console.error(error);
224
+ };
225
+ const stopPropagation = (event) => {
226
+ if (options.noDragEventsBubbling?.()) event.stopPropagation();
227
+ };
228
+ const onWindowFocus = () => {
229
+ if (!fsAccessApiWorks && state.isFileDialogActive) setTimeout(() => {
230
+ if (inputRef.value && !inputRef.value.files?.length) {
231
+ state.isFileDialogActive = false;
232
+ options.onFileDialogCancel?.();
233
+ }
234
+ }, 300);
235
+ };
236
+ const onDocumentDragOver = (event) => event.preventDefault();
237
+ const onDocumentDrop = (event) => {
238
+ if (rootRef.value && event.target && rootRef.value.contains(event.target)) return;
239
+ event.preventDefault();
240
+ dragTargets = [];
241
+ };
242
+ (0, vue.onMounted)(() => {
243
+ window.addEventListener("focus", onWindowFocus, false);
244
+ if (options.preventDropOnDocument?.() ?? true) {
245
+ document.addEventListener("dragover", onDocumentDragOver, false);
246
+ document.addEventListener("drop", onDocumentDrop, false);
247
+ }
248
+ if ((options.autoFocus?.() ?? false) && !options.disabled?.()) rootRef.value?.focus();
249
+ });
250
+ (0, vue.onUnmounted)(() => {
251
+ window.removeEventListener("focus", onWindowFocus, false);
252
+ document.removeEventListener("dragover", onDocumentDragOver);
253
+ document.removeEventListener("drop", onDocumentDrop);
254
+ });
255
+ const setFiles = (files, event) => {
256
+ const acceptedFiles = [];
257
+ const fileRejections = [];
258
+ const minSize = options.minSize?.();
259
+ const maxSize = options.maxSize?.();
260
+ const multiple = options.multiple?.() ?? true;
261
+ const maxFiles = options.maxFiles?.();
262
+ const validator = options.validator?.();
263
+ files.forEach((file) => {
264
+ const [accepted, acceptError] = fileAccepted(file, acceptAttr.value);
265
+ const [sizeMatch, sizeError] = fileMatchSize(file, minSize, maxSize);
266
+ const customErrors = validator ? validator(file) : null;
267
+ if (accepted && sizeMatch && !customErrors) acceptedFiles.push(file);
268
+ else {
269
+ const errors = [acceptError, sizeError].filter((e) => !!e);
270
+ if (customErrors) errors.push(...Array.isArray(customErrors) ? customErrors : [customErrors]);
271
+ fileRejections.push({
272
+ file,
273
+ errors
274
+ });
275
+ }
276
+ });
277
+ if (!multiple && acceptedFiles.length > 1 || multiple && (maxFiles ?? 0) >= 1 && acceptedFiles.length > maxFiles) {
278
+ acceptedFiles.forEach((file) => fileRejections.push({
279
+ file,
280
+ errors: [TOO_MANY_FILES_REJECTION]
281
+ }));
282
+ acceptedFiles.length = 0;
283
+ }
284
+ options.onDrop?.(acceptedFiles, fileRejections, event);
285
+ if (fileRejections.length > 0) options.onDropRejected?.(fileRejections, event);
286
+ if (acceptedFiles.length > 0) options.onDropAccepted?.(acceptedFiles, event);
287
+ };
288
+ const onDragEnterCb = (event) => {
289
+ event.preventDefault();
290
+ stopPropagation(event);
291
+ dragTargets = [...dragTargets, event.target];
292
+ if (isEvtWithFiles(event)) Promise.resolve(getFilesFromEvent$1(event)).then((files) => {
293
+ const isDragAccept = files.length > 0 && allFilesAccepted({
294
+ files,
295
+ accept: acceptAttr.value,
296
+ minSize: options.minSize?.(),
297
+ maxSize: options.maxSize?.(),
298
+ multiple: options.multiple?.() ?? true,
299
+ maxFiles: options.maxFiles?.(),
300
+ validator: options.validator?.()
301
+ });
302
+ const isDragReject = files.length > 0 && !isDragAccept;
303
+ state.isDragActive = true;
304
+ state.isDragAccept = isDragAccept;
305
+ state.isDragReject = isDragReject;
306
+ options.onDragEnter?.(event);
307
+ }).catch(onErr);
308
+ };
309
+ const onDragOverCb = (event) => {
310
+ event.preventDefault();
311
+ stopPropagation(event);
312
+ const hasFiles = isEvtWithFiles(event);
313
+ if (hasFiles && event.dataTransfer) try {
314
+ event.dataTransfer.dropEffect = "copy";
315
+ } catch {}
316
+ if (hasFiles) options.onDragOver?.(event);
317
+ };
318
+ const onDragLeaveCb = (event) => {
319
+ event.preventDefault();
320
+ stopPropagation(event);
321
+ const targets = dragTargets.filter((target) => rootRef.value && rootRef.value.contains(target));
322
+ const targetIdx = targets.indexOf(event.target);
323
+ if (targetIdx !== -1) targets.splice(targetIdx, 1);
324
+ dragTargets = targets;
325
+ if (targets.length > 0) return;
326
+ state.isDragActive = false;
327
+ state.isDragAccept = false;
328
+ state.isDragReject = false;
329
+ if (isEvtWithFiles(event)) options.onDragLeave?.(event);
330
+ };
331
+ const onDropCb = (event) => {
332
+ event.preventDefault();
333
+ stopPropagation(event);
334
+ dragTargets = [];
335
+ if (isEvtWithFiles(event)) Promise.resolve(getFilesFromEvent$1(event)).then((files) => setFiles(files, event)).catch(onErr);
336
+ state.isDragActive = false;
337
+ state.isDragAccept = false;
338
+ state.isDragReject = false;
339
+ };
340
+ const openFileDialog = () => {
341
+ if (options.disabled?.()) return;
342
+ if (fsAccessApiWorks) {
343
+ state.isFileDialogActive = true;
344
+ options.onFileDialogOpen?.();
345
+ const opts = {
346
+ multiple: options.multiple?.() ?? true,
347
+ types: pickerTypes.value
348
+ };
349
+ window.showOpenFilePicker(opts).then((handles) => getFilesFromEvent$1(handles)).then((files) => {
350
+ setFiles(files, null);
351
+ state.isFileDialogActive = false;
352
+ }).catch((e) => {
353
+ if (isAbort(e)) {
354
+ options.onFileDialogCancel?.();
355
+ state.isFileDialogActive = false;
356
+ } else if (isSecurityError(e)) if (inputRef.value) {
357
+ inputRef.value.value = "";
358
+ inputRef.value.click();
359
+ } else onErr(/* @__PURE__ */ new Error("Cannot open the file picker: no <input> was rendered as a fallback."));
360
+ else onErr(e);
361
+ });
362
+ return;
363
+ }
364
+ if (inputRef.value) {
365
+ state.isFileDialogActive = true;
366
+ options.onFileDialogOpen?.();
367
+ inputRef.value.value = "";
368
+ inputRef.value.click();
369
+ }
370
+ };
371
+ const onKeyDownCb = (event) => {
372
+ if (!rootRef.value || rootRef.value !== event.target) return;
373
+ if (event.key === " " || event.key === "Enter") {
374
+ event.preventDefault();
375
+ openFileDialog();
376
+ }
377
+ };
378
+ const onFocusCb = () => {
379
+ state.isFocused = true;
380
+ };
381
+ const onBlurCb = () => {
382
+ state.isFocused = false;
383
+ };
384
+ const onClickCb = () => {
385
+ if (!options.noClick?.()) openFileDialog();
386
+ };
387
+ const onInputClickCb = (event) => {
388
+ event.stopPropagation();
389
+ };
390
+ const onInputChangeCb = (event) => {
391
+ onDropCb(event);
392
+ };
393
+ const composeHandler = (fn) => options.disabled?.() ? null : fn;
394
+ const composeKeyboardHandler = (fn) => options.noKeyboard?.() ? null : composeHandler(fn);
395
+ const composeDragHandler = (fn) => options.noDrag?.() ? null : composeHandler(fn);
396
+ const getRootProps = (overrides = {}) => ({
397
+ onKeydown: composeKeyboardHandler(onKeyDownCb),
398
+ onFocus: composeKeyboardHandler(onFocusCb),
399
+ onBlur: composeKeyboardHandler(onBlurCb),
400
+ onClick: composeHandler(onClickCb),
401
+ onDragenter: composeDragHandler(onDragEnterCb),
402
+ onDragover: composeDragHandler(onDragOverCb),
403
+ onDragleave: composeDragHandler(onDragLeaveCb),
404
+ onDrop: composeDragHandler(onDropCb),
405
+ role: "presentation",
406
+ ref: (el) => {
407
+ rootRef.value = el?.$el ?? el ?? null;
408
+ },
409
+ ...!options.disabled?.() && !options.noKeyboard?.() ? { tabindex: 0 } : {},
410
+ ...overrides
411
+ });
412
+ const getInputProps = (overrides = {}) => ({
413
+ type: "file",
414
+ accept: acceptAttr.value,
415
+ multiple: options.multiple?.() ?? true,
416
+ style: {
417
+ border: 0,
418
+ clip: "rect(0, 0, 0, 0)",
419
+ clipPath: "inset(50%)",
420
+ height: "1px",
421
+ margin: "0 -1px -1px 0",
422
+ overflow: "hidden",
423
+ padding: 0,
424
+ position: "absolute",
425
+ width: "1px",
426
+ whiteSpace: "nowrap"
427
+ },
428
+ onChange: composeHandler(onInputChangeCb),
429
+ onClick: composeHandler(onInputClickCb),
430
+ tabindex: -1,
431
+ ref: (el) => {
432
+ inputRef.value = el?.$el ?? el ?? null;
433
+ },
434
+ ...overrides
435
+ });
436
+ return {
437
+ state,
438
+ rootRef,
439
+ inputRef,
440
+ isFocused: (0, vue.computed)(() => state.isFocused && !options.disabled?.()),
441
+ isDragActive: (0, vue.computed)(() => state.isDragActive),
442
+ isDragAccept: (0, vue.computed)(() => state.isDragAccept),
443
+ isDragReject: (0, vue.computed)(() => state.isDragReject),
444
+ getRootProps,
445
+ getInputProps,
446
+ open: () => composeHandler(openFileDialog)?.()
447
+ };
448
+ }
449
+ var Dropzone_module_default = {
450
+ root: "_root_27ynu_1",
451
+ inner: "_inner_27ynu_53",
452
+ fullScreen: "_fullScreen_27ynu_62",
453
+ dropzone: "_dropzone_27ynu_71"
454
+ };
455
+ //#endregion
456
+ //#region src/Dropzone.ts
457
+ var defaultProps$1 = {
458
+ multiple: true,
459
+ maxSize: Infinity,
460
+ activateOnClick: true,
461
+ activateOnDrag: true,
462
+ dragEventsBubbling: true,
463
+ activateOnKeyboard: true,
464
+ useFsAccessApi: false,
465
+ preventDropOnDocument: true,
466
+ variant: "light",
467
+ rejectColor: "red"
468
+ };
469
+ var varsResolver = (0, _mantine_vue_core.createVarsResolver)((theme, { radius, variant, acceptColor, rejectColor }) => {
470
+ const acceptColors = theme.variantColorResolver({
471
+ color: acceptColor || theme.primaryColor,
472
+ theme,
473
+ variant
474
+ });
475
+ const rejectColors = theme.variantColorResolver({
476
+ color: rejectColor || "red",
477
+ theme,
478
+ variant
479
+ });
480
+ return { root: {
481
+ "--dropzone-radius": (0, _mantine_vue_core.getRadius)(radius),
482
+ "--dropzone-accept-color": acceptColors.color,
483
+ "--dropzone-accept-bg": acceptColors.background,
484
+ "--dropzone-reject-color": rejectColors.color,
485
+ "--dropzone-reject-bg": rejectColors.background
486
+ } };
487
+ });
488
+ var DropzoneBaseComponent = (0, vue.defineComponent)({
489
+ name: "Dropzone",
490
+ inheritAttrs: false,
491
+ props: {
492
+ acceptColor: {
493
+ type: String,
494
+ default: void 0
495
+ },
496
+ rejectColor: {
497
+ type: String,
498
+ default: void 0
499
+ },
500
+ radius: {
501
+ type: [String, Number],
502
+ default: void 0
503
+ },
504
+ disabled: {
505
+ type: Boolean,
506
+ default: false
507
+ },
508
+ loading: {
509
+ type: Boolean,
510
+ default: false
511
+ },
512
+ accept: {
513
+ type: [Object, Array],
514
+ default: void 0
515
+ },
516
+ multiple: {
517
+ type: Boolean,
518
+ default: void 0
519
+ },
520
+ maxSize: {
521
+ type: Number,
522
+ default: void 0
523
+ },
524
+ name: {
525
+ type: String,
526
+ default: void 0
527
+ },
528
+ maxFiles: {
529
+ type: Number,
530
+ default: void 0
531
+ },
532
+ autoFocus: {
533
+ type: Boolean,
534
+ default: false
535
+ },
536
+ activateOnClick: {
537
+ type: Boolean,
538
+ default: void 0
539
+ },
540
+ activateOnDrag: {
541
+ type: Boolean,
542
+ default: void 0
543
+ },
544
+ activateOnKeyboard: {
545
+ type: Boolean,
546
+ default: void 0
547
+ },
548
+ dragEventsBubbling: {
549
+ type: Boolean,
550
+ default: void 0
551
+ },
552
+ preventDropOnDocument: {
553
+ type: Boolean,
554
+ default: void 0
555
+ },
556
+ useFsAccessApi: {
557
+ type: Boolean,
558
+ default: void 0
559
+ },
560
+ enablePointerEvents: {
561
+ type: Boolean,
562
+ default: false
563
+ },
564
+ variant: {
565
+ type: String,
566
+ default: void 0
567
+ },
568
+ loaderProps: {
569
+ type: Object,
570
+ default: void 0
571
+ },
572
+ inputProps: {
573
+ type: Object,
574
+ default: void 0
575
+ },
576
+ validator: {
577
+ type: Function,
578
+ default: void 0
579
+ },
580
+ getFilesFromEvent: {
581
+ type: Function,
582
+ default: void 0
583
+ },
584
+ openRef: {
585
+ type: [Object, Function],
586
+ default: void 0
587
+ },
588
+ onDrop: {
589
+ type: Function,
590
+ required: true
591
+ },
592
+ onDropAny: {
593
+ type: Function,
594
+ default: void 0
595
+ },
596
+ onReject: {
597
+ type: Function,
598
+ default: void 0
599
+ },
600
+ onDragEnter: {
601
+ type: Function,
602
+ default: void 0
603
+ },
604
+ onDragLeave: {
605
+ type: Function,
606
+ default: void 0
607
+ },
608
+ onDragOver: {
609
+ type: Function,
610
+ default: void 0
611
+ },
612
+ onFileDialogCancel: {
613
+ type: Function,
614
+ default: void 0
615
+ },
616
+ onFileDialogOpen: {
617
+ type: Function,
618
+ default: void 0
619
+ },
620
+ classNames: {
621
+ type: [Object, Function],
622
+ default: void 0
623
+ },
624
+ styles: {
625
+ type: [Object, Function],
626
+ default: void 0
627
+ },
628
+ vars: {
629
+ type: [Object, Function],
630
+ default: void 0
631
+ },
632
+ unstyled: {
633
+ type: Boolean,
634
+ default: false
635
+ }
636
+ },
637
+ setup(rawProps, { attrs, slots }) {
638
+ const props = (0, _mantine_vue_core.useProps)("Dropzone", defaultProps$1, rawProps);
639
+ const getStyles = (0, _mantine_vue_core.useStyles)({
640
+ name: "Dropzone",
641
+ classes: Dropzone_module_default,
642
+ props,
643
+ className: attrs.class,
644
+ style: attrs.style,
645
+ classNames: props.classNames,
646
+ styles: props.styles,
647
+ vars: props.vars,
648
+ varsResolver,
649
+ unstyled: props.unstyled
650
+ });
651
+ const dz = useDropzone({
652
+ accept: () => Array.isArray(props.accept) ? props.accept.reduce((r, key) => ({
653
+ ...r,
654
+ [key]: []
655
+ }), {}) : props.accept,
656
+ disabled: () => props.disabled || props.loading,
657
+ multiple: () => props.multiple,
658
+ maxSize: () => props.maxSize,
659
+ maxFiles: () => props.maxFiles,
660
+ autoFocus: () => props.autoFocus,
661
+ noClick: () => !props.activateOnClick,
662
+ noDrag: () => !props.activateOnDrag,
663
+ noDragEventsBubbling: () => !props.dragEventsBubbling,
664
+ noKeyboard: () => !props.activateOnKeyboard,
665
+ preventDropOnDocument: () => props.preventDropOnDocument,
666
+ useFsAccessApi: () => props.useFsAccessApi,
667
+ validator: () => props.validator,
668
+ getFilesFromEvent: () => props.getFilesFromEvent,
669
+ onDrop: (files, fileRejections) => props.onDropAny?.(files, fileRejections),
670
+ onDropAccepted: (files) => props.onDrop(files),
671
+ onDropRejected: (fileRejections) => props.onReject?.(fileRejections),
672
+ onDragEnter: (event) => props.onDragEnter?.(event),
673
+ onDragLeave: (event) => props.onDragLeave?.(event),
674
+ onDragOver: (event) => props.onDragOver?.(event),
675
+ onFileDialogCancel: () => props.onFileDialogCancel?.(),
676
+ onFileDialogOpen: () => props.onFileDialogOpen?.()
677
+ });
678
+ (0, _mantine_vue_hooks.assignRef)(props.openRef, dz.open);
679
+ provideDropzoneContext({
680
+ get accept() {
681
+ return dz.isDragActive.value && dz.isDragAccept.value;
682
+ },
683
+ get reject() {
684
+ return dz.isDragActive.value && dz.isDragReject.value;
685
+ },
686
+ get idle() {
687
+ const accepted = dz.isDragActive.value && dz.isDragAccept.value;
688
+ const rejected = dz.isDragActive.value && dz.isDragReject.value;
689
+ return !accepted && !rejected;
690
+ }
691
+ });
692
+ return () => {
693
+ const isAccepted = dz.isDragActive.value && dz.isDragAccept.value;
694
+ const isRejected = dz.isDragActive.value && dz.isDragReject.value;
695
+ const isIdle = !isAccepted && !isRejected;
696
+ const rootProps = dz.getRootProps();
697
+ const inputProps = dz.getInputProps(props.inputProps);
698
+ return (0, vue.h)(_mantine_vue_core.Box, {
699
+ ...rootProps,
700
+ ...getStyles("root"),
701
+ ...attrs,
702
+ mod: [{
703
+ accept: isAccepted,
704
+ reject: isRejected,
705
+ idle: isIdle,
706
+ disabled: props.disabled,
707
+ loading: props.loading,
708
+ "activate-on-click": props.activateOnClick
709
+ }, attrs.mod]
710
+ }, () => [
711
+ (0, vue.h)(_mantine_vue_core.LoadingOverlay, {
712
+ visible: props.loading,
713
+ overlayProps: { radius: props.radius },
714
+ unstyled: props.unstyled,
715
+ loaderProps: props.loaderProps
716
+ }),
717
+ (0, vue.h)("input", {
718
+ ...inputProps,
719
+ name: props.name
720
+ }),
721
+ (0, vue.h)("div", {
722
+ ...getStyles("inner"),
723
+ "data-enable-pointer-events": props.enablePointerEvents || void 0
724
+ }, slots.default?.())
725
+ ]);
726
+ };
727
+ }
728
+ });
729
+ var Dropzone$1 = Object.assign((0, _mantine_vue_core.withBoxProps)(DropzoneBaseComponent), {
730
+ classes: Dropzone_module_default,
731
+ varsResolver,
732
+ Accept: DropzoneAccept,
733
+ Idle: DropzoneIdle,
734
+ Reject: DropzoneReject
735
+ });
736
+ //#endregion
737
+ //#region src/DropzoneFullScreen.ts
738
+ var defaultProps = {
739
+ maxSize: Infinity,
740
+ activateOnDrag: true,
741
+ dragEventsBubbling: true,
742
+ activateOnKeyboard: true,
743
+ active: true,
744
+ zIndex: (0, _mantine_vue_core.getDefaultZIndex)("max"),
745
+ withinPortal: true
746
+ };
747
+ var DropzoneFullScreenBaseComponent = (0, vue.defineComponent)({
748
+ name: "DropzoneFullScreen",
749
+ inheritAttrs: false,
750
+ props: {
751
+ active: {
752
+ type: Boolean,
753
+ default: void 0
754
+ },
755
+ onDrop: {
756
+ type: Function,
757
+ required: true
758
+ },
759
+ onReject: {
760
+ type: Function,
761
+ default: void 0
762
+ },
763
+ zIndex: {
764
+ type: [String, Number],
765
+ default: void 0
766
+ },
767
+ withinPortal: {
768
+ type: Boolean,
769
+ default: void 0
770
+ },
771
+ portalProps: {
772
+ type: Object,
773
+ default: void 0
774
+ },
775
+ classNames: {
776
+ type: [Object, Function],
777
+ default: void 0
778
+ },
779
+ styles: {
780
+ type: [Object, Function],
781
+ default: void 0
782
+ },
783
+ unstyled: {
784
+ type: Boolean,
785
+ default: false
786
+ }
787
+ },
788
+ setup(rawProps, { attrs, slots }) {
789
+ const props = (0, _mantine_vue_core.useProps)("DropzoneFullScreen", defaultProps, rawProps);
790
+ const getStyles = (0, _mantine_vue_core.useStyles)({
791
+ name: "DropzoneFullScreen",
792
+ classes: Dropzone_module_default,
793
+ props,
794
+ className: attrs.class,
795
+ style: attrs.style,
796
+ classNames: props.classNames,
797
+ styles: props.styles,
798
+ unstyled: props.unstyled,
799
+ rootSelector: "fullScreen"
800
+ });
801
+ const counter = (0, vue.ref)(0);
802
+ const [visible, { open, close }] = (0, _mantine_vue_hooks.useDisclosure)(false);
803
+ const handleDragEnter = (event) => {
804
+ if (event.dataTransfer?.types.includes("Files")) {
805
+ counter.value += 1;
806
+ open();
807
+ }
808
+ };
809
+ const handleDragLeave = () => {
810
+ counter.value -= 1;
811
+ };
812
+ (0, vue.watch)(counter, (value) => {
813
+ if (value === 0) close();
814
+ });
815
+ let attached = false;
816
+ const attach = () => {
817
+ if (attached) return;
818
+ document.addEventListener("dragenter", handleDragEnter, false);
819
+ document.addEventListener("dragleave", handleDragLeave, false);
820
+ attached = true;
821
+ };
822
+ const detach = () => {
823
+ if (!attached) return;
824
+ document.removeEventListener("dragenter", handleDragEnter, false);
825
+ document.removeEventListener("dragleave", handleDragLeave, false);
826
+ attached = false;
827
+ };
828
+ (0, vue.watch)(() => props.active, (active) => {
829
+ detach();
830
+ if (active) attach();
831
+ }, { immediate: true });
832
+ (0, vue.onUnmounted)(detach);
833
+ return () => (0, vue.h)(_mantine_vue_core.OptionalPortal, {
834
+ ...props.portalProps,
835
+ withinPortal: props.withinPortal
836
+ }, () => (0, vue.h)("div", { ...getStyles("fullScreen", { style: {
837
+ opacity: visible.value ? 1 : 0,
838
+ pointerEvents: visible.value ? "all" : "none",
839
+ zIndex: props.zIndex
840
+ } }) }, [(0, vue.h)(Dropzone$1, {
841
+ activateOnClick: false,
842
+ ...attrs,
843
+ classNames: props.classNames,
844
+ styles: props.styles,
845
+ unstyled: props.unstyled,
846
+ class: Dropzone_module_default.dropzone,
847
+ onDrop: (files) => {
848
+ props.onDrop(files);
849
+ close();
850
+ counter.value = 0;
851
+ },
852
+ onReject: (fileRejections) => {
853
+ props.onReject?.(fileRejections);
854
+ close();
855
+ counter.value = 0;
856
+ }
857
+ }, slots)]));
858
+ }
859
+ });
860
+ var DropzoneFullScreen = (0, _mantine_vue_core.withBoxProps)(DropzoneFullScreenBaseComponent);
861
+ //#endregion
862
+ //#region src/mime-types.ts
863
+ var MIME_TYPES = {
864
+ png: "image/png",
865
+ gif: "image/gif",
866
+ jpeg: "image/jpeg",
867
+ svg: "image/svg+xml",
868
+ webp: "image/webp",
869
+ avif: "image/avif",
870
+ heic: "image/heic",
871
+ heif: "image/heif",
872
+ mp4: "video/mp4",
873
+ zip: "application/zip",
874
+ rar: "application/x-rar",
875
+ "7z": "application/x-7z-compressed",
876
+ csv: "text/csv",
877
+ pdf: "application/pdf",
878
+ doc: "application/msword",
879
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
880
+ xls: "application/vnd.ms-excel",
881
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
882
+ ppt: "application/vnd.ms-powerpoint",
883
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
884
+ exe: "application/vnd.microsoft.portable-executable"
885
+ };
886
+ var IMAGE_MIME_TYPE = [
887
+ MIME_TYPES.png,
888
+ MIME_TYPES.gif,
889
+ MIME_TYPES.jpeg,
890
+ MIME_TYPES.svg,
891
+ MIME_TYPES.webp,
892
+ MIME_TYPES.avif,
893
+ MIME_TYPES.heic,
894
+ MIME_TYPES.heif
895
+ ];
896
+ var PDF_MIME_TYPE = [MIME_TYPES.pdf];
897
+ var MS_WORD_MIME_TYPE = [MIME_TYPES.doc, MIME_TYPES.docx];
898
+ var MS_EXCEL_MIME_TYPE = [MIME_TYPES.xls, MIME_TYPES.xlsx];
899
+ var MS_POWERPOINT_MIME_TYPE = [MIME_TYPES.ppt, MIME_TYPES.pptx];
900
+ var EXE_MIME_TYPE = [MIME_TYPES.exe];
901
+ //#endregion
902
+ //#region src/index.ts
903
+ Object.assign(Dropzone$1, { FullScreen: DropzoneFullScreen });
904
+ var Dropzone = Dropzone$1;
905
+ //#endregion
906
+ exports.Dropzone = Dropzone;
907
+ exports.DropzoneAccept = DropzoneAccept;
908
+ exports.DropzoneFullScreen = DropzoneFullScreen;
909
+ exports.DropzoneIdle = DropzoneIdle;
910
+ exports.DropzoneReject = DropzoneReject;
911
+ exports.EXE_MIME_TYPE = EXE_MIME_TYPE;
912
+ exports.ErrorCode = ErrorCode;
913
+ exports.FILE_INVALID_TYPE = FILE_INVALID_TYPE;
914
+ exports.FILE_TOO_LARGE = FILE_TOO_LARGE;
915
+ exports.FILE_TOO_SMALL = FILE_TOO_SMALL;
916
+ exports.IMAGE_MIME_TYPE = IMAGE_MIME_TYPE;
917
+ exports.MIME_TYPES = MIME_TYPES;
918
+ exports.MS_EXCEL_MIME_TYPE = MS_EXCEL_MIME_TYPE;
919
+ exports.MS_POWERPOINT_MIME_TYPE = MS_POWERPOINT_MIME_TYPE;
920
+ exports.MS_WORD_MIME_TYPE = MS_WORD_MIME_TYPE;
921
+ exports.PDF_MIME_TYPE = PDF_MIME_TYPE;
922
+ exports.TOO_MANY_FILES = TOO_MANY_FILES;
923
+ exports.TOO_MANY_FILES_REJECTION = TOO_MANY_FILES_REJECTION;
924
+ exports.acceptPropAsAcceptAttr = acceptPropAsAcceptAttr;
925
+ exports.allFilesAccepted = allFilesAccepted;
926
+ exports.canUseFileSystemAccessAPI = canUseFileSystemAccessAPI;
927
+ exports.fileAccepted = fileAccepted;
928
+ exports.fileMatchSize = fileMatchSize;
929
+ exports.getInvalidTypeRejectionErr = getInvalidTypeRejectionErr;
930
+ exports.getTooLargeRejectionErr = getTooLargeRejectionErr;
931
+ exports.getTooSmallRejectionErr = getTooSmallRejectionErr;
932
+ exports.isAbort = isAbort;
933
+ exports.isDataTransferItemWithEmptyType = isDataTransferItemWithEmptyType;
934
+ exports.isEvtWithFiles = isEvtWithFiles;
935
+ exports.isExt = isExt;
936
+ exports.isMIMEType = isMIMEType;
937
+ exports.isSecurityError = isSecurityError;
938
+ exports.pickerOptionsFromAccept = pickerOptionsFromAccept;
939
+ exports.useDropzone = useDropzone;
940
+
941
+ //# sourceMappingURL=index.cjs.map