@popsure/dirty-swan 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +62 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/components/downloadButton/index.d.ts +3 -3
- package/dist/cjs/lib/components/downloadButton/index.stories.d.ts +36 -0
- package/dist/cjs/lib/components/input/checkbox/index.d.ts +17 -0
- package/dist/cjs/lib/components/input/checkbox/index.stories.d.ts +64 -0
- package/dist/cjs/lib/components/markdown/index.d.ts +9 -8
- package/dist/cjs/lib/components/markdown/index.stories.d.ts +44 -0
- package/dist/cjs/lib/components/signaturePad/index.d.ts +4 -4
- package/dist/cjs/lib/components/signaturePad/index.stories.d.ts +21 -0
- package/dist/cjs/lib/index.d.ts +5 -4
- package/dist/index.css +4 -0
- package/dist/index.css.map +1 -1
- package/dist/lib/scss/private/components/_input.scss +4 -0
- package/package.json +1 -1
- package/src/App.tsx +1 -1
- package/src/global.d.ts +1 -0
- package/src/index.tsx +1 -0
- package/src/lib/components/downloadButton/index.stories.tsx +58 -0
- package/src/lib/components/downloadButton/index.tsx +3 -3
- package/src/lib/components/input/checkbox/index.stories.tsx +214 -0
- package/src/lib/components/input/checkbox/index.test.tsx +110 -0
- package/src/lib/components/input/checkbox/index.tsx +129 -0
- package/src/lib/components/markdown/index.stories.tsx +69 -0
- package/src/lib/components/markdown/index.tsx +11 -9
- package/src/lib/components/signaturePad/index.stories.tsx +35 -0
- package/src/lib/components/signaturePad/index.tsx +6 -6
- package/src/lib/index.tsx +5 -3
- package/src/lib/scss/private/components/_input.scss +4 -0
- package/dist/esm/App.d.ts +0 -3
- package/dist/esm/_commonjsHelpers-e7f67fd8.js +0 -23
- package/dist/esm/_commonjsHelpers-e7f67fd8.js.map +0 -1
- package/dist/esm/components/autocompleteAddress/index.js +0 -2062
- package/dist/esm/components/autocompleteAddress/index.js.map +0 -1
- package/dist/esm/components/autocompleteAddress/index.stories.js +0 -110
- package/dist/esm/components/autocompleteAddress/index.stories.js.map +0 -1
- package/dist/esm/components/autocompleteAddress/index.test.js +0 -115
- package/dist/esm/components/autocompleteAddress/index.test.js.map +0 -1
- package/dist/esm/components/button/index.js +0 -26
- package/dist/esm/components/button/index.js.map +0 -1
- package/dist/esm/components/cards/cardButton/index.js +0 -6
- package/dist/esm/components/cards/cardButton/index.js.map +0 -1
- package/dist/esm/components/cards/cardWithLeftIcon/index.js +0 -7
- package/dist/esm/components/cards/cardWithLeftIcon/index.js.map +0 -1
- package/dist/esm/components/cards/cardWithTopIcon/index.js +0 -7
- package/dist/esm/components/cards/cardWithTopIcon/index.js.map +0 -1
- package/dist/esm/components/cards/cardWithTopLeftIcon/index.js +0 -7
- package/dist/esm/components/cards/cardWithTopLeftIcon/index.js.map +0 -1
- package/dist/esm/components/cards/index.js +0 -125
- package/dist/esm/components/cards/index.js.map +0 -1
- package/dist/esm/components/cards/infoCard/index.js +0 -7
- package/dist/esm/components/cards/infoCard/index.js.map +0 -1
- package/dist/esm/components/chip/index.js +0 -22
- package/dist/esm/components/chip/index.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/AccordionItem/AccordionItem.js +0 -32
- package/dist/esm/components/comparisonTable/components/AccordionItem/AccordionItem.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/AccordionItem/index.js +0 -8
- package/dist/esm/components/comparisonTable/components/AccordionItem/index.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/Chevron.js +0 -10
- package/dist/esm/components/comparisonTable/components/Chevron.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/Row/index.js +0 -36
- package/dist/esm/components/comparisonTable/components/Row/index.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableArrows/Arrow.js +0 -10
- package/dist/esm/components/comparisonTable/components/TableArrows/Arrow.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableArrows/index.js +0 -24
- package/dist/esm/components/comparisonTable/components/TableArrows/index.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableButton/index.js +0 -15
- package/dist/esm/components/comparisonTable/components/TableButton/index.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableButton/index.test.js +0 -37
- package/dist/esm/components/comparisonTable/components/TableButton/index.test.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableInfoButton/index.js +0 -22
- package/dist/esm/components/comparisonTable/components/TableInfoButton/index.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableRating/StarIcon.js +0 -10
- package/dist/esm/components/comparisonTable/components/TableRating/StarIcon.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableRating/ZapIcon.js +0 -10
- package/dist/esm/components/comparisonTable/components/TableRating/ZapIcon.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableRating/index.js +0 -27
- package/dist/esm/components/comparisonTable/components/TableRating/index.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableRowHeader/index.js +0 -18
- package/dist/esm/components/comparisonTable/components/TableRowHeader/index.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableRowHeader/index.test.js +0 -82
- package/dist/esm/components/comparisonTable/components/TableRowHeader/index.test.js.map +0 -1
- package/dist/esm/components/comparisonTable/components/TableTrueFalse.js +0 -13
- package/dist/esm/components/comparisonTable/components/TableTrueFalse.js.map +0 -1
- package/dist/esm/components/comparisonTable/index.js +0 -1683
- package/dist/esm/components/comparisonTable/index.js.map +0 -1
- package/dist/esm/components/dateSelector/index.js +0 -2180
- package/dist/esm/components/dateSelector/index.js.map +0 -1
- package/dist/esm/components/dateSelector/index.test.js +0 -65
- package/dist/esm/components/dateSelector/index.test.js.map +0 -1
- package/dist/esm/components/downloadButton/index.js +0 -36
- package/dist/esm/components/downloadButton/index.js.map +0 -1
- package/dist/esm/components/input/autoSuggestInput/index.js +0 -2157
- package/dist/esm/components/input/autoSuggestInput/index.js.map +0 -1
- package/dist/esm/components/input/autoSuggestMultiSelect/index.js +0 -41
- package/dist/esm/components/input/autoSuggestMultiSelect/index.js.map +0 -1
- package/dist/esm/components/input/currency/index.js +0 -63
- package/dist/esm/components/input/currency/index.js.map +0 -1
- package/dist/esm/components/input/currency/index.test.js +0 -209
- package/dist/esm/components/input/currency/index.test.js.map +0 -1
- package/dist/esm/components/input/iban/index.js +0 -33
- package/dist/esm/components/input/iban/index.js.map +0 -1
- package/dist/esm/components/input/index.js +0 -29
- package/dist/esm/components/input/index.js.map +0 -1
- package/dist/esm/components/markdown/index.js +0 -22178
- package/dist/esm/components/markdown/index.js.map +0 -1
- package/dist/esm/components/modal/bottomModal/index.js +0 -35
- package/dist/esm/components/modal/bottomModal/index.js.map +0 -1
- package/dist/esm/components/modal/bottomOrRegularModal/index.js +0 -36
- package/dist/esm/components/modal/bottomOrRegularModal/index.js.map +0 -1
- package/dist/esm/components/modal/regularModal/index.js +0 -28
- package/dist/esm/components/modal/regularModal/index.js.map +0 -1
- package/dist/esm/components/multiDropzone/UploadFileCell/index.js +0 -6
- package/dist/esm/components/multiDropzone/UploadFileCell/index.js.map +0 -1
- package/dist/esm/components/multiDropzone/index.js +0 -2862
- package/dist/esm/components/multiDropzone/index.js.map +0 -1
- package/dist/esm/components/multiDropzone/index.test.js +0 -201
- package/dist/esm/components/multiDropzone/index.test.js.map +0 -1
- package/dist/esm/components/segmentedControl/index.js +0 -42
- package/dist/esm/components/segmentedControl/index.js.map +0 -1
- package/dist/esm/components/segmentedControl/index.stories.js +0 -62
- package/dist/esm/components/segmentedControl/index.stories.js.map +0 -1
- package/dist/esm/components/segmentedControl/index.test.js +0 -63
- package/dist/esm/components/segmentedControl/index.test.js.map +0 -1
- package/dist/esm/components/signaturePad/index.js +0 -560
- package/dist/esm/components/signaturePad/index.js.map +0 -1
- package/dist/esm/customRender-4157fcff.js +0 -24102
- package/dist/esm/customRender-4157fcff.js.map +0 -1
- package/dist/esm/extend-expect-46bdce4a.js +0 -7406
- package/dist/esm/extend-expect-46bdce4a.js.map +0 -1
- package/dist/esm/index-1463d5e9.js +0 -382
- package/dist/esm/index-1463d5e9.js.map +0 -1
- package/dist/esm/index-171a0108.js +0 -997
- package/dist/esm/index-171a0108.js.map +0 -1
- package/dist/esm/index-21239ab0.js +0 -237
- package/dist/esm/index-21239ab0.js.map +0 -1
- package/dist/esm/index-47663d39.js +0 -48
- package/dist/esm/index-47663d39.js.map +0 -1
- package/dist/esm/index-6ced5532.js +0 -69
- package/dist/esm/index-6ced5532.js.map +0 -1
- package/dist/esm/index-db2e797f.js +0 -13
- package/dist/esm/index-db2e797f.js.map +0 -1
- package/dist/esm/index-dd80248b.js +0 -91
- package/dist/esm/index-dd80248b.js.map +0 -1
- package/dist/esm/index-e9e37a34.js +0 -62
- package/dist/esm/index-e9e37a34.js.map +0 -1
- package/dist/esm/index-fb46adf9.js +0 -12
- package/dist/esm/index-fb46adf9.js.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.js +0 -49
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/components/autocompleteAddress/index.d.ts +0 -20
- package/dist/esm/lib/components/autocompleteAddress/index.stories.d.ts +0 -66
- package/dist/esm/lib/components/autocompleteAddress/mapStyle.d.ts +0 -2
- package/dist/esm/lib/components/autocompleteAddress/util/index.d.ts +0 -4
- package/dist/esm/lib/components/button/icons/index.d.ts +0 -9
- package/dist/esm/lib/components/button/index.d.ts +0 -13
- package/dist/esm/lib/components/cards/cardButton/index.d.ts +0 -16
- package/dist/esm/lib/components/cards/cardWithLeftIcon/index.d.ts +0 -14
- package/dist/esm/lib/components/cards/cardWithTopIcon/index.d.ts +0 -15
- package/dist/esm/lib/components/cards/cardWithTopLeftIcon/index.d.ts +0 -14
- package/dist/esm/lib/components/cards/icons/index.d.ts +0 -13
- package/dist/esm/lib/components/cards/index.d.ts +0 -16
- package/dist/esm/lib/components/cards/infoCard/index.d.ts +0 -13
- package/dist/esm/lib/components/chip/index.d.ts +0 -6
- package/dist/esm/lib/components/comparisonTable/components/AccordionItem/AccordionItem.d.ts +0 -9
- package/dist/esm/lib/components/comparisonTable/components/AccordionItem/index.d.ts +0 -1
- package/dist/esm/lib/components/comparisonTable/components/Chevron.d.ts +0 -4
- package/dist/esm/lib/components/comparisonTable/components/Row/index.d.ts +0 -11
- package/dist/esm/lib/components/comparisonTable/components/TableArrows/Arrow.d.ts +0 -4
- package/dist/esm/lib/components/comparisonTable/components/TableArrows/index.d.ts +0 -10
- package/dist/esm/lib/components/comparisonTable/components/TableButton/index.d.ts +0 -8
- package/dist/esm/lib/components/comparisonTable/components/TableButton/index.test.d.ts +0 -1
- package/dist/esm/lib/components/comparisonTable/components/TableInfoButton/index.d.ts +0 -5
- package/dist/esm/lib/components/comparisonTable/components/TableRating/StarIcon.d.ts +0 -4
- package/dist/esm/lib/components/comparisonTable/components/TableRating/ZapIcon.d.ts +0 -4
- package/dist/esm/lib/components/comparisonTable/components/TableRating/index.d.ts +0 -7
- package/dist/esm/lib/components/comparisonTable/components/TableRowHeader/index.d.ts +0 -9
- package/dist/esm/lib/components/comparisonTable/components/TableRowHeader/index.test.d.ts +0 -1
- package/dist/esm/lib/components/comparisonTable/components/TableTrueFalse.d.ts +0 -5
- package/dist/esm/lib/components/comparisonTable/hooks/useComparisonTable.d.ts +0 -14
- package/dist/esm/lib/components/comparisonTable/index.d.ts +0 -52
- package/dist/esm/lib/components/dateSelector/index.d.ts +0 -23
- package/dist/esm/lib/components/dateSelector/index.test.d.ts +0 -1
- package/dist/esm/lib/components/downloadButton/index.d.ts +0 -10
- package/dist/esm/lib/components/input/autoSuggestInput/index.d.ts +0 -15
- package/dist/esm/lib/components/input/autoSuggestMultiSelect/index.d.ts +0 -11
- package/dist/esm/lib/components/input/currency/format/index.d.ts +0 -2
- package/dist/esm/lib/components/input/currency/index.d.ts +0 -7
- package/dist/esm/lib/components/input/currency/index.test.d.ts +0 -1
- package/dist/esm/lib/components/input/iban/formatIban/index.d.ts +0 -1
- package/dist/esm/lib/components/input/iban/index.d.ts +0 -6
- package/dist/esm/lib/components/input/index.d.ts +0 -16
- package/dist/esm/lib/components/markdown/index.d.ts +0 -9
- package/dist/esm/lib/components/modal/bottomModal/index.d.ts +0 -3
- package/dist/esm/lib/components/modal/bottomOrRegularModal/index.d.ts +0 -3
- package/dist/esm/lib/components/modal/hooks/useOnClose.d.ts +0 -9
- package/dist/esm/lib/components/modal/index.d.ts +0 -13
- package/dist/esm/lib/components/modal/regularModal/index.d.ts +0 -3
- package/dist/esm/lib/components/multiDropzone/UploadFileCell/index.d.ts +0 -10
- package/dist/esm/lib/components/multiDropzone/icons/index.d.ts +0 -11
- package/dist/esm/lib/components/multiDropzone/index.d.ts +0 -15
- package/dist/esm/lib/components/multiDropzone/index.test.d.ts +0 -1
- package/dist/esm/lib/components/multiDropzone/types.d.ts +0 -42
- package/dist/esm/lib/components/multiDropzone/utils/index.d.ts +0 -11
- package/dist/esm/lib/components/segmentedControl/index.d.ts +0 -12
- package/dist/esm/lib/components/segmentedControl/index.stories.d.ts +0 -37
- package/dist/esm/lib/components/segmentedControl/index.test.d.ts +0 -1
- package/dist/esm/lib/components/signaturePad/index.d.ts +0 -19
- package/dist/esm/lib/hooks/useOnClickOutside.d.ts +0 -2
- package/dist/esm/lib/index.d.ts +0 -21
- package/dist/esm/lib/models/autoSuggestInput/index.d.ts +0 -4
- package/dist/esm/lib/models/download.d.ts +0 -1
- package/dist/esm/lib/scss/private/base/demo.d.ts +0 -5
- package/dist/esm/lib/scss/public/demo.d.ts +0 -2
- package/dist/esm/lib/util/calendarDate/index.d.ts +0 -3
- package/dist/esm/lib/util/formatBytes/index.d.ts +0 -1
- package/dist/esm/lib/util/generateId/index.d.ts +0 -2
- package/dist/esm/lib/util/images/index.d.ts +0 -11
- package/dist/esm/lib/util/images/index.stories.d.ts +0 -12
- package/dist/esm/lib/util/testUtils/customRender.d.ts +0 -7
- package/dist/esm/lib/util/testUtils/index.d.ts +0 -2
- package/dist/esm/lib/util/zeroFill.d.ts +0 -1
- package/dist/esm/mapStyle-1288a869.js +0 -187
- package/dist/esm/mapStyle-1288a869.js.map +0 -1
- package/dist/esm/scss/private/base/demo.js +0 -80
- package/dist/esm/scss/private/base/demo.js.map +0 -1
- package/dist/esm/scss/public/demo.js +0 -290
- package/dist/esm/scss/public/demo.js.map +0 -1
- package/dist/esm/style-inject.es-1f59c1d0.js +0 -29
- package/dist/esm/style-inject.es-1f59c1d0.js.map +0 -1
- package/dist/esm/tslib.es6-5bc94358.js +0 -104
- package/dist/esm/tslib.es6-5bc94358.js.map +0 -1
- package/dist/esm/useOnClose-d818a54f.js +0 -46
- package/dist/esm/useOnClose-d818a54f.js.map +0 -1
- package/dist/esm/util/images/index.stories.js +0 -23
- package/dist/esm/util/images/index.stories.js.map +0 -1
- package/dist/esm/util/testUtils/customRender.js +0 -7
- package/dist/esm/util/testUtils/customRender.js.map +0 -1
- package/src/lib/components/downloadButton/index.stories.mdx +0 -59
- package/src/lib/components/markdown/index.stories.mdx +0 -22
- package/src/lib/components/signaturePad/index.stories.mdx +0 -17
- /package/dist/{esm/lib/components/autocompleteAddress → cjs/lib/components/input/checkbox}/index.test.d.ts +0 -0
|
@@ -1,2862 +0,0 @@
|
|
|
1
|
-
import { d as __spreadArray$1, _ as __assign } from '../../tslib.es6-5bc94358.js';
|
|
2
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import React__default, { useMemo, useRef, useReducer, useEffect, useCallback, forwardRef, useImperativeHandle, Fragment, useState } from 'react';
|
|
4
|
-
import { c as classnames } from '../../index-e9e37a34.js';
|
|
5
|
-
import { o as objectAssign } from '../../index-dd80248b.js';
|
|
6
|
-
import { A as AnimateHeight } from '../../index-21239ab0.js';
|
|
7
|
-
import { g as generateId } from '../../index-fb46adf9.js';
|
|
8
|
-
import { s as styleInject } from '../../style-inject.es-1f59c1d0.js';
|
|
9
|
-
import { i as icons, U as UploadFileCell } from '../../index-6ced5532.js';
|
|
10
|
-
|
|
11
|
-
var propTypes = {exports: {}};
|
|
12
|
-
|
|
13
|
-
var reactIs = {exports: {}};
|
|
14
|
-
|
|
15
|
-
var reactIs_production_min = {};
|
|
16
|
-
|
|
17
|
-
/** @license React v16.13.1
|
|
18
|
-
* react-is.production.min.js
|
|
19
|
-
*
|
|
20
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
21
|
-
*
|
|
22
|
-
* This source code is licensed under the MIT license found in the
|
|
23
|
-
* LICENSE file in the root directory of this source tree.
|
|
24
|
-
*/
|
|
25
|
-
var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k$1=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.concurrent_mode"):60111,n=b?Symbol.for("react.forward_ref"):60112,p=b?Symbol.for("react.suspense"):60113,q=b?
|
|
26
|
-
Symbol.for("react.suspense_list"):60120,r=b?Symbol.for("react.memo"):60115,t=b?Symbol.for("react.lazy"):60116,v=b?Symbol.for("react.block"):60121,w=b?Symbol.for("react.fundamental"):60117,x=b?Symbol.for("react.responder"):60118,y=b?Symbol.for("react.scope"):60119;
|
|
27
|
-
function z(a){if("object"===typeof a&&null!==a){var u=a.$$typeof;switch(u){case c:switch(a=a.type,a){case l:case m:case e:case g:case f:case p:return a;default:switch(a=a&&a.$$typeof,a){case k$1:case n:case t:case r:case h:return a;default:return u}}case d:return u}}}function A(a){return z(a)===m}reactIs_production_min.AsyncMode=l;reactIs_production_min.ConcurrentMode=m;reactIs_production_min.ContextConsumer=k$1;reactIs_production_min.ContextProvider=h;reactIs_production_min.Element=c;reactIs_production_min.ForwardRef=n;reactIs_production_min.Fragment=e;reactIs_production_min.Lazy=t;reactIs_production_min.Memo=r;reactIs_production_min.Portal=d;
|
|
28
|
-
reactIs_production_min.Profiler=g;reactIs_production_min.StrictMode=f;reactIs_production_min.Suspense=p;reactIs_production_min.isAsyncMode=function(a){return A(a)||z(a)===l};reactIs_production_min.isConcurrentMode=A;reactIs_production_min.isContextConsumer=function(a){return z(a)===k$1};reactIs_production_min.isContextProvider=function(a){return z(a)===h};reactIs_production_min.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};reactIs_production_min.isForwardRef=function(a){return z(a)===n};reactIs_production_min.isFragment=function(a){return z(a)===e};reactIs_production_min.isLazy=function(a){return z(a)===t};
|
|
29
|
-
reactIs_production_min.isMemo=function(a){return z(a)===r};reactIs_production_min.isPortal=function(a){return z(a)===d};reactIs_production_min.isProfiler=function(a){return z(a)===g};reactIs_production_min.isStrictMode=function(a){return z(a)===f};reactIs_production_min.isSuspense=function(a){return z(a)===p};
|
|
30
|
-
reactIs_production_min.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===m||a===g||a===f||a===p||a===q||"object"===typeof a&&null!==a&&(a.$$typeof===t||a.$$typeof===r||a.$$typeof===h||a.$$typeof===k$1||a.$$typeof===n||a.$$typeof===w||a.$$typeof===x||a.$$typeof===y||a.$$typeof===v)};reactIs_production_min.typeOf=z;
|
|
31
|
-
|
|
32
|
-
var reactIs_development = {};
|
|
33
|
-
|
|
34
|
-
/** @license React v16.13.1
|
|
35
|
-
* react-is.development.js
|
|
36
|
-
*
|
|
37
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
38
|
-
*
|
|
39
|
-
* This source code is licensed under the MIT license found in the
|
|
40
|
-
* LICENSE file in the root directory of this source tree.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (process.env.NODE_ENV !== "production") {
|
|
46
|
-
(function() {
|
|
47
|
-
|
|
48
|
-
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
49
|
-
// nor polyfill, then a plain number is used for performance.
|
|
50
|
-
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
51
|
-
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
|
52
|
-
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
|
53
|
-
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
|
54
|
-
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
|
55
|
-
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
|
56
|
-
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
|
57
|
-
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
|
|
58
|
-
// (unstable) APIs that have been removed. Can we remove the symbols?
|
|
59
|
-
|
|
60
|
-
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
|
61
|
-
var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
|
|
62
|
-
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
|
63
|
-
var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
|
|
64
|
-
var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
|
|
65
|
-
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
|
66
|
-
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
|
67
|
-
var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9;
|
|
68
|
-
var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
|
|
69
|
-
var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
|
|
70
|
-
var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7;
|
|
71
|
-
|
|
72
|
-
function isValidElementType(type) {
|
|
73
|
-
return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
|
|
74
|
-
type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function typeOf(object) {
|
|
78
|
-
if (typeof object === 'object' && object !== null) {
|
|
79
|
-
var $$typeof = object.$$typeof;
|
|
80
|
-
|
|
81
|
-
switch ($$typeof) {
|
|
82
|
-
case REACT_ELEMENT_TYPE:
|
|
83
|
-
var type = object.type;
|
|
84
|
-
|
|
85
|
-
switch (type) {
|
|
86
|
-
case REACT_ASYNC_MODE_TYPE:
|
|
87
|
-
case REACT_CONCURRENT_MODE_TYPE:
|
|
88
|
-
case REACT_FRAGMENT_TYPE:
|
|
89
|
-
case REACT_PROFILER_TYPE:
|
|
90
|
-
case REACT_STRICT_MODE_TYPE:
|
|
91
|
-
case REACT_SUSPENSE_TYPE:
|
|
92
|
-
return type;
|
|
93
|
-
|
|
94
|
-
default:
|
|
95
|
-
var $$typeofType = type && type.$$typeof;
|
|
96
|
-
|
|
97
|
-
switch ($$typeofType) {
|
|
98
|
-
case REACT_CONTEXT_TYPE:
|
|
99
|
-
case REACT_FORWARD_REF_TYPE:
|
|
100
|
-
case REACT_LAZY_TYPE:
|
|
101
|
-
case REACT_MEMO_TYPE:
|
|
102
|
-
case REACT_PROVIDER_TYPE:
|
|
103
|
-
return $$typeofType;
|
|
104
|
-
|
|
105
|
-
default:
|
|
106
|
-
return $$typeof;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
case REACT_PORTAL_TYPE:
|
|
112
|
-
return $$typeof;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return undefined;
|
|
117
|
-
} // AsyncMode is deprecated along with isAsyncMode
|
|
118
|
-
|
|
119
|
-
var AsyncMode = REACT_ASYNC_MODE_TYPE;
|
|
120
|
-
var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
|
|
121
|
-
var ContextConsumer = REACT_CONTEXT_TYPE;
|
|
122
|
-
var ContextProvider = REACT_PROVIDER_TYPE;
|
|
123
|
-
var Element = REACT_ELEMENT_TYPE;
|
|
124
|
-
var ForwardRef = REACT_FORWARD_REF_TYPE;
|
|
125
|
-
var Fragment = REACT_FRAGMENT_TYPE;
|
|
126
|
-
var Lazy = REACT_LAZY_TYPE;
|
|
127
|
-
var Memo = REACT_MEMO_TYPE;
|
|
128
|
-
var Portal = REACT_PORTAL_TYPE;
|
|
129
|
-
var Profiler = REACT_PROFILER_TYPE;
|
|
130
|
-
var StrictMode = REACT_STRICT_MODE_TYPE;
|
|
131
|
-
var Suspense = REACT_SUSPENSE_TYPE;
|
|
132
|
-
var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
|
|
133
|
-
|
|
134
|
-
function isAsyncMode(object) {
|
|
135
|
-
{
|
|
136
|
-
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
|
|
137
|
-
hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
|
|
138
|
-
|
|
139
|
-
console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
|
|
144
|
-
}
|
|
145
|
-
function isConcurrentMode(object) {
|
|
146
|
-
return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
|
|
147
|
-
}
|
|
148
|
-
function isContextConsumer(object) {
|
|
149
|
-
return typeOf(object) === REACT_CONTEXT_TYPE;
|
|
150
|
-
}
|
|
151
|
-
function isContextProvider(object) {
|
|
152
|
-
return typeOf(object) === REACT_PROVIDER_TYPE;
|
|
153
|
-
}
|
|
154
|
-
function isElement(object) {
|
|
155
|
-
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
156
|
-
}
|
|
157
|
-
function isForwardRef(object) {
|
|
158
|
-
return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
|
159
|
-
}
|
|
160
|
-
function isFragment(object) {
|
|
161
|
-
return typeOf(object) === REACT_FRAGMENT_TYPE;
|
|
162
|
-
}
|
|
163
|
-
function isLazy(object) {
|
|
164
|
-
return typeOf(object) === REACT_LAZY_TYPE;
|
|
165
|
-
}
|
|
166
|
-
function isMemo(object) {
|
|
167
|
-
return typeOf(object) === REACT_MEMO_TYPE;
|
|
168
|
-
}
|
|
169
|
-
function isPortal(object) {
|
|
170
|
-
return typeOf(object) === REACT_PORTAL_TYPE;
|
|
171
|
-
}
|
|
172
|
-
function isProfiler(object) {
|
|
173
|
-
return typeOf(object) === REACT_PROFILER_TYPE;
|
|
174
|
-
}
|
|
175
|
-
function isStrictMode(object) {
|
|
176
|
-
return typeOf(object) === REACT_STRICT_MODE_TYPE;
|
|
177
|
-
}
|
|
178
|
-
function isSuspense(object) {
|
|
179
|
-
return typeOf(object) === REACT_SUSPENSE_TYPE;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
reactIs_development.AsyncMode = AsyncMode;
|
|
183
|
-
reactIs_development.ConcurrentMode = ConcurrentMode;
|
|
184
|
-
reactIs_development.ContextConsumer = ContextConsumer;
|
|
185
|
-
reactIs_development.ContextProvider = ContextProvider;
|
|
186
|
-
reactIs_development.Element = Element;
|
|
187
|
-
reactIs_development.ForwardRef = ForwardRef;
|
|
188
|
-
reactIs_development.Fragment = Fragment;
|
|
189
|
-
reactIs_development.Lazy = Lazy;
|
|
190
|
-
reactIs_development.Memo = Memo;
|
|
191
|
-
reactIs_development.Portal = Portal;
|
|
192
|
-
reactIs_development.Profiler = Profiler;
|
|
193
|
-
reactIs_development.StrictMode = StrictMode;
|
|
194
|
-
reactIs_development.Suspense = Suspense;
|
|
195
|
-
reactIs_development.isAsyncMode = isAsyncMode;
|
|
196
|
-
reactIs_development.isConcurrentMode = isConcurrentMode;
|
|
197
|
-
reactIs_development.isContextConsumer = isContextConsumer;
|
|
198
|
-
reactIs_development.isContextProvider = isContextProvider;
|
|
199
|
-
reactIs_development.isElement = isElement;
|
|
200
|
-
reactIs_development.isForwardRef = isForwardRef;
|
|
201
|
-
reactIs_development.isFragment = isFragment;
|
|
202
|
-
reactIs_development.isLazy = isLazy;
|
|
203
|
-
reactIs_development.isMemo = isMemo;
|
|
204
|
-
reactIs_development.isPortal = isPortal;
|
|
205
|
-
reactIs_development.isProfiler = isProfiler;
|
|
206
|
-
reactIs_development.isStrictMode = isStrictMode;
|
|
207
|
-
reactIs_development.isSuspense = isSuspense;
|
|
208
|
-
reactIs_development.isValidElementType = isValidElementType;
|
|
209
|
-
reactIs_development.typeOf = typeOf;
|
|
210
|
-
})();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (process.env.NODE_ENV === 'production') {
|
|
214
|
-
reactIs.exports = reactIs_production_min;
|
|
215
|
-
} else {
|
|
216
|
-
reactIs.exports = reactIs_development;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
221
|
-
*
|
|
222
|
-
* This source code is licensed under the MIT license found in the
|
|
223
|
-
* LICENSE file in the root directory of this source tree.
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
var ReactPropTypesSecret$3 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
|
227
|
-
|
|
228
|
-
var ReactPropTypesSecret_1 = ReactPropTypesSecret$3;
|
|
229
|
-
|
|
230
|
-
var has$2 = Function.call.bind(Object.prototype.hasOwnProperty);
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
234
|
-
*
|
|
235
|
-
* This source code is licensed under the MIT license found in the
|
|
236
|
-
* LICENSE file in the root directory of this source tree.
|
|
237
|
-
*/
|
|
238
|
-
|
|
239
|
-
var printWarning$1 = function() {};
|
|
240
|
-
|
|
241
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
242
|
-
var ReactPropTypesSecret$2 = ReactPropTypesSecret_1;
|
|
243
|
-
var loggedTypeFailures = {};
|
|
244
|
-
var has$1 = has$2;
|
|
245
|
-
|
|
246
|
-
printWarning$1 = function(text) {
|
|
247
|
-
var message = 'Warning: ' + text;
|
|
248
|
-
if (typeof console !== 'undefined') {
|
|
249
|
-
console.error(message);
|
|
250
|
-
}
|
|
251
|
-
try {
|
|
252
|
-
// --- Welcome to debugging React ---
|
|
253
|
-
// This error was thrown as a convenience so that you can use this stack
|
|
254
|
-
// to find the callsite that caused this warning to fire.
|
|
255
|
-
throw new Error(message);
|
|
256
|
-
} catch (x) { /**/ }
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Assert that the values match with the type specs.
|
|
262
|
-
* Error messages are memorized and will only be shown once.
|
|
263
|
-
*
|
|
264
|
-
* @param {object} typeSpecs Map of name to a ReactPropType
|
|
265
|
-
* @param {object} values Runtime values that need to be type-checked
|
|
266
|
-
* @param {string} location e.g. "prop", "context", "child context"
|
|
267
|
-
* @param {string} componentName Name of the component for error messages.
|
|
268
|
-
* @param {?Function} getStack Returns the component stack.
|
|
269
|
-
* @private
|
|
270
|
-
*/
|
|
271
|
-
function checkPropTypes$1(typeSpecs, values, location, componentName, getStack) {
|
|
272
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
273
|
-
for (var typeSpecName in typeSpecs) {
|
|
274
|
-
if (has$1(typeSpecs, typeSpecName)) {
|
|
275
|
-
var error;
|
|
276
|
-
// Prop type validation may throw. In case they do, we don't want to
|
|
277
|
-
// fail the render phase where it didn't fail before. So we log it.
|
|
278
|
-
// After these have been cleaned up, we'll let them throw.
|
|
279
|
-
try {
|
|
280
|
-
// This is intentionally an invariant that gets caught. It's the same
|
|
281
|
-
// behavior as without this statement except with a better message.
|
|
282
|
-
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
|
283
|
-
var err = Error(
|
|
284
|
-
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
|
285
|
-
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' +
|
|
286
|
-
'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'
|
|
287
|
-
);
|
|
288
|
-
err.name = 'Invariant Violation';
|
|
289
|
-
throw err;
|
|
290
|
-
}
|
|
291
|
-
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$2);
|
|
292
|
-
} catch (ex) {
|
|
293
|
-
error = ex;
|
|
294
|
-
}
|
|
295
|
-
if (error && !(error instanceof Error)) {
|
|
296
|
-
printWarning$1(
|
|
297
|
-
(componentName || 'React class') + ': type specification of ' +
|
|
298
|
-
location + ' `' + typeSpecName + '` is invalid; the type checker ' +
|
|
299
|
-
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
|
|
300
|
-
'You may have forgotten to pass an argument to the type checker ' +
|
|
301
|
-
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
|
|
302
|
-
'shape all require an argument).'
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
306
|
-
// Only monitor this failure once because there tends to be a lot of the
|
|
307
|
-
// same error.
|
|
308
|
-
loggedTypeFailures[error.message] = true;
|
|
309
|
-
|
|
310
|
-
var stack = getStack ? getStack() : '';
|
|
311
|
-
|
|
312
|
-
printWarning$1(
|
|
313
|
-
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Resets warning cache when testing.
|
|
323
|
-
*
|
|
324
|
-
* @private
|
|
325
|
-
*/
|
|
326
|
-
checkPropTypes$1.resetWarningCache = function() {
|
|
327
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
328
|
-
loggedTypeFailures = {};
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
var checkPropTypes_1 = checkPropTypes$1;
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
336
|
-
*
|
|
337
|
-
* This source code is licensed under the MIT license found in the
|
|
338
|
-
* LICENSE file in the root directory of this source tree.
|
|
339
|
-
*/
|
|
340
|
-
|
|
341
|
-
var ReactIs$1 = reactIs.exports;
|
|
342
|
-
var assign = objectAssign;
|
|
343
|
-
|
|
344
|
-
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
|
|
345
|
-
var has = has$2;
|
|
346
|
-
var checkPropTypes = checkPropTypes_1;
|
|
347
|
-
|
|
348
|
-
var printWarning = function() {};
|
|
349
|
-
|
|
350
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
351
|
-
printWarning = function(text) {
|
|
352
|
-
var message = 'Warning: ' + text;
|
|
353
|
-
if (typeof console !== 'undefined') {
|
|
354
|
-
console.error(message);
|
|
355
|
-
}
|
|
356
|
-
try {
|
|
357
|
-
// --- Welcome to debugging React ---
|
|
358
|
-
// This error was thrown as a convenience so that you can use this stack
|
|
359
|
-
// to find the callsite that caused this warning to fire.
|
|
360
|
-
throw new Error(message);
|
|
361
|
-
} catch (x) {}
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function emptyFunctionThatReturnsNull() {
|
|
366
|
-
return null;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) {
|
|
370
|
-
/* global Symbol */
|
|
371
|
-
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
|
372
|
-
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Returns the iterator method function contained on the iterable object.
|
|
376
|
-
*
|
|
377
|
-
* Be sure to invoke the function with the iterable as context:
|
|
378
|
-
*
|
|
379
|
-
* var iteratorFn = getIteratorFn(myIterable);
|
|
380
|
-
* if (iteratorFn) {
|
|
381
|
-
* var iterator = iteratorFn.call(myIterable);
|
|
382
|
-
* ...
|
|
383
|
-
* }
|
|
384
|
-
*
|
|
385
|
-
* @param {?object} maybeIterable
|
|
386
|
-
* @return {?function}
|
|
387
|
-
*/
|
|
388
|
-
function getIteratorFn(maybeIterable) {
|
|
389
|
-
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
|
390
|
-
if (typeof iteratorFn === 'function') {
|
|
391
|
-
return iteratorFn;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Collection of methods that allow declaration and validation of props that are
|
|
397
|
-
* supplied to React components. Example usage:
|
|
398
|
-
*
|
|
399
|
-
* var Props = require('ReactPropTypes');
|
|
400
|
-
* var MyArticle = React.createClass({
|
|
401
|
-
* propTypes: {
|
|
402
|
-
* // An optional string prop named "description".
|
|
403
|
-
* description: Props.string,
|
|
404
|
-
*
|
|
405
|
-
* // A required enum prop named "category".
|
|
406
|
-
* category: Props.oneOf(['News','Photos']).isRequired,
|
|
407
|
-
*
|
|
408
|
-
* // A prop named "dialog" that requires an instance of Dialog.
|
|
409
|
-
* dialog: Props.instanceOf(Dialog).isRequired
|
|
410
|
-
* },
|
|
411
|
-
* render: function() { ... }
|
|
412
|
-
* });
|
|
413
|
-
*
|
|
414
|
-
* A more formal specification of how these methods are used:
|
|
415
|
-
*
|
|
416
|
-
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
|
417
|
-
* decl := ReactPropTypes.{type}(.isRequired)?
|
|
418
|
-
*
|
|
419
|
-
* Each and every declaration produces a function with the same signature. This
|
|
420
|
-
* allows the creation of custom validation functions. For example:
|
|
421
|
-
*
|
|
422
|
-
* var MyLink = React.createClass({
|
|
423
|
-
* propTypes: {
|
|
424
|
-
* // An optional string or URI prop named "href".
|
|
425
|
-
* href: function(props, propName, componentName) {
|
|
426
|
-
* var propValue = props[propName];
|
|
427
|
-
* if (propValue != null && typeof propValue !== 'string' &&
|
|
428
|
-
* !(propValue instanceof URI)) {
|
|
429
|
-
* return new Error(
|
|
430
|
-
* 'Expected a string or an URI for ' + propName + ' in ' +
|
|
431
|
-
* componentName
|
|
432
|
-
* );
|
|
433
|
-
* }
|
|
434
|
-
* }
|
|
435
|
-
* },
|
|
436
|
-
* render: function() {...}
|
|
437
|
-
* });
|
|
438
|
-
*
|
|
439
|
-
* @internal
|
|
440
|
-
*/
|
|
441
|
-
|
|
442
|
-
var ANONYMOUS = '<<anonymous>>';
|
|
443
|
-
|
|
444
|
-
// Important!
|
|
445
|
-
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
|
|
446
|
-
var ReactPropTypes = {
|
|
447
|
-
array: createPrimitiveTypeChecker('array'),
|
|
448
|
-
bigint: createPrimitiveTypeChecker('bigint'),
|
|
449
|
-
bool: createPrimitiveTypeChecker('boolean'),
|
|
450
|
-
func: createPrimitiveTypeChecker('function'),
|
|
451
|
-
number: createPrimitiveTypeChecker('number'),
|
|
452
|
-
object: createPrimitiveTypeChecker('object'),
|
|
453
|
-
string: createPrimitiveTypeChecker('string'),
|
|
454
|
-
symbol: createPrimitiveTypeChecker('symbol'),
|
|
455
|
-
|
|
456
|
-
any: createAnyTypeChecker(),
|
|
457
|
-
arrayOf: createArrayOfTypeChecker,
|
|
458
|
-
element: createElementTypeChecker(),
|
|
459
|
-
elementType: createElementTypeTypeChecker(),
|
|
460
|
-
instanceOf: createInstanceTypeChecker,
|
|
461
|
-
node: createNodeChecker(),
|
|
462
|
-
objectOf: createObjectOfTypeChecker,
|
|
463
|
-
oneOf: createEnumTypeChecker,
|
|
464
|
-
oneOfType: createUnionTypeChecker,
|
|
465
|
-
shape: createShapeTypeChecker,
|
|
466
|
-
exact: createStrictShapeTypeChecker,
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
471
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
472
|
-
*/
|
|
473
|
-
/*eslint-disable no-self-compare*/
|
|
474
|
-
function is(x, y) {
|
|
475
|
-
// SameValue algorithm
|
|
476
|
-
if (x === y) {
|
|
477
|
-
// Steps 1-5, 7-10
|
|
478
|
-
// Steps 6.b-6.e: +0 != -0
|
|
479
|
-
return x !== 0 || 1 / x === 1 / y;
|
|
480
|
-
} else {
|
|
481
|
-
// Step 6.a: NaN == NaN
|
|
482
|
-
return x !== x && y !== y;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
/*eslint-enable no-self-compare*/
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* We use an Error-like object for backward compatibility as people may call
|
|
489
|
-
* PropTypes directly and inspect their output. However, we don't use real
|
|
490
|
-
* Errors anymore. We don't inspect their stack anyway, and creating them
|
|
491
|
-
* is prohibitively expensive if they are created too often, such as what
|
|
492
|
-
* happens in oneOfType() for any type before the one that matched.
|
|
493
|
-
*/
|
|
494
|
-
function PropTypeError(message, data) {
|
|
495
|
-
this.message = message;
|
|
496
|
-
this.data = data && typeof data === 'object' ? data: {};
|
|
497
|
-
this.stack = '';
|
|
498
|
-
}
|
|
499
|
-
// Make `instanceof Error` still work for returned errors.
|
|
500
|
-
PropTypeError.prototype = Error.prototype;
|
|
501
|
-
|
|
502
|
-
function createChainableTypeChecker(validate) {
|
|
503
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
504
|
-
var manualPropTypeCallCache = {};
|
|
505
|
-
var manualPropTypeWarningCount = 0;
|
|
506
|
-
}
|
|
507
|
-
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
|
508
|
-
componentName = componentName || ANONYMOUS;
|
|
509
|
-
propFullName = propFullName || propName;
|
|
510
|
-
|
|
511
|
-
if (secret !== ReactPropTypesSecret$1) {
|
|
512
|
-
if (throwOnDirectAccess) {
|
|
513
|
-
// New behavior only for users of `prop-types` package
|
|
514
|
-
var err = new Error(
|
|
515
|
-
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
|
516
|
-
'Use `PropTypes.checkPropTypes()` to call them. ' +
|
|
517
|
-
'Read more at http://fb.me/use-check-prop-types'
|
|
518
|
-
);
|
|
519
|
-
err.name = 'Invariant Violation';
|
|
520
|
-
throw err;
|
|
521
|
-
} else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
|
|
522
|
-
// Old behavior for people using React.PropTypes
|
|
523
|
-
var cacheKey = componentName + ':' + propName;
|
|
524
|
-
if (
|
|
525
|
-
!manualPropTypeCallCache[cacheKey] &&
|
|
526
|
-
// Avoid spamming the console because they are often not actionable except for lib authors
|
|
527
|
-
manualPropTypeWarningCount < 3
|
|
528
|
-
) {
|
|
529
|
-
printWarning(
|
|
530
|
-
'You are manually calling a React.PropTypes validation ' +
|
|
531
|
-
'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
|
|
532
|
-
'and will throw in the standalone `prop-types` package. ' +
|
|
533
|
-
'You may be seeing this warning due to a third-party PropTypes ' +
|
|
534
|
-
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
|
|
535
|
-
);
|
|
536
|
-
manualPropTypeCallCache[cacheKey] = true;
|
|
537
|
-
manualPropTypeWarningCount++;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
if (props[propName] == null) {
|
|
542
|
-
if (isRequired) {
|
|
543
|
-
if (props[propName] === null) {
|
|
544
|
-
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
|
545
|
-
}
|
|
546
|
-
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
|
547
|
-
}
|
|
548
|
-
return null;
|
|
549
|
-
} else {
|
|
550
|
-
return validate(props, propName, componentName, location, propFullName);
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
var chainedCheckType = checkType.bind(null, false);
|
|
555
|
-
chainedCheckType.isRequired = checkType.bind(null, true);
|
|
556
|
-
|
|
557
|
-
return chainedCheckType;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
function createPrimitiveTypeChecker(expectedType) {
|
|
561
|
-
function validate(props, propName, componentName, location, propFullName, secret) {
|
|
562
|
-
var propValue = props[propName];
|
|
563
|
-
var propType = getPropType(propValue);
|
|
564
|
-
if (propType !== expectedType) {
|
|
565
|
-
// `propValue` being instance of, say, date/regexp, pass the 'object'
|
|
566
|
-
// check, but we can offer a more precise error message here rather than
|
|
567
|
-
// 'of type `object`'.
|
|
568
|
-
var preciseType = getPreciseType(propValue);
|
|
569
|
-
|
|
570
|
-
return new PropTypeError(
|
|
571
|
-
'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'),
|
|
572
|
-
{expectedType: expectedType}
|
|
573
|
-
);
|
|
574
|
-
}
|
|
575
|
-
return null;
|
|
576
|
-
}
|
|
577
|
-
return createChainableTypeChecker(validate);
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
function createAnyTypeChecker() {
|
|
581
|
-
return createChainableTypeChecker(emptyFunctionThatReturnsNull);
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
function createArrayOfTypeChecker(typeChecker) {
|
|
585
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
586
|
-
if (typeof typeChecker !== 'function') {
|
|
587
|
-
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
|
588
|
-
}
|
|
589
|
-
var propValue = props[propName];
|
|
590
|
-
if (!Array.isArray(propValue)) {
|
|
591
|
-
var propType = getPropType(propValue);
|
|
592
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
593
|
-
}
|
|
594
|
-
for (var i = 0; i < propValue.length; i++) {
|
|
595
|
-
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret$1);
|
|
596
|
-
if (error instanceof Error) {
|
|
597
|
-
return error;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
return null;
|
|
601
|
-
}
|
|
602
|
-
return createChainableTypeChecker(validate);
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
function createElementTypeChecker() {
|
|
606
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
607
|
-
var propValue = props[propName];
|
|
608
|
-
if (!isValidElement(propValue)) {
|
|
609
|
-
var propType = getPropType(propValue);
|
|
610
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
|
611
|
-
}
|
|
612
|
-
return null;
|
|
613
|
-
}
|
|
614
|
-
return createChainableTypeChecker(validate);
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
function createElementTypeTypeChecker() {
|
|
618
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
619
|
-
var propValue = props[propName];
|
|
620
|
-
if (!ReactIs$1.isValidElementType(propValue)) {
|
|
621
|
-
var propType = getPropType(propValue);
|
|
622
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
|
|
623
|
-
}
|
|
624
|
-
return null;
|
|
625
|
-
}
|
|
626
|
-
return createChainableTypeChecker(validate);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
function createInstanceTypeChecker(expectedClass) {
|
|
630
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
631
|
-
if (!(props[propName] instanceof expectedClass)) {
|
|
632
|
-
var expectedClassName = expectedClass.name || ANONYMOUS;
|
|
633
|
-
var actualClassName = getClassName(props[propName]);
|
|
634
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
|
635
|
-
}
|
|
636
|
-
return null;
|
|
637
|
-
}
|
|
638
|
-
return createChainableTypeChecker(validate);
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
function createEnumTypeChecker(expectedValues) {
|
|
642
|
-
if (!Array.isArray(expectedValues)) {
|
|
643
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
644
|
-
if (arguments.length > 1) {
|
|
645
|
-
printWarning(
|
|
646
|
-
'Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' +
|
|
647
|
-
'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).'
|
|
648
|
-
);
|
|
649
|
-
} else {
|
|
650
|
-
printWarning('Invalid argument supplied to oneOf, expected an array.');
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
return emptyFunctionThatReturnsNull;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
657
|
-
var propValue = props[propName];
|
|
658
|
-
for (var i = 0; i < expectedValues.length; i++) {
|
|
659
|
-
if (is(propValue, expectedValues[i])) {
|
|
660
|
-
return null;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
|
|
665
|
-
var type = getPreciseType(value);
|
|
666
|
-
if (type === 'symbol') {
|
|
667
|
-
return String(value);
|
|
668
|
-
}
|
|
669
|
-
return value;
|
|
670
|
-
});
|
|
671
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
|
672
|
-
}
|
|
673
|
-
return createChainableTypeChecker(validate);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
function createObjectOfTypeChecker(typeChecker) {
|
|
677
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
678
|
-
if (typeof typeChecker !== 'function') {
|
|
679
|
-
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
|
680
|
-
}
|
|
681
|
-
var propValue = props[propName];
|
|
682
|
-
var propType = getPropType(propValue);
|
|
683
|
-
if (propType !== 'object') {
|
|
684
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
685
|
-
}
|
|
686
|
-
for (var key in propValue) {
|
|
687
|
-
if (has(propValue, key)) {
|
|
688
|
-
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret$1);
|
|
689
|
-
if (error instanceof Error) {
|
|
690
|
-
return error;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
return null;
|
|
695
|
-
}
|
|
696
|
-
return createChainableTypeChecker(validate);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
700
|
-
if (!Array.isArray(arrayOfTypeCheckers)) {
|
|
701
|
-
process.env.NODE_ENV !== 'production' ? printWarning('Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
|
|
702
|
-
return emptyFunctionThatReturnsNull;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
706
|
-
var checker = arrayOfTypeCheckers[i];
|
|
707
|
-
if (typeof checker !== 'function') {
|
|
708
|
-
printWarning(
|
|
709
|
-
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' +
|
|
710
|
-
'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.'
|
|
711
|
-
);
|
|
712
|
-
return emptyFunctionThatReturnsNull;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
717
|
-
var expectedTypes = [];
|
|
718
|
-
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
719
|
-
var checker = arrayOfTypeCheckers[i];
|
|
720
|
-
var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret$1);
|
|
721
|
-
if (checkerResult == null) {
|
|
722
|
-
return null;
|
|
723
|
-
}
|
|
724
|
-
if (checkerResult.data && has(checkerResult.data, 'expectedType')) {
|
|
725
|
-
expectedTypes.push(checkerResult.data.expectedType);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': '';
|
|
729
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.'));
|
|
730
|
-
}
|
|
731
|
-
return createChainableTypeChecker(validate);
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
function createNodeChecker() {
|
|
735
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
736
|
-
if (!isNode(props[propName])) {
|
|
737
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
738
|
-
}
|
|
739
|
-
return null;
|
|
740
|
-
}
|
|
741
|
-
return createChainableTypeChecker(validate);
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
function invalidValidatorError(componentName, location, propFullName, key, type) {
|
|
745
|
-
return new PropTypeError(
|
|
746
|
-
(componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' +
|
|
747
|
-
'it must be a function, usually from the `prop-types` package, but received `' + type + '`.'
|
|
748
|
-
);
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
function createShapeTypeChecker(shapeTypes) {
|
|
752
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
753
|
-
var propValue = props[propName];
|
|
754
|
-
var propType = getPropType(propValue);
|
|
755
|
-
if (propType !== 'object') {
|
|
756
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
757
|
-
}
|
|
758
|
-
for (var key in shapeTypes) {
|
|
759
|
-
var checker = shapeTypes[key];
|
|
760
|
-
if (typeof checker !== 'function') {
|
|
761
|
-
return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
|
|
762
|
-
}
|
|
763
|
-
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret$1);
|
|
764
|
-
if (error) {
|
|
765
|
-
return error;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
return null;
|
|
769
|
-
}
|
|
770
|
-
return createChainableTypeChecker(validate);
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
function createStrictShapeTypeChecker(shapeTypes) {
|
|
774
|
-
function validate(props, propName, componentName, location, propFullName) {
|
|
775
|
-
var propValue = props[propName];
|
|
776
|
-
var propType = getPropType(propValue);
|
|
777
|
-
if (propType !== 'object') {
|
|
778
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
779
|
-
}
|
|
780
|
-
// We need to check all keys in case some are required but missing from props.
|
|
781
|
-
var allKeys = assign({}, props[propName], shapeTypes);
|
|
782
|
-
for (var key in allKeys) {
|
|
783
|
-
var checker = shapeTypes[key];
|
|
784
|
-
if (has(shapeTypes, key) && typeof checker !== 'function') {
|
|
785
|
-
return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
|
|
786
|
-
}
|
|
787
|
-
if (!checker) {
|
|
788
|
-
return new PropTypeError(
|
|
789
|
-
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
|
|
790
|
-
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
|
|
791
|
-
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
|
-
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret$1);
|
|
795
|
-
if (error) {
|
|
796
|
-
return error;
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
return null;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
return createChainableTypeChecker(validate);
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
function isNode(propValue) {
|
|
806
|
-
switch (typeof propValue) {
|
|
807
|
-
case 'number':
|
|
808
|
-
case 'string':
|
|
809
|
-
case 'undefined':
|
|
810
|
-
return true;
|
|
811
|
-
case 'boolean':
|
|
812
|
-
return !propValue;
|
|
813
|
-
case 'object':
|
|
814
|
-
if (Array.isArray(propValue)) {
|
|
815
|
-
return propValue.every(isNode);
|
|
816
|
-
}
|
|
817
|
-
if (propValue === null || isValidElement(propValue)) {
|
|
818
|
-
return true;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
var iteratorFn = getIteratorFn(propValue);
|
|
822
|
-
if (iteratorFn) {
|
|
823
|
-
var iterator = iteratorFn.call(propValue);
|
|
824
|
-
var step;
|
|
825
|
-
if (iteratorFn !== propValue.entries) {
|
|
826
|
-
while (!(step = iterator.next()).done) {
|
|
827
|
-
if (!isNode(step.value)) {
|
|
828
|
-
return false;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
} else {
|
|
832
|
-
// Iterator will provide entry [k,v] tuples rather than values.
|
|
833
|
-
while (!(step = iterator.next()).done) {
|
|
834
|
-
var entry = step.value;
|
|
835
|
-
if (entry) {
|
|
836
|
-
if (!isNode(entry[1])) {
|
|
837
|
-
return false;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
} else {
|
|
843
|
-
return false;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
return true;
|
|
847
|
-
default:
|
|
848
|
-
return false;
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
function isSymbol(propType, propValue) {
|
|
853
|
-
// Native Symbol.
|
|
854
|
-
if (propType === 'symbol') {
|
|
855
|
-
return true;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
// falsy value can't be a Symbol
|
|
859
|
-
if (!propValue) {
|
|
860
|
-
return false;
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
|
864
|
-
if (propValue['@@toStringTag'] === 'Symbol') {
|
|
865
|
-
return true;
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
// Fallback for non-spec compliant Symbols which are polyfilled.
|
|
869
|
-
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
|
870
|
-
return true;
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
return false;
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
// Equivalent of `typeof` but with special handling for array and regexp.
|
|
877
|
-
function getPropType(propValue) {
|
|
878
|
-
var propType = typeof propValue;
|
|
879
|
-
if (Array.isArray(propValue)) {
|
|
880
|
-
return 'array';
|
|
881
|
-
}
|
|
882
|
-
if (propValue instanceof RegExp) {
|
|
883
|
-
// Old webkits (at least until Android 4.0) return 'function' rather than
|
|
884
|
-
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
|
885
|
-
// passes PropTypes.object.
|
|
886
|
-
return 'object';
|
|
887
|
-
}
|
|
888
|
-
if (isSymbol(propType, propValue)) {
|
|
889
|
-
return 'symbol';
|
|
890
|
-
}
|
|
891
|
-
return propType;
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
// This handles more types than `getPropType`. Only used for error messages.
|
|
895
|
-
// See `createPrimitiveTypeChecker`.
|
|
896
|
-
function getPreciseType(propValue) {
|
|
897
|
-
if (typeof propValue === 'undefined' || propValue === null) {
|
|
898
|
-
return '' + propValue;
|
|
899
|
-
}
|
|
900
|
-
var propType = getPropType(propValue);
|
|
901
|
-
if (propType === 'object') {
|
|
902
|
-
if (propValue instanceof Date) {
|
|
903
|
-
return 'date';
|
|
904
|
-
} else if (propValue instanceof RegExp) {
|
|
905
|
-
return 'regexp';
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
return propType;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
// Returns a string that is postfixed to a warning about an invalid type.
|
|
912
|
-
// For example, "undefined" or "of type array"
|
|
913
|
-
function getPostfixForTypeWarning(value) {
|
|
914
|
-
var type = getPreciseType(value);
|
|
915
|
-
switch (type) {
|
|
916
|
-
case 'array':
|
|
917
|
-
case 'object':
|
|
918
|
-
return 'an ' + type;
|
|
919
|
-
case 'boolean':
|
|
920
|
-
case 'date':
|
|
921
|
-
case 'regexp':
|
|
922
|
-
return 'a ' + type;
|
|
923
|
-
default:
|
|
924
|
-
return type;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
// Returns class name of the object, if any.
|
|
929
|
-
function getClassName(propValue) {
|
|
930
|
-
if (!propValue.constructor || !propValue.constructor.name) {
|
|
931
|
-
return ANONYMOUS;
|
|
932
|
-
}
|
|
933
|
-
return propValue.constructor.name;
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
ReactPropTypes.checkPropTypes = checkPropTypes;
|
|
937
|
-
ReactPropTypes.resetWarningCache = checkPropTypes.resetWarningCache;
|
|
938
|
-
ReactPropTypes.PropTypes = ReactPropTypes;
|
|
939
|
-
|
|
940
|
-
return ReactPropTypes;
|
|
941
|
-
};
|
|
942
|
-
|
|
943
|
-
/**
|
|
944
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
945
|
-
*
|
|
946
|
-
* This source code is licensed under the MIT license found in the
|
|
947
|
-
* LICENSE file in the root directory of this source tree.
|
|
948
|
-
*/
|
|
949
|
-
|
|
950
|
-
var ReactPropTypesSecret = ReactPropTypesSecret_1;
|
|
951
|
-
|
|
952
|
-
function emptyFunction() {}
|
|
953
|
-
function emptyFunctionWithReset() {}
|
|
954
|
-
emptyFunctionWithReset.resetWarningCache = emptyFunction;
|
|
955
|
-
|
|
956
|
-
var factoryWithThrowingShims = function() {
|
|
957
|
-
function shim(props, propName, componentName, location, propFullName, secret) {
|
|
958
|
-
if (secret === ReactPropTypesSecret) {
|
|
959
|
-
// It is still safe when called from React.
|
|
960
|
-
return;
|
|
961
|
-
}
|
|
962
|
-
var err = new Error(
|
|
963
|
-
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
|
|
964
|
-
'Use PropTypes.checkPropTypes() to call them. ' +
|
|
965
|
-
'Read more at http://fb.me/use-check-prop-types'
|
|
966
|
-
);
|
|
967
|
-
err.name = 'Invariant Violation';
|
|
968
|
-
throw err;
|
|
969
|
-
} shim.isRequired = shim;
|
|
970
|
-
function getShim() {
|
|
971
|
-
return shim;
|
|
972
|
-
} // Important!
|
|
973
|
-
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
|
|
974
|
-
var ReactPropTypes = {
|
|
975
|
-
array: shim,
|
|
976
|
-
bigint: shim,
|
|
977
|
-
bool: shim,
|
|
978
|
-
func: shim,
|
|
979
|
-
number: shim,
|
|
980
|
-
object: shim,
|
|
981
|
-
string: shim,
|
|
982
|
-
symbol: shim,
|
|
983
|
-
|
|
984
|
-
any: shim,
|
|
985
|
-
arrayOf: getShim,
|
|
986
|
-
element: shim,
|
|
987
|
-
elementType: shim,
|
|
988
|
-
instanceOf: getShim,
|
|
989
|
-
node: shim,
|
|
990
|
-
objectOf: getShim,
|
|
991
|
-
oneOf: getShim,
|
|
992
|
-
oneOfType: getShim,
|
|
993
|
-
shape: getShim,
|
|
994
|
-
exact: getShim,
|
|
995
|
-
|
|
996
|
-
checkPropTypes: emptyFunctionWithReset,
|
|
997
|
-
resetWarningCache: emptyFunction
|
|
998
|
-
};
|
|
999
|
-
|
|
1000
|
-
ReactPropTypes.PropTypes = ReactPropTypes;
|
|
1001
|
-
|
|
1002
|
-
return ReactPropTypes;
|
|
1003
|
-
};
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
1007
|
-
*
|
|
1008
|
-
* This source code is licensed under the MIT license found in the
|
|
1009
|
-
* LICENSE file in the root directory of this source tree.
|
|
1010
|
-
*/
|
|
1011
|
-
|
|
1012
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1013
|
-
var ReactIs = reactIs.exports;
|
|
1014
|
-
|
|
1015
|
-
// By explicitly using `prop-types` you are opting into new development behavior.
|
|
1016
|
-
// http://fb.me/prop-types-in-prod
|
|
1017
|
-
var throwOnDirectAccess = true;
|
|
1018
|
-
propTypes.exports = factoryWithTypeCheckers(ReactIs.isElement, throwOnDirectAccess);
|
|
1019
|
-
} else {
|
|
1020
|
-
// By explicitly using `prop-types` you are opting into new production behavior.
|
|
1021
|
-
// http://fb.me/prop-types-in-prod
|
|
1022
|
-
propTypes.exports = factoryWithThrowingShims();
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
var PropTypes = propTypes.exports;
|
|
1026
|
-
|
|
1027
|
-
/******************************************************************************
|
|
1028
|
-
Copyright (c) Microsoft Corporation.
|
|
1029
|
-
|
|
1030
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
1031
|
-
purpose with or without fee is hereby granted.
|
|
1032
|
-
|
|
1033
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1034
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1035
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1036
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1037
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1038
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1039
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
1040
|
-
***************************************************************************** */
|
|
1041
|
-
|
|
1042
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
1043
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1044
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1045
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1046
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1047
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1048
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1049
|
-
});
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
function __generator(thisArg, body) {
|
|
1053
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
1054
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
1055
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
1056
|
-
function step(op) {
|
|
1057
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
1058
|
-
while (_) try {
|
|
1059
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
1060
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
1061
|
-
switch (op[0]) {
|
|
1062
|
-
case 0: case 1: t = op; break;
|
|
1063
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
1064
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
1065
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
1066
|
-
default:
|
|
1067
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
1068
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
1069
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
1070
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
1071
|
-
if (t[2]) _.ops.pop();
|
|
1072
|
-
_.trys.pop(); continue;
|
|
1073
|
-
}
|
|
1074
|
-
op = body.call(thisArg, _);
|
|
1075
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
1076
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
function __read(o, n) {
|
|
1081
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
1082
|
-
if (!m) return o;
|
|
1083
|
-
var i = m.call(o), r, ar = [], e;
|
|
1084
|
-
try {
|
|
1085
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
1086
|
-
}
|
|
1087
|
-
catch (error) { e = { error: error }; }
|
|
1088
|
-
finally {
|
|
1089
|
-
try {
|
|
1090
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
1091
|
-
}
|
|
1092
|
-
finally { if (e) throw e.error; }
|
|
1093
|
-
}
|
|
1094
|
-
return ar;
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
function __spreadArray(to, from, pack) {
|
|
1098
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
1099
|
-
if (ar || !(i in from)) {
|
|
1100
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
1101
|
-
ar[i] = from[i];
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
var COMMON_MIME_TYPES = new Map([
|
|
1108
|
-
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
|
1109
|
-
['aac', 'audio/aac'],
|
|
1110
|
-
['abw', 'application/x-abiword'],
|
|
1111
|
-
['arc', 'application/x-freearc'],
|
|
1112
|
-
['avif', 'image/avif'],
|
|
1113
|
-
['avi', 'video/x-msvideo'],
|
|
1114
|
-
['azw', 'application/vnd.amazon.ebook'],
|
|
1115
|
-
['bin', 'application/octet-stream'],
|
|
1116
|
-
['bmp', 'image/bmp'],
|
|
1117
|
-
['bz', 'application/x-bzip'],
|
|
1118
|
-
['bz2', 'application/x-bzip2'],
|
|
1119
|
-
['cda', 'application/x-cdf'],
|
|
1120
|
-
['csh', 'application/x-csh'],
|
|
1121
|
-
['css', 'text/css'],
|
|
1122
|
-
['csv', 'text/csv'],
|
|
1123
|
-
['doc', 'application/msword'],
|
|
1124
|
-
['docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
1125
|
-
['eot', 'application/vnd.ms-fontobject'],
|
|
1126
|
-
['epub', 'application/epub+zip'],
|
|
1127
|
-
['gz', 'application/gzip'],
|
|
1128
|
-
['gif', 'image/gif'],
|
|
1129
|
-
['heic', 'image/heic'],
|
|
1130
|
-
['heif', 'image/heif'],
|
|
1131
|
-
['htm', 'text/html'],
|
|
1132
|
-
['html', 'text/html'],
|
|
1133
|
-
['ico', 'image/vnd.microsoft.icon'],
|
|
1134
|
-
['ics', 'text/calendar'],
|
|
1135
|
-
['jar', 'application/java-archive'],
|
|
1136
|
-
['jpeg', 'image/jpeg'],
|
|
1137
|
-
['jpg', 'image/jpeg'],
|
|
1138
|
-
['js', 'text/javascript'],
|
|
1139
|
-
['json', 'application/json'],
|
|
1140
|
-
['jsonld', 'application/ld+json'],
|
|
1141
|
-
['mid', 'audio/midi'],
|
|
1142
|
-
['midi', 'audio/midi'],
|
|
1143
|
-
['mjs', 'text/javascript'],
|
|
1144
|
-
['mp3', 'audio/mpeg'],
|
|
1145
|
-
['mp4', 'video/mp4'],
|
|
1146
|
-
['mpeg', 'video/mpeg'],
|
|
1147
|
-
['mpkg', 'application/vnd.apple.installer+xml'],
|
|
1148
|
-
['odp', 'application/vnd.oasis.opendocument.presentation'],
|
|
1149
|
-
['ods', 'application/vnd.oasis.opendocument.spreadsheet'],
|
|
1150
|
-
['odt', 'application/vnd.oasis.opendocument.text'],
|
|
1151
|
-
['oga', 'audio/ogg'],
|
|
1152
|
-
['ogv', 'video/ogg'],
|
|
1153
|
-
['ogx', 'application/ogg'],
|
|
1154
|
-
['opus', 'audio/opus'],
|
|
1155
|
-
['otf', 'font/otf'],
|
|
1156
|
-
['png', 'image/png'],
|
|
1157
|
-
['pdf', 'application/pdf'],
|
|
1158
|
-
['php', 'application/x-httpd-php'],
|
|
1159
|
-
['ppt', 'application/vnd.ms-powerpoint'],
|
|
1160
|
-
['pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'],
|
|
1161
|
-
['rar', 'application/vnd.rar'],
|
|
1162
|
-
['rtf', 'application/rtf'],
|
|
1163
|
-
['sh', 'application/x-sh'],
|
|
1164
|
-
['svg', 'image/svg+xml'],
|
|
1165
|
-
['swf', 'application/x-shockwave-flash'],
|
|
1166
|
-
['tar', 'application/x-tar'],
|
|
1167
|
-
['tif', 'image/tiff'],
|
|
1168
|
-
['tiff', 'image/tiff'],
|
|
1169
|
-
['ts', 'video/mp2t'],
|
|
1170
|
-
['ttf', 'font/ttf'],
|
|
1171
|
-
['txt', 'text/plain'],
|
|
1172
|
-
['vsd', 'application/vnd.visio'],
|
|
1173
|
-
['wav', 'audio/wav'],
|
|
1174
|
-
['weba', 'audio/webm'],
|
|
1175
|
-
['webm', 'video/webm'],
|
|
1176
|
-
['webp', 'image/webp'],
|
|
1177
|
-
['woff', 'font/woff'],
|
|
1178
|
-
['woff2', 'font/woff2'],
|
|
1179
|
-
['xhtml', 'application/xhtml+xml'],
|
|
1180
|
-
['xls', 'application/vnd.ms-excel'],
|
|
1181
|
-
['xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
1182
|
-
['xml', 'application/xml'],
|
|
1183
|
-
['xul', 'application/vnd.mozilla.xul+xml'],
|
|
1184
|
-
['zip', 'application/zip'],
|
|
1185
|
-
['7z', 'application/x-7z-compressed'],
|
|
1186
|
-
// Others
|
|
1187
|
-
['mkv', 'video/x-matroska'],
|
|
1188
|
-
['mov', 'video/quicktime'],
|
|
1189
|
-
['msg', 'application/vnd.ms-outlook']
|
|
1190
|
-
]);
|
|
1191
|
-
function toFileWithPath(file, path) {
|
|
1192
|
-
var f = withMimeType(file);
|
|
1193
|
-
if (typeof f.path !== 'string') { // on electron, path is already set to the absolute path
|
|
1194
|
-
var webkitRelativePath = file.webkitRelativePath;
|
|
1195
|
-
Object.defineProperty(f, 'path', {
|
|
1196
|
-
value: typeof path === 'string'
|
|
1197
|
-
? path
|
|
1198
|
-
// If <input webkitdirectory> is set,
|
|
1199
|
-
// the File will have a {webkitRelativePath} property
|
|
1200
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory
|
|
1201
|
-
: typeof webkitRelativePath === 'string' && webkitRelativePath.length > 0
|
|
1202
|
-
? webkitRelativePath
|
|
1203
|
-
: file.name,
|
|
1204
|
-
writable: false,
|
|
1205
|
-
configurable: false,
|
|
1206
|
-
enumerable: true
|
|
1207
|
-
});
|
|
1208
|
-
}
|
|
1209
|
-
return f;
|
|
1210
|
-
}
|
|
1211
|
-
function withMimeType(file) {
|
|
1212
|
-
var name = file.name;
|
|
1213
|
-
var hasExtension = name && name.lastIndexOf('.') !== -1;
|
|
1214
|
-
if (hasExtension && !file.type) {
|
|
1215
|
-
var ext = name.split('.')
|
|
1216
|
-
.pop().toLowerCase();
|
|
1217
|
-
var type = COMMON_MIME_TYPES.get(ext);
|
|
1218
|
-
if (type) {
|
|
1219
|
-
Object.defineProperty(file, 'type', {
|
|
1220
|
-
value: type,
|
|
1221
|
-
writable: false,
|
|
1222
|
-
configurable: false,
|
|
1223
|
-
enumerable: true
|
|
1224
|
-
});
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
return file;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
var FILES_TO_IGNORE = [
|
|
1231
|
-
// Thumbnail cache files for macOS and Windows
|
|
1232
|
-
'.DS_Store',
|
|
1233
|
-
'Thumbs.db' // Windows
|
|
1234
|
-
];
|
|
1235
|
-
/**
|
|
1236
|
-
* Convert a DragEvent's DataTrasfer object to a list of File objects
|
|
1237
|
-
* NOTE: If some of the items are folders,
|
|
1238
|
-
* everything will be flattened and placed in the same list but the paths will be kept as a {path} property.
|
|
1239
|
-
*
|
|
1240
|
-
* EXPERIMENTAL: A list of https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle objects can also be passed as an arg
|
|
1241
|
-
* and a list of File objects will be returned.
|
|
1242
|
-
*
|
|
1243
|
-
* @param evt
|
|
1244
|
-
*/
|
|
1245
|
-
function fromEvent(evt) {
|
|
1246
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1247
|
-
return __generator(this, function (_a) {
|
|
1248
|
-
if (isObject(evt) && isDataTransfer(evt.dataTransfer)) {
|
|
1249
|
-
return [2 /*return*/, getDataTransferFiles(evt.dataTransfer, evt.type)];
|
|
1250
|
-
}
|
|
1251
|
-
else if (isChangeEvt(evt)) {
|
|
1252
|
-
return [2 /*return*/, getInputFiles(evt)];
|
|
1253
|
-
}
|
|
1254
|
-
else if (Array.isArray(evt) && evt.every(function (item) { return 'getFile' in item && typeof item.getFile === 'function'; })) {
|
|
1255
|
-
return [2 /*return*/, getFsHandleFiles(evt)];
|
|
1256
|
-
}
|
|
1257
|
-
return [2 /*return*/, []];
|
|
1258
|
-
});
|
|
1259
|
-
});
|
|
1260
|
-
}
|
|
1261
|
-
function isDataTransfer(value) {
|
|
1262
|
-
return isObject(value);
|
|
1263
|
-
}
|
|
1264
|
-
function isChangeEvt(value) {
|
|
1265
|
-
return isObject(value) && isObject(value.target);
|
|
1266
|
-
}
|
|
1267
|
-
function isObject(v) {
|
|
1268
|
-
return typeof v === 'object' && v !== null;
|
|
1269
|
-
}
|
|
1270
|
-
function getInputFiles(evt) {
|
|
1271
|
-
return fromList(evt.target.files).map(function (file) { return toFileWithPath(file); });
|
|
1272
|
-
}
|
|
1273
|
-
// Ee expect each handle to be https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle
|
|
1274
|
-
function getFsHandleFiles(handles) {
|
|
1275
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1276
|
-
var files;
|
|
1277
|
-
return __generator(this, function (_a) {
|
|
1278
|
-
switch (_a.label) {
|
|
1279
|
-
case 0: return [4 /*yield*/, Promise.all(handles.map(function (h) { return h.getFile(); }))];
|
|
1280
|
-
case 1:
|
|
1281
|
-
files = _a.sent();
|
|
1282
|
-
return [2 /*return*/, files.map(function (file) { return toFileWithPath(file); })];
|
|
1283
|
-
}
|
|
1284
|
-
});
|
|
1285
|
-
});
|
|
1286
|
-
}
|
|
1287
|
-
function getDataTransferFiles(dt, type) {
|
|
1288
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1289
|
-
var items, files;
|
|
1290
|
-
return __generator(this, function (_a) {
|
|
1291
|
-
switch (_a.label) {
|
|
1292
|
-
case 0:
|
|
1293
|
-
if (!dt.items) return [3 /*break*/, 2];
|
|
1294
|
-
items = fromList(dt.items)
|
|
1295
|
-
.filter(function (item) { return item.kind === 'file'; });
|
|
1296
|
-
// According to https://html.spec.whatwg.org/multipage/dnd.html#dndevents,
|
|
1297
|
-
// only 'dragstart' and 'drop' has access to the data (source node)
|
|
1298
|
-
if (type !== 'drop') {
|
|
1299
|
-
return [2 /*return*/, items];
|
|
1300
|
-
}
|
|
1301
|
-
return [4 /*yield*/, Promise.all(items.map(toFilePromises))];
|
|
1302
|
-
case 1:
|
|
1303
|
-
files = _a.sent();
|
|
1304
|
-
return [2 /*return*/, noIgnoredFiles(flatten(files))];
|
|
1305
|
-
case 2: return [2 /*return*/, noIgnoredFiles(fromList(dt.files)
|
|
1306
|
-
.map(function (file) { return toFileWithPath(file); }))];
|
|
1307
|
-
}
|
|
1308
|
-
});
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
function noIgnoredFiles(files) {
|
|
1312
|
-
return files.filter(function (file) { return FILES_TO_IGNORE.indexOf(file.name) === -1; });
|
|
1313
|
-
}
|
|
1314
|
-
// IE11 does not support Array.from()
|
|
1315
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Browser_compatibility
|
|
1316
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/FileList
|
|
1317
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItemList
|
|
1318
|
-
function fromList(items) {
|
|
1319
|
-
if (items === null) {
|
|
1320
|
-
return [];
|
|
1321
|
-
}
|
|
1322
|
-
var files = [];
|
|
1323
|
-
// tslint:disable: prefer-for-of
|
|
1324
|
-
for (var i = 0; i < items.length; i++) {
|
|
1325
|
-
var file = items[i];
|
|
1326
|
-
files.push(file);
|
|
1327
|
-
}
|
|
1328
|
-
return files;
|
|
1329
|
-
}
|
|
1330
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem
|
|
1331
|
-
function toFilePromises(item) {
|
|
1332
|
-
if (typeof item.webkitGetAsEntry !== 'function') {
|
|
1333
|
-
return fromDataTransferItem(item);
|
|
1334
|
-
}
|
|
1335
|
-
var entry = item.webkitGetAsEntry();
|
|
1336
|
-
// Safari supports dropping an image node from a different window and can be retrieved using
|
|
1337
|
-
// the DataTransferItem.getAsFile() API
|
|
1338
|
-
// NOTE: FileSystemEntry.file() throws if trying to get the file
|
|
1339
|
-
if (entry && entry.isDirectory) {
|
|
1340
|
-
return fromDirEntry(entry);
|
|
1341
|
-
}
|
|
1342
|
-
return fromDataTransferItem(item);
|
|
1343
|
-
}
|
|
1344
|
-
function flatten(items) {
|
|
1345
|
-
return items.reduce(function (acc, files) { return __spreadArray(__spreadArray([], __read(acc), false), __read((Array.isArray(files) ? flatten(files) : [files])), false); }, []);
|
|
1346
|
-
}
|
|
1347
|
-
function fromDataTransferItem(item) {
|
|
1348
|
-
var file = item.getAsFile();
|
|
1349
|
-
if (!file) {
|
|
1350
|
-
return Promise.reject("".concat(item, " is not a File"));
|
|
1351
|
-
}
|
|
1352
|
-
var fwp = toFileWithPath(file);
|
|
1353
|
-
return Promise.resolve(fwp);
|
|
1354
|
-
}
|
|
1355
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry
|
|
1356
|
-
function fromEntry(entry) {
|
|
1357
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1358
|
-
return __generator(this, function (_a) {
|
|
1359
|
-
return [2 /*return*/, entry.isDirectory ? fromDirEntry(entry) : fromFileEntry(entry)];
|
|
1360
|
-
});
|
|
1361
|
-
});
|
|
1362
|
-
}
|
|
1363
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry
|
|
1364
|
-
function fromDirEntry(entry) {
|
|
1365
|
-
var reader = entry.createReader();
|
|
1366
|
-
return new Promise(function (resolve, reject) {
|
|
1367
|
-
var entries = [];
|
|
1368
|
-
function readEntries() {
|
|
1369
|
-
var _this = this;
|
|
1370
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry/createReader
|
|
1371
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader/readEntries
|
|
1372
|
-
reader.readEntries(function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
1373
|
-
var files, err_1, items;
|
|
1374
|
-
return __generator(this, function (_a) {
|
|
1375
|
-
switch (_a.label) {
|
|
1376
|
-
case 0:
|
|
1377
|
-
if (!!batch.length) return [3 /*break*/, 5];
|
|
1378
|
-
_a.label = 1;
|
|
1379
|
-
case 1:
|
|
1380
|
-
_a.trys.push([1, 3, , 4]);
|
|
1381
|
-
return [4 /*yield*/, Promise.all(entries)];
|
|
1382
|
-
case 2:
|
|
1383
|
-
files = _a.sent();
|
|
1384
|
-
resolve(files);
|
|
1385
|
-
return [3 /*break*/, 4];
|
|
1386
|
-
case 3:
|
|
1387
|
-
err_1 = _a.sent();
|
|
1388
|
-
reject(err_1);
|
|
1389
|
-
return [3 /*break*/, 4];
|
|
1390
|
-
case 4: return [3 /*break*/, 6];
|
|
1391
|
-
case 5:
|
|
1392
|
-
items = Promise.all(batch.map(fromEntry));
|
|
1393
|
-
entries.push(items);
|
|
1394
|
-
// Continue reading
|
|
1395
|
-
readEntries();
|
|
1396
|
-
_a.label = 6;
|
|
1397
|
-
case 6: return [2 /*return*/];
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
}); }, function (err) {
|
|
1401
|
-
reject(err);
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
readEntries();
|
|
1405
|
-
});
|
|
1406
|
-
}
|
|
1407
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry
|
|
1408
|
-
function fromFileEntry(entry) {
|
|
1409
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1410
|
-
return __generator(this, function (_a) {
|
|
1411
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
1412
|
-
entry.file(function (file) {
|
|
1413
|
-
var fwp = toFileWithPath(file, entry.fullPath);
|
|
1414
|
-
resolve(fwp);
|
|
1415
|
-
}, function (err) {
|
|
1416
|
-
reject(err);
|
|
1417
|
-
});
|
|
1418
|
-
})];
|
|
1419
|
-
});
|
|
1420
|
-
});
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
var _default = function (file, acceptedFiles) {
|
|
1424
|
-
if (file && acceptedFiles) {
|
|
1425
|
-
var acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(',');
|
|
1426
|
-
var fileName = file.name || '';
|
|
1427
|
-
var mimeType = (file.type || '').toLowerCase();
|
|
1428
|
-
var baseMimeType = mimeType.replace(/\/.*$/, '');
|
|
1429
|
-
return acceptedFilesArray.some(function (type) {
|
|
1430
|
-
var validType = type.trim().toLowerCase();
|
|
1431
|
-
|
|
1432
|
-
if (validType.charAt(0) === '.') {
|
|
1433
|
-
return fileName.toLowerCase().endsWith(validType);
|
|
1434
|
-
} else if (validType.endsWith('/*')) {
|
|
1435
|
-
// This is something like a image/* mime type
|
|
1436
|
-
return baseMimeType === validType.replace(/\/.*$/, '');
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
return mimeType === validType;
|
|
1440
|
-
});
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
return true;
|
|
1444
|
-
};
|
|
1445
|
-
|
|
1446
|
-
function _toConsumableArray$1(arr) { return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread$1(); }
|
|
1447
|
-
|
|
1448
|
-
function _nonIterableSpread$1() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1449
|
-
|
|
1450
|
-
function _iterableToArray$1(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
1451
|
-
|
|
1452
|
-
function _arrayWithoutHoles$1(arr) { if (Array.isArray(arr)) return _arrayLikeToArray$1(arr); }
|
|
1453
|
-
|
|
1454
|
-
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1455
|
-
|
|
1456
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty$1(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1457
|
-
|
|
1458
|
-
function _defineProperty$1(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1459
|
-
|
|
1460
|
-
function _slicedToArray$1(arr, i) { return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest$1(); }
|
|
1461
|
-
|
|
1462
|
-
function _nonIterableRest$1() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1463
|
-
|
|
1464
|
-
function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
|
|
1465
|
-
|
|
1466
|
-
function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
1467
|
-
|
|
1468
|
-
function _iterableToArrayLimit$1(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
1469
|
-
|
|
1470
|
-
function _arrayWithHoles$1(arr) { if (Array.isArray(arr)) return arr; }
|
|
1471
|
-
|
|
1472
|
-
var FILE_INVALID_TYPE = "file-invalid-type";
|
|
1473
|
-
var FILE_TOO_LARGE = "file-too-large";
|
|
1474
|
-
var FILE_TOO_SMALL = "file-too-small";
|
|
1475
|
-
var TOO_MANY_FILES = "too-many-files";
|
|
1476
|
-
var ErrorCode = {
|
|
1477
|
-
FileInvalidType: FILE_INVALID_TYPE,
|
|
1478
|
-
FileTooLarge: FILE_TOO_LARGE,
|
|
1479
|
-
FileTooSmall: FILE_TOO_SMALL,
|
|
1480
|
-
TooManyFiles: TOO_MANY_FILES
|
|
1481
|
-
}; // File Errors
|
|
1482
|
-
|
|
1483
|
-
var getInvalidTypeRejectionErr = function getInvalidTypeRejectionErr(accept) {
|
|
1484
|
-
accept = Array.isArray(accept) && accept.length === 1 ? accept[0] : accept;
|
|
1485
|
-
var messageSuffix = Array.isArray(accept) ? "one of ".concat(accept.join(", ")) : accept;
|
|
1486
|
-
return {
|
|
1487
|
-
code: FILE_INVALID_TYPE,
|
|
1488
|
-
message: "File type must be ".concat(messageSuffix)
|
|
1489
|
-
};
|
|
1490
|
-
};
|
|
1491
|
-
var getTooLargeRejectionErr = function getTooLargeRejectionErr(maxSize) {
|
|
1492
|
-
return {
|
|
1493
|
-
code: FILE_TOO_LARGE,
|
|
1494
|
-
message: "File is larger than ".concat(maxSize, " ").concat(maxSize === 1 ? "byte" : "bytes")
|
|
1495
|
-
};
|
|
1496
|
-
};
|
|
1497
|
-
var getTooSmallRejectionErr = function getTooSmallRejectionErr(minSize) {
|
|
1498
|
-
return {
|
|
1499
|
-
code: FILE_TOO_SMALL,
|
|
1500
|
-
message: "File is smaller than ".concat(minSize, " ").concat(minSize === 1 ? "byte" : "bytes")
|
|
1501
|
-
};
|
|
1502
|
-
};
|
|
1503
|
-
var TOO_MANY_FILES_REJECTION = {
|
|
1504
|
-
code: TOO_MANY_FILES,
|
|
1505
|
-
message: "Too many files"
|
|
1506
|
-
}; // Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
|
|
1507
|
-
// that MIME type will always be accepted
|
|
1508
|
-
|
|
1509
|
-
function fileAccepted(file, accept) {
|
|
1510
|
-
var isAcceptable = file.type === "application/x-moz-file" || _default(file, accept);
|
|
1511
|
-
return [isAcceptable, isAcceptable ? null : getInvalidTypeRejectionErr(accept)];
|
|
1512
|
-
}
|
|
1513
|
-
function fileMatchSize(file, minSize, maxSize) {
|
|
1514
|
-
if (isDefined(file.size)) {
|
|
1515
|
-
if (isDefined(minSize) && isDefined(maxSize)) {
|
|
1516
|
-
if (file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];
|
|
1517
|
-
if (file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];
|
|
1518
|
-
} else if (isDefined(minSize) && file.size < minSize) return [false, getTooSmallRejectionErr(minSize)];else if (isDefined(maxSize) && file.size > maxSize) return [false, getTooLargeRejectionErr(maxSize)];
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
return [true, null];
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
function isDefined(value) {
|
|
1525
|
-
return value !== undefined && value !== null;
|
|
1526
|
-
}
|
|
1527
|
-
/**
|
|
1528
|
-
*
|
|
1529
|
-
* @param {object} options
|
|
1530
|
-
* @param {File[]} options.files
|
|
1531
|
-
* @param {string|string[]} [options.accept]
|
|
1532
|
-
* @param {number} [options.minSize]
|
|
1533
|
-
* @param {number} [options.maxSize]
|
|
1534
|
-
* @param {boolean} [options.multiple]
|
|
1535
|
-
* @param {number} [options.maxFiles]
|
|
1536
|
-
* @param {(f: File) => FileError|FileError[]|null} [options.validator]
|
|
1537
|
-
* @returns
|
|
1538
|
-
*/
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
function allFilesAccepted(_ref) {
|
|
1542
|
-
var files = _ref.files,
|
|
1543
|
-
accept = _ref.accept,
|
|
1544
|
-
minSize = _ref.minSize,
|
|
1545
|
-
maxSize = _ref.maxSize,
|
|
1546
|
-
multiple = _ref.multiple,
|
|
1547
|
-
maxFiles = _ref.maxFiles,
|
|
1548
|
-
validator = _ref.validator;
|
|
1549
|
-
|
|
1550
|
-
if (!multiple && files.length > 1 || multiple && maxFiles >= 1 && files.length > maxFiles) {
|
|
1551
|
-
return false;
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
return files.every(function (file) {
|
|
1555
|
-
var _fileAccepted = fileAccepted(file, accept),
|
|
1556
|
-
_fileAccepted2 = _slicedToArray$1(_fileAccepted, 1),
|
|
1557
|
-
accepted = _fileAccepted2[0];
|
|
1558
|
-
|
|
1559
|
-
var _fileMatchSize = fileMatchSize(file, minSize, maxSize),
|
|
1560
|
-
_fileMatchSize2 = _slicedToArray$1(_fileMatchSize, 1),
|
|
1561
|
-
sizeMatch = _fileMatchSize2[0];
|
|
1562
|
-
|
|
1563
|
-
var customErrors = validator ? validator(file) : null;
|
|
1564
|
-
return accepted && sizeMatch && !customErrors;
|
|
1565
|
-
});
|
|
1566
|
-
} // React's synthetic events has event.isPropagationStopped,
|
|
1567
|
-
// but to remain compatibility with other libs (Preact) fall back
|
|
1568
|
-
// to check event.cancelBubble
|
|
1569
|
-
|
|
1570
|
-
function isPropagationStopped(event) {
|
|
1571
|
-
if (typeof event.isPropagationStopped === "function") {
|
|
1572
|
-
return event.isPropagationStopped();
|
|
1573
|
-
} else if (typeof event.cancelBubble !== "undefined") {
|
|
1574
|
-
return event.cancelBubble;
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
return false;
|
|
1578
|
-
}
|
|
1579
|
-
function isEvtWithFiles(event) {
|
|
1580
|
-
if (!event.dataTransfer) {
|
|
1581
|
-
return !!event.target && !!event.target.files;
|
|
1582
|
-
} // https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types
|
|
1583
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Recommended_drag_types#file
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
return Array.prototype.some.call(event.dataTransfer.types, function (type) {
|
|
1587
|
-
return type === "Files" || type === "application/x-moz-file";
|
|
1588
|
-
});
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
function onDocumentDragOver(event) {
|
|
1592
|
-
event.preventDefault();
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
function isIe(userAgent) {
|
|
1596
|
-
return userAgent.indexOf("MSIE") !== -1 || userAgent.indexOf("Trident/") !== -1;
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
function isEdge(userAgent) {
|
|
1600
|
-
return userAgent.indexOf("Edge/") !== -1;
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
function isIeOrEdge() {
|
|
1604
|
-
var userAgent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.navigator.userAgent;
|
|
1605
|
-
return isIe(userAgent) || isEdge(userAgent);
|
|
1606
|
-
}
|
|
1607
|
-
/**
|
|
1608
|
-
* This is intended to be used to compose event handlers
|
|
1609
|
-
* They are executed in order until one of them calls `event.isPropagationStopped()`.
|
|
1610
|
-
* Note that the check is done on the first invoke too,
|
|
1611
|
-
* meaning that if propagation was stopped before invoking the fns,
|
|
1612
|
-
* no handlers will be executed.
|
|
1613
|
-
*
|
|
1614
|
-
* @param {Function} fns the event hanlder functions
|
|
1615
|
-
* @return {Function} the event handler to add to an element
|
|
1616
|
-
*/
|
|
1617
|
-
|
|
1618
|
-
function composeEventHandlers() {
|
|
1619
|
-
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1620
|
-
fns[_key] = arguments[_key];
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
return function (event) {
|
|
1624
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1625
|
-
args[_key2 - 1] = arguments[_key2];
|
|
1626
|
-
}
|
|
1627
|
-
|
|
1628
|
-
return fns.some(function (fn) {
|
|
1629
|
-
if (!isPropagationStopped(event) && fn) {
|
|
1630
|
-
fn.apply(void 0, [event].concat(args));
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1633
|
-
return isPropagationStopped(event);
|
|
1634
|
-
});
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1637
|
-
/**
|
|
1638
|
-
* canUseFileSystemAccessAPI checks if the [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API)
|
|
1639
|
-
* is supported by the browser.
|
|
1640
|
-
* @returns {boolean}
|
|
1641
|
-
*/
|
|
1642
|
-
|
|
1643
|
-
function canUseFileSystemAccessAPI() {
|
|
1644
|
-
return "showOpenFilePicker" in window;
|
|
1645
|
-
}
|
|
1646
|
-
/**
|
|
1647
|
-
* Convert the `{accept}` dropzone prop to the
|
|
1648
|
-
* `{types}` option for https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker
|
|
1649
|
-
*
|
|
1650
|
-
* @param {AcceptProp} accept
|
|
1651
|
-
* @returns {{accept: string[]}[]}
|
|
1652
|
-
*/
|
|
1653
|
-
|
|
1654
|
-
function pickerOptionsFromAccept(accept) {
|
|
1655
|
-
if (isDefined(accept)) {
|
|
1656
|
-
var acceptForPicker = Object.entries(accept).filter(function (_ref2) {
|
|
1657
|
-
var _ref3 = _slicedToArray$1(_ref2, 2),
|
|
1658
|
-
mimeType = _ref3[0],
|
|
1659
|
-
ext = _ref3[1];
|
|
1660
|
-
|
|
1661
|
-
var ok = true;
|
|
1662
|
-
|
|
1663
|
-
if (!isMIMEType(mimeType)) {
|
|
1664
|
-
console.warn("Skipped \"".concat(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."));
|
|
1665
|
-
ok = false;
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
if (!Array.isArray(ext) || !ext.every(isExt)) {
|
|
1669
|
-
console.warn("Skipped \"".concat(mimeType, "\" because an invalid file extension was provided."));
|
|
1670
|
-
ok = false;
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
return ok;
|
|
1674
|
-
}).reduce(function (agg, _ref4) {
|
|
1675
|
-
var _ref5 = _slicedToArray$1(_ref4, 2),
|
|
1676
|
-
mimeType = _ref5[0],
|
|
1677
|
-
ext = _ref5[1];
|
|
1678
|
-
|
|
1679
|
-
return _objectSpread$1(_objectSpread$1({}, agg), {}, _defineProperty$1({}, mimeType, ext));
|
|
1680
|
-
}, {});
|
|
1681
|
-
return [{
|
|
1682
|
-
accept: acceptForPicker
|
|
1683
|
-
}];
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
return accept;
|
|
1687
|
-
}
|
|
1688
|
-
/**
|
|
1689
|
-
* Convert the `{accept}` dropzone prop to an array of MIME types/extensions.
|
|
1690
|
-
* @param {AcceptProp} accept
|
|
1691
|
-
* @returns {string}
|
|
1692
|
-
*/
|
|
1693
|
-
|
|
1694
|
-
function acceptPropAsAcceptAttr(accept) {
|
|
1695
|
-
if (isDefined(accept)) {
|
|
1696
|
-
return Object.entries(accept).reduce(function (a, _ref6) {
|
|
1697
|
-
var _ref7 = _slicedToArray$1(_ref6, 2),
|
|
1698
|
-
mimeType = _ref7[0],
|
|
1699
|
-
ext = _ref7[1];
|
|
1700
|
-
|
|
1701
|
-
return [].concat(_toConsumableArray$1(a), [mimeType], _toConsumableArray$1(ext));
|
|
1702
|
-
}, []) // Silently discard invalid entries as pickerOptionsFromAccept warns about these
|
|
1703
|
-
.filter(function (v) {
|
|
1704
|
-
return isMIMEType(v) || isExt(v);
|
|
1705
|
-
}).join(",");
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
return undefined;
|
|
1709
|
-
}
|
|
1710
|
-
/**
|
|
1711
|
-
* Check if v is an exception caused by aborting a request (e.g window.showOpenFilePicker()).
|
|
1712
|
-
*
|
|
1713
|
-
* See https://developer.mozilla.org/en-US/docs/Web/API/DOMException.
|
|
1714
|
-
* @param {any} v
|
|
1715
|
-
* @returns {boolean} True if v is an abort exception.
|
|
1716
|
-
*/
|
|
1717
|
-
|
|
1718
|
-
function isAbort(v) {
|
|
1719
|
-
return v instanceof DOMException && (v.name === "AbortError" || v.code === v.ABORT_ERR);
|
|
1720
|
-
}
|
|
1721
|
-
/**
|
|
1722
|
-
* Check if v is a security error.
|
|
1723
|
-
*
|
|
1724
|
-
* See https://developer.mozilla.org/en-US/docs/Web/API/DOMException.
|
|
1725
|
-
* @param {any} v
|
|
1726
|
-
* @returns {boolean} True if v is a security error.
|
|
1727
|
-
*/
|
|
1728
|
-
|
|
1729
|
-
function isSecurityError(v) {
|
|
1730
|
-
return v instanceof DOMException && (v.name === "SecurityError" || v.code === v.SECURITY_ERR);
|
|
1731
|
-
}
|
|
1732
|
-
/**
|
|
1733
|
-
* Check if v is a MIME type string.
|
|
1734
|
-
*
|
|
1735
|
-
* See accepted format: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#unique_file_type_specifiers.
|
|
1736
|
-
*
|
|
1737
|
-
* @param {string} v
|
|
1738
|
-
*/
|
|
1739
|
-
|
|
1740
|
-
function isMIMEType(v) {
|
|
1741
|
-
return v === "audio/*" || v === "video/*" || v === "image/*" || v === "text/*" || /\w+\/[-+.\w]+/g.test(v);
|
|
1742
|
-
}
|
|
1743
|
-
/**
|
|
1744
|
-
* Check if v is a file extension.
|
|
1745
|
-
* @param {string} v
|
|
1746
|
-
*/
|
|
1747
|
-
|
|
1748
|
-
function isExt(v) {
|
|
1749
|
-
return /^.*\.[\w]+$/.test(v);
|
|
1750
|
-
}
|
|
1751
|
-
/**
|
|
1752
|
-
* @typedef {Object.<string, string[]>} AcceptProp
|
|
1753
|
-
*/
|
|
1754
|
-
|
|
1755
|
-
/**
|
|
1756
|
-
* @typedef {object} FileError
|
|
1757
|
-
* @property {string} message
|
|
1758
|
-
* @property {ErrorCode|string} code
|
|
1759
|
-
*/
|
|
1760
|
-
|
|
1761
|
-
/**
|
|
1762
|
-
* @typedef {"file-invalid-type"|"file-too-large"|"file-too-small"|"too-many-files"} ErrorCode
|
|
1763
|
-
*/
|
|
1764
|
-
|
|
1765
|
-
var _excluded = ["children"],
|
|
1766
|
-
_excluded2 = ["open"],
|
|
1767
|
-
_excluded3 = ["refKey", "role", "onKeyDown", "onFocus", "onBlur", "onClick", "onDragEnter", "onDragOver", "onDragLeave", "onDrop"],
|
|
1768
|
-
_excluded4 = ["refKey", "onChange", "onClick"];
|
|
1769
|
-
|
|
1770
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
1771
|
-
|
|
1772
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1773
|
-
|
|
1774
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
1775
|
-
|
|
1776
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
1777
|
-
|
|
1778
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
1779
|
-
|
|
1780
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1781
|
-
|
|
1782
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
1783
|
-
|
|
1784
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
1785
|
-
|
|
1786
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
1787
|
-
|
|
1788
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
1789
|
-
|
|
1790
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1791
|
-
|
|
1792
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1793
|
-
|
|
1794
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1795
|
-
|
|
1796
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
1797
|
-
|
|
1798
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
1799
|
-
/**
|
|
1800
|
-
* Convenience wrapper component for the `useDropzone` hook
|
|
1801
|
-
*
|
|
1802
|
-
* ```jsx
|
|
1803
|
-
* <Dropzone>
|
|
1804
|
-
* {({getRootProps, getInputProps}) => (
|
|
1805
|
-
* <div {...getRootProps()}>
|
|
1806
|
-
* <input {...getInputProps()} />
|
|
1807
|
-
* <p>Drag 'n' drop some files here, or click to select files</p>
|
|
1808
|
-
* </div>
|
|
1809
|
-
* )}
|
|
1810
|
-
* </Dropzone>
|
|
1811
|
-
* ```
|
|
1812
|
-
*/
|
|
1813
|
-
|
|
1814
|
-
var Dropzone = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
1815
|
-
var children = _ref.children,
|
|
1816
|
-
params = _objectWithoutProperties(_ref, _excluded);
|
|
1817
|
-
|
|
1818
|
-
var _useDropzone = useDropzone(params),
|
|
1819
|
-
open = _useDropzone.open,
|
|
1820
|
-
props = _objectWithoutProperties(_useDropzone, _excluded2);
|
|
1821
|
-
|
|
1822
|
-
useImperativeHandle(ref, function () {
|
|
1823
|
-
return {
|
|
1824
|
-
open: open
|
|
1825
|
-
};
|
|
1826
|
-
}, [open]); // TODO: Figure out why react-styleguidist cannot create docs if we don't return a jsx element
|
|
1827
|
-
|
|
1828
|
-
return /*#__PURE__*/React__default.createElement(Fragment, null, children(_objectSpread(_objectSpread({}, props), {}, {
|
|
1829
|
-
open: open
|
|
1830
|
-
})));
|
|
1831
|
-
});
|
|
1832
|
-
Dropzone.displayName = "Dropzone"; // Add default props for react-docgen
|
|
1833
|
-
|
|
1834
|
-
var defaultProps = {
|
|
1835
|
-
disabled: false,
|
|
1836
|
-
getFilesFromEvent: fromEvent,
|
|
1837
|
-
maxSize: Infinity,
|
|
1838
|
-
minSize: 0,
|
|
1839
|
-
multiple: true,
|
|
1840
|
-
maxFiles: 0,
|
|
1841
|
-
preventDropOnDocument: true,
|
|
1842
|
-
noClick: false,
|
|
1843
|
-
noKeyboard: false,
|
|
1844
|
-
noDrag: false,
|
|
1845
|
-
noDragEventsBubbling: false,
|
|
1846
|
-
validator: null,
|
|
1847
|
-
useFsAccessApi: true,
|
|
1848
|
-
autoFocus: false
|
|
1849
|
-
};
|
|
1850
|
-
Dropzone.defaultProps = defaultProps;
|
|
1851
|
-
Dropzone.propTypes = {
|
|
1852
|
-
/**
|
|
1853
|
-
* Render function that exposes the dropzone state and prop getter fns
|
|
1854
|
-
*
|
|
1855
|
-
* @param {object} params
|
|
1856
|
-
* @param {Function} params.getRootProps Returns the props you should apply to the root drop container you render
|
|
1857
|
-
* @param {Function} params.getInputProps Returns the props you should apply to hidden file input you render
|
|
1858
|
-
* @param {Function} params.open Open the native file selection dialog
|
|
1859
|
-
* @param {boolean} params.isFocused Dropzone area is in focus
|
|
1860
|
-
* @param {boolean} params.isFileDialogActive File dialog is opened
|
|
1861
|
-
* @param {boolean} params.isDragActive Active drag is in progress
|
|
1862
|
-
* @param {boolean} params.isDragAccept Dragged files are accepted
|
|
1863
|
-
* @param {boolean} params.isDragReject Some dragged files are rejected
|
|
1864
|
-
* @param {File[]} params.acceptedFiles Accepted files
|
|
1865
|
-
* @param {FileRejection[]} params.fileRejections Rejected files and why they were rejected
|
|
1866
|
-
*/
|
|
1867
|
-
children: PropTypes.func,
|
|
1868
|
-
|
|
1869
|
-
/**
|
|
1870
|
-
* Set accepted file types.
|
|
1871
|
-
* Checkout https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker types option for more information.
|
|
1872
|
-
* Keep in mind that mime type determination is not reliable across platforms. CSV files,
|
|
1873
|
-
* for example, are reported as text/plain under macOS but as application/vnd.ms-excel under
|
|
1874
|
-
* Windows. In some cases there might not be a mime type set at all (https://github.com/react-dropzone/react-dropzone/issues/276).
|
|
1875
|
-
*/
|
|
1876
|
-
accept: PropTypes.objectOf(PropTypes.arrayOf(PropTypes.string)),
|
|
1877
|
-
|
|
1878
|
-
/**
|
|
1879
|
-
* Allow drag 'n' drop (or selection from the file dialog) of multiple files
|
|
1880
|
-
*/
|
|
1881
|
-
multiple: PropTypes.bool,
|
|
1882
|
-
|
|
1883
|
-
/**
|
|
1884
|
-
* If false, allow dropped items to take over the current browser window
|
|
1885
|
-
*/
|
|
1886
|
-
preventDropOnDocument: PropTypes.bool,
|
|
1887
|
-
|
|
1888
|
-
/**
|
|
1889
|
-
* If true, disables click to open the native file selection dialog
|
|
1890
|
-
*/
|
|
1891
|
-
noClick: PropTypes.bool,
|
|
1892
|
-
|
|
1893
|
-
/**
|
|
1894
|
-
* If true, disables SPACE/ENTER to open the native file selection dialog.
|
|
1895
|
-
* Note that it also stops tracking the focus state.
|
|
1896
|
-
*/
|
|
1897
|
-
noKeyboard: PropTypes.bool,
|
|
1898
|
-
|
|
1899
|
-
/**
|
|
1900
|
-
* If true, disables drag 'n' drop
|
|
1901
|
-
*/
|
|
1902
|
-
noDrag: PropTypes.bool,
|
|
1903
|
-
|
|
1904
|
-
/**
|
|
1905
|
-
* If true, stops drag event propagation to parents
|
|
1906
|
-
*/
|
|
1907
|
-
noDragEventsBubbling: PropTypes.bool,
|
|
1908
|
-
|
|
1909
|
-
/**
|
|
1910
|
-
* Minimum file size (in bytes)
|
|
1911
|
-
*/
|
|
1912
|
-
minSize: PropTypes.number,
|
|
1913
|
-
|
|
1914
|
-
/**
|
|
1915
|
-
* Maximum file size (in bytes)
|
|
1916
|
-
*/
|
|
1917
|
-
maxSize: PropTypes.number,
|
|
1918
|
-
|
|
1919
|
-
/**
|
|
1920
|
-
* Maximum accepted number of files
|
|
1921
|
-
* The default value is 0 which means there is no limitation to how many files are accepted.
|
|
1922
|
-
*/
|
|
1923
|
-
maxFiles: PropTypes.number,
|
|
1924
|
-
|
|
1925
|
-
/**
|
|
1926
|
-
* Enable/disable the dropzone
|
|
1927
|
-
*/
|
|
1928
|
-
disabled: PropTypes.bool,
|
|
1929
|
-
|
|
1930
|
-
/**
|
|
1931
|
-
* Use this to provide a custom file aggregator
|
|
1932
|
-
*
|
|
1933
|
-
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
1934
|
-
*/
|
|
1935
|
-
getFilesFromEvent: PropTypes.func,
|
|
1936
|
-
|
|
1937
|
-
/**
|
|
1938
|
-
* Cb for when closing the file dialog with no selection
|
|
1939
|
-
*/
|
|
1940
|
-
onFileDialogCancel: PropTypes.func,
|
|
1941
|
-
|
|
1942
|
-
/**
|
|
1943
|
-
* Cb for when opening the file dialog
|
|
1944
|
-
*/
|
|
1945
|
-
onFileDialogOpen: PropTypes.func,
|
|
1946
|
-
|
|
1947
|
-
/**
|
|
1948
|
-
* Set to true to use the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API
|
|
1949
|
-
* to open the file picker instead of using an `<input type="file">` click event.
|
|
1950
|
-
*/
|
|
1951
|
-
useFsAccessApi: PropTypes.bool,
|
|
1952
|
-
|
|
1953
|
-
/**
|
|
1954
|
-
* Set to true to focus the root element on render
|
|
1955
|
-
*/
|
|
1956
|
-
autoFocus: PropTypes.bool,
|
|
1957
|
-
|
|
1958
|
-
/**
|
|
1959
|
-
* Cb for when the `dragenter` event occurs.
|
|
1960
|
-
*
|
|
1961
|
-
* @param {DragEvent} event
|
|
1962
|
-
*/
|
|
1963
|
-
onDragEnter: PropTypes.func,
|
|
1964
|
-
|
|
1965
|
-
/**
|
|
1966
|
-
* Cb for when the `dragleave` event occurs
|
|
1967
|
-
*
|
|
1968
|
-
* @param {DragEvent} event
|
|
1969
|
-
*/
|
|
1970
|
-
onDragLeave: PropTypes.func,
|
|
1971
|
-
|
|
1972
|
-
/**
|
|
1973
|
-
* Cb for when the `dragover` event occurs
|
|
1974
|
-
*
|
|
1975
|
-
* @param {DragEvent} event
|
|
1976
|
-
*/
|
|
1977
|
-
onDragOver: PropTypes.func,
|
|
1978
|
-
|
|
1979
|
-
/**
|
|
1980
|
-
* Cb for when the `drop` event occurs.
|
|
1981
|
-
* Note that this callback is invoked after the `getFilesFromEvent` callback is done.
|
|
1982
|
-
*
|
|
1983
|
-
* Files are accepted or rejected based on the `accept`, `multiple`, `minSize` and `maxSize` props.
|
|
1984
|
-
* `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.
|
|
1985
|
-
* If `multiple` is set to false and additional files are dropped,
|
|
1986
|
-
* all files besides the first will be rejected.
|
|
1987
|
-
* Any file which does not have a size in the [`minSize`, `maxSize`] range, will be rejected as well.
|
|
1988
|
-
*
|
|
1989
|
-
* Note that the `onDrop` callback will always be invoked regardless if the dropped files were accepted or rejected.
|
|
1990
|
-
* If you'd like to react to a specific scenario, use the `onDropAccepted`/`onDropRejected` props.
|
|
1991
|
-
*
|
|
1992
|
-
* `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.
|
|
1993
|
-
* For example, with [SuperAgent](https://github.com/visionmedia/superagent) as a http/ajax library:
|
|
1994
|
-
*
|
|
1995
|
-
* ```js
|
|
1996
|
-
* function onDrop(acceptedFiles) {
|
|
1997
|
-
* const req = request.post('/upload')
|
|
1998
|
-
* acceptedFiles.forEach(file => {
|
|
1999
|
-
* req.attach(file.name, file)
|
|
2000
|
-
* })
|
|
2001
|
-
* req.end(callback)
|
|
2002
|
-
* }
|
|
2003
|
-
* ```
|
|
2004
|
-
*
|
|
2005
|
-
* @param {File[]} acceptedFiles
|
|
2006
|
-
* @param {FileRejection[]} fileRejections
|
|
2007
|
-
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
2008
|
-
*/
|
|
2009
|
-
onDrop: PropTypes.func,
|
|
2010
|
-
|
|
2011
|
-
/**
|
|
2012
|
-
* Cb for when the `drop` event occurs.
|
|
2013
|
-
* Note that if no files are accepted, this callback is not invoked.
|
|
2014
|
-
*
|
|
2015
|
-
* @param {File[]} files
|
|
2016
|
-
* @param {(DragEvent|Event)} event
|
|
2017
|
-
*/
|
|
2018
|
-
onDropAccepted: PropTypes.func,
|
|
2019
|
-
|
|
2020
|
-
/**
|
|
2021
|
-
* Cb for when the `drop` event occurs.
|
|
2022
|
-
* Note that if no files are rejected, this callback is not invoked.
|
|
2023
|
-
*
|
|
2024
|
-
* @param {FileRejection[]} fileRejections
|
|
2025
|
-
* @param {(DragEvent|Event)} event
|
|
2026
|
-
*/
|
|
2027
|
-
onDropRejected: PropTypes.func,
|
|
2028
|
-
|
|
2029
|
-
/**
|
|
2030
|
-
* Cb for when there's some error from any of the promises.
|
|
2031
|
-
*
|
|
2032
|
-
* @param {Error} error
|
|
2033
|
-
*/
|
|
2034
|
-
onError: PropTypes.func,
|
|
2035
|
-
|
|
2036
|
-
/**
|
|
2037
|
-
* Custom validation function. It must return null if there's no errors.
|
|
2038
|
-
* @param {File} file
|
|
2039
|
-
* @returns {FileError|FileError[]|null}
|
|
2040
|
-
*/
|
|
2041
|
-
validator: PropTypes.func
|
|
2042
|
-
};
|
|
2043
|
-
/**
|
|
2044
|
-
* A function that is invoked for the `dragenter`,
|
|
2045
|
-
* `dragover` and `dragleave` events.
|
|
2046
|
-
* It is not invoked if the items are not files (such as link, text, etc.).
|
|
2047
|
-
*
|
|
2048
|
-
* @callback dragCb
|
|
2049
|
-
* @param {DragEvent} event
|
|
2050
|
-
*/
|
|
2051
|
-
|
|
2052
|
-
/**
|
|
2053
|
-
* A function that is invoked for the `drop` or input change event.
|
|
2054
|
-
* It is not invoked if the items are not files (such as link, text, etc.).
|
|
2055
|
-
*
|
|
2056
|
-
* @callback dropCb
|
|
2057
|
-
* @param {File[]} acceptedFiles List of accepted files
|
|
2058
|
-
* @param {FileRejection[]} fileRejections List of rejected files and why they were rejected
|
|
2059
|
-
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
2060
|
-
*/
|
|
2061
|
-
|
|
2062
|
-
/**
|
|
2063
|
-
* A function that is invoked for the `drop` or input change event.
|
|
2064
|
-
* It is not invoked if the items are files (such as link, text, etc.).
|
|
2065
|
-
*
|
|
2066
|
-
* @callback dropAcceptedCb
|
|
2067
|
-
* @param {File[]} files List of accepted files that meet the given criteria
|
|
2068
|
-
* (`accept`, `multiple`, `minSize`, `maxSize`)
|
|
2069
|
-
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
2070
|
-
*/
|
|
2071
|
-
|
|
2072
|
-
/**
|
|
2073
|
-
* A function that is invoked for the `drop` or input change event.
|
|
2074
|
-
*
|
|
2075
|
-
* @callback dropRejectedCb
|
|
2076
|
-
* @param {File[]} files List of rejected files that do not meet the given criteria
|
|
2077
|
-
* (`accept`, `multiple`, `minSize`, `maxSize`)
|
|
2078
|
-
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
2079
|
-
*/
|
|
2080
|
-
|
|
2081
|
-
/**
|
|
2082
|
-
* A function that is used aggregate files,
|
|
2083
|
-
* in a asynchronous fashion, from drag or input change events.
|
|
2084
|
-
*
|
|
2085
|
-
* @callback getFilesFromEvent
|
|
2086
|
-
* @param {(DragEvent|Event)} event A drag event or input change event (if files were selected via the file dialog)
|
|
2087
|
-
* @returns {(File[]|Promise<File[]>)}
|
|
2088
|
-
*/
|
|
2089
|
-
|
|
2090
|
-
/**
|
|
2091
|
-
* An object with the current dropzone state.
|
|
2092
|
-
*
|
|
2093
|
-
* @typedef {object} DropzoneState
|
|
2094
|
-
* @property {boolean} isFocused Dropzone area is in focus
|
|
2095
|
-
* @property {boolean} isFileDialogActive File dialog is opened
|
|
2096
|
-
* @property {boolean} isDragActive Active drag is in progress
|
|
2097
|
-
* @property {boolean} isDragAccept Dragged files are accepted
|
|
2098
|
-
* @property {boolean} isDragReject Some dragged files are rejected
|
|
2099
|
-
* @property {File[]} acceptedFiles Accepted files
|
|
2100
|
-
* @property {FileRejection[]} fileRejections Rejected files and why they were rejected
|
|
2101
|
-
*/
|
|
2102
|
-
|
|
2103
|
-
/**
|
|
2104
|
-
* An object with the dropzone methods.
|
|
2105
|
-
*
|
|
2106
|
-
* @typedef {object} DropzoneMethods
|
|
2107
|
-
* @property {Function} getRootProps Returns the props you should apply to the root drop container you render
|
|
2108
|
-
* @property {Function} getInputProps Returns the props you should apply to hidden file input you render
|
|
2109
|
-
* @property {Function} open Open the native file selection dialog
|
|
2110
|
-
*/
|
|
2111
|
-
|
|
2112
|
-
var initialState = {
|
|
2113
|
-
isFocused: false,
|
|
2114
|
-
isFileDialogActive: false,
|
|
2115
|
-
isDragActive: false,
|
|
2116
|
-
isDragAccept: false,
|
|
2117
|
-
isDragReject: false,
|
|
2118
|
-
acceptedFiles: [],
|
|
2119
|
-
fileRejections: []
|
|
2120
|
-
};
|
|
2121
|
-
/**
|
|
2122
|
-
* A React hook that creates a drag 'n' drop area.
|
|
2123
|
-
*
|
|
2124
|
-
* ```jsx
|
|
2125
|
-
* function MyDropzone(props) {
|
|
2126
|
-
* const {getRootProps, getInputProps} = useDropzone({
|
|
2127
|
-
* onDrop: acceptedFiles => {
|
|
2128
|
-
* // do something with the File objects, e.g. upload to some server
|
|
2129
|
-
* }
|
|
2130
|
-
* });
|
|
2131
|
-
* return (
|
|
2132
|
-
* <div {...getRootProps()}>
|
|
2133
|
-
* <input {...getInputProps()} />
|
|
2134
|
-
* <p>Drag and drop some files here, or click to select files</p>
|
|
2135
|
-
* </div>
|
|
2136
|
-
* )
|
|
2137
|
-
* }
|
|
2138
|
-
* ```
|
|
2139
|
-
*
|
|
2140
|
-
* @function useDropzone
|
|
2141
|
-
*
|
|
2142
|
-
* @param {object} props
|
|
2143
|
-
* @param {import("./utils").AcceptProp} [props.accept] Set accepted file types.
|
|
2144
|
-
* Checkout https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker types option for more information.
|
|
2145
|
-
* Keep in mind that mime type determination is not reliable across platforms. CSV files,
|
|
2146
|
-
* for example, are reported as text/plain under macOS but as application/vnd.ms-excel under
|
|
2147
|
-
* Windows. In some cases there might not be a mime type set at all (https://github.com/react-dropzone/react-dropzone/issues/276).
|
|
2148
|
-
* @param {boolean} [props.multiple=true] Allow drag 'n' drop (or selection from the file dialog) of multiple files
|
|
2149
|
-
* @param {boolean} [props.preventDropOnDocument=true] If false, allow dropped items to take over the current browser window
|
|
2150
|
-
* @param {boolean} [props.noClick=false] If true, disables click to open the native file selection dialog
|
|
2151
|
-
* @param {boolean} [props.noKeyboard=false] If true, disables SPACE/ENTER to open the native file selection dialog.
|
|
2152
|
-
* Note that it also stops tracking the focus state.
|
|
2153
|
-
* @param {boolean} [props.noDrag=false] If true, disables drag 'n' drop
|
|
2154
|
-
* @param {boolean} [props.noDragEventsBubbling=false] If true, stops drag event propagation to parents
|
|
2155
|
-
* @param {number} [props.minSize=0] Minimum file size (in bytes)
|
|
2156
|
-
* @param {number} [props.maxSize=Infinity] Maximum file size (in bytes)
|
|
2157
|
-
* @param {boolean} [props.disabled=false] Enable/disable the dropzone
|
|
2158
|
-
* @param {getFilesFromEvent} [props.getFilesFromEvent] Use this to provide a custom file aggregator
|
|
2159
|
-
* @param {Function} [props.onFileDialogCancel] Cb for when closing the file dialog with no selection
|
|
2160
|
-
* @param {boolean} [props.useFsAccessApi] Set to true to use the https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API
|
|
2161
|
-
* to open the file picker instead of using an `<input type="file">` click event.
|
|
2162
|
-
* @param {boolean} autoFocus Set to true to auto focus the root element.
|
|
2163
|
-
* @param {Function} [props.onFileDialogOpen] Cb for when opening the file dialog
|
|
2164
|
-
* @param {dragCb} [props.onDragEnter] Cb for when the `dragenter` event occurs.
|
|
2165
|
-
* @param {dragCb} [props.onDragLeave] Cb for when the `dragleave` event occurs
|
|
2166
|
-
* @param {dragCb} [props.onDragOver] Cb for when the `dragover` event occurs
|
|
2167
|
-
* @param {dropCb} [props.onDrop] Cb for when the `drop` event occurs.
|
|
2168
|
-
* Note that this callback is invoked after the `getFilesFromEvent` callback is done.
|
|
2169
|
-
*
|
|
2170
|
-
* Files are accepted or rejected based on the `accept`, `multiple`, `minSize` and `maxSize` props.
|
|
2171
|
-
* `accept` must be an object with keys as 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) and the value an array of file extensions (optional).
|
|
2172
|
-
* If `multiple` is set to false and additional files are dropped,
|
|
2173
|
-
* all files besides the first will be rejected.
|
|
2174
|
-
* Any file which does not have a size in the [`minSize`, `maxSize`] range, will be rejected as well.
|
|
2175
|
-
*
|
|
2176
|
-
* Note that the `onDrop` callback will always be invoked regardless if the dropped files were accepted or rejected.
|
|
2177
|
-
* If you'd like to react to a specific scenario, use the `onDropAccepted`/`onDropRejected` props.
|
|
2178
|
-
*
|
|
2179
|
-
* `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.
|
|
2180
|
-
* For example, with [SuperAgent](https://github.com/visionmedia/superagent) as a http/ajax library:
|
|
2181
|
-
*
|
|
2182
|
-
* ```js
|
|
2183
|
-
* function onDrop(acceptedFiles) {
|
|
2184
|
-
* const req = request.post('/upload')
|
|
2185
|
-
* acceptedFiles.forEach(file => {
|
|
2186
|
-
* req.attach(file.name, file)
|
|
2187
|
-
* })
|
|
2188
|
-
* req.end(callback)
|
|
2189
|
-
* }
|
|
2190
|
-
* ```
|
|
2191
|
-
* @param {dropAcceptedCb} [props.onDropAccepted]
|
|
2192
|
-
* @param {dropRejectedCb} [props.onDropRejected]
|
|
2193
|
-
* @param {(error: Error) => void} [props.onError]
|
|
2194
|
-
*
|
|
2195
|
-
* @returns {DropzoneState & DropzoneMethods}
|
|
2196
|
-
*/
|
|
2197
|
-
|
|
2198
|
-
function useDropzone() {
|
|
2199
|
-
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2200
|
-
|
|
2201
|
-
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
|
|
2202
|
-
accept = _defaultProps$props.accept,
|
|
2203
|
-
disabled = _defaultProps$props.disabled,
|
|
2204
|
-
getFilesFromEvent = _defaultProps$props.getFilesFromEvent,
|
|
2205
|
-
maxSize = _defaultProps$props.maxSize,
|
|
2206
|
-
minSize = _defaultProps$props.minSize,
|
|
2207
|
-
multiple = _defaultProps$props.multiple,
|
|
2208
|
-
maxFiles = _defaultProps$props.maxFiles,
|
|
2209
|
-
onDragEnter = _defaultProps$props.onDragEnter,
|
|
2210
|
-
onDragLeave = _defaultProps$props.onDragLeave,
|
|
2211
|
-
onDragOver = _defaultProps$props.onDragOver,
|
|
2212
|
-
onDrop = _defaultProps$props.onDrop,
|
|
2213
|
-
onDropAccepted = _defaultProps$props.onDropAccepted,
|
|
2214
|
-
onDropRejected = _defaultProps$props.onDropRejected,
|
|
2215
|
-
onFileDialogCancel = _defaultProps$props.onFileDialogCancel,
|
|
2216
|
-
onFileDialogOpen = _defaultProps$props.onFileDialogOpen,
|
|
2217
|
-
useFsAccessApi = _defaultProps$props.useFsAccessApi,
|
|
2218
|
-
autoFocus = _defaultProps$props.autoFocus,
|
|
2219
|
-
preventDropOnDocument = _defaultProps$props.preventDropOnDocument,
|
|
2220
|
-
noClick = _defaultProps$props.noClick,
|
|
2221
|
-
noKeyboard = _defaultProps$props.noKeyboard,
|
|
2222
|
-
noDrag = _defaultProps$props.noDrag,
|
|
2223
|
-
noDragEventsBubbling = _defaultProps$props.noDragEventsBubbling,
|
|
2224
|
-
onError = _defaultProps$props.onError,
|
|
2225
|
-
validator = _defaultProps$props.validator;
|
|
2226
|
-
|
|
2227
|
-
var acceptAttr = useMemo(function () {
|
|
2228
|
-
return acceptPropAsAcceptAttr(accept);
|
|
2229
|
-
}, [accept]);
|
|
2230
|
-
var pickerTypes = useMemo(function () {
|
|
2231
|
-
return pickerOptionsFromAccept(accept);
|
|
2232
|
-
}, [accept]);
|
|
2233
|
-
var onFileDialogOpenCb = useMemo(function () {
|
|
2234
|
-
return typeof onFileDialogOpen === "function" ? onFileDialogOpen : noop;
|
|
2235
|
-
}, [onFileDialogOpen]);
|
|
2236
|
-
var onFileDialogCancelCb = useMemo(function () {
|
|
2237
|
-
return typeof onFileDialogCancel === "function" ? onFileDialogCancel : noop;
|
|
2238
|
-
}, [onFileDialogCancel]);
|
|
2239
|
-
/**
|
|
2240
|
-
* @constant
|
|
2241
|
-
* @type {React.MutableRefObject<HTMLElement>}
|
|
2242
|
-
*/
|
|
2243
|
-
|
|
2244
|
-
var rootRef = useRef(null);
|
|
2245
|
-
var inputRef = useRef(null);
|
|
2246
|
-
|
|
2247
|
-
var _useReducer = useReducer(reducer, initialState),
|
|
2248
|
-
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
2249
|
-
state = _useReducer2[0],
|
|
2250
|
-
dispatch = _useReducer2[1];
|
|
2251
|
-
|
|
2252
|
-
var isFocused = state.isFocused,
|
|
2253
|
-
isFileDialogActive = state.isFileDialogActive;
|
|
2254
|
-
var fsAccessApiWorksRef = useRef(typeof window !== "undefined" && window.isSecureContext && useFsAccessApi && canUseFileSystemAccessAPI()); // Update file dialog active state when the window is focused on
|
|
2255
|
-
|
|
2256
|
-
var onWindowFocus = function onWindowFocus() {
|
|
2257
|
-
// Execute the timeout only if the file dialog is opened in the browser
|
|
2258
|
-
if (!fsAccessApiWorksRef.current && isFileDialogActive) {
|
|
2259
|
-
setTimeout(function () {
|
|
2260
|
-
if (inputRef.current) {
|
|
2261
|
-
var files = inputRef.current.files;
|
|
2262
|
-
|
|
2263
|
-
if (!files.length) {
|
|
2264
|
-
dispatch({
|
|
2265
|
-
type: "closeDialog"
|
|
2266
|
-
});
|
|
2267
|
-
onFileDialogCancelCb();
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
}, 300);
|
|
2271
|
-
}
|
|
2272
|
-
};
|
|
2273
|
-
|
|
2274
|
-
useEffect(function () {
|
|
2275
|
-
window.addEventListener("focus", onWindowFocus, false);
|
|
2276
|
-
return function () {
|
|
2277
|
-
window.removeEventListener("focus", onWindowFocus, false);
|
|
2278
|
-
};
|
|
2279
|
-
}, [inputRef, isFileDialogActive, onFileDialogCancelCb, fsAccessApiWorksRef]);
|
|
2280
|
-
var dragTargetsRef = useRef([]);
|
|
2281
|
-
|
|
2282
|
-
var onDocumentDrop = function onDocumentDrop(event) {
|
|
2283
|
-
if (rootRef.current && rootRef.current.contains(event.target)) {
|
|
2284
|
-
// If we intercepted an event for our instance, let it propagate down to the instance's onDrop handler
|
|
2285
|
-
return;
|
|
2286
|
-
}
|
|
2287
|
-
|
|
2288
|
-
event.preventDefault();
|
|
2289
|
-
dragTargetsRef.current = [];
|
|
2290
|
-
};
|
|
2291
|
-
|
|
2292
|
-
useEffect(function () {
|
|
2293
|
-
if (preventDropOnDocument) {
|
|
2294
|
-
document.addEventListener("dragover", onDocumentDragOver, false);
|
|
2295
|
-
document.addEventListener("drop", onDocumentDrop, false);
|
|
2296
|
-
}
|
|
2297
|
-
|
|
2298
|
-
return function () {
|
|
2299
|
-
if (preventDropOnDocument) {
|
|
2300
|
-
document.removeEventListener("dragover", onDocumentDragOver);
|
|
2301
|
-
document.removeEventListener("drop", onDocumentDrop);
|
|
2302
|
-
}
|
|
2303
|
-
};
|
|
2304
|
-
}, [rootRef, preventDropOnDocument]); // Auto focus the root when autoFocus is true
|
|
2305
|
-
|
|
2306
|
-
useEffect(function () {
|
|
2307
|
-
if (!disabled && autoFocus && rootRef.current) {
|
|
2308
|
-
rootRef.current.focus();
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
|
-
return function () {};
|
|
2312
|
-
}, [rootRef, autoFocus, disabled]);
|
|
2313
|
-
var onErrCb = useCallback(function (e) {
|
|
2314
|
-
if (onError) {
|
|
2315
|
-
onError(e);
|
|
2316
|
-
} else {
|
|
2317
|
-
// Let the user know something's gone wrong if they haven't provided the onError cb.
|
|
2318
|
-
console.error(e);
|
|
2319
|
-
}
|
|
2320
|
-
}, [onError]);
|
|
2321
|
-
var onDragEnterCb = useCallback(function (event) {
|
|
2322
|
-
event.preventDefault(); // Persist here because we need the event later after getFilesFromEvent() is done
|
|
2323
|
-
|
|
2324
|
-
event.persist();
|
|
2325
|
-
stopPropagation(event);
|
|
2326
|
-
dragTargetsRef.current = [].concat(_toConsumableArray(dragTargetsRef.current), [event.target]);
|
|
2327
|
-
|
|
2328
|
-
if (isEvtWithFiles(event)) {
|
|
2329
|
-
Promise.resolve(getFilesFromEvent(event)).then(function (files) {
|
|
2330
|
-
if (isPropagationStopped(event) && !noDragEventsBubbling) {
|
|
2331
|
-
return;
|
|
2332
|
-
}
|
|
2333
|
-
|
|
2334
|
-
var fileCount = files.length;
|
|
2335
|
-
var isDragAccept = fileCount > 0 && allFilesAccepted({
|
|
2336
|
-
files: files,
|
|
2337
|
-
accept: acceptAttr,
|
|
2338
|
-
minSize: minSize,
|
|
2339
|
-
maxSize: maxSize,
|
|
2340
|
-
multiple: multiple,
|
|
2341
|
-
maxFiles: maxFiles,
|
|
2342
|
-
validator: validator
|
|
2343
|
-
});
|
|
2344
|
-
var isDragReject = fileCount > 0 && !isDragAccept;
|
|
2345
|
-
dispatch({
|
|
2346
|
-
isDragAccept: isDragAccept,
|
|
2347
|
-
isDragReject: isDragReject,
|
|
2348
|
-
isDragActive: true,
|
|
2349
|
-
type: "setDraggedFiles"
|
|
2350
|
-
});
|
|
2351
|
-
|
|
2352
|
-
if (onDragEnter) {
|
|
2353
|
-
onDragEnter(event);
|
|
2354
|
-
}
|
|
2355
|
-
}).catch(function (e) {
|
|
2356
|
-
return onErrCb(e);
|
|
2357
|
-
});
|
|
2358
|
-
}
|
|
2359
|
-
}, [getFilesFromEvent, onDragEnter, onErrCb, noDragEventsBubbling, acceptAttr, minSize, maxSize, multiple, maxFiles, validator]);
|
|
2360
|
-
var onDragOverCb = useCallback(function (event) {
|
|
2361
|
-
event.preventDefault();
|
|
2362
|
-
event.persist();
|
|
2363
|
-
stopPropagation(event);
|
|
2364
|
-
var hasFiles = isEvtWithFiles(event);
|
|
2365
|
-
|
|
2366
|
-
if (hasFiles && event.dataTransfer) {
|
|
2367
|
-
try {
|
|
2368
|
-
event.dataTransfer.dropEffect = "copy";
|
|
2369
|
-
} catch (_unused) {}
|
|
2370
|
-
/* eslint-disable-line no-empty */
|
|
2371
|
-
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
if (hasFiles && onDragOver) {
|
|
2375
|
-
onDragOver(event);
|
|
2376
|
-
}
|
|
2377
|
-
|
|
2378
|
-
return false;
|
|
2379
|
-
}, [onDragOver, noDragEventsBubbling]);
|
|
2380
|
-
var onDragLeaveCb = useCallback(function (event) {
|
|
2381
|
-
event.preventDefault();
|
|
2382
|
-
event.persist();
|
|
2383
|
-
stopPropagation(event); // Only deactivate once the dropzone and all children have been left
|
|
2384
|
-
|
|
2385
|
-
var targets = dragTargetsRef.current.filter(function (target) {
|
|
2386
|
-
return rootRef.current && rootRef.current.contains(target);
|
|
2387
|
-
}); // Make sure to remove a target present multiple times only once
|
|
2388
|
-
// (Firefox may fire dragenter/dragleave multiple times on the same element)
|
|
2389
|
-
|
|
2390
|
-
var targetIdx = targets.indexOf(event.target);
|
|
2391
|
-
|
|
2392
|
-
if (targetIdx !== -1) {
|
|
2393
|
-
targets.splice(targetIdx, 1);
|
|
2394
|
-
}
|
|
2395
|
-
|
|
2396
|
-
dragTargetsRef.current = targets;
|
|
2397
|
-
|
|
2398
|
-
if (targets.length > 0) {
|
|
2399
|
-
return;
|
|
2400
|
-
}
|
|
2401
|
-
|
|
2402
|
-
dispatch({
|
|
2403
|
-
type: "setDraggedFiles",
|
|
2404
|
-
isDragActive: false,
|
|
2405
|
-
isDragAccept: false,
|
|
2406
|
-
isDragReject: false
|
|
2407
|
-
});
|
|
2408
|
-
|
|
2409
|
-
if (isEvtWithFiles(event) && onDragLeave) {
|
|
2410
|
-
onDragLeave(event);
|
|
2411
|
-
}
|
|
2412
|
-
}, [rootRef, onDragLeave, noDragEventsBubbling]);
|
|
2413
|
-
var setFiles = useCallback(function (files, event) {
|
|
2414
|
-
var acceptedFiles = [];
|
|
2415
|
-
var fileRejections = [];
|
|
2416
|
-
files.forEach(function (file) {
|
|
2417
|
-
var _fileAccepted = fileAccepted(file, acceptAttr),
|
|
2418
|
-
_fileAccepted2 = _slicedToArray(_fileAccepted, 2),
|
|
2419
|
-
accepted = _fileAccepted2[0],
|
|
2420
|
-
acceptError = _fileAccepted2[1];
|
|
2421
|
-
|
|
2422
|
-
var _fileMatchSize = fileMatchSize(file, minSize, maxSize),
|
|
2423
|
-
_fileMatchSize2 = _slicedToArray(_fileMatchSize, 2),
|
|
2424
|
-
sizeMatch = _fileMatchSize2[0],
|
|
2425
|
-
sizeError = _fileMatchSize2[1];
|
|
2426
|
-
|
|
2427
|
-
var customErrors = validator ? validator(file) : null;
|
|
2428
|
-
|
|
2429
|
-
if (accepted && sizeMatch && !customErrors) {
|
|
2430
|
-
acceptedFiles.push(file);
|
|
2431
|
-
} else {
|
|
2432
|
-
var errors = [acceptError, sizeError];
|
|
2433
|
-
|
|
2434
|
-
if (customErrors) {
|
|
2435
|
-
errors = errors.concat(customErrors);
|
|
2436
|
-
}
|
|
2437
|
-
|
|
2438
|
-
fileRejections.push({
|
|
2439
|
-
file: file,
|
|
2440
|
-
errors: errors.filter(function (e) {
|
|
2441
|
-
return e;
|
|
2442
|
-
})
|
|
2443
|
-
});
|
|
2444
|
-
}
|
|
2445
|
-
});
|
|
2446
|
-
|
|
2447
|
-
if (!multiple && acceptedFiles.length > 1 || multiple && maxFiles >= 1 && acceptedFiles.length > maxFiles) {
|
|
2448
|
-
// Reject everything and empty accepted files
|
|
2449
|
-
acceptedFiles.forEach(function (file) {
|
|
2450
|
-
fileRejections.push({
|
|
2451
|
-
file: file,
|
|
2452
|
-
errors: [TOO_MANY_FILES_REJECTION]
|
|
2453
|
-
});
|
|
2454
|
-
});
|
|
2455
|
-
acceptedFiles.splice(0);
|
|
2456
|
-
}
|
|
2457
|
-
|
|
2458
|
-
dispatch({
|
|
2459
|
-
acceptedFiles: acceptedFiles,
|
|
2460
|
-
fileRejections: fileRejections,
|
|
2461
|
-
type: "setFiles"
|
|
2462
|
-
});
|
|
2463
|
-
|
|
2464
|
-
if (onDrop) {
|
|
2465
|
-
onDrop(acceptedFiles, fileRejections, event);
|
|
2466
|
-
}
|
|
2467
|
-
|
|
2468
|
-
if (fileRejections.length > 0 && onDropRejected) {
|
|
2469
|
-
onDropRejected(fileRejections, event);
|
|
2470
|
-
}
|
|
2471
|
-
|
|
2472
|
-
if (acceptedFiles.length > 0 && onDropAccepted) {
|
|
2473
|
-
onDropAccepted(acceptedFiles, event);
|
|
2474
|
-
}
|
|
2475
|
-
}, [dispatch, multiple, acceptAttr, minSize, maxSize, maxFiles, onDrop, onDropAccepted, onDropRejected, validator]);
|
|
2476
|
-
var onDropCb = useCallback(function (event) {
|
|
2477
|
-
event.preventDefault(); // Persist here because we need the event later after getFilesFromEvent() is done
|
|
2478
|
-
|
|
2479
|
-
event.persist();
|
|
2480
|
-
stopPropagation(event);
|
|
2481
|
-
dragTargetsRef.current = [];
|
|
2482
|
-
|
|
2483
|
-
if (isEvtWithFiles(event)) {
|
|
2484
|
-
Promise.resolve(getFilesFromEvent(event)).then(function (files) {
|
|
2485
|
-
if (isPropagationStopped(event) && !noDragEventsBubbling) {
|
|
2486
|
-
return;
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
|
-
setFiles(files, event);
|
|
2490
|
-
}).catch(function (e) {
|
|
2491
|
-
return onErrCb(e);
|
|
2492
|
-
});
|
|
2493
|
-
}
|
|
2494
|
-
|
|
2495
|
-
dispatch({
|
|
2496
|
-
type: "reset"
|
|
2497
|
-
});
|
|
2498
|
-
}, [getFilesFromEvent, setFiles, onErrCb, noDragEventsBubbling]); // Fn for opening the file dialog programmatically
|
|
2499
|
-
|
|
2500
|
-
var openFileDialog = useCallback(function () {
|
|
2501
|
-
// No point to use FS access APIs if context is not secure
|
|
2502
|
-
// https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts#feature_detection
|
|
2503
|
-
if (fsAccessApiWorksRef.current) {
|
|
2504
|
-
dispatch({
|
|
2505
|
-
type: "openDialog"
|
|
2506
|
-
});
|
|
2507
|
-
onFileDialogOpenCb(); // https://developer.mozilla.org/en-US/docs/Web/API/window/showOpenFilePicker
|
|
2508
|
-
|
|
2509
|
-
var opts = {
|
|
2510
|
-
multiple: multiple,
|
|
2511
|
-
types: pickerTypes
|
|
2512
|
-
};
|
|
2513
|
-
window.showOpenFilePicker(opts).then(function (handles) {
|
|
2514
|
-
return getFilesFromEvent(handles);
|
|
2515
|
-
}).then(function (files) {
|
|
2516
|
-
setFiles(files, null);
|
|
2517
|
-
dispatch({
|
|
2518
|
-
type: "closeDialog"
|
|
2519
|
-
});
|
|
2520
|
-
}).catch(function (e) {
|
|
2521
|
-
// AbortError means the user canceled
|
|
2522
|
-
if (isAbort(e)) {
|
|
2523
|
-
onFileDialogCancelCb(e);
|
|
2524
|
-
dispatch({
|
|
2525
|
-
type: "closeDialog"
|
|
2526
|
-
});
|
|
2527
|
-
} else if (isSecurityError(e)) {
|
|
2528
|
-
fsAccessApiWorksRef.current = false; // CORS, so cannot use this API
|
|
2529
|
-
// Try using the input
|
|
2530
|
-
|
|
2531
|
-
if (inputRef.current) {
|
|
2532
|
-
inputRef.current.value = null;
|
|
2533
|
-
inputRef.current.click();
|
|
2534
|
-
} else {
|
|
2535
|
-
onErrCb(new Error("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."));
|
|
2536
|
-
}
|
|
2537
|
-
} else {
|
|
2538
|
-
onErrCb(e);
|
|
2539
|
-
}
|
|
2540
|
-
});
|
|
2541
|
-
return;
|
|
2542
|
-
}
|
|
2543
|
-
|
|
2544
|
-
if (inputRef.current) {
|
|
2545
|
-
dispatch({
|
|
2546
|
-
type: "openDialog"
|
|
2547
|
-
});
|
|
2548
|
-
onFileDialogOpenCb();
|
|
2549
|
-
inputRef.current.value = null;
|
|
2550
|
-
inputRef.current.click();
|
|
2551
|
-
}
|
|
2552
|
-
}, [dispatch, onFileDialogOpenCb, onFileDialogCancelCb, useFsAccessApi, setFiles, onErrCb, pickerTypes, multiple]); // Cb to open the file dialog when SPACE/ENTER occurs on the dropzone
|
|
2553
|
-
|
|
2554
|
-
var onKeyDownCb = useCallback(function (event) {
|
|
2555
|
-
// Ignore keyboard events bubbling up the DOM tree
|
|
2556
|
-
if (!rootRef.current || !rootRef.current.isEqualNode(event.target)) {
|
|
2557
|
-
return;
|
|
2558
|
-
}
|
|
2559
|
-
|
|
2560
|
-
if (event.key === " " || event.key === "Enter" || event.keyCode === 32 || event.keyCode === 13) {
|
|
2561
|
-
event.preventDefault();
|
|
2562
|
-
openFileDialog();
|
|
2563
|
-
}
|
|
2564
|
-
}, [rootRef, openFileDialog]); // Update focus state for the dropzone
|
|
2565
|
-
|
|
2566
|
-
var onFocusCb = useCallback(function () {
|
|
2567
|
-
dispatch({
|
|
2568
|
-
type: "focus"
|
|
2569
|
-
});
|
|
2570
|
-
}, []);
|
|
2571
|
-
var onBlurCb = useCallback(function () {
|
|
2572
|
-
dispatch({
|
|
2573
|
-
type: "blur"
|
|
2574
|
-
});
|
|
2575
|
-
}, []); // Cb to open the file dialog when click occurs on the dropzone
|
|
2576
|
-
|
|
2577
|
-
var onClickCb = useCallback(function () {
|
|
2578
|
-
if (noClick) {
|
|
2579
|
-
return;
|
|
2580
|
-
} // In IE11/Edge the file-browser dialog is blocking, therefore, use setTimeout()
|
|
2581
|
-
// to ensure React can handle state changes
|
|
2582
|
-
// See: https://github.com/react-dropzone/react-dropzone/issues/450
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
if (isIeOrEdge()) {
|
|
2586
|
-
setTimeout(openFileDialog, 0);
|
|
2587
|
-
} else {
|
|
2588
|
-
openFileDialog();
|
|
2589
|
-
}
|
|
2590
|
-
}, [noClick, openFileDialog]);
|
|
2591
|
-
|
|
2592
|
-
var composeHandler = function composeHandler(fn) {
|
|
2593
|
-
return disabled ? null : fn;
|
|
2594
|
-
};
|
|
2595
|
-
|
|
2596
|
-
var composeKeyboardHandler = function composeKeyboardHandler(fn) {
|
|
2597
|
-
return noKeyboard ? null : composeHandler(fn);
|
|
2598
|
-
};
|
|
2599
|
-
|
|
2600
|
-
var composeDragHandler = function composeDragHandler(fn) {
|
|
2601
|
-
return noDrag ? null : composeHandler(fn);
|
|
2602
|
-
};
|
|
2603
|
-
|
|
2604
|
-
var stopPropagation = function stopPropagation(event) {
|
|
2605
|
-
if (noDragEventsBubbling) {
|
|
2606
|
-
event.stopPropagation();
|
|
2607
|
-
}
|
|
2608
|
-
};
|
|
2609
|
-
|
|
2610
|
-
var getRootProps = useMemo(function () {
|
|
2611
|
-
return function () {
|
|
2612
|
-
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
2613
|
-
_ref2$refKey = _ref2.refKey,
|
|
2614
|
-
refKey = _ref2$refKey === void 0 ? "ref" : _ref2$refKey,
|
|
2615
|
-
role = _ref2.role,
|
|
2616
|
-
onKeyDown = _ref2.onKeyDown,
|
|
2617
|
-
onFocus = _ref2.onFocus,
|
|
2618
|
-
onBlur = _ref2.onBlur,
|
|
2619
|
-
onClick = _ref2.onClick,
|
|
2620
|
-
onDragEnter = _ref2.onDragEnter,
|
|
2621
|
-
onDragOver = _ref2.onDragOver,
|
|
2622
|
-
onDragLeave = _ref2.onDragLeave,
|
|
2623
|
-
onDrop = _ref2.onDrop,
|
|
2624
|
-
rest = _objectWithoutProperties(_ref2, _excluded3);
|
|
2625
|
-
|
|
2626
|
-
return _objectSpread(_objectSpread(_defineProperty({
|
|
2627
|
-
onKeyDown: composeKeyboardHandler(composeEventHandlers(onKeyDown, onKeyDownCb)),
|
|
2628
|
-
onFocus: composeKeyboardHandler(composeEventHandlers(onFocus, onFocusCb)),
|
|
2629
|
-
onBlur: composeKeyboardHandler(composeEventHandlers(onBlur, onBlurCb)),
|
|
2630
|
-
onClick: composeHandler(composeEventHandlers(onClick, onClickCb)),
|
|
2631
|
-
onDragEnter: composeDragHandler(composeEventHandlers(onDragEnter, onDragEnterCb)),
|
|
2632
|
-
onDragOver: composeDragHandler(composeEventHandlers(onDragOver, onDragOverCb)),
|
|
2633
|
-
onDragLeave: composeDragHandler(composeEventHandlers(onDragLeave, onDragLeaveCb)),
|
|
2634
|
-
onDrop: composeDragHandler(composeEventHandlers(onDrop, onDropCb)),
|
|
2635
|
-
role: typeof role === "string" && role !== "" ? role : "presentation"
|
|
2636
|
-
}, refKey, rootRef), !disabled && !noKeyboard ? {
|
|
2637
|
-
tabIndex: 0
|
|
2638
|
-
} : {}), rest);
|
|
2639
|
-
};
|
|
2640
|
-
}, [rootRef, onKeyDownCb, onFocusCb, onBlurCb, onClickCb, onDragEnterCb, onDragOverCb, onDragLeaveCb, onDropCb, noKeyboard, noDrag, disabled]);
|
|
2641
|
-
var onInputElementClick = useCallback(function (event) {
|
|
2642
|
-
event.stopPropagation();
|
|
2643
|
-
}, []);
|
|
2644
|
-
var getInputProps = useMemo(function () {
|
|
2645
|
-
return function () {
|
|
2646
|
-
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
2647
|
-
_ref3$refKey = _ref3.refKey,
|
|
2648
|
-
refKey = _ref3$refKey === void 0 ? "ref" : _ref3$refKey,
|
|
2649
|
-
onChange = _ref3.onChange,
|
|
2650
|
-
onClick = _ref3.onClick,
|
|
2651
|
-
rest = _objectWithoutProperties(_ref3, _excluded4);
|
|
2652
|
-
|
|
2653
|
-
var inputProps = _defineProperty({
|
|
2654
|
-
accept: acceptAttr,
|
|
2655
|
-
multiple: multiple,
|
|
2656
|
-
type: "file",
|
|
2657
|
-
style: {
|
|
2658
|
-
display: "none"
|
|
2659
|
-
},
|
|
2660
|
-
onChange: composeHandler(composeEventHandlers(onChange, onDropCb)),
|
|
2661
|
-
onClick: composeHandler(composeEventHandlers(onClick, onInputElementClick)),
|
|
2662
|
-
tabIndex: -1
|
|
2663
|
-
}, refKey, inputRef);
|
|
2664
|
-
|
|
2665
|
-
return _objectSpread(_objectSpread({}, inputProps), rest);
|
|
2666
|
-
};
|
|
2667
|
-
}, [inputRef, accept, multiple, onDropCb, disabled]);
|
|
2668
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
2669
|
-
isFocused: isFocused && !disabled,
|
|
2670
|
-
getRootProps: getRootProps,
|
|
2671
|
-
getInputProps: getInputProps,
|
|
2672
|
-
rootRef: rootRef,
|
|
2673
|
-
inputRef: inputRef,
|
|
2674
|
-
open: composeHandler(openFileDialog)
|
|
2675
|
-
});
|
|
2676
|
-
}
|
|
2677
|
-
/**
|
|
2678
|
-
* @param {DropzoneState} state
|
|
2679
|
-
* @param {{type: string} & DropzoneState} action
|
|
2680
|
-
* @returns {DropzoneState}
|
|
2681
|
-
*/
|
|
2682
|
-
|
|
2683
|
-
function reducer(state, action) {
|
|
2684
|
-
/* istanbul ignore next */
|
|
2685
|
-
switch (action.type) {
|
|
2686
|
-
case "focus":
|
|
2687
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
2688
|
-
isFocused: true
|
|
2689
|
-
});
|
|
2690
|
-
|
|
2691
|
-
case "blur":
|
|
2692
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
2693
|
-
isFocused: false
|
|
2694
|
-
});
|
|
2695
|
-
|
|
2696
|
-
case "openDialog":
|
|
2697
|
-
return _objectSpread(_objectSpread({}, initialState), {}, {
|
|
2698
|
-
isFileDialogActive: true
|
|
2699
|
-
});
|
|
2700
|
-
|
|
2701
|
-
case "closeDialog":
|
|
2702
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
2703
|
-
isFileDialogActive: false
|
|
2704
|
-
});
|
|
2705
|
-
|
|
2706
|
-
case "setDraggedFiles":
|
|
2707
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
2708
|
-
isDragActive: action.isDragActive,
|
|
2709
|
-
isDragAccept: action.isDragAccept,
|
|
2710
|
-
isDragReject: action.isDragReject
|
|
2711
|
-
});
|
|
2712
|
-
|
|
2713
|
-
case "setFiles":
|
|
2714
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
2715
|
-
acceptedFiles: action.acceptedFiles,
|
|
2716
|
-
fileRejections: action.fileRejections
|
|
2717
|
-
});
|
|
2718
|
-
|
|
2719
|
-
case "reset":
|
|
2720
|
-
return _objectSpread({}, initialState);
|
|
2721
|
-
|
|
2722
|
-
default:
|
|
2723
|
-
return state;
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2726
|
-
|
|
2727
|
-
function noop() {}
|
|
2728
|
-
|
|
2729
|
-
var css_248z = ".style-module_container__Uyltc {\n background-color: transparent;\n}\n\n.style-module_dropzoneContainer__yZoGP {\n border: 1px dashed var(--ds-primary-500);\n padding: 32px 0;\n background-color: white;\n transition: all 0.6s ease-in-out;\n}\n\n.style-module_img__11JI8 {\n vertical-align: middle;\n margin-right: 8px;\n height: 18px;\n}\n\n.style-module_textInline__2F21z {\n display: inline-flex;\n}\n\n.style-module_dropzoneContainer__yZoGP:focus {\n outline: none;\n}\n\n.style-module_dropzoneContainer__yZoGP:hover {\n background-color: var(--ds-primary-100);\n transition: 0.5s ease;\n}\n\n.style-module_dropzoneContainerDisabled__1X3gP {\n pointer-events: none;\n opacity: 0.4;\n}";
|
|
2730
|
-
var styles = {"container":"style-module_container__Uyltc","dropzoneContainer":"style-module_dropzoneContainer__yZoGP","img":"style-module_img__11JI8","textInline":"style-module_textInline__2F21z","dropzoneContainerDisabled":"style-module_dropzoneContainerDisabled__1X3gP"};
|
|
2731
|
-
styleInject(css_248z);
|
|
2732
|
-
|
|
2733
|
-
var k = 1024;
|
|
2734
|
-
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
2735
|
-
function formatBytes(bytes, decimals) {
|
|
2736
|
-
if (decimals === void 0) { decimals = 0; }
|
|
2737
|
-
if (!+bytes) {
|
|
2738
|
-
return '0 Bytes';
|
|
2739
|
-
}
|
|
2740
|
-
var dm = decimals < 0 ? 0 : decimals;
|
|
2741
|
-
var i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
2742
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
|
|
2743
|
-
}
|
|
2744
|
-
|
|
2745
|
-
var FileMimeTypes;
|
|
2746
|
-
(function (FileMimeTypes) {
|
|
2747
|
-
FileMimeTypes["bmp"] = "image/bmp";
|
|
2748
|
-
FileMimeTypes["doc"] = "application/msword";
|
|
2749
|
-
FileMimeTypes["docx"] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
2750
|
-
FileMimeTypes["heic"] = "image/heic";
|
|
2751
|
-
FileMimeTypes["jpeg"] = "image/jpeg";
|
|
2752
|
-
FileMimeTypes["jpg"] = "image/jpg";
|
|
2753
|
-
FileMimeTypes["pdf"] = "application/pdf";
|
|
2754
|
-
FileMimeTypes["png"] = "image/png";
|
|
2755
|
-
FileMimeTypes["tif"] = "image/tiff";
|
|
2756
|
-
FileMimeTypes["tiff"] = "image/tiff";
|
|
2757
|
-
FileMimeTypes["webp"] = "image/webp";
|
|
2758
|
-
})(FileMimeTypes || (FileMimeTypes = {}));
|
|
2759
|
-
var DOCUMENT_FILES = ['doc', 'docx', 'pdf'];
|
|
2760
|
-
var IMAGE_FILES = ['heic', 'bmp', 'jpeg', 'jpg', 'png'];
|
|
2761
|
-
|
|
2762
|
-
var getUploadStatus = function (progress, error) {
|
|
2763
|
-
if (error) {
|
|
2764
|
-
return 'ERROR';
|
|
2765
|
-
}
|
|
2766
|
-
if (progress < 100) {
|
|
2767
|
-
return 'UPLOADING';
|
|
2768
|
-
}
|
|
2769
|
-
return 'COMPLETE';
|
|
2770
|
-
};
|
|
2771
|
-
var formatMimeType = function (values) {
|
|
2772
|
-
var formatedValues = {};
|
|
2773
|
-
values.forEach(function (value) {
|
|
2774
|
-
formatedValues[FileMimeTypes[value]] = ["." + value];
|
|
2775
|
-
});
|
|
2776
|
-
return formatedValues;
|
|
2777
|
-
};
|
|
2778
|
-
var DOCUMENT_FILES_ACCEPT = formatMimeType(DOCUMENT_FILES);
|
|
2779
|
-
var IMAGE_FILES_ACCEPT = formatMimeType(IMAGE_FILES);
|
|
2780
|
-
var getFormattedAcceptObject = function (accept) {
|
|
2781
|
-
if (accept === void 0) { accept = {}; }
|
|
2782
|
-
if (accept === "document") {
|
|
2783
|
-
return DOCUMENT_FILES_ACCEPT;
|
|
2784
|
-
}
|
|
2785
|
-
if (accept === "image") {
|
|
2786
|
-
return IMAGE_FILES_ACCEPT;
|
|
2787
|
-
}
|
|
2788
|
-
return accept;
|
|
2789
|
-
};
|
|
2790
|
-
var formatAcceptFileList = function (accept) { return (Object.values(accept)
|
|
2791
|
-
.reduce(function (acc, value) { return __spreadArray$1(__spreadArray$1([], acc), value); }, [])
|
|
2792
|
-
.join(", ")
|
|
2793
|
-
.replace(/\./g, '')
|
|
2794
|
-
.toUpperCase()); };
|
|
2795
|
-
var getErrorMessage = function (_a, _b, textOverrides) {
|
|
2796
|
-
var code = _a.code, message = _a.message;
|
|
2797
|
-
var _c = _b.fileList, fileList = _c === void 0 ? "" : _c, maxSize = _b.maxSize;
|
|
2798
|
-
switch (code) {
|
|
2799
|
-
case ErrorCode.FileInvalidType:
|
|
2800
|
-
return ((textOverrides === null || textOverrides === void 0 ? void 0 : textOverrides.fileTypeError) || "File type must be one of") + " " + fileList;
|
|
2801
|
-
case ErrorCode.FileTooLarge:
|
|
2802
|
-
return ((textOverrides === null || textOverrides === void 0 ? void 0 : textOverrides.fileTooLargeError) || "File is too large. It must be less than") + " " + formatBytes(maxSize || 0) + ".";
|
|
2803
|
-
default:
|
|
2804
|
-
return message;
|
|
2805
|
-
}
|
|
2806
|
-
};
|
|
2807
|
-
|
|
2808
|
-
var MultiDropZone = function (_a) {
|
|
2809
|
-
var _b;
|
|
2810
|
-
var accept = _a.accept, uploadedFiles = _a.uploadedFiles, onFileSelect = _a.onFileSelect, uploading = _a.uploading, onRemoveFile = _a.onRemoveFile, _c = _a.isCondensed, isCondensed = _c === void 0 ? false : _c, _d = _a.maxFiles, maxFiles = _d === void 0 ? 0 : _d, maxSize = _a.maxSize, textOverrides = _a.textOverrides;
|
|
2811
|
-
var _e = useState([]), errors = _e[0], setErrors = _e[1];
|
|
2812
|
-
var formattedAccept = getFormattedAcceptObject(accept);
|
|
2813
|
-
var fileList = formatAcceptFileList(formattedAccept);
|
|
2814
|
-
var maxSizePlaceholder = maxSize && maxSize > 0
|
|
2815
|
-
? ((textOverrides === null || textOverrides === void 0 ? void 0 : textOverrides.sizeUpToText) || "up to") + " " + formatBytes(maxSize)
|
|
2816
|
-
: "";
|
|
2817
|
-
var placeholder = ((textOverrides === null || textOverrides === void 0 ? void 0 : textOverrides.supportsTextShort) || "Supports") + " " + (fileList || "JPEG, PNG, PDF") + " " + maxSizePlaceholder;
|
|
2818
|
-
var isOverMaxFiles = maxFiles > 0 && uploadedFiles.length > maxFiles;
|
|
2819
|
-
var removeError = function (removeId) { return (setErrors(errors.filter(function (_a) {
|
|
2820
|
-
var id = _a.id;
|
|
2821
|
-
return id !== removeId;
|
|
2822
|
-
}))); };
|
|
2823
|
-
var onDrop = useCallback(function (acceptedFiles, filesRejected) {
|
|
2824
|
-
onFileSelect(acceptedFiles);
|
|
2825
|
-
setErrors(function (previousErrors) { return (__spreadArray$1(__spreadArray$1([], previousErrors), filesRejected.map(function (_a) {
|
|
2826
|
-
var errors = _a.errors;
|
|
2827
|
-
return ({
|
|
2828
|
-
id: generateId(),
|
|
2829
|
-
message: getErrorMessage(errors[0], { fileList: fileList, maxSize: maxSize }, textOverrides),
|
|
2830
|
-
});
|
|
2831
|
-
}))); });
|
|
2832
|
-
}, [fileList, maxSize, onFileSelect, textOverrides]);
|
|
2833
|
-
var _f = useDropzone({
|
|
2834
|
-
accept: formattedAccept,
|
|
2835
|
-
disabled: uploading,
|
|
2836
|
-
maxSize: maxSize,
|
|
2837
|
-
onDrop: onDrop,
|
|
2838
|
-
}), getRootProps = _f.getRootProps, getInputProps = _f.getInputProps;
|
|
2839
|
-
return (jsxs("div", __assign({ className: styles.container }, { children: [jsxs("div", __assign({ className: classnames("w100 ta-center br8 c-pointer " + styles.dropzoneContainer, (_b = {},
|
|
2840
|
-
_b[styles['dropzoneContainerDisabled']] = uploading,
|
|
2841
|
-
_b)) }, getRootProps(), { children: [jsx("input", __assign({ "data-testid": "ds-drop-input" }, getInputProps()), void 0),
|
|
2842
|
-
jsx("img", { className: isCondensed ? styles.img : '', src: isCondensed ? icons.uploadSmallIcon : icons.uploadIcon, alt: "purple cloud with an arrow" }, void 0),
|
|
2843
|
-
jsx("div", __assign({ className: "p-h4 mt8 " + (isCondensed ? styles.textInline : '') }, { children: uploading
|
|
2844
|
-
? (textOverrides === null || textOverrides === void 0 ? void 0 : textOverrides.currentlyUploadingText) ||
|
|
2845
|
-
'Please wait while uploading file...'
|
|
2846
|
-
: (textOverrides === null || textOverrides === void 0 ? void 0 : textOverrides.instructionsText) || 'Choose file or drag & drop' }), void 0),
|
|
2847
|
-
jsx("div", __assign({ className: "p-p--small tc-grey-500" }, { children: (textOverrides === null || textOverrides === void 0 ? void 0 : textOverrides.supportsText) || placeholder }), void 0)] }), void 0),
|
|
2848
|
-
errors.map(function (_a) {
|
|
2849
|
-
var id = _a.id, message = _a.message;
|
|
2850
|
-
return message && (jsx(UploadFileCell, { uploadStatus: "ERROR", file: {
|
|
2851
|
-
error: message,
|
|
2852
|
-
id: id,
|
|
2853
|
-
name: message,
|
|
2854
|
-
progress: 0,
|
|
2855
|
-
}, onRemoveFile: function () { return removeError(id); }, uploading: false }, id));
|
|
2856
|
-
}),
|
|
2857
|
-
uploadedFiles.length > 0 && (jsx("div", __assign({ className: "w100 mt16" }, { children: uploadedFiles.map(function (file) { return (jsx(UploadFileCell, { uploadStatus: getUploadStatus(file.progress, file.error), file: file, onRemoveFile: onRemoveFile, uploading: uploading }, file.id)); }) }), void 0)),
|
|
2858
|
-
jsx(AnimateHeight, __assign({ duration: 300, height: isOverMaxFiles ? 'auto' : 0 }, { children: jsx("p", __assign({ className: "tc-red-500 p-p--small" }, { children: (textOverrides === null || textOverrides === void 0 ? void 0 : textOverrides.tooManyFilesError) || "Too many files." }), void 0) }), void 0)] }), void 0));
|
|
2859
|
-
};
|
|
2860
|
-
|
|
2861
|
-
export default MultiDropZone;
|
|
2862
|
-
//# sourceMappingURL=index.js.map
|