shineout 1.7.1 → 1.8.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/DatePicker/utils.js +1 -1
- package/css/Form/Field.js +8 -4
- package/css/Form/Form.js +3 -0
- package/css/Form/Item.js +1 -1
- package/css/Form/index.d.ts +1 -0
- package/css/Form/inputable.js +1 -1
- package/css/Pagination/Jumper.js +3 -0
- package/css/index.d.ts +1 -1
- package/css/index.js +1 -1
- package/dist/shineout.js +24 -14
- package/dist/shineout.js.map +1 -1
- package/dist/shineout.min.js +1 -1
- package/es/Alert/index.js +127 -107
- package/es/Alert/styles/index.js +3 -4
- package/es/AnimationList/AbsoluteList.js +257 -193
- package/es/AnimationList/LazyList.js +120 -92
- package/es/AnimationList/List.js +43 -23
- package/es/AnimationList/index.js +19 -14
- package/es/AnimationList/styles/index.js +3 -4
- package/es/Breadcrumb/index.js +77 -69
- package/es/Breadcrumb/styles/index.js +3 -4
- package/es/Button/Button.js +91 -74
- package/es/Button/Group.js +42 -28
- package/es/Button/Once.js +39 -23
- package/es/Button/index.js +7 -10
- package/es/Button/styles/index.js +3 -4
- package/es/Card/Accordion.js +58 -45
- package/es/Card/Body.js +55 -42
- package/es/Card/Card.js +85 -79
- package/es/Card/Footer.js +38 -15
- package/es/Card/Header.js +52 -34
- package/es/Card/Submit.js +51 -33
- package/es/Card/context.js +22 -16
- package/es/Card/index.js +16 -19
- package/es/Card/styles/index.js +3 -4
- package/es/CardGroup/CardGroup.js +93 -69
- package/es/CardGroup/Item.js +61 -43
- package/es/CardGroup/context.js +12 -10
- package/es/CardGroup/index.js +7 -10
- package/es/CardGroup/styles/index.js +3 -4
- package/es/Carousel/Item.js +31 -17
- package/es/Carousel/index.js +156 -123
- package/es/Carousel/styles/index.js +3 -4
- package/es/Cascader/Cascader.js +397 -346
- package/es/Cascader/FilterList.js +185 -142
- package/es/Cascader/Input.js +102 -79
- package/es/Cascader/List.js +66 -41
- package/es/Cascader/Node.js +153 -110
- package/es/Cascader/Result.js +289 -232
- package/es/Cascader/filter.js +92 -61
- package/es/Cascader/index.js +13 -18
- package/es/Cascader/styles/index.js +3 -4
- package/es/Checkbox/CheckItem.js +168 -154
- package/es/Checkbox/Checkbox.js +2 -3
- package/es/Checkbox/Group.js +106 -85
- package/es/Checkbox/context.js +12 -10
- package/es/Checkbox/index.js +14 -21
- package/es/Checkbox/styles/index.js +3 -4
- package/es/DataList/BaseItem.js +39 -21
- package/es/DataList/Extra.js +33 -17
- package/es/DataList/List.js +166 -140
- package/es/DataList/Meta.js +109 -74
- package/es/DataList/Pagination.js +9 -10
- package/es/DataList/index.js +13 -19
- package/es/DataList/styles/index.js +3 -4
- package/es/DatePicker/Container.js +468 -449
- package/es/DatePicker/Day.js +265 -258
- package/es/DatePicker/Icon.js +34 -20
- package/es/DatePicker/Month.js +101 -79
- package/es/DatePicker/Picker.js +110 -83
- package/es/DatePicker/Quick.js +52 -39
- package/es/DatePicker/Range.js +241 -192
- package/es/DatePicker/Text.js +103 -91
- package/es/DatePicker/Time.js +165 -147
- package/es/DatePicker/TimeScroll.js +148 -116
- package/es/DatePicker/Year.js +74 -53
- package/es/DatePicker/index.js +16 -18
- package/es/DatePicker/paramUtils.js +92 -58
- package/es/DatePicker/styles/index.js +3 -4
- package/es/DatePicker/utils.js +189 -198
- package/es/DatePicker/value.js +139 -98
- package/es/Datum/Form.js +333 -282
- package/es/Datum/List.js +319 -201
- package/es/Datum/Tree.js +298 -239
- package/es/Datum/hoc.js +104 -69
- package/es/Datum/index.js +7 -8
- package/es/Datum/types.js +20 -25
- package/es/Divider/index.js +50 -32
- package/es/Divider/styles/index.js +3 -4
- package/es/Drawer/index.js +14 -9
- package/es/Dropdown/Item.js +56 -43
- package/es/Dropdown/index.js +273 -259
- package/es/Dropdown/styles/index.js +3 -4
- package/es/EditableArea/EditableArea.js +157 -136
- package/es/EditableArea/index.js +8 -15
- package/es/EditableArea/styles/index.js +3 -4
- package/es/Form/Block.js +83 -57
- package/es/Form/BlockField.js +32 -17
- package/es/Form/Field.js +59 -35
- package/es/Form/FieldError.js +27 -21
- package/es/Form/FieldSet.js +214 -156
- package/es/Form/Flow.js +51 -32
- package/es/Form/Form.js +181 -144
- package/es/Form/Item.js +181 -166
- package/es/Form/Loop.js +202 -146
- package/es/Form/formButton.js +58 -42
- package/es/Form/formContext.js +104 -95
- package/es/Form/index.d.ts +1 -0
- package/es/Form/index.js +40 -45
- package/es/Form/inputable.js +368 -292
- package/es/Form/mode.js +15 -9
- package/es/Form/styles/index.js +4 -5
- package/es/Gap/index.js +71 -47
- package/es/Gap/styles/index.js +3 -4
- package/es/Gap/support.js +11 -14
- package/es/Grid/index.js +88 -58
- package/es/Grid/utils.js +57 -58
- package/es/Icon/Icon.js +43 -42
- package/es/Icon/index.js +39 -22
- package/es/Icon/styles/index.js +3 -4
- package/es/Image/Gallery.js +128 -113
- package/es/Image/Group.js +60 -36
- package/es/Image/Image.js +227 -153
- package/es/Image/Magnify.js +123 -94
- package/es/Image/events.js +29 -26
- package/es/Image/index.js +6 -9
- package/es/Image/styles/index.js +3 -4
- package/es/Input/Group.js +17 -11
- package/es/Input/Input.js +158 -134
- package/es/Input/Number.js +199 -175
- package/es/Input/Password.js +54 -31
- package/es/Input/clear.js +41 -25
- package/es/Input/index.js +23 -35
- package/es/Input/styles/index.js +3 -4
- package/es/Lazyload/index.js +63 -42
- package/es/Lazyload/styles/index.js +3 -4
- package/es/Menu/Item.js +275 -236
- package/es/Menu/List.js +75 -67
- package/es/Menu/Root.js +372 -334
- package/es/Menu/context.js +18 -12
- package/es/Menu/index.js +3 -5
- package/es/Menu/styles/index.js +3 -4
- package/es/Message/Container.js +155 -119
- package/es/Message/index.js +42 -30
- package/es/Message/messager.js +29 -33
- package/es/Message/styles/index.js +3 -4
- package/es/Modal/Modal.js +80 -60
- package/es/Modal/Panel.js +258 -234
- package/es/Modal/context.js +15 -15
- package/es/Modal/events.js +213 -182
- package/es/Modal/index.js +12 -14
- package/es/Modal/styles/index.js +3 -4
- package/es/Pagination/Item.js +46 -32
- package/es/Pagination/Jumper.js +79 -66
- package/es/Pagination/Links.js +110 -82
- package/es/Pagination/Next.js +52 -31
- package/es/Pagination/PageSizeList.js +57 -40
- package/es/Pagination/Pagination.js +78 -54
- package/es/Pagination/Prev.js +49 -30
- package/es/Pagination/Simple.js +32 -18
- package/es/Pagination/index.js +68 -41
- package/es/Pagination/styles/index.js +3 -4
- package/es/Popover/Confirm.js +107 -64
- package/es/Popover/Panel.js +284 -231
- package/es/Popover/context.js +15 -12
- package/es/Popover/events.js +80 -86
- package/es/Popover/index.js +12 -14
- package/es/Popover/styles/index.js +3 -4
- package/es/Progress/Circle.js +70 -59
- package/es/Progress/Line.js +51 -39
- package/es/Progress/Popup.js +42 -24
- package/es/Progress/analyzeColor.js +18 -9
- package/es/Progress/index.js +13 -15
- package/es/Progress/styles/index.js +3 -4
- package/es/Radio/Group.js +105 -94
- package/es/Radio/Radio.js +2 -3
- package/es/Radio/index.js +15 -17
- package/es/Radio/styles/index.js +1 -1
- package/es/Rate/Rate.js +216 -167
- package/es/Rate/index.js +17 -10
- package/es/Rate/styles/index.js +3 -4
- package/es/Rule/convert.js +48 -57
- package/es/Rule/index.js +63 -40
- package/es/Rule/length.js +53 -38
- package/es/Rule/regExp.js +23 -14
- package/es/Rule/required.js +26 -18
- package/es/Rule/styles/index.js +1 -1
- package/es/Rule/type.js +26 -18
- package/es/Scroll/Bar.js +145 -117
- package/es/Scroll/Scroll.js +277 -217
- package/es/Scroll/context.js +20 -13
- package/es/Scroll/fixedLength.js +33 -24
- package/es/Scroll/index.js +89 -55
- package/es/Scroll/styles/index.js +3 -4
- package/es/Select/BoxList.js +218 -189
- package/es/Select/BoxOption.js +64 -38
- package/es/Select/FlexBox.js +107 -75
- package/es/Select/FlexResult.js +65 -49
- package/es/Select/Input.js +137 -113
- package/es/Select/More.js +124 -121
- package/es/Select/Option.js +73 -52
- package/es/Select/OptionList.js +236 -200
- package/es/Select/OptionTree.js +111 -96
- package/es/Select/Result.js +297 -271
- package/es/Select/Select.js +517 -491
- package/es/Select/filter.js +221 -148
- package/es/Select/group.js +74 -45
- package/es/Select/index.js +32 -31
- package/es/Select/styles/index.js +3 -4
- package/es/Slider/Container.js +145 -132
- package/es/Slider/Indicator.js +28 -13
- package/es/Slider/Slider.js +132 -103
- package/es/Slider/index.js +5 -8
- package/es/Slider/styles/index.js +3 -4
- package/es/Slider/utils.js +26 -30
- package/es/Spin/Multiple.js +153 -109
- package/es/Spin/Simple.js +33 -22
- package/es/Spin/Spin.js +29 -29
- package/es/Spin/index.js +66 -84
- package/es/Spin/styles/index.js +27 -30
- package/es/Sticky/context.js +12 -10
- package/es/Sticky/index.js +255 -194
- package/es/Sticky/styles/index.js +1 -1
- package/es/Switch/Switch.js +2 -3
- package/es/Switch/index.js +8 -14
- package/es/Table/Checkbox.js +68 -39
- package/es/Table/CheckboxAll.js +121 -64
- package/es/Table/Colgroup.js +72 -47
- package/es/Table/Expand.js +63 -43
- package/es/Table/SeperateTable.js +594 -444
- package/es/Table/SimpleTable.js +215 -136
- package/es/Table/Sorter.js +83 -62
- package/es/Table/Table.js +157 -157
- package/es/Table/Tbody.js +240 -176
- package/es/Table/Td.js +169 -130
- package/es/Table/Thead.js +206 -177
- package/es/Table/Tr.js +249 -205
- package/es/Table/TreeExpand.js +151 -116
- package/es/Table/context.js +15 -15
- package/es/Table/fixedAuto.js +82 -59
- package/es/Table/index.js +309 -228
- package/es/Table/resizable.js +89 -56
- package/es/Table/select.js +238 -215
- package/es/Table/styles/index.js +3 -4
- package/es/Tabs/Header.js +203 -160
- package/es/Tabs/Link.js +46 -28
- package/es/Tabs/Panel.js +49 -33
- package/es/Tabs/Tab.js +97 -79
- package/es/Tabs/Tabs.js +211 -177
- package/es/Tabs/Wrapper.js +37 -17
- package/es/Tabs/index.js +7 -10
- package/es/Tabs/styles/index.js +3 -4
- package/es/Tag/Input.js +70 -54
- package/es/Tag/Tag.js +198 -156
- package/es/Tag/index.js +5 -8
- package/es/Tag/styles/index.js +3 -4
- package/es/Textarea/Textarea.js +139 -118
- package/es/Textarea/index.js +10 -19
- package/es/Tooltip/Container.js +140 -127
- package/es/Tooltip/events.js +49 -55
- package/es/Tooltip/index.js +5 -8
- package/es/Tooltip/styles/index.js +3 -4
- package/es/Transfer/Card.js +212 -177
- package/es/Transfer/Transfer.js +160 -153
- package/es/Transfer/btns.js +97 -80
- package/es/Transfer/context.js +2 -3
- package/es/Transfer/filter.js +65 -35
- package/es/Transfer/index.js +9 -13
- package/es/Transfer/item.js +66 -41
- package/es/Transfer/select.js +15 -16
- package/es/Transfer/styles/index.js +3 -4
- package/es/Tree/Checkbox.js +72 -50
- package/es/Tree/Content.js +136 -95
- package/es/Tree/List.js +82 -53
- package/es/Tree/Node.js +237 -202
- package/es/Tree/Root.js +23 -19
- package/es/Tree/Tree.js +262 -197
- package/es/Tree/index.js +6 -9
- package/es/Tree/styles/index.js +3 -4
- package/es/Tree/toggle.js +89 -51
- package/es/TreeSelect/Input.js +73 -60
- package/es/TreeSelect/Result.js +213 -181
- package/es/TreeSelect/TreeSelect.js +327 -312
- package/es/TreeSelect/datum.js +56 -44
- package/es/TreeSelect/filter.js +134 -96
- package/es/TreeSelect/index.js +15 -23
- package/es/TreeSelect/styles/index.js +3 -4
- package/es/TreeSelect/tiled.js +143 -106
- package/es/Upload/Dragger.js +63 -39
- package/es/Upload/Drop.js +79 -57
- package/es/Upload/File.js +61 -48
- package/es/Upload/FileInput.js +53 -40
- package/es/Upload/Image.js +158 -115
- package/es/Upload/ImageFile.js +63 -43
- package/es/Upload/ImageResult.js +139 -114
- package/es/Upload/Progress.js +117 -105
- package/es/Upload/RemoveConfirm.js +58 -42
- package/es/Upload/Result.js +73 -58
- package/es/Upload/Upload.js +649 -490
- package/es/Upload/accept.js +33 -13
- package/es/Upload/context.js +12 -10
- package/es/Upload/index.js +16 -20
- package/es/Upload/request.js +48 -46
- package/es/Upload/styles/index.js +3 -4
- package/es/component.js +45 -24
- package/es/config.js +27 -19
- package/es/context/implementation.js +132 -94
- package/es/context/index.js +3 -4
- package/es/hoc/coin.js +118 -81
- package/es/hoc/config.js +31 -17
- package/es/hoc/delay.js +99 -55
- package/es/hoc/draggable.js +90 -80
- package/es/hoc/fetch.js +56 -33
- package/es/hoc/hidable.js +119 -98
- package/es/hoc/inputBorder.js +158 -158
- package/es/hoc/moveable.js +124 -96
- package/es/hoc/pagable.js +74 -55
- package/es/hoc/resizable.js +132 -100
- package/es/hoc/styles/index.js +7 -8
- package/es/hoc/trim.js +54 -32
- package/es/icons/Caret.js +14 -15
- package/es/icons/index.js +31 -85
- package/es/index.d.ts +1 -1
- package/es/index.js +58 -57
- package/es/locale/en_US.js +9 -30
- package/es/locale/index.js +13 -14
- package/es/locale/zh-CN.js +9 -17
- package/es/styles/expose.js +3 -4
- package/es/styles/index.js +1 -1
- package/es/utils/accept.js +15 -12
- package/es/utils/classname.js +23 -12
- package/es/utils/cleanProps.js +9 -21
- package/es/utils/clone.js +34 -27
- package/es/utils/color.js +310 -276
- package/es/utils/css-accessors.js +94 -45
- package/es/utils/dom/detect.js +29 -29
- package/es/utils/dom/document.js +23 -19
- package/es/utils/dom/element.js +139 -105
- package/es/utils/dom/getDataset.js +9 -9
- package/es/utils/dom/isDOMElement.js +3 -5
- package/es/utils/dom/normalizeWheel.js +32 -28
- package/es/utils/dom/popContainer.js +12 -13
- package/es/utils/dom/popover.js +79 -59
- package/es/utils/dom/ready.js +5 -6
- package/es/utils/dom/translate.js +10 -12
- package/es/utils/errors.js +47 -28
- package/es/utils/expose.js +97 -58
- package/es/utils/flat.js +122 -107
- package/es/utils/func.js +38 -20
- package/es/utils/hash.js +24 -20
- package/es/utils/index.js +24 -49
- package/es/utils/is.js +91 -70
- package/es/utils/lazyload.js +104 -86
- package/es/utils/notification.js +34 -20
- package/es/utils/numbers.js +61 -51
- package/es/utils/objects.js +221 -140
- package/es/utils/proptypes.js +21 -34
- package/es/utils/shallowEqual.js +46 -42
- package/es/utils/strings.js +50 -32
- package/es/utils/transform.js +24 -9
- package/es/utils/tree.js +78 -63
- package/es/utils/uid.js +14 -17
- package/es/utils/validate/index.js +71 -50
- package/es/utils/validate/isJson.js +7 -10
- package/es/utils/validate/nullable.js +10 -9
- package/es/utils/validate/range.js +22 -19
- package/es/utils/validate/rangeLength.js +19 -16
- package/es/utils/validate/regExp.js +10 -10
- package/es/utils/validate/required.js +11 -8
- package/es/utils/validate/type.js +56 -59
- package/es/utils/vars-inject.js +3420 -4248
- package/lib/DatePicker/utils.js +1 -1
- package/lib/Form/Field.js +8 -4
- package/lib/Form/Form.js +3 -0
- package/lib/Form/Item.js +1 -1
- package/lib/Form/index.d.ts +1 -0
- package/lib/Form/inputable.js +1 -1
- package/lib/Pagination/Jumper.js +3 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +3 -2
package/es/Upload/Upload.js
CHANGED
|
@@ -1,542 +1,700 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{ key: 'customValidator', param: blob => blob },
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
const promised = (action, ...args) => {
|
|
37
|
-
const res = action(...args)
|
|
38
|
-
if (res && typeof res.then === 'function') return res
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
if (res instanceof Error) reject(res)
|
|
41
|
-
resolve(true)
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
class Upload extends PureComponent {
|
|
46
|
-
constructor(props) {
|
|
47
|
-
super(props)
|
|
48
|
-
|
|
49
|
-
this.state = {
|
|
50
|
-
files: {},
|
|
51
|
-
recycle: [],
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.addFile = this.addFile.bind(this)
|
|
55
|
-
this.bindElement = this.bindElement.bind(this)
|
|
56
|
-
this.handleAddClick = this.handleAddClick.bind(this)
|
|
57
|
-
this.removeFile = this.removeFile.bind(this)
|
|
58
|
-
this.removeValue = this.removeValue.bind(this)
|
|
59
|
-
this.recoverValue = this.recoverValue.bind(this)
|
|
60
|
-
this.validatorHandle = this.validatorHandle.bind(this)
|
|
61
|
-
this.useValidator = this.useValidator.bind(this)
|
|
62
|
-
this.handleFileDrop = this.handleFileDrop.bind(this)
|
|
63
|
-
this.handleReplace = this.handleReplace.bind(this)
|
|
64
|
-
|
|
65
|
-
props.validateHook(this.validate.bind(this))
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
4
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
5
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import classnames from 'classnames';
|
|
10
|
+
import immer from 'immer';
|
|
11
|
+
import Gap from '../Gap';
|
|
12
|
+
import { PureComponent } from '../component';
|
|
13
|
+
import { getUidStr } from '../utils/uid';
|
|
14
|
+
import { FormError } from '../utils/errors';
|
|
15
|
+
import { uploadClass } from './styles';
|
|
16
|
+
import defaultRequest, { ERROR, UPLOADING } from './request';
|
|
17
|
+
import FileInput from './FileInput';
|
|
18
|
+
import File from './File';
|
|
19
|
+
import ImageFile from './ImageFile';
|
|
20
|
+
import Result from './Result';
|
|
21
|
+
import ImageResult from './ImageResult';
|
|
22
|
+
import { Provider } from './context';
|
|
23
|
+
import Drop from './Drop';
|
|
24
|
+
import attrAccept from '../utils/accept';
|
|
25
|
+
import { isFunc } from '../utils/is';
|
|
26
|
+
import { getLocale } from '../locale';
|
|
27
|
+
import acceptHOC from './accept';
|
|
28
|
+
import getDataset from '../utils/dom/getDataset';
|
|
29
|
+
var VALIDATORITEMS = [{
|
|
30
|
+
key: 'size',
|
|
31
|
+
param: function param(blob) {
|
|
32
|
+
return blob.size;
|
|
66
33
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
return canDelete
|
|
34
|
+
}, {
|
|
35
|
+
key: 'ext',
|
|
36
|
+
param: function param(blob) {
|
|
37
|
+
var exts = blob.name.split('.');
|
|
38
|
+
return exts[exts.length - 1];
|
|
74
39
|
}
|
|
40
|
+
}, {
|
|
41
|
+
key: 'customValidator',
|
|
42
|
+
param: function param(blob) {
|
|
43
|
+
return blob;
|
|
44
|
+
}
|
|
45
|
+
}];
|
|
75
46
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (typeof action === 'function') return action(file)
|
|
80
|
-
return ''
|
|
47
|
+
var promised = function promised(action) {
|
|
48
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
49
|
+
args[_key - 1] = arguments[_key];
|
|
81
50
|
}
|
|
82
51
|
|
|
83
|
-
|
|
84
|
-
|
|
52
|
+
var res = action.apply(void 0, args);
|
|
53
|
+
if (res && typeof res.then === 'function') return res;
|
|
54
|
+
return new Promise(function (resolve, reject) {
|
|
55
|
+
if (res instanceof Error) reject(res);
|
|
56
|
+
resolve(true);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
85
59
|
|
|
86
|
-
|
|
60
|
+
var Upload =
|
|
61
|
+
/*#__PURE__*/
|
|
62
|
+
function (_PureComponent) {
|
|
63
|
+
_inheritsLoose(Upload, _PureComponent);
|
|
87
64
|
|
|
88
|
-
|
|
89
|
-
|
|
65
|
+
function Upload(props) {
|
|
66
|
+
var _this;
|
|
90
67
|
|
|
91
|
-
|
|
92
|
-
|
|
68
|
+
_this = _PureComponent.call(this, props) || this;
|
|
69
|
+
_this.state = {
|
|
70
|
+
files: {},
|
|
71
|
+
recycle: []
|
|
72
|
+
};
|
|
73
|
+
_this.addFile = _this.addFile.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
74
|
+
_this.bindElement = _this.bindElement.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
75
|
+
_this.handleAddClick = _this.handleAddClick.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
76
|
+
_this.removeFile = _this.removeFile.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
77
|
+
_this.removeValue = _this.removeValue.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
78
|
+
_this.recoverValue = _this.recoverValue.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
79
|
+
_this.validatorHandle = _this.validatorHandle.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
80
|
+
_this.useValidator = _this.useValidator.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
81
|
+
_this.handleFileDrop = _this.handleFileDrop.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
82
|
+
_this.handleReplace = _this.handleReplace.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
|
83
|
+
props.validateHook(_this.validate.bind(_assertThisInitialized(_assertThisInitialized(_this))));
|
|
84
|
+
return _this;
|
|
93
85
|
}
|
|
94
86
|
|
|
95
|
-
|
|
96
|
-
const { disabled } = this.props
|
|
97
|
-
if (disabled) return
|
|
98
|
-
this.input.click()
|
|
99
|
-
}
|
|
87
|
+
var _proto = Upload.prototype;
|
|
100
88
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return new Promise((resolve, reject) => {
|
|
104
|
-
if (Object.keys(files).length > 0) reject(new FormError(''))
|
|
105
|
-
resolve(true)
|
|
106
|
-
})
|
|
107
|
-
}
|
|
89
|
+
_proto.getCanDelete = function getCanDelete(item, index) {
|
|
90
|
+
var canDelete = this.props.canDelete;
|
|
108
91
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
92
|
+
if (isFunc(canDelete)) {
|
|
93
|
+
return canDelete(item, index);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return canDelete;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
_proto.getAction = function getAction(file) {
|
|
100
|
+
var action = this.props.action;
|
|
101
|
+
if (typeof action === 'string') return action;
|
|
102
|
+
if (typeof action === 'function') return action(file);
|
|
103
|
+
return '';
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
_proto.validatorHandle = function validatorHandle(error, file) {
|
|
107
|
+
var vth = this.props.validatorHandle;
|
|
108
|
+
if (typeof vth === 'function') return vth(error, file);
|
|
109
|
+
return vth;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
_proto.bindElement = function bindElement(input) {
|
|
113
|
+
this.input = input;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
_proto.handleAddClick = function handleAddClick() {
|
|
117
|
+
var disabled = this.props.disabled;
|
|
118
|
+
if (disabled) return;
|
|
119
|
+
this.input.click();
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
_proto.validate = function validate() {
|
|
123
|
+
var files = this.state.files;
|
|
124
|
+
return new Promise(function (resolve, reject) {
|
|
125
|
+
if (Object.keys(files).length > 0) reject(new FormError(''));
|
|
126
|
+
resolve(true);
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
_proto.removeFile = function removeFile(id) {
|
|
131
|
+
var onErrorRemove = this.props.onErrorRemove;
|
|
132
|
+
var file = this.state.files[id];
|
|
112
133
|
|
|
113
134
|
if (file) {
|
|
114
|
-
if (file.xhr && file.xhr.abort) file.xhr.abort()
|
|
115
|
-
this.setState(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (file.status === ERROR && onErrorRemove) {
|
|
121
|
-
onErrorRemove(file.xhr, file.blob, file)
|
|
122
|
-
}
|
|
135
|
+
if (file.xhr && file.xhr.abort) file.xhr.abort();
|
|
136
|
+
this.setState(immer(function (draft) {
|
|
137
|
+
delete draft.files[id];
|
|
138
|
+
}), function () {
|
|
139
|
+
if (file.status === ERROR && onErrorRemove) {
|
|
140
|
+
onErrorRemove(file.xhr, file.blob, file);
|
|
123
141
|
}
|
|
124
|
-
)
|
|
142
|
+
});
|
|
125
143
|
}
|
|
126
|
-
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
_proto.removeValue = function removeValue(index) {
|
|
147
|
+
var _this2 = this;
|
|
148
|
+
|
|
149
|
+
var _this$props = this.props,
|
|
150
|
+
recoverAble = _this$props.recoverAble,
|
|
151
|
+
disabled = _this$props.disabled,
|
|
152
|
+
beforeRemove = _this$props.beforeRemove;
|
|
153
|
+
if (disabled) return;
|
|
154
|
+
var current = this.props.value[index];
|
|
155
|
+
var startRemove = typeof beforeRemove === 'function' ? beforeRemove(current) : Promise.resolve();
|
|
156
|
+
startRemove.then(function () {
|
|
157
|
+
_this2.setState(immer(function (draft) {
|
|
158
|
+
draft.recycle.push(_this2.props.value[index]);
|
|
159
|
+
|
|
160
|
+
if (typeof recoverAble === 'number' && draft.recycle.length > recoverAble) {
|
|
161
|
+
draft.recycle.shift();
|
|
162
|
+
}
|
|
163
|
+
}));
|
|
164
|
+
|
|
165
|
+
var value = immer(_this2.props.value, function (draft) {
|
|
166
|
+
draft.splice(index, 1);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
_this2.props.onChange(value);
|
|
170
|
+
}).catch(function () {});
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
_proto.recoverValue = function recoverValue(index, value) {
|
|
174
|
+
var disabled = this.props.disabled;
|
|
175
|
+
if (disabled) return;
|
|
176
|
+
this.props.onChange(immer(this.props.value, function (draft) {
|
|
177
|
+
draft.push(value);
|
|
178
|
+
}));
|
|
179
|
+
this.setState(immer(function (draft) {
|
|
180
|
+
draft.recycle.splice(index, 1);
|
|
181
|
+
}));
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
_proto.useValidator =
|
|
185
|
+
/*#__PURE__*/
|
|
186
|
+
function () {
|
|
187
|
+
var _useValidator = _asyncToGenerator(
|
|
188
|
+
/*#__PURE__*/
|
|
189
|
+
_regeneratorRuntime.mark(function _callee(blob) {
|
|
190
|
+
var _this$props2, validator, accept, forceAccept, forceAcceptErrorMsg, files, error, i, acceptRes, item;
|
|
191
|
+
|
|
192
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
193
|
+
while (1) {
|
|
194
|
+
switch (_context.prev = _context.next) {
|
|
195
|
+
case 0:
|
|
196
|
+
_this$props2 = this.props, validator = _this$props2.validator, accept = _this$props2.accept, forceAccept = _this$props2.forceAccept, forceAcceptErrorMsg = _this$props2.forceAcceptErrorMsg;
|
|
197
|
+
files = this.state.files;
|
|
198
|
+
error = null;
|
|
199
|
+
i = 0;
|
|
200
|
+
|
|
201
|
+
if (!forceAccept) {
|
|
202
|
+
_context.next = 8;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
127
205
|
|
|
128
|
-
|
|
129
|
-
const { recoverAble, disabled, beforeRemove } = this.props
|
|
130
|
-
if (disabled) return
|
|
131
|
-
const current = this.props.value[index]
|
|
132
|
-
const startRemove = typeof beforeRemove === 'function' ? beforeRemove(current) : Promise.resolve()
|
|
133
|
-
startRemove
|
|
134
|
-
.then(() => {
|
|
135
|
-
this.setState(
|
|
136
|
-
immer(draft => {
|
|
137
|
-
draft.recycle.push(this.props.value[index])
|
|
138
|
-
if (typeof recoverAble === 'number' && draft.recycle.length > recoverAble) {
|
|
139
|
-
draft.recycle.shift()
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
)
|
|
143
|
-
const value = immer(this.props.value, draft => {
|
|
144
|
-
draft.splice(index, 1)
|
|
145
|
-
})
|
|
146
|
-
this.props.onChange(value)
|
|
147
|
-
})
|
|
148
|
-
.catch(() => {})
|
|
149
|
-
}
|
|
206
|
+
acceptRes = attrAccept(blob, accept);
|
|
150
207
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
immer(this.props.value, draft => {
|
|
156
|
-
draft.push(value)
|
|
157
|
-
})
|
|
158
|
-
)
|
|
159
|
-
this.setState(
|
|
160
|
-
immer(draft => {
|
|
161
|
-
draft.recycle.splice(index, 1)
|
|
162
|
-
})
|
|
163
|
-
)
|
|
164
|
-
}
|
|
208
|
+
if (acceptRes) {
|
|
209
|
+
_context.next = 8;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
165
212
|
|
|
166
|
-
|
|
167
|
-
const { validator, accept, forceAccept, forceAcceptErrorMsg } = this.props
|
|
168
|
-
const { files } = this.state
|
|
169
|
-
let error = null
|
|
170
|
-
let i = 0
|
|
213
|
+
return _context.abrupt("return", new Error(forceAcceptErrorMsg || getLocale('invalidAccept')));
|
|
171
214
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
215
|
+
case 8:
|
|
216
|
+
if (!VALIDATORITEMS[i]) {
|
|
217
|
+
_context.next = 24;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
item = VALIDATORITEMS[i];
|
|
222
|
+
|
|
223
|
+
if (!(typeof validator[item.key] === 'function')) {
|
|
224
|
+
_context.next = 21;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
_context.prev = 11;
|
|
229
|
+
_context.next = 14;
|
|
230
|
+
return promised(validator[item.key], item.param(blob), files);
|
|
231
|
+
|
|
232
|
+
case 14:
|
|
233
|
+
_context.next = 19;
|
|
234
|
+
break;
|
|
235
|
+
|
|
236
|
+
case 16:
|
|
237
|
+
_context.prev = 16;
|
|
238
|
+
_context.t0 = _context["catch"](11);
|
|
239
|
+
error = _context.t0 instanceof Error ? _context.t0 : new Error(_context.t0);
|
|
240
|
+
|
|
241
|
+
case 19:
|
|
242
|
+
if (!(error instanceof Error)) {
|
|
243
|
+
_context.next = 21;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return _context.abrupt("return", error);
|
|
248
|
+
|
|
249
|
+
case 21:
|
|
250
|
+
i += 1;
|
|
251
|
+
_context.next = 8;
|
|
252
|
+
break;
|
|
176
253
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
error = err instanceof Error ? err : new Error(err)
|
|
254
|
+
case 24:
|
|
255
|
+
return _context.abrupt("return", null);
|
|
256
|
+
|
|
257
|
+
case 25:
|
|
258
|
+
case "end":
|
|
259
|
+
return _context.stop();
|
|
260
|
+
}
|
|
185
261
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
262
|
+
}, _callee, this, [[11, 16]]);
|
|
263
|
+
}));
|
|
264
|
+
|
|
265
|
+
function useValidator(_x) {
|
|
266
|
+
return _useValidator.apply(this, arguments);
|
|
189
267
|
}
|
|
190
268
|
|
|
191
|
-
return
|
|
192
|
-
}
|
|
269
|
+
return useValidator;
|
|
270
|
+
}();
|
|
271
|
+
|
|
272
|
+
_proto.addFile =
|
|
273
|
+
/*#__PURE__*/
|
|
274
|
+
function () {
|
|
275
|
+
var _addFile = _asyncToGenerator(
|
|
276
|
+
/*#__PURE__*/
|
|
277
|
+
_regeneratorRuntime.mark(function _callee2(e) {
|
|
278
|
+
var _this3 = this;
|
|
279
|
+
|
|
280
|
+
var _this$props3, beforeUpload, value, limit, filesFilter, files, finishedCode, fileList, addLength, list, _loop, i, _ret;
|
|
281
|
+
|
|
282
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
283
|
+
while (1) {
|
|
284
|
+
switch (_context3.prev = _context3.next) {
|
|
285
|
+
case 0:
|
|
286
|
+
_this$props3 = this.props, beforeUpload = _this$props3.beforeUpload, value = _this$props3.value, limit = _this$props3.limit, filesFilter = _this$props3.filesFilter; // eslint-disable-next-line
|
|
287
|
+
|
|
288
|
+
files = _objectSpread({}, this.state.files);
|
|
289
|
+
finishedCode = false;
|
|
290
|
+
fileList = e.fromDragger && e.files ? e.files : e.target.files;
|
|
291
|
+
if (filesFilter) fileList = filesFilter(Array.from(fileList)) || [];
|
|
292
|
+
addLength = limit - value.length - Object.keys(this.state.files).length;
|
|
293
|
+
|
|
294
|
+
if (!(addLength <= 0)) {
|
|
295
|
+
_context3.next = 8;
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
193
298
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
299
|
+
return _context3.abrupt("return");
|
|
300
|
+
|
|
301
|
+
case 8:
|
|
302
|
+
list = Array.from({
|
|
303
|
+
length: Math.min(fileList.length, addLength)
|
|
304
|
+
});
|
|
305
|
+
_loop =
|
|
306
|
+
/*#__PURE__*/
|
|
307
|
+
_regeneratorRuntime.mark(function _loop(i) {
|
|
308
|
+
var blob, id, file, error;
|
|
309
|
+
return _regeneratorRuntime.wrap(function _loop$(_context2) {
|
|
310
|
+
while (1) {
|
|
311
|
+
switch (_context2.prev = _context2.next) {
|
|
312
|
+
case 0:
|
|
313
|
+
blob = fileList[i];
|
|
314
|
+
id = getUidStr();
|
|
315
|
+
file = {
|
|
316
|
+
name: blob.name,
|
|
317
|
+
process: -1,
|
|
318
|
+
status: UPLOADING,
|
|
319
|
+
blob: blob
|
|
320
|
+
};
|
|
321
|
+
files[id] = file; // eslint-disable-next-line no-await-in-loop
|
|
322
|
+
|
|
323
|
+
_context2.next = 6;
|
|
324
|
+
return _this3.useValidator(blob);
|
|
325
|
+
|
|
326
|
+
case 6:
|
|
327
|
+
error = _context2.sent;
|
|
328
|
+
|
|
329
|
+
if (!(error instanceof Error)) {
|
|
330
|
+
_context2.next = 15;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (_this3.validatorHandle(error, file.blob)) {
|
|
335
|
+
_context2.next = 11;
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
delete files[id];
|
|
340
|
+
return _context2.abrupt("return", "continue");
|
|
341
|
+
|
|
342
|
+
case 11:
|
|
343
|
+
file.message = error.message;
|
|
344
|
+
file.status = ERROR;
|
|
345
|
+
|
|
346
|
+
if (beforeUpload) {
|
|
347
|
+
beforeUpload(blob, _this3.validatorHandle) // eslint-disable-next-line no-loop-func
|
|
348
|
+
.then(function (args) {
|
|
349
|
+
if (finishedCode) {
|
|
350
|
+
_this3.setState(immer(function (draft) {
|
|
351
|
+
draft.files[id] = Object.assign({}, draft.files[id], args);
|
|
352
|
+
}));
|
|
353
|
+
} else {
|
|
354
|
+
files[id] = Object.assign({}, files[id], args);
|
|
355
|
+
}
|
|
356
|
+
}).catch(function () {
|
|
357
|
+
return true;
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return _context2.abrupt("return", "continue");
|
|
362
|
+
|
|
363
|
+
case 15:
|
|
364
|
+
if (beforeUpload) {
|
|
365
|
+
beforeUpload(blob, _this3.validatorHandle) // eslint-disable-next-line no-loop-func
|
|
366
|
+
.then(function (args) {
|
|
367
|
+
if (args.status !== ERROR) files[id].xhr = _this3.uploadFile(id, blob, args.data);
|
|
368
|
+
|
|
369
|
+
if (finishedCode) {
|
|
370
|
+
_this3.setState(immer(function (draft) {
|
|
371
|
+
draft.files[id] = Object.assign({}, draft.files[id], args);
|
|
372
|
+
}));
|
|
373
|
+
} else {
|
|
374
|
+
files[id] = Object.assign({}, files[id], args);
|
|
375
|
+
}
|
|
376
|
+
}) // eslint-disable-next-line no-loop-func
|
|
377
|
+
.catch(function () {
|
|
378
|
+
if (finishedCode) {
|
|
379
|
+
_this3.setState(immer(function (draft) {
|
|
380
|
+
delete draft.files[id];
|
|
381
|
+
}));
|
|
382
|
+
} else {
|
|
383
|
+
delete files[id];
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
} else {
|
|
387
|
+
files[id].xhr = _this3.uploadFile(id, blob);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
case 16:
|
|
391
|
+
case "end":
|
|
392
|
+
return _context2.stop();
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}, _loop, this);
|
|
396
|
+
});
|
|
397
|
+
i = 0;
|
|
398
|
+
|
|
399
|
+
case 11:
|
|
400
|
+
if (!(i < list.length)) {
|
|
401
|
+
_context3.next = 19;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
213
404
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (!this.validatorHandle(error, file.blob)) {
|
|
219
|
-
delete files[id]
|
|
220
|
-
continue
|
|
221
|
-
}
|
|
405
|
+
return _context3.delegateYield(_loop(i), "t0", 13);
|
|
406
|
+
|
|
407
|
+
case 13:
|
|
408
|
+
_ret = _context3.t0;
|
|
222
409
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (beforeUpload) {
|
|
227
|
-
beforeUpload(blob, this.validatorHandle)
|
|
228
|
-
// eslint-disable-next-line no-loop-func
|
|
229
|
-
.then(args => {
|
|
230
|
-
if (finishedCode) {
|
|
231
|
-
this.setState(
|
|
232
|
-
immer(draft => {
|
|
233
|
-
draft.files[id] = Object.assign({}, draft.files[id], args)
|
|
234
|
-
})
|
|
235
|
-
)
|
|
236
|
-
} else {
|
|
237
|
-
files[id] = Object.assign({}, files[id], args)
|
|
410
|
+
if (!(_ret === "continue")) {
|
|
411
|
+
_context3.next = 16;
|
|
412
|
+
break;
|
|
238
413
|
}
|
|
239
|
-
|
|
240
|
-
|
|
414
|
+
|
|
415
|
+
return _context3.abrupt("continue", 16);
|
|
416
|
+
|
|
417
|
+
case 16:
|
|
418
|
+
i++;
|
|
419
|
+
_context3.next = 11;
|
|
420
|
+
break;
|
|
421
|
+
|
|
422
|
+
case 19:
|
|
423
|
+
finishedCode = true;
|
|
424
|
+
this.setState({
|
|
425
|
+
files: files
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
case 21:
|
|
429
|
+
case "end":
|
|
430
|
+
return _context3.stop();
|
|
431
|
+
}
|
|
241
432
|
}
|
|
242
|
-
|
|
243
|
-
|
|
433
|
+
}, _callee2, this);
|
|
434
|
+
}));
|
|
244
435
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
// eslint-disable-next-line no-loop-func
|
|
248
|
-
.then(args => {
|
|
249
|
-
if (args.status !== ERROR) files[id].xhr = this.uploadFile(id, blob, args.data)
|
|
250
|
-
if (finishedCode) {
|
|
251
|
-
this.setState(
|
|
252
|
-
immer(draft => {
|
|
253
|
-
draft.files[id] = Object.assign({}, draft.files[id], args)
|
|
254
|
-
})
|
|
255
|
-
)
|
|
256
|
-
} else {
|
|
257
|
-
files[id] = Object.assign({}, files[id], args)
|
|
258
|
-
}
|
|
259
|
-
})
|
|
260
|
-
// eslint-disable-next-line no-loop-func
|
|
261
|
-
.catch(() => {
|
|
262
|
-
if (finishedCode) {
|
|
263
|
-
this.setState(
|
|
264
|
-
immer(draft => {
|
|
265
|
-
delete draft.files[id]
|
|
266
|
-
})
|
|
267
|
-
)
|
|
268
|
-
} else {
|
|
269
|
-
delete files[id]
|
|
270
|
-
}
|
|
271
|
-
})
|
|
272
|
-
} else {
|
|
273
|
-
files[id].xhr = this.uploadFile(id, blob)
|
|
274
|
-
}
|
|
436
|
+
function addFile(_x2) {
|
|
437
|
+
return _addFile.apply(this, arguments);
|
|
275
438
|
}
|
|
276
|
-
finishedCode = true
|
|
277
|
-
this.setState({ files })
|
|
278
|
-
}
|
|
279
439
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
440
|
+
return addFile;
|
|
441
|
+
}();
|
|
442
|
+
|
|
443
|
+
_proto.uploadFile = function uploadFile(id, file, data) {
|
|
444
|
+
var _this4 = this;
|
|
445
|
+
|
|
446
|
+
var _this$props4 = this.props,
|
|
447
|
+
onSuccess = _this$props4.onSuccess,
|
|
448
|
+
name = _this$props4.name,
|
|
449
|
+
htmlName = _this$props4.htmlName,
|
|
450
|
+
cors = _this$props4.cors,
|
|
451
|
+
params = _this$props4.params,
|
|
452
|
+
withCredentials = _this$props4.withCredentials,
|
|
453
|
+
headers = _this$props4.headers,
|
|
454
|
+
request = _this$props4.request,
|
|
455
|
+
_onProgress = _this$props4.onProgress,
|
|
456
|
+
onStart = _this$props4.onStart,
|
|
457
|
+
responseType = _this$props4.responseType;
|
|
458
|
+
var req = request || defaultRequest;
|
|
459
|
+
var throttle = false;
|
|
460
|
+
var options = {
|
|
299
461
|
url: this.getAction(file),
|
|
300
462
|
name: htmlName || name,
|
|
301
|
-
cors,
|
|
302
|
-
params,
|
|
303
|
-
withCredentials,
|
|
304
|
-
file,
|
|
305
|
-
headers,
|
|
306
|
-
responseType,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
// expose the file progress to Upload.Button
|
|
325
|
-
() => {
|
|
326
|
-
if (typeof onProgress === 'function') {
|
|
327
|
-
onProgress(this.state.files[id])
|
|
328
|
-
}
|
|
463
|
+
cors: cors,
|
|
464
|
+
params: params,
|
|
465
|
+
withCredentials: withCredentials,
|
|
466
|
+
file: file,
|
|
467
|
+
headers: headers,
|
|
468
|
+
responseType: responseType,
|
|
469
|
+
onStart: onStart,
|
|
470
|
+
onProgress: function onProgress(e, msg) {
|
|
471
|
+
var percent = typeof e.percent === 'number' ? e.percent : e.loaded / e.total * 100;
|
|
472
|
+
if (throttle) return;
|
|
473
|
+
throttle = true;
|
|
474
|
+
setTimeout(function () {
|
|
475
|
+
throttle = false;
|
|
476
|
+
}, 16);
|
|
477
|
+
|
|
478
|
+
if (_this4.state.files[id]) {
|
|
479
|
+
_this4.setState(immer(function (draft) {
|
|
480
|
+
draft.files[id].process = percent;
|
|
481
|
+
if (msg) draft.files[id].message = msg;
|
|
482
|
+
}), // expose the file progress to Upload.Button
|
|
483
|
+
function () {
|
|
484
|
+
if (typeof _onProgress === 'function') {
|
|
485
|
+
_onProgress(_this4.state.files[id]);
|
|
329
486
|
}
|
|
330
|
-
)
|
|
487
|
+
});
|
|
331
488
|
}
|
|
332
489
|
},
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
onLoad: xhr => {
|
|
490
|
+
onSuccess: onSuccess,
|
|
491
|
+
onLoad: function onLoad(xhr) {
|
|
337
492
|
if (!/^2|1223/.test(xhr.status)) {
|
|
338
|
-
|
|
339
|
-
|
|
493
|
+
_this4.handleError(id, xhr, file);
|
|
494
|
+
|
|
495
|
+
return;
|
|
340
496
|
}
|
|
341
497
|
|
|
342
|
-
|
|
343
|
-
if (xhr.responseType === 'text' || !xhr.responseType) value = xhr.responseText
|
|
344
|
-
if (!value) value = xhr.response
|
|
498
|
+
var value;
|
|
499
|
+
if (xhr.responseType === 'text' || !xhr.responseType) value = xhr.responseText;
|
|
500
|
+
if (!value) value = xhr.response;
|
|
345
501
|
|
|
346
502
|
if (onSuccess) {
|
|
347
|
-
value = onSuccess(value, file, data, xhr)
|
|
503
|
+
value = onSuccess(value, file, data, xhr);
|
|
348
504
|
}
|
|
349
505
|
|
|
350
506
|
if (value instanceof Error) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
})
|
|
357
|
-
)
|
|
507
|
+
_this4.setState(immer(function (draft) {
|
|
508
|
+
draft.files[id].status = ERROR;
|
|
509
|
+
draft.files[id].name = file.name;
|
|
510
|
+
draft.files[id].message = value.message;
|
|
511
|
+
}));
|
|
358
512
|
} else {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
})
|
|
363
|
-
)
|
|
364
|
-
// add value
|
|
365
|
-
const values = immer(this.props.value, draft => {
|
|
366
|
-
draft.push(value)
|
|
367
|
-
})
|
|
368
|
-
this.props.onChange(values)
|
|
369
|
-
}
|
|
370
|
-
},
|
|
513
|
+
_this4.setState(immer(function (draft) {
|
|
514
|
+
delete draft.files[id];
|
|
515
|
+
})); // add value
|
|
371
516
|
|
|
372
|
-
onError: xhr => this.handleError(id, xhr, file),
|
|
373
|
-
}
|
|
374
|
-
if (onProgress === false || onProgress === null) {
|
|
375
|
-
delete options.onProgress
|
|
376
|
-
}
|
|
377
517
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
handleFileDrop(files) {
|
|
382
|
-
this.addFile({ files, fromDragger: true })
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
handleReplace(files, index) {
|
|
386
|
-
this.removeValue(index)
|
|
387
|
-
setTimeout(() => {
|
|
388
|
-
this.addFile({ files, fromDragger: true })
|
|
389
|
-
})
|
|
390
|
-
}
|
|
518
|
+
var values = immer(_this4.props.value, function (draft) {
|
|
519
|
+
draft.push(value);
|
|
520
|
+
});
|
|
391
521
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
this.setState(
|
|
400
|
-
immer(draft => {
|
|
401
|
-
if (!draft.files[id]) return
|
|
402
|
-
draft.files[id].status = ERROR
|
|
403
|
-
draft.files[id].message = message
|
|
404
|
-
})
|
|
405
|
-
)
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
renderHandle() {
|
|
409
|
-
const { limit, value, children, accept, multiple, disabled, webkitdirectory, drop } = this.props
|
|
410
|
-
const count = value.length + Object.keys(this.state.files).length
|
|
411
|
-
if (limit > 0 && limit <= count) return null
|
|
522
|
+
_this4.props.onChange(values);
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
onError: function onError(xhr) {
|
|
526
|
+
return _this4.handleError(id, xhr, file);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
412
529
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
addFile: this.addFile,
|
|
416
|
-
accept,
|
|
417
|
-
disabled,
|
|
418
|
-
limit,
|
|
530
|
+
if (_onProgress === false || _onProgress === null) {
|
|
531
|
+
delete options.onProgress;
|
|
419
532
|
}
|
|
420
533
|
|
|
421
|
-
return (
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
)
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
)
|
|
469
|
-
|
|
470
|
-
|
|
534
|
+
return req(options);
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
_proto.handleFileDrop = function handleFileDrop(files) {
|
|
538
|
+
this.addFile({
|
|
539
|
+
files: files,
|
|
540
|
+
fromDragger: true
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
_proto.handleReplace = function handleReplace(files, index) {
|
|
545
|
+
var _this5 = this;
|
|
546
|
+
|
|
547
|
+
this.removeValue(index);
|
|
548
|
+
setTimeout(function () {
|
|
549
|
+
_this5.addFile({
|
|
550
|
+
files: files,
|
|
551
|
+
fromDragger: true
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
_proto.handleError = function handleError(id, xhr, file) {
|
|
557
|
+
var _this$props5 = this.props,
|
|
558
|
+
onError = _this$props5.onError,
|
|
559
|
+
onHttpError = _this$props5.onHttpError;
|
|
560
|
+
var message = xhr.statusText;
|
|
561
|
+
if (onError) message = onError(xhr, file);
|
|
562
|
+
if (onHttpError) message = onHttpError(xhr, file) || message;
|
|
563
|
+
this.setState(immer(function (draft) {
|
|
564
|
+
if (!draft.files[id]) return;
|
|
565
|
+
draft.files[id].status = ERROR;
|
|
566
|
+
draft.files[id].message = message;
|
|
567
|
+
}));
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
_proto.renderHandle = function renderHandle() {
|
|
571
|
+
var _this$props6 = this.props,
|
|
572
|
+
limit = _this$props6.limit,
|
|
573
|
+
value = _this$props6.value,
|
|
574
|
+
children = _this$props6.children,
|
|
575
|
+
accept = _this$props6.accept,
|
|
576
|
+
multiple = _this$props6.multiple,
|
|
577
|
+
disabled = _this$props6.disabled,
|
|
578
|
+
webkitdirectory = _this$props6.webkitdirectory,
|
|
579
|
+
drop = _this$props6.drop;
|
|
580
|
+
var count = value.length + Object.keys(this.state.files).length;
|
|
581
|
+
if (limit > 0 && limit <= count) return null;
|
|
582
|
+
var dragProps = {
|
|
583
|
+
multiple: multiple,
|
|
584
|
+
addFile: this.addFile,
|
|
585
|
+
accept: accept,
|
|
586
|
+
disabled: disabled,
|
|
587
|
+
limit: limit
|
|
588
|
+
};
|
|
589
|
+
return React.createElement(Drop, {
|
|
590
|
+
drop: drop,
|
|
591
|
+
accept: accept,
|
|
592
|
+
disabled: disabled,
|
|
593
|
+
onDrop: this.handleFileDrop,
|
|
594
|
+
multiple: multiple || limit > 1
|
|
595
|
+
}, React.createElement("span", {
|
|
596
|
+
className: uploadClass('handle', disabled && 'disabled'),
|
|
597
|
+
onClick: this.handleAddClick
|
|
598
|
+
}, React.createElement(Provider, {
|
|
599
|
+
value: dragProps
|
|
600
|
+
}, children), React.createElement(FileInput, {
|
|
601
|
+
webkitdirectory: webkitdirectory,
|
|
602
|
+
accept: accept,
|
|
603
|
+
ref: this.bindElement,
|
|
604
|
+
multiple: multiple,
|
|
605
|
+
onChange: this.addFile
|
|
606
|
+
})));
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
_proto.render = function render() {
|
|
610
|
+
var _this6 = this;
|
|
611
|
+
|
|
612
|
+
var _this$props7 = this.props,
|
|
613
|
+
limit = _this$props7.limit,
|
|
614
|
+
value = _this$props7.value,
|
|
615
|
+
renderResult = _this$props7.renderResult,
|
|
616
|
+
style = _this$props7.style,
|
|
617
|
+
imageStyle = _this$props7.imageStyle,
|
|
618
|
+
recoverAble = _this$props7.recoverAble,
|
|
619
|
+
showUploadList = _this$props7.showUploadList,
|
|
620
|
+
CustomResult = _this$props7.customResult,
|
|
621
|
+
disabled = _this$props7.disabled,
|
|
622
|
+
renderContent = _this$props7.renderContent,
|
|
623
|
+
accept = _this$props7.accept,
|
|
624
|
+
drop = _this$props7.drop,
|
|
625
|
+
leftHandler = _this$props7.leftHandler,
|
|
626
|
+
onPreview = _this$props7.onPreview,
|
|
627
|
+
removeConfirm = _this$props7.removeConfirm,
|
|
628
|
+
GapProps = _this$props7.GapProps;
|
|
629
|
+
var _this$state = this.state,
|
|
630
|
+
files = _this$state.files,
|
|
631
|
+
recycle = _this$state.recycle;
|
|
632
|
+
var fileDrop = drop && !imageStyle;
|
|
633
|
+
var className = classnames(uploadClass('_', disabled && 'disabled', showUploadList === false && 'hide-list', fileDrop && 'file-drop'), this.props.className);
|
|
634
|
+
var FileComponent = imageStyle ? ImageFile : File;
|
|
635
|
+
var ResultComponent = imageStyle ? ImageResult : Result;
|
|
471
636
|
|
|
472
637
|
if (CustomResult) {
|
|
473
|
-
return (
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
638
|
+
return React.createElement("div", {
|
|
639
|
+
className: className,
|
|
640
|
+
style: style
|
|
641
|
+
}, this.renderHandle(), React.createElement(CustomResult, {
|
|
642
|
+
value: value,
|
|
643
|
+
files: files,
|
|
644
|
+
onValueRemove: this.removeValue,
|
|
645
|
+
onFileRemove: this.removeFile
|
|
646
|
+
}));
|
|
479
647
|
}
|
|
480
648
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
showRecover={recoverAble && limit > value.length}
|
|
531
|
-
onRecover={this.recoverValue}
|
|
532
|
-
style={imageStyle}
|
|
533
|
-
/>
|
|
534
|
-
))}
|
|
535
|
-
</Wrapper>
|
|
536
|
-
</div>
|
|
537
|
-
)
|
|
538
|
-
}
|
|
539
|
-
}
|
|
649
|
+
var Wrapper = imageStyle ? Gap : React.Fragment;
|
|
650
|
+
return React.createElement("div", _extends({
|
|
651
|
+
className: className,
|
|
652
|
+
style: style
|
|
653
|
+
}, getDataset(this.props)), React.createElement(Wrapper, imageStyle ? GapProps : null, !imageStyle && this.renderHandle(), imageStyle && leftHandler && this.renderHandle(), showUploadList && value.map(function (v, i) {
|
|
654
|
+
return React.createElement(Drop, {
|
|
655
|
+
drop: drop,
|
|
656
|
+
multiple: false,
|
|
657
|
+
key: i,
|
|
658
|
+
accept: accept,
|
|
659
|
+
dropData: i,
|
|
660
|
+
disabled: disabled,
|
|
661
|
+
onDrop: _this6.handleReplace
|
|
662
|
+
}, React.createElement(ResultComponent, {
|
|
663
|
+
renderContent: renderContent,
|
|
664
|
+
value: v,
|
|
665
|
+
values: value,
|
|
666
|
+
index: i,
|
|
667
|
+
style: imageStyle,
|
|
668
|
+
renderResult: renderResult,
|
|
669
|
+
onRemove: _this6.getCanDelete(v, i) ? _this6.removeValue : undefined,
|
|
670
|
+
removeConfirm: removeConfirm,
|
|
671
|
+
onPreview: onPreview
|
|
672
|
+
}));
|
|
673
|
+
}), showUploadList && Object.keys(files).map(function (id) {
|
|
674
|
+
return React.createElement(FileComponent, _extends({}, files[id], {
|
|
675
|
+
key: id,
|
|
676
|
+
id: id,
|
|
677
|
+
style: imageStyle,
|
|
678
|
+
onRemove: _this6.removeFile
|
|
679
|
+
}));
|
|
680
|
+
}), imageStyle && !leftHandler && this.renderHandle(), recoverAble && recycle.map(function (v, i) {
|
|
681
|
+
return React.createElement(ResultComponent, {
|
|
682
|
+
renderContent: renderContent,
|
|
683
|
+
key: i,
|
|
684
|
+
value: v,
|
|
685
|
+
values: recycle,
|
|
686
|
+
index: i,
|
|
687
|
+
renderResult: renderResult,
|
|
688
|
+
recoverAble: !!recoverAble,
|
|
689
|
+
showRecover: recoverAble && limit > value.length,
|
|
690
|
+
onRecover: _this6.recoverValue,
|
|
691
|
+
style: imageStyle
|
|
692
|
+
});
|
|
693
|
+
})));
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
return Upload;
|
|
697
|
+
}(PureComponent);
|
|
540
698
|
|
|
541
699
|
Upload.propTypes = {
|
|
542
700
|
accept: PropTypes.string,
|
|
@@ -583,9 +741,8 @@ Upload.propTypes = {
|
|
|
583
741
|
forceAcceptErrorMsg: PropTypes.string,
|
|
584
742
|
canDelete: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
|
|
585
743
|
GapProps: PropTypes.shape({}),
|
|
586
|
-
responseType: PropTypes.string
|
|
587
|
-
}
|
|
588
|
-
|
|
744
|
+
responseType: PropTypes.string
|
|
745
|
+
};
|
|
589
746
|
Upload.defaultProps = {
|
|
590
747
|
cors: false,
|
|
591
748
|
limit: 100,
|
|
@@ -596,7 +753,9 @@ Upload.defaultProps = {
|
|
|
596
753
|
showUploadList: true,
|
|
597
754
|
validatorHandle: true,
|
|
598
755
|
canDelete: true,
|
|
599
|
-
GapProps: {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
756
|
+
GapProps: {
|
|
757
|
+
column: 12,
|
|
758
|
+
row: 12
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
export default acceptHOC(Upload);
|