Greasy Fork is available in English.

@mantine᜵dropzone-umd

A UMD build of @mantine/dropzone

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greatest.deepsurf.us/scripts/510665/1456079/%40mantine%E1%9C%B5dropzone-umd.js

  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('prop-types'), require('@mantine/core'), require('@mantine/hooks')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', 'prop-types', '@mantine/core', '@mantine/hooks'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MantineDropzone = {}, global.ReactJSXRuntime, global.React, global.PropTypes, global.MantineCore, global.MantineHooks));
  5. })(this, (function (exports, jsxRuntime, React, PropTypes, core, hooks) { 'use strict';
  6.  
  7. /* esm.sh - esbuild bundle(@mantine/dropzone@7.13.0) es2022 development */
  8. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/@mantine+dropzone@7.13.0_@mantine+core@7.13.0_@mantine+hooks@7.13.0_react-dom@18.3.1_react@18.3.1/node_modules/@mantine/dropzone/esm/Dropzone.mjs
  9.  
  10. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/react-dropzone-esm@15.0.1_react@18.3.1/node_modules/react-dropzone-esm/dist/esm/file.mjs
  11. var COMMON_MIME_TYPES = /* @__PURE__ */ new Map([
  12. // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
  13. ["aac", "audio/aac"],
  14. ["abw", "application/x-abiword"],
  15. ["arc", "application/x-freearc"],
  16. ["avif", "image/avif"],
  17. ["avi", "video/x-msvideo"],
  18. ["azw", "application/vnd.amazon.ebook"],
  19. ["bin", "application/octet-stream"],
  20. ["bmp", "image/bmp"],
  21. ["bz", "application/x-bzip"],
  22. ["bz2", "application/x-bzip2"],
  23. ["cda", "application/x-cdf"],
  24. ["csh", "application/x-csh"],
  25. ["css", "text/css"],
  26. ["csv", "text/csv"],
  27. ["doc", "application/msword"],
  28. [
  29. "docx",
  30. "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
  31. ],
  32. ["eot", "application/vnd.ms-fontobject"],
  33. ["epub", "application/epub+zip"],
  34. ["gz", "application/gzip"],
  35. ["gif", "image/gif"],
  36. ["heic", "image/heic"],
  37. ["heif", "image/heif"],
  38. ["htm", "text/html"],
  39. ["html", "text/html"],
  40. ["ico", "image/vnd.microsoft.icon"],
  41. ["ics", "text/calendar"],
  42. ["jar", "application/java-archive"],
  43. ["jpeg", "image/jpeg"],
  44. ["jpg", "image/jpeg"],
  45. ["js", "text/javascript"],
  46. ["json", "application/json"],
  47. ["jsonld", "application/ld+json"],
  48. ["mid", "audio/midi"],
  49. ["midi", "audio/midi"],
  50. ["mjs", "text/javascript"],
  51. ["mp3", "audio/mpeg"],
  52. ["mp4", "video/mp4"],
  53. ["mpeg", "video/mpeg"],
  54. ["mpkg", "application/vnd.apple.installer+xml"],
  55. ["odp", "application/vnd.oasis.opendocument.presentation"],
  56. ["ods", "application/vnd.oasis.opendocument.spreadsheet"],
  57. ["odt", "application/vnd.oasis.opendocument.text"],
  58. ["oga", "audio/ogg"],
  59. ["ogv", "video/ogg"],
  60. ["ogx", "application/ogg"],
  61. ["opus", "audio/opus"],
  62. ["otf", "font/otf"],
  63. ["png", "image/png"],
  64. ["pdf", "application/pdf"],
  65. ["php", "application/x-httpd-php"],
  66. ["ppt", "application/vnd.ms-powerpoint"],
  67. [
  68. "pptx",
  69. "application/vnd.openxmlformats-officedocument.presentationml.presentation"
  70. ],
  71. ["rar", "application/vnd.rar"],
  72. ["rtf", "application/rtf"],
  73. ["sh", "application/x-sh"],
  74. ["svg", "image/svg+xml"],
  75. ["swf", "application/x-shockwave-flash"],
  76. ["tar", "application/x-tar"],
  77. ["tif", "image/tiff"],
  78. ["tiff", "image/tiff"],
  79. ["ts", "video/mp2t"],
  80. ["ttf", "font/ttf"],
  81. ["txt", "text/plain"],
  82. ["vsd", "application/vnd.visio"],
  83. ["wav", "audio/wav"],
  84. ["weba", "audio/webm"],
  85. ["webm", "video/webm"],
  86. ["webp", "image/webp"],
  87. ["woff", "font/woff"],
  88. ["woff2", "font/woff2"],
  89. ["xhtml", "application/xhtml+xml"],
  90. ["xls", "application/vnd.ms-excel"],
  91. ["xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
  92. ["xml", "application/xml"],
  93. ["xul", "application/vnd.mozilla.xul+xml"],
  94. ["zip", "application/zip"],
  95. ["7z", "application/x-7z-compressed"],
  96. // Others
  97. ["mkv", "video/x-matroska"],
  98. ["mov", "video/quicktime"],
  99. ["msg", "application/vnd.ms-outlook"]
  100. ]);
  101. function toFileWithPath(file, path) {
  102. const f = withMimeType(file);
  103. if (typeof f.path !== "string") {
  104. const { webkitRelativePath } = file;
  105. Object.defineProperty(f, "path", {
  106. value: typeof path === "string" ? path : (
  107. // If <input webkitdirectory> is set,
  108. // the File will have a {webkitRelativePath} property
  109. // https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory
  110. typeof webkitRelativePath === "string" && webkitRelativePath.length > 0 ? webkitRelativePath : file.name
  111. ),
  112. writable: false,
  113. configurable: false,
  114. enumerable: true
  115. });
  116. }
  117. return f;
  118. }
  119. function withMimeType(file) {
  120. const { name } = file;
  121. const hasExtension = name && name.lastIndexOf(".") !== -1;
  122. if (hasExtension && !file.type) {
  123. const ext = name.split(".").pop().toLowerCase();
  124. const type = COMMON_MIME_TYPES.get(ext);
  125. if (type) {
  126. Object.defineProperty(file, "type", {
  127. value: type,
  128. writable: false,
  129. configurable: false,
  130. enumerable: true
  131. });
  132. }
  133. }
  134. return file;
  135. }
  136.  
  137. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/react-dropzone-esm@15.0.1_react@18.3.1/node_modules/react-dropzone-esm/dist/esm/file-selector.mjs
  138. var __async = (__this, __arguments, generator) => {
  139. return new Promise((resolve, reject) => {
  140. var fulfilled = (value) => {
  141. try {
  142. step(generator.next(value));
  143. } catch (e) {
  144. reject(e);
  145. }
  146. };
  147. var rejected = (value) => {
  148. try {
  149. step(generator.throw(value));
  150. } catch (e) {
  151. reject(e);
  152. }
  153. };
  154. var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
  155. step((generator = generator.apply(__this, __arguments)).next());
  156. });
  157. };
  158. var FILES_TO_IGNORE = [
  159. // Thumbnail cache files for macOS and Windows
  160. ".DS_Store",
  161. // macOs
  162. "Thumbs.db"
  163. // Windows
  164. ];
  165. function fromEvent(evt) {
  166. return __async(this, null, function* () {
  167. if (isObject(evt) && isDataTransfer(evt.dataTransfer)) {
  168. return getDataTransferFiles(evt.dataTransfer, evt.type);
  169. } else if (isChangeEvt(evt)) {
  170. return getInputFiles(evt);
  171. } else if (Array.isArray(evt) && evt.every((item) => "getFile" in item && typeof item.getFile === "function")) {
  172. return getFsHandleFiles(evt);
  173. }
  174. return [];
  175. });
  176. }
  177. function isDataTransfer(value) {
  178. return isObject(value);
  179. }
  180. function isChangeEvt(value) {
  181. return isObject(value) && isObject(value.target);
  182. }
  183. function isObject(v) {
  184. return typeof v === "object" && v !== null;
  185. }
  186. function getInputFiles(evt) {
  187. return fromList(evt.target.files).map((file) => toFileWithPath(file));
  188. }
  189. function getFsHandleFiles(handles) {
  190. return __async(this, null, function* () {
  191. const files = yield Promise.all(handles.map((h) => h.getFile()));
  192. return files.map((file) => toFileWithPath(file));
  193. });
  194. }
  195. function getDataTransferFiles(dt, type) {
  196. return __async(this, null, function* () {
  197. if (dt.items) {
  198. const items = fromList(dt.items).filter((item) => item.kind === "file");
  199. if (type !== "drop") {
  200. return items;
  201. }
  202. const files = yield Promise.all(items.map(toFilePromises));
  203. return noIgnoredFiles(flatten(files));
  204. }
  205. return noIgnoredFiles(fromList(dt.files).map((file) => toFileWithPath(file)));
  206. });
  207. }
  208. function noIgnoredFiles(files) {
  209. return files.filter((file) => FILES_TO_IGNORE.indexOf(file.name) === -1);
  210. }
  211. function fromList(items) {
  212. if (items === null) {
  213. return [];
  214. }
  215. const files = [];
  216. for (let i = 0; i < items.length; i++) {
  217. const file = items[i];
  218. files.push(file);
  219. }
  220. return files;
  221. }
  222. function toFilePromises(item) {
  223. if (typeof item.webkitGetAsEntry !== "function") {
  224. return fromDataTransferItem(item);
  225. }
  226. const entry = item.webkitGetAsEntry();
  227. if (entry && entry.isDirectory) {
  228. return fromDirEntry(entry);
  229. }
  230. return fromDataTransferItem(item);
  231. }
  232. function flatten(items) {
  233. return items.reduce(
  234. (acc, files) => [
  235. ...acc,
  236. ...Array.isArray(files) ? flatten(files) : [files]
  237. ],
  238. []
  239. );
  240. }
  241. function fromDataTransferItem(item) {
  242. const file = item.getAsFile();
  243. if (!file) {
  244. return Promise.reject(`${item} is not a File`);
  245. }
  246. const fwp = toFileWithPath(file);
  247. return Promise.resolve(fwp);
  248. }
  249. function fromEntry(entry) {
  250. return __async(this, null, function* () {
  251. return entry.isDirectory ? fromDirEntry(entry) : fromFileEntry(entry);
  252. });
  253. }
  254. function fromDirEntry(entry) {
  255. const reader = entry.createReader();
  256. return new Promise((resolve, reject) => {
  257. const entries = [];
  258. function readEntries() {
  259. reader.readEntries(
  260. (batch) => __async(this, null, function* () {
  261. if (!batch.length) {
  262. try {
  263. const files = yield Promise.all(entries);
  264. resolve(files);
  265. } catch (err) {
  266. reject(err);
  267. }
  268. } else {
  269. const items = Promise.all(batch.map(fromEntry));
  270. entries.push(items);
  271. readEntries();
  272. }
  273. }),
  274. (err) => {
  275. reject(err);
  276. }
  277. );
  278. }
  279. readEntries();
  280. });
  281. }
  282. function fromFileEntry(entry) {
  283. return __async(this, null, function* () {
  284. return new Promise((resolve, reject) => {
  285. entry.file(
  286. (file) => {
  287. const fwp = toFileWithPath(file, entry.fullPath);
  288. resolve(fwp);
  289. },
  290. (err) => {
  291. reject(err);
  292. }
  293. );
  294. });
  295. });
  296. }
  297.  
  298. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/react-dropzone-esm@15.0.1_react@18.3.1/node_modules/react-dropzone-esm/dist/esm/attr-accept.mjs
  299. function accepts(file, acceptedFiles) {
  300. if (file && acceptedFiles) {
  301. const acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(",");
  302. const fileName = file.name || "";
  303. const mimeType = (file.type || "").toLowerCase();
  304. const baseMimeType = mimeType.replace(/\/.*$/, "");
  305. return acceptedFilesArray.some((type) => {
  306. const validType = type.trim().toLowerCase();
  307. if (validType.charAt(0) === ".") {
  308. return fileName.toLowerCase().endsWith(validType);
  309. } else if (validType.endsWith("/*")) {
  310. return baseMimeType === validType.replace(/\/.*$/, "");
  311. }
  312. return mimeType === validType;
  313. });
  314. }
  315. return true;
  316. }
  317.  
  318. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/react-dropzone-esm@15.0.1_react@18.3.1/node_modules/react-dropzone-esm/dist/esm/utils.mjs
  319. var __defProp = Object.defineProperty;
  320. var __defProps = Object.defineProperties;
  321. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  322. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  323. var __hasOwnProp = Object.prototype.hasOwnProperty;
  324. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  325. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  326. var __spreadValues = (a, b) => {
  327. for (var prop in b || (b = {}))
  328. if (__hasOwnProp.call(b, prop))
  329. __defNormalProp(a, prop, b[prop]);
  330. if (__getOwnPropSymbols)
  331. for (var prop of __getOwnPropSymbols(b)) {
  332. if (__propIsEnum.call(b, prop))
  333. __defNormalProp(a, prop, b[prop]);
  334. }
  335. return a;
  336. };
  337. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  338. var FILE_INVALID_TYPE = "file-invalid-type";
  339. var FILE_TOO_LARGE = "file-too-large";
  340. var FILE_TOO_SMALL = "file-too-small";
  341. var TOO_MANY_FILES = "too-many-files";
  342. var getInvalidTypeRejectionErr = (accept) => {
  343. accept = Array.isArray(accept) && accept.length === 1 ? accept[0] : accept;
  344. const messageSuffix = Array.isArray(accept) ? `one of ${accept.join(", ")}` : accept;
  345. return {
  346. code: FILE_INVALID_TYPE,
  347. message: `File type must be ${messageSuffix}`
  348. };
  349. };
  350. var getTooLargeRejectionErr = (maxSize) => {
  351. return {
  352. code: FILE_TOO_LARGE,
  353. message: `File is larger than ${maxSize} ${maxSize === 1 ? "byte" : "bytes"}`
  354. };
  355. };
  356. var getTooSmallRejectionErr = (minSize) => {
  357. return {
  358. code: FILE_TOO_SMALL,
  359. message: `File is smaller than ${minSize} ${minSize === 1 ? "byte" : "bytes"}`
  360. };
  361. };
  362. var TOO_MANY_FILES_REJECTION = {
  363. code: TOO_MANY_FILES,
  364. message: "Too many files"
  365. };
  366. function fileAccepted(file, accept) {
  367. const isAcceptable = file.type === "application/x-moz-file" || accepts(file, accept);
  368. return [
  369. isAcceptable,
  370. isAcceptable ? null : getInvalidTypeRejectionErr(accept)
  371. ];
  372. }
  373. function fileMatchSize(file, minSize, maxSize) {
  374. if (isDefined(file.size)) {
  375. if (isDefined(minSize) && isDefined(maxSize)) {
  376. if (file.size > maxSize)
  377. return [false, getTooLargeRejectionErr(maxSize)];
  378. if (file.size < minSize)
  379. return [false, getTooSmallRejectionErr(minSize)];
  380. } else if (isDefined(minSize) && file.size < minSize)
  381. return [false, getTooSmallRejectionErr(minSize)];
  382. else if (isDefined(maxSize) && file.size > maxSize)
  383. return [false, getTooLargeRejectionErr(maxSize)];
  384. }
  385. return [true, null];
  386. }
  387. function isDefined(value) {
  388. return value !== void 0 && value !== null;
  389. }
  390. function allFilesAccepted({
  391. files,
  392. accept,
  393. minSize,
  394. maxSize,
  395. multiple,
  396. maxFiles,
  397. validator
  398. }) {
  399. if (!multiple && files.length > 1 || multiple && maxFiles >= 1 && files.length > maxFiles) {
  400. return false;
  401. }
  402. return files.every((file) => {
  403. const [accepted] = fileAccepted(file, accept);
  404. const [sizeMatch] = fileMatchSize(file, minSize, maxSize);
  405. const customErrors = validator ? validator(file) : null;
  406. return accepted && sizeMatch && !customErrors;
  407. });
  408. }
  409. function isPropagationStopped(event) {
  410. if (typeof event.isPropagationStopped === "function") {
  411. return event.isPropagationStopped();
  412. } else if (typeof event.cancelBubble !== "undefined") {
  413. return event.cancelBubble;
  414. }
  415. return false;
  416. }
  417. function isEvtWithFiles(event) {
  418. if (!event.dataTransfer) {
  419. return !!event.target && !!event.target.files;
  420. }
  421. return Array.prototype.some.call(
  422. event.dataTransfer.types,
  423. (type) => type === "Files" || type === "application/x-moz-file"
  424. );
  425. }
  426. function onDocumentDragOver(event) {
  427. event.preventDefault();
  428. }
  429. function isIe(userAgent) {
  430. return userAgent.indexOf("MSIE") !== -1 || userAgent.indexOf("Trident/") !== -1;
  431. }
  432. function isEdge(userAgent) {
  433. return userAgent.indexOf("Edge/") !== -1;
  434. }
  435. function isIeOrEdge(userAgent = window.navigator.userAgent) {
  436. return isIe(userAgent) || isEdge(userAgent);
  437. }
  438. function composeEventHandlers(...fns) {
  439. return (event, ...args) => fns.some((fn) => {
  440. if (!isPropagationStopped(event) && fn) {
  441. fn(event, ...args);
  442. }
  443. return isPropagationStopped(event);
  444. });
  445. }
  446. function canUseFileSystemAccessAPI() {
  447. return "showOpenFilePicker" in window;
  448. }
  449. function pickerOptionsFromAccept(accept) {
  450. if (isDefined(accept)) {
  451. const acceptForPicker = Object.entries(accept).filter(([mimeType, ext]) => {
  452. let ok = true;
  453. if (!isMIMEType(mimeType)) {
  454. console.warn(
  455. `Skipped "${mimeType}" because it is not a valid MIME type. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types for a list of valid MIME types.`
  456. );
  457. ok = false;
  458. }
  459. if (!Array.isArray(ext) || !ext.every(isExt)) {
  460. console.warn(
  461. `Skipped "${mimeType}" because an invalid file extension was provided.`
  462. );
  463. ok = false;
  464. }
  465. return ok;
  466. }).reduce(
  467. (agg, [mimeType, ext]) => __spreadProps(__spreadValues({}, agg), {
  468. [mimeType]: ext
  469. }),
  470. {}
  471. );
  472. return [
  473. {
  474. // description is required due to https://crbug.com/1264708
  475. description: "Files",
  476. accept: acceptForPicker
  477. }
  478. ];
  479. }
  480. return accept;
  481. }
  482. function acceptPropAsAcceptAttr(accept) {
  483. if (isDefined(accept)) {
  484. return Object.entries(accept).reduce((a, [mimeType, ext]) => [...a, mimeType, ...ext], []).filter((v) => isMIMEType(v) || isExt(v)).join(",");
  485. }
  486. return void 0;
  487. }
  488. function isAbort(v) {
  489. return v instanceof DOMException && (v.name === "AbortError" || v.code === v.ABORT_ERR);
  490. }
  491. function isSecurityError(v) {
  492. return v instanceof DOMException && (v.name === "SecurityError" || v.code === v.SECURITY_ERR);
  493. }
  494. function isMIMEType(v) {
  495. return v === "audio/*" || v === "video/*" || v === "image/*" || v === "text/*" || /\w+\/[-+.\w]+/g.test(v);
  496. }
  497. function isExt(v) {
  498. return /^.*\.[\w]+$/.test(v);
  499. }
  500.  
  501. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/react-dropzone-esm@15.0.1_react@18.3.1/node_modules/react-dropzone-esm/dist/esm/index.mjs
  502. var __defProp2 = Object.defineProperty;
  503. var __defProps2 = Object.defineProperties;
  504. var __getOwnPropDescs2 = Object.getOwnPropertyDescriptors;
  505. var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
  506. var __hasOwnProp2 = Object.prototype.hasOwnProperty;
  507. var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
  508. var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  509. var __spreadValues2 = (a, b) => {
  510. for (var prop in b || (b = {}))
  511. if (__hasOwnProp2.call(b, prop))
  512. __defNormalProp2(a, prop, b[prop]);
  513. if (__getOwnPropSymbols2)
  514. for (var prop of __getOwnPropSymbols2(b)) {
  515. if (__propIsEnum2.call(b, prop))
  516. __defNormalProp2(a, prop, b[prop]);
  517. }
  518. return a;
  519. };
  520. var __spreadProps2 = (a, b) => __defProps2(a, __getOwnPropDescs2(b));
  521. var __objRest = (source, exclude) => {
  522. var target = {};
  523. for (var prop in source)
  524. if (__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0)
  525. target[prop] = source[prop];
  526. if (source != null && __getOwnPropSymbols2)
  527. for (var prop of __getOwnPropSymbols2(source)) {
  528. if (exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop))
  529. target[prop] = source[prop];
  530. }
  531. return target;
  532. };
  533. var Dropzone = React.forwardRef((_a, ref) => {
  534. var _b = _a, { children } = _b, params = __objRest(_b, ["children"]);
  535. const _a2 = useDropzone(params), { open } = _a2, props = __objRest(_a2, ["open"]);
  536. React.useImperativeHandle(ref, () => ({ open }), [open]);
  537. return /* @__PURE__ */ React.createElement(React.Fragment, null, children(__spreadProps2(__spreadValues2({}, props), { open })));
  538. });
  539. Dropzone.displayName = "Dropzone";
  540. var defaultProps = {
  541. disabled: false,
  542. getFilesFromEvent: fromEvent,
  543. maxSize: Infinity,
  544. minSize: 0,
  545. multiple: true,
  546. maxFiles: 0,
  547. preventDropOnDocument: true,
  548. noClick: false,
  549. noKeyboard: false,
  550. noDrag: false,
  551. noDragEventsBubbling: false,
  552. validator: null,
  553. useFsAccessApi: true,
  554. autoFocus: false
  555. };
  556. Dropzone.defaultProps = defaultProps;
  557. Dropzone.propTypes = {
  558. /**
  559. * Render function that exposes the dropzone state and prop getter fns
  560. *
  561. * @param {object} params
  562. * @param {Function} params.getRootProps Returns the props you should apply to the root drop container you render
  563. * @param {Function} params.getInputProps Returns the props you should apply to hidden file input you render
  564. * @param {Function} params.open Open the native file selection dialog
  565. * @param {boolean} params.isFocused Dropzone area is in focus
  566. * @param {boolean} params.isFileDialogActive File dialog is opened
  567. * @param {boolean} params.isDragActive Active drag is in progress
  568. * @param {boolean} params.isDragAccept Dragged files are accepted
  569. * @param {boolean} params.isDragReject Some dragged files are rejected
  570. * @param {File[]} params.acceptedFiles Accepted files
  571. * @param {FileRejection[]} params.fileRejections Rejected files and why they were rejected
  572. */
  573. children: PropTypes.func,
  574. /**
  575. * Set accepted file types.
  576. * Checkout https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker types option for more information.
  577. * Keep in mind that mime type determination is not reliable across platforms. CSV files,
  578. * for example, are reported as text/plain under macOS but as application/vnd.ms-excel under
  579. * Windows. In some cases there might not be a mime type set at all (https://github.com/react-dropzone/react-dropzone/issues/276).
  580. */
  581. accept: PropTypes.objectOf(PropTypes.arrayOf(PropTypes.string)),
  582. /**
  583. * Allow drag 'n' drop (or selection from the file dialog) of multiple files
  584. */
  585. multiple: PropTypes.bool,
  586. /**
  587. * If false, allow dropped items to take over the current browser window
  588. */
  589. preventDropOnDocument: PropTypes.bool,
  590. /**
  591. * If true, disables click to open the native file selection dialog
  592. */
  593. noClick: PropTypes.bool,
  594. /**
  595. * If true, disables SPACE/ENTER to open the native file selection dialog.
  596. * Note that it also stops tracking the focus state.
  597. */
  598. noKeyboard: PropTypes.bool,
  599. /**
  600. * If true, disables drag 'n' drop
  601. */
  602. noDrag: PropTypes.bool,
  603. /**
  604. * If true, stops drag event propagation to parents
  605. */
  606. noDragEventsBubbling: PropTypes.bool,
  607. /**
  608. * Minimum file size (in bytes)
  609. */
  610. minSize: PropTypes.number,
  611. /**
  612. * Maximum file size (in bytes)
  613. */
  614. maxSize: PropTypes.number,
  615. /**
  616. * Maximum accepted number of files
  617. * The default value is 0 which means there is no limitation to how many files are accepted.
  618. */
  619. maxFiles: PropTypes.number,
  620. /**
  621. * Enable/disable the dropzone
  622. */
  623. disabled: PropTypes.bool,
  624. /**
  625. * Use this to provide a custom file aggregator
  626. *
  627. * @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
  628. */
  629. getFilesFromEvent: PropTypes.func,
  630. /**
  631. * Cb for when closing the file dialog with no selection
  632. */
  633. onFileDialogCancel: PropTypes.func,
  634. /**
  635. * Cb for when opening the file dialog
  636. */
  637. onFileDialogOpen: PropTypes.func,
  638. /**
  639. * Set to true to use the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API
  640. * to open the file picker instead of using an `<input type="file">` click event.
  641. */
  642. useFsAccessApi: PropTypes.bool,
  643. /**
  644. * Set to true to focus the root element on render
  645. */
  646. autoFocus: PropTypes.bool,
  647. /**
  648. * Cb for when the `dragenter` event occurs.
  649. *
  650. * @param {DragEvent} event
  651. */
  652. onDragEnter: PropTypes.func,
  653. /**
  654. * Cb for when the `dragleave` event occurs
  655. *
  656. * @param {DragEvent} event
  657. */
  658. onDragLeave: PropTypes.func,
  659. /**
  660. * Cb for when the `dragover` event occurs
  661. *
  662. * @param {DragEvent} event
  663. */
  664. onDragOver: PropTypes.func,
  665. /**
  666. * Cb for when the `drop` event occurs.
  667. * Note that this callback is invoked after the `getFilesFromEvent` callback is done.
  668. *
  669. * Files are accepted or rejected based on the `accept`, `multiple`, `minSize` and `maxSize` props.
  670. * `accept` must be a valid [MIME type](http://www.iana.org/assignments/media-types/media-types.xhtml) according to [input element specification](https://www.w3.org/wiki/HTML/Elements/input/file) or a valid file extension.
  671. * If `multiple` is set to false and additional files are dropped,
  672. * all files besides the first will be rejected.
  673. * Any file which does not have a size in the [`minSize`, `maxSize`] range, will be rejected as well.
  674. *
  675. * Note that the `onDrop` callback will always be invoked regardless if the dropped files were accepted or rejected.
  676. * If you'd like to react to a specific scenario, use the `onDropAccepted`/`onDropRejected` props.
  677. *
  678. * `onDrop` will provide you with an array of [File](https://developer.mozilla.org/en-US/docs/Web/API/File) objects which you can then process and send to a server.
  679. * For example, with [SuperAgent](https://github.com/visionmedia/superagent) as a http/ajax library:
  680. *
  681. * ```js
  682. * function onDrop(acceptedFiles) {
  683. * const req = request.post('/upload')
  684. * acceptedFiles.forEach(file => {
  685. * req.attach(file.name, file)
  686. * })
  687. * req.end(callback)
  688. * }
  689. * ```
  690. *
  691. * @param {File[]} acceptedFiles
  692. * @param {FileRejection[]} fileRejections
  693. * @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
  694. */
  695. onDrop: PropTypes.func,
  696. /**
  697. * Cb for when the `drop` event occurs.
  698. * Note that if no files are accepted, this callback is not invoked.
  699. *
  700. * @param {File[]} files
  701. * @param {(DragEvent|Event)} event
  702. */
  703. onDropAccepted: PropTypes.func,
  704. /**
  705. * Cb for when the `drop` event occurs.
  706. * Note that if no files are rejected, this callback is not invoked.
  707. *
  708. * @param {FileRejection[]} fileRejections
  709. * @param {(DragEvent|Event)} event
  710. */
  711. onDropRejected: PropTypes.func,
  712. /**
  713. * Cb for when there's some error from any of the promises.
  714. *
  715. * @param {Error} error
  716. */
  717. onError: PropTypes.func,
  718. /**
  719. * Custom validation function. It must return null if there's no errors.
  720. * @param {File} file
  721. * @returns {FileError|FileError[]|null}
  722. */
  723. validator: PropTypes.func
  724. };
  725. var initialState = {
  726. isFocused: false,
  727. isFileDialogActive: false,
  728. isDragActive: false,
  729. isDragAccept: false,
  730. isDragReject: false,
  731. acceptedFiles: [],
  732. fileRejections: []
  733. };
  734. function useDropzone(props = {}) {
  735. const {
  736. accept,
  737. disabled,
  738. getFilesFromEvent,
  739. maxSize,
  740. minSize,
  741. multiple,
  742. maxFiles,
  743. onDragEnter,
  744. onDragLeave,
  745. onDragOver,
  746. onDrop,
  747. onDropAccepted,
  748. onDropRejected,
  749. onFileDialogCancel,
  750. onFileDialogOpen,
  751. useFsAccessApi,
  752. autoFocus,
  753. preventDropOnDocument,
  754. noClick,
  755. noKeyboard,
  756. noDrag,
  757. noDragEventsBubbling,
  758. onError,
  759. validator
  760. } = __spreadValues2(__spreadValues2({}, defaultProps), props);
  761. const acceptAttr = React.useMemo(() => acceptPropAsAcceptAttr(accept), [accept]);
  762. const pickerTypes = React.useMemo(() => pickerOptionsFromAccept(accept), [accept]);
  763. const onFileDialogOpenCb = React.useMemo(
  764. () => typeof onFileDialogOpen === "function" ? onFileDialogOpen : noop,
  765. [onFileDialogOpen]
  766. );
  767. const onFileDialogCancelCb = React.useMemo(
  768. () => typeof onFileDialogCancel === "function" ? onFileDialogCancel : noop,
  769. [onFileDialogCancel]
  770. );
  771. const rootRef = React.useRef(null);
  772. const inputRef = React.useRef(null);
  773. const [state, dispatch] = React.useReducer(reducer, initialState);
  774. const { isFocused, isFileDialogActive } = state;
  775. const fsAccessApiWorksRef = React.useRef(
  776. typeof window !== "undefined" && window.isSecureContext && useFsAccessApi && canUseFileSystemAccessAPI()
  777. );
  778. const onWindowFocus = () => {
  779. if (!fsAccessApiWorksRef.current && isFileDialogActive) {
  780. setTimeout(() => {
  781. if (inputRef.current) {
  782. const { files } = inputRef.current;
  783. if (!files.length) {
  784. dispatch({ type: "closeDialog" });
  785. onFileDialogCancelCb();
  786. }
  787. }
  788. }, 300);
  789. }
  790. };
  791. React.useEffect(() => {
  792. window.addEventListener("focus", onWindowFocus, false);
  793. return () => {
  794. window.removeEventListener("focus", onWindowFocus, false);
  795. };
  796. }, [inputRef, isFileDialogActive, onFileDialogCancelCb, fsAccessApiWorksRef]);
  797. const dragTargetsRef = React.useRef([]);
  798. const onDocumentDrop = (event) => {
  799. if (rootRef.current && rootRef.current.contains(event.target)) {
  800. return;
  801. }
  802. event.preventDefault();
  803. dragTargetsRef.current = [];
  804. };
  805. React.useEffect(() => {
  806. if (preventDropOnDocument) {
  807. document.addEventListener("dragover", onDocumentDragOver, false);
  808. document.addEventListener("drop", onDocumentDrop, false);
  809. }
  810. return () => {
  811. if (preventDropOnDocument) {
  812. document.removeEventListener("dragover", onDocumentDragOver);
  813. document.removeEventListener("drop", onDocumentDrop);
  814. }
  815. };
  816. }, [rootRef, preventDropOnDocument]);
  817. React.useEffect(() => {
  818. if (!disabled && autoFocus && rootRef.current) {
  819. rootRef.current.focus();
  820. }
  821. return () => {
  822. };
  823. }, [rootRef, autoFocus, disabled]);
  824. const onErrCb = React.useCallback(
  825. (e) => {
  826. if (onError) {
  827. onError(e);
  828. } else {
  829. console.error(e);
  830. }
  831. },
  832. [onError]
  833. );
  834. const onDragEnterCb = React.useCallback(
  835. (event) => {
  836. event.preventDefault();
  837. event.persist();
  838. stopPropagation(event);
  839. dragTargetsRef.current = [...dragTargetsRef.current, event.target];
  840. if (isEvtWithFiles(event)) {
  841. Promise.resolve(getFilesFromEvent(event)).then((files) => {
  842. if (isPropagationStopped(event) && !noDragEventsBubbling) {
  843. return;
  844. }
  845. const fileCount = files.length;
  846. const isDragAccept = fileCount > 0 && allFilesAccepted({
  847. files,
  848. accept: acceptAttr,
  849. minSize,
  850. maxSize,
  851. multiple,
  852. maxFiles,
  853. validator
  854. });
  855. const isDragReject = fileCount > 0 && !isDragAccept;
  856. dispatch({
  857. isDragAccept,
  858. isDragReject,
  859. isDragActive: true,
  860. type: "setDraggedFiles"
  861. });
  862. if (onDragEnter) {
  863. onDragEnter(event);
  864. }
  865. }).catch((e) => onErrCb(e));
  866. }
  867. },
  868. [
  869. getFilesFromEvent,
  870. onDragEnter,
  871. onErrCb,
  872. noDragEventsBubbling,
  873. acceptAttr,
  874. minSize,
  875. maxSize,
  876. multiple,
  877. maxFiles,
  878. validator
  879. ]
  880. );
  881. const onDragOverCb = React.useCallback(
  882. (event) => {
  883. event.preventDefault();
  884. event.persist();
  885. stopPropagation(event);
  886. const hasFiles = isEvtWithFiles(event);
  887. if (hasFiles && event.dataTransfer) {
  888. try {
  889. event.dataTransfer.dropEffect = "copy";
  890. } catch (e) {
  891. }
  892. }
  893. if (hasFiles && onDragOver) {
  894. onDragOver(event);
  895. }
  896. return false;
  897. },
  898. [onDragOver, noDragEventsBubbling]
  899. );
  900. const onDragLeaveCb = React.useCallback(
  901. (event) => {
  902. event.preventDefault();
  903. event.persist();
  904. stopPropagation(event);
  905. const targets = dragTargetsRef.current.filter(
  906. (target) => rootRef.current && rootRef.current.contains(target)
  907. );
  908. const targetIdx = targets.indexOf(event.target);
  909. if (targetIdx !== -1) {
  910. targets.splice(targetIdx, 1);
  911. }
  912. dragTargetsRef.current = targets;
  913. if (targets.length > 0) {
  914. return;
  915. }
  916. dispatch({
  917. type: "setDraggedFiles",
  918. isDragActive: false,
  919. isDragAccept: false,
  920. isDragReject: false
  921. });
  922. if (isEvtWithFiles(event) && onDragLeave) {
  923. onDragLeave(event);
  924. }
  925. },
  926. [rootRef, onDragLeave, noDragEventsBubbling]
  927. );
  928. const setFiles = React.useCallback(
  929. (files, event) => {
  930. const acceptedFiles = [];
  931. const fileRejections = [];
  932. files.forEach((file) => {
  933. const [accepted, acceptError] = fileAccepted(file, acceptAttr);
  934. const [sizeMatch, sizeError] = fileMatchSize(file, minSize, maxSize);
  935. const customErrors = validator ? validator(file) : null;
  936. if (accepted && sizeMatch && !customErrors) {
  937. acceptedFiles.push(file);
  938. } else {
  939. let errors = [acceptError, sizeError];
  940. if (customErrors) {
  941. errors = errors.concat(customErrors);
  942. }
  943. fileRejections.push({ file, errors: errors.filter((e) => e) });
  944. }
  945. });
  946. if (!multiple && acceptedFiles.length > 1 || multiple && maxFiles >= 1 && acceptedFiles.length > maxFiles) {
  947. acceptedFiles.forEach((file) => {
  948. fileRejections.push({ file, errors: [TOO_MANY_FILES_REJECTION] });
  949. });
  950. acceptedFiles.splice(0);
  951. }
  952. dispatch({
  953. acceptedFiles,
  954. fileRejections,
  955. type: "setFiles"
  956. });
  957. if (onDrop) {
  958. onDrop(acceptedFiles, fileRejections, event);
  959. }
  960. if (fileRejections.length > 0 && onDropRejected) {
  961. onDropRejected(fileRejections, event);
  962. }
  963. if (acceptedFiles.length > 0 && onDropAccepted) {
  964. onDropAccepted(acceptedFiles, event);
  965. }
  966. },
  967. [
  968. dispatch,
  969. multiple,
  970. acceptAttr,
  971. minSize,
  972. maxSize,
  973. maxFiles,
  974. onDrop,
  975. onDropAccepted,
  976. onDropRejected,
  977. validator
  978. ]
  979. );
  980. const onDropCb = React.useCallback(
  981. (event) => {
  982. event.preventDefault();
  983. event.persist();
  984. stopPropagation(event);
  985. dragTargetsRef.current = [];
  986. if (isEvtWithFiles(event)) {
  987. Promise.resolve(getFilesFromEvent(event)).then((files) => {
  988. if (isPropagationStopped(event) && !noDragEventsBubbling) {
  989. return;
  990. }
  991. setFiles(files, event);
  992. }).catch((e) => onErrCb(e));
  993. }
  994. dispatch({ type: "reset" });
  995. },
  996. [getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling]
  997. );
  998. const openFileDialog = React.useCallback(() => {
  999. if (fsAccessApiWorksRef.current) {
  1000. dispatch({ type: "openDialog" });
  1001. onFileDialogOpenCb();
  1002. const opts = {
  1003. multiple,
  1004. types: pickerTypes
  1005. };
  1006. window.showOpenFilePicker(opts).then((handles) => getFilesFromEvent(handles)).then((files) => {
  1007. setFiles(files, null);
  1008. dispatch({ type: "closeDialog" });
  1009. }).catch((e) => {
  1010. if (isAbort(e)) {
  1011. onFileDialogCancelCb(e);
  1012. dispatch({ type: "closeDialog" });
  1013. } else if (isSecurityError(e)) {
  1014. fsAccessApiWorksRef.current = false;
  1015. if (inputRef.current) {
  1016. inputRef.current.value = null;
  1017. inputRef.current.click();
  1018. } else {
  1019. onErrCb(
  1020. new Error(
  1021. "Cannot open the file picker because the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API is not supported and no <input> was provided."
  1022. )
  1023. );
  1024. }
  1025. } else {
  1026. onErrCb(e);
  1027. }
  1028. });
  1029. return;
  1030. }
  1031. if (inputRef.current) {
  1032. dispatch({ type: "openDialog" });
  1033. onFileDialogOpenCb();
  1034. inputRef.current.value = null;
  1035. inputRef.current.click();
  1036. }
  1037. }, [
  1038. dispatch,
  1039. onFileDialogOpenCb,
  1040. onFileDialogCancelCb,
  1041. useFsAccessApi,
  1042. setFiles,
  1043. onErrCb,
  1044. pickerTypes,
  1045. multiple
  1046. ]);
  1047. const onKeyDownCb = React.useCallback(
  1048. (event) => {
  1049. if (!rootRef.current || !rootRef.current.isEqualNode(event.target)) {
  1050. return;
  1051. }
  1052. if (event.key === " " || event.key === "Enter" || event.keyCode === 32 || event.keyCode === 13) {
  1053. event.preventDefault();
  1054. openFileDialog();
  1055. }
  1056. },
  1057. [rootRef, openFileDialog]
  1058. );
  1059. const onFocusCb = React.useCallback(() => {
  1060. dispatch({ type: "focus" });
  1061. }, []);
  1062. const onBlurCb = React.useCallback(() => {
  1063. dispatch({ type: "blur" });
  1064. }, []);
  1065. const onClickCb = React.useCallback(() => {
  1066. if (noClick) {
  1067. return;
  1068. }
  1069. if (isIeOrEdge()) {
  1070. setTimeout(openFileDialog, 0);
  1071. } else {
  1072. openFileDialog();
  1073. }
  1074. }, [noClick, openFileDialog]);
  1075. const composeHandler = (fn) => {
  1076. return disabled ? null : fn;
  1077. };
  1078. const composeKeyboardHandler = (fn) => {
  1079. return noKeyboard ? null : composeHandler(fn);
  1080. };
  1081. const composeDragHandler = (fn) => {
  1082. return noDrag ? null : composeHandler(fn);
  1083. };
  1084. const stopPropagation = (event) => {
  1085. if (noDragEventsBubbling) {
  1086. event.stopPropagation();
  1087. }
  1088. };
  1089. const getRootProps = React.useMemo(
  1090. () => (_a = {}) => {
  1091. var _b = _a, {
  1092. refKey = "ref",
  1093. role,
  1094. onKeyDown,
  1095. onFocus,
  1096. onBlur,
  1097. onClick,
  1098. onDragEnter: onDragEnter2,
  1099. onDragOver: onDragOver2,
  1100. onDragLeave: onDragLeave2,
  1101. onDrop: onDrop2
  1102. } = _b, rest = __objRest(_b, [
  1103. "refKey",
  1104. "role",
  1105. "onKeyDown",
  1106. "onFocus",
  1107. "onBlur",
  1108. "onClick",
  1109. "onDragEnter",
  1110. "onDragOver",
  1111. "onDragLeave",
  1112. "onDrop"
  1113. ]);
  1114. return __spreadValues2(__spreadValues2({
  1115. onKeyDown: composeKeyboardHandler(
  1116. composeEventHandlers(onKeyDown, onKeyDownCb)
  1117. ),
  1118. onFocus: composeKeyboardHandler(
  1119. composeEventHandlers(onFocus, onFocusCb)
  1120. ),
  1121. onBlur: composeKeyboardHandler(composeEventHandlers(onBlur, onBlurCb)),
  1122. onClick: composeHandler(composeEventHandlers(onClick, onClickCb)),
  1123. onDragEnter: composeDragHandler(
  1124. composeEventHandlers(onDragEnter2, onDragEnterCb)
  1125. ),
  1126. onDragOver: composeDragHandler(
  1127. composeEventHandlers(onDragOver2, onDragOverCb)
  1128. ),
  1129. onDragLeave: composeDragHandler(
  1130. composeEventHandlers(onDragLeave2, onDragLeaveCb)
  1131. ),
  1132. onDrop: composeDragHandler(composeEventHandlers(onDrop2, onDropCb)),
  1133. role: typeof role === "string" && role !== "" ? role : "presentation",
  1134. [refKey]: rootRef
  1135. }, !disabled && !noKeyboard ? { tabIndex: 0 } : {}), rest);
  1136. },
  1137. [
  1138. rootRef,
  1139. onKeyDownCb,
  1140. onFocusCb,
  1141. onBlurCb,
  1142. onClickCb,
  1143. onDragEnterCb,
  1144. onDragOverCb,
  1145. onDragLeaveCb,
  1146. onDropCb,
  1147. noKeyboard,
  1148. noDrag,
  1149. disabled
  1150. ]
  1151. );
  1152. const onInputElementClick = React.useCallback((event) => {
  1153. event.stopPropagation();
  1154. }, []);
  1155. const getInputProps = React.useMemo(
  1156. () => (_a = {}) => {
  1157. var _b = _a, { refKey = "ref", onChange, onClick } = _b, rest = __objRest(_b, ["refKey", "onChange", "onClick"]);
  1158. const inputProps = {
  1159. accept: acceptAttr,
  1160. multiple,
  1161. type: "file",
  1162. style: { display: "none" },
  1163. onChange: composeHandler(composeEventHandlers(onChange, onDropCb)),
  1164. onClick: composeHandler(
  1165. composeEventHandlers(onClick, onInputElementClick)
  1166. ),
  1167. tabIndex: -1,
  1168. [refKey]: inputRef
  1169. };
  1170. return __spreadValues2(__spreadValues2({}, inputProps), rest);
  1171. },
  1172. [inputRef, accept, multiple, onDropCb, disabled]
  1173. );
  1174. return __spreadProps2(__spreadValues2({}, state), {
  1175. isFocused: isFocused && !disabled,
  1176. getRootProps,
  1177. getInputProps,
  1178. rootRef,
  1179. inputRef,
  1180. open: composeHandler(openFileDialog)
  1181. });
  1182. }
  1183. function reducer(state, action) {
  1184. switch (action.type) {
  1185. case "focus":
  1186. return __spreadProps2(__spreadValues2({}, state), {
  1187. isFocused: true
  1188. });
  1189. case "blur":
  1190. return __spreadProps2(__spreadValues2({}, state), {
  1191. isFocused: false
  1192. });
  1193. case "openDialog":
  1194. return __spreadProps2(__spreadValues2({}, initialState), {
  1195. isFileDialogActive: true
  1196. });
  1197. case "closeDialog":
  1198. return __spreadProps2(__spreadValues2({}, state), {
  1199. isFileDialogActive: false
  1200. });
  1201. case "setDraggedFiles":
  1202. return __spreadProps2(__spreadValues2({}, state), {
  1203. isDragActive: action.isDragActive,
  1204. isDragAccept: action.isDragAccept,
  1205. isDragReject: action.isDragReject
  1206. });
  1207. case "setFiles":
  1208. return __spreadProps2(__spreadValues2({}, state), {
  1209. acceptedFiles: action.acceptedFiles,
  1210. fileRejections: action.fileRejections
  1211. });
  1212. case "reset":
  1213. return __spreadValues2({}, initialState);
  1214. default:
  1215. return state;
  1216. }
  1217. }
  1218. function noop() {
  1219. }
  1220. var [DropzoneProvider, useDropzoneContext] = core.createSafeContext(
  1221. "Dropzone component was not found in tree"
  1222. );
  1223. function createDropzoneStatus(status) {
  1224. const Component = (props) => {
  1225. const { children, ...others } = core.useProps(`Dropzone${hooks.upperFirst(status)}`, {}, props);
  1226. const ctx = useDropzoneContext();
  1227. const _children = core.isElement(children) ? children : /* @__PURE__ */ jsxRuntime.jsx("span", { children });
  1228. if (ctx[status]) {
  1229. return React.cloneElement(_children, others);
  1230. }
  1231. return null;
  1232. };
  1233. Component.displayName = `@mantine/dropzone/${hooks.upperFirst(status)}`;
  1234. return Component;
  1235. }
  1236. var DropzoneAccept = createDropzoneStatus("accept");
  1237. var DropzoneReject = createDropzoneStatus("reject");
  1238. var DropzoneIdle = createDropzoneStatus("idle");
  1239.  
  1240. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/@mantine+dropzone@7.13.0_@mantine+core@7.13.0_@mantine+hooks@7.13.0_react-dom@18.3.1_react@18.3.1/node_modules/@mantine/dropzone/esm/Dropzone.module.css.mjs
  1241. var classes = { "root": "m_d46a4834", "inner": "m_b85f7144", "fullScreen": "m_96f6e9ad", "dropzone": "m_7946116d" };
  1242.  
  1243. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/@mantine+dropzone@7.13.0_@mantine+core@7.13.0_@mantine+hooks@7.13.0_react-dom@18.3.1_react@18.3.1/node_modules/@mantine/dropzone/esm/Dropzone.mjs
  1244. var defaultProps2 = {
  1245. loading: false,
  1246. multiple: true,
  1247. maxSize: Infinity,
  1248. autoFocus: false,
  1249. activateOnClick: true,
  1250. activateOnDrag: true,
  1251. dragEventsBubbling: true,
  1252. activateOnKeyboard: true,
  1253. useFsAccessApi: true,
  1254. variant: "light",
  1255. rejectColor: "red"
  1256. };
  1257. var varsResolver = core.createVarsResolver(
  1258. (theme, { radius, variant, acceptColor, rejectColor }) => {
  1259. const acceptColors = theme.variantColorResolver({
  1260. color: acceptColor || theme.primaryColor,
  1261. theme,
  1262. variant
  1263. });
  1264. const rejectColors = theme.variantColorResolver({
  1265. color: rejectColor || "red",
  1266. theme,
  1267. variant
  1268. });
  1269. return {
  1270. root: {
  1271. "--dropzone-radius": core.getRadius(radius),
  1272. "--dropzone-accept-color": acceptColors.color,
  1273. "--dropzone-accept-bg": acceptColors.background,
  1274. "--dropzone-reject-color": rejectColors.color,
  1275. "--dropzone-reject-bg": rejectColors.background
  1276. }
  1277. };
  1278. }
  1279. );
  1280. var Dropzone2 = core.factory((_props, ref) => {
  1281. const props = core.useProps("Dropzone", defaultProps2, _props);
  1282. const {
  1283. classNames,
  1284. className,
  1285. style,
  1286. styles,
  1287. unstyled,
  1288. vars,
  1289. radius,
  1290. disabled,
  1291. loading,
  1292. multiple,
  1293. maxSize,
  1294. accept,
  1295. children,
  1296. onDropAny,
  1297. onDrop,
  1298. onReject,
  1299. openRef,
  1300. name,
  1301. maxFiles,
  1302. autoFocus,
  1303. activateOnClick,
  1304. activateOnDrag,
  1305. dragEventsBubbling,
  1306. activateOnKeyboard,
  1307. onDragEnter,
  1308. onDragLeave,
  1309. onDragOver,
  1310. onFileDialogCancel,
  1311. onFileDialogOpen,
  1312. preventDropOnDocument,
  1313. useFsAccessApi,
  1314. getFilesFromEvent,
  1315. validator,
  1316. rejectColor,
  1317. acceptColor,
  1318. enablePointerEvents,
  1319. loaderProps,
  1320. inputProps,
  1321. mod,
  1322. ...others
  1323. } = props;
  1324. const getStyles = core.useStyles({
  1325. name: "Dropzone",
  1326. classes,
  1327. props,
  1328. className,
  1329. style,
  1330. classNames,
  1331. styles,
  1332. unstyled,
  1333. vars,
  1334. varsResolver
  1335. });
  1336. const { getRootProps, getInputProps, isDragAccept, isDragReject, open } = useDropzone({
  1337. onDrop: onDropAny,
  1338. onDropAccepted: onDrop,
  1339. onDropRejected: onReject,
  1340. disabled: disabled || loading,
  1341. accept: Array.isArray(accept) ? accept.reduce((r, key) => ({ ...r, [key]: [] }), {}) : accept,
  1342. multiple,
  1343. maxSize,
  1344. maxFiles,
  1345. autoFocus,
  1346. noClick: !activateOnClick,
  1347. noDrag: !activateOnDrag,
  1348. noDragEventsBubbling: !dragEventsBubbling,
  1349. noKeyboard: !activateOnKeyboard,
  1350. onDragEnter,
  1351. onDragLeave,
  1352. onDragOver,
  1353. onFileDialogCancel,
  1354. onFileDialogOpen,
  1355. preventDropOnDocument,
  1356. useFsAccessApi,
  1357. validator,
  1358. ...getFilesFromEvent ? { getFilesFromEvent } : null
  1359. });
  1360. hooks.assignRef(openRef, open);
  1361. const isIdle = !isDragAccept && !isDragReject;
  1362. return /* @__PURE__ */ jsxRuntime.jsx(DropzoneProvider, { value: { accept: isDragAccept, reject: isDragReject, idle: isIdle }, children: /* @__PURE__ */ jsxRuntime.jsxs(
  1363. core.Box,
  1364. {
  1365. ...getRootProps(),
  1366. ...getStyles("root", { focusable: true }),
  1367. ...others,
  1368. mod: [
  1369. {
  1370. accept: isDragAccept,
  1371. reject: isDragReject,
  1372. idle: isIdle,
  1373. loading,
  1374. "activate-on-click": activateOnClick
  1375. },
  1376. mod
  1377. ],
  1378. children: [
  1379. /* @__PURE__ */ jsxRuntime.jsx(
  1380. core.LoadingOverlay,
  1381. {
  1382. visible: loading,
  1383. overlayProps: { radius },
  1384. unstyled,
  1385. loaderProps
  1386. }
  1387. ),
  1388. /* @__PURE__ */ jsxRuntime.jsx("input", { ...getInputProps(inputProps), name }),
  1389. /* @__PURE__ */ jsxRuntime.jsx(
  1390. "div",
  1391. {
  1392. ...getStyles("inner"),
  1393. ref,
  1394. "data-enable-pointer-events": enablePointerEvents || void 0,
  1395. children
  1396. }
  1397. )
  1398. ]
  1399. }
  1400. ) });
  1401. });
  1402. Dropzone2.classes = classes;
  1403. Dropzone2.displayName = "@mantine/dropzone/Dropzone";
  1404. Dropzone2.Accept = DropzoneAccept;
  1405. Dropzone2.Idle = DropzoneIdle;
  1406. Dropzone2.Reject = DropzoneReject;
  1407. var defaultProps3 = {
  1408. loading: false,
  1409. maxSize: Infinity,
  1410. activateOnClick: false,
  1411. activateOnDrag: true,
  1412. dragEventsBubbling: true,
  1413. activateOnKeyboard: true,
  1414. active: true,
  1415. zIndex: core.getDefaultZIndex("max"),
  1416. withinPortal: true
  1417. };
  1418. var DropzoneFullScreen = core.factory((_props, ref) => {
  1419. const props = core.useProps("DropzoneFullScreen", defaultProps3, _props);
  1420. const {
  1421. classNames,
  1422. className,
  1423. style,
  1424. styles,
  1425. unstyled,
  1426. vars,
  1427. active,
  1428. onDrop,
  1429. onReject,
  1430. zIndex,
  1431. withinPortal,
  1432. portalProps,
  1433. ...others
  1434. } = props;
  1435. const getStyles = core.useStyles({
  1436. name: "DropzoneFullScreen",
  1437. classes,
  1438. props,
  1439. className,
  1440. style,
  1441. classNames,
  1442. styles,
  1443. unstyled,
  1444. rootSelector: "fullScreen"
  1445. });
  1446. const { resolvedClassNames, resolvedStyles } = core.useResolvedStylesApi({
  1447. classNames,
  1448. styles,
  1449. props
  1450. });
  1451. const [counter, setCounter] = React.useState(0);
  1452. const [visible, { open, close }] = hooks.useDisclosure(false);
  1453. const handleDragEnter = (event) => {
  1454. if (event.dataTransfer?.types.includes("Files")) {
  1455. setCounter((prev) => prev + 1);
  1456. open();
  1457. }
  1458. };
  1459. const handleDragLeave = () => {
  1460. setCounter((prev) => prev - 1);
  1461. };
  1462. React.useEffect(() => {
  1463. counter === 0 && close();
  1464. }, [counter]);
  1465. React.useEffect(() => {
  1466. if (!active) {
  1467. return void 0;
  1468. }
  1469. document.addEventListener("dragenter", handleDragEnter, false);
  1470. document.addEventListener("dragleave", handleDragLeave, false);
  1471. return () => {
  1472. document.removeEventListener("dragenter", handleDragEnter, false);
  1473. document.removeEventListener("dragleave", handleDragLeave, false);
  1474. };
  1475. }, [active]);
  1476. return /* @__PURE__ */ jsxRuntime.jsx(core.OptionalPortal, { ...portalProps, withinPortal, children: /* @__PURE__ */ jsxRuntime.jsx(
  1477. core.Box,
  1478. {
  1479. ...getStyles("fullScreen", {
  1480. style: { opacity: visible ? 1 : 0, pointerEvents: visible ? "all" : "none", zIndex }
  1481. }),
  1482. ref,
  1483. children: /* @__PURE__ */ jsxRuntime.jsx(
  1484. Dropzone2,
  1485. {
  1486. ...others,
  1487. classNames: resolvedClassNames,
  1488. styles: resolvedStyles,
  1489. unstyled,
  1490. className: classes.dropzone,
  1491. onDrop: (files) => {
  1492. onDrop?.(files);
  1493. close();
  1494. setCounter(0);
  1495. },
  1496. onReject: (files) => {
  1497. onReject?.(files);
  1498. close();
  1499. setCounter(0);
  1500. }
  1501. }
  1502. )
  1503. }
  1504. ) });
  1505. });
  1506. DropzoneFullScreen.classes = classes;
  1507. DropzoneFullScreen.displayName = "@mantine/dropzone/DropzoneFullScreen";
  1508.  
  1509. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/@mantine+dropzone@7.13.0_@mantine+core@7.13.0_@mantine+hooks@7.13.0_react-dom@18.3.1_react@18.3.1/node_modules/@mantine/dropzone/esm/mime-types.mjs
  1510. var MIME_TYPES = {
  1511. // Images
  1512. png: "image/png",
  1513. gif: "image/gif",
  1514. jpeg: "image/jpeg",
  1515. svg: "image/svg+xml",
  1516. webp: "image/webp",
  1517. avif: "image/avif",
  1518. heic: "image/heic",
  1519. // Documents
  1520. mp4: "video/mp4",
  1521. zip: "application/zip",
  1522. rar: "application/x-rar",
  1523. "7z": "application/x-7z-compressed",
  1524. csv: "text/csv",
  1525. pdf: "application/pdf",
  1526. doc: "application/msword",
  1527. docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  1528. xls: "application/vnd.ms-excel",
  1529. xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  1530. ppt: "application/vnd.ms-powerpoint",
  1531. pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
  1532. exe: "application/vnd.microsoft.portable-executable"
  1533. };
  1534. var IMAGE_MIME_TYPE = [
  1535. MIME_TYPES.png,
  1536. MIME_TYPES.gif,
  1537. MIME_TYPES.jpeg,
  1538. MIME_TYPES.svg,
  1539. MIME_TYPES.webp,
  1540. MIME_TYPES.avif,
  1541. MIME_TYPES.heic
  1542. ];
  1543. var PDF_MIME_TYPE = [MIME_TYPES.pdf];
  1544. var MS_WORD_MIME_TYPE = [MIME_TYPES.doc, MIME_TYPES.docx];
  1545. var MS_EXCEL_MIME_TYPE = [MIME_TYPES.xls, MIME_TYPES.xlsx];
  1546. var MS_POWERPOINT_MIME_TYPE = [MIME_TYPES.ppt, MIME_TYPES.pptx];
  1547. var EXE_MIME_TYPE = [MIME_TYPES.exe];
  1548.  
  1549. // ../esmd/npm/@mantine/dropzone@7.13.0/node_modules/.pnpm/@mantine+dropzone@7.13.0_@mantine+core@7.13.0_@mantine+hooks@7.13.0_react-dom@18.3.1_react@18.3.1/node_modules/@mantine/dropzone/esm/index.mjs
  1550. Dropzone2.FullScreen = DropzoneFullScreen;
  1551. var Dropzone3 = Dropzone2;
  1552.  
  1553. exports.Dropzone = Dropzone3;
  1554. exports.DropzoneAccept = DropzoneAccept;
  1555. exports.DropzoneFullScreen = DropzoneFullScreen;
  1556. exports.DropzoneIdle = DropzoneIdle;
  1557. exports.DropzoneReject = DropzoneReject;
  1558. exports.EXE_MIME_TYPE = EXE_MIME_TYPE;
  1559. exports.IMAGE_MIME_TYPE = IMAGE_MIME_TYPE;
  1560. exports.MIME_TYPES = MIME_TYPES;
  1561. exports.MS_EXCEL_MIME_TYPE = MS_EXCEL_MIME_TYPE;
  1562. exports.MS_POWERPOINT_MIME_TYPE = MS_POWERPOINT_MIME_TYPE;
  1563. exports.MS_WORD_MIME_TYPE = MS_WORD_MIME_TYPE;
  1564. exports.PDF_MIME_TYPE = PDF_MIME_TYPE;
  1565.  
  1566. }));