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.
Files changed (381) hide show
  1. package/css/DatePicker/utils.js +1 -1
  2. package/css/Form/Field.js +8 -4
  3. package/css/Form/Form.js +3 -0
  4. package/css/Form/Item.js +1 -1
  5. package/css/Form/index.d.ts +1 -0
  6. package/css/Form/inputable.js +1 -1
  7. package/css/Pagination/Jumper.js +3 -0
  8. package/css/index.d.ts +1 -1
  9. package/css/index.js +1 -1
  10. package/dist/shineout.js +24 -14
  11. package/dist/shineout.js.map +1 -1
  12. package/dist/shineout.min.js +1 -1
  13. package/es/Alert/index.js +127 -107
  14. package/es/Alert/styles/index.js +3 -4
  15. package/es/AnimationList/AbsoluteList.js +257 -193
  16. package/es/AnimationList/LazyList.js +120 -92
  17. package/es/AnimationList/List.js +43 -23
  18. package/es/AnimationList/index.js +19 -14
  19. package/es/AnimationList/styles/index.js +3 -4
  20. package/es/Breadcrumb/index.js +77 -69
  21. package/es/Breadcrumb/styles/index.js +3 -4
  22. package/es/Button/Button.js +91 -74
  23. package/es/Button/Group.js +42 -28
  24. package/es/Button/Once.js +39 -23
  25. package/es/Button/index.js +7 -10
  26. package/es/Button/styles/index.js +3 -4
  27. package/es/Card/Accordion.js +58 -45
  28. package/es/Card/Body.js +55 -42
  29. package/es/Card/Card.js +85 -79
  30. package/es/Card/Footer.js +38 -15
  31. package/es/Card/Header.js +52 -34
  32. package/es/Card/Submit.js +51 -33
  33. package/es/Card/context.js +22 -16
  34. package/es/Card/index.js +16 -19
  35. package/es/Card/styles/index.js +3 -4
  36. package/es/CardGroup/CardGroup.js +93 -69
  37. package/es/CardGroup/Item.js +61 -43
  38. package/es/CardGroup/context.js +12 -10
  39. package/es/CardGroup/index.js +7 -10
  40. package/es/CardGroup/styles/index.js +3 -4
  41. package/es/Carousel/Item.js +31 -17
  42. package/es/Carousel/index.js +156 -123
  43. package/es/Carousel/styles/index.js +3 -4
  44. package/es/Cascader/Cascader.js +397 -346
  45. package/es/Cascader/FilterList.js +185 -142
  46. package/es/Cascader/Input.js +102 -79
  47. package/es/Cascader/List.js +66 -41
  48. package/es/Cascader/Node.js +153 -110
  49. package/es/Cascader/Result.js +289 -232
  50. package/es/Cascader/filter.js +92 -61
  51. package/es/Cascader/index.js +13 -18
  52. package/es/Cascader/styles/index.js +3 -4
  53. package/es/Checkbox/CheckItem.js +168 -154
  54. package/es/Checkbox/Checkbox.js +2 -3
  55. package/es/Checkbox/Group.js +106 -85
  56. package/es/Checkbox/context.js +12 -10
  57. package/es/Checkbox/index.js +14 -21
  58. package/es/Checkbox/styles/index.js +3 -4
  59. package/es/DataList/BaseItem.js +39 -21
  60. package/es/DataList/Extra.js +33 -17
  61. package/es/DataList/List.js +166 -140
  62. package/es/DataList/Meta.js +109 -74
  63. package/es/DataList/Pagination.js +9 -10
  64. package/es/DataList/index.js +13 -19
  65. package/es/DataList/styles/index.js +3 -4
  66. package/es/DatePicker/Container.js +468 -449
  67. package/es/DatePicker/Day.js +265 -258
  68. package/es/DatePicker/Icon.js +34 -20
  69. package/es/DatePicker/Month.js +101 -79
  70. package/es/DatePicker/Picker.js +110 -83
  71. package/es/DatePicker/Quick.js +52 -39
  72. package/es/DatePicker/Range.js +241 -192
  73. package/es/DatePicker/Text.js +103 -91
  74. package/es/DatePicker/Time.js +165 -147
  75. package/es/DatePicker/TimeScroll.js +148 -116
  76. package/es/DatePicker/Year.js +74 -53
  77. package/es/DatePicker/index.js +16 -18
  78. package/es/DatePicker/paramUtils.js +92 -58
  79. package/es/DatePicker/styles/index.js +3 -4
  80. package/es/DatePicker/utils.js +189 -198
  81. package/es/DatePicker/value.js +139 -98
  82. package/es/Datum/Form.js +333 -282
  83. package/es/Datum/List.js +319 -201
  84. package/es/Datum/Tree.js +298 -239
  85. package/es/Datum/hoc.js +104 -69
  86. package/es/Datum/index.js +7 -8
  87. package/es/Datum/types.js +20 -25
  88. package/es/Divider/index.js +50 -32
  89. package/es/Divider/styles/index.js +3 -4
  90. package/es/Drawer/index.js +14 -9
  91. package/es/Dropdown/Item.js +56 -43
  92. package/es/Dropdown/index.js +273 -259
  93. package/es/Dropdown/styles/index.js +3 -4
  94. package/es/EditableArea/EditableArea.js +157 -136
  95. package/es/EditableArea/index.js +8 -15
  96. package/es/EditableArea/styles/index.js +3 -4
  97. package/es/Form/Block.js +83 -57
  98. package/es/Form/BlockField.js +32 -17
  99. package/es/Form/Field.js +59 -35
  100. package/es/Form/FieldError.js +27 -21
  101. package/es/Form/FieldSet.js +214 -156
  102. package/es/Form/Flow.js +51 -32
  103. package/es/Form/Form.js +181 -144
  104. package/es/Form/Item.js +181 -166
  105. package/es/Form/Loop.js +202 -146
  106. package/es/Form/formButton.js +58 -42
  107. package/es/Form/formContext.js +104 -95
  108. package/es/Form/index.d.ts +1 -0
  109. package/es/Form/index.js +40 -45
  110. package/es/Form/inputable.js +368 -292
  111. package/es/Form/mode.js +15 -9
  112. package/es/Form/styles/index.js +4 -5
  113. package/es/Gap/index.js +71 -47
  114. package/es/Gap/styles/index.js +3 -4
  115. package/es/Gap/support.js +11 -14
  116. package/es/Grid/index.js +88 -58
  117. package/es/Grid/utils.js +57 -58
  118. package/es/Icon/Icon.js +43 -42
  119. package/es/Icon/index.js +39 -22
  120. package/es/Icon/styles/index.js +3 -4
  121. package/es/Image/Gallery.js +128 -113
  122. package/es/Image/Group.js +60 -36
  123. package/es/Image/Image.js +227 -153
  124. package/es/Image/Magnify.js +123 -94
  125. package/es/Image/events.js +29 -26
  126. package/es/Image/index.js +6 -9
  127. package/es/Image/styles/index.js +3 -4
  128. package/es/Input/Group.js +17 -11
  129. package/es/Input/Input.js +158 -134
  130. package/es/Input/Number.js +199 -175
  131. package/es/Input/Password.js +54 -31
  132. package/es/Input/clear.js +41 -25
  133. package/es/Input/index.js +23 -35
  134. package/es/Input/styles/index.js +3 -4
  135. package/es/Lazyload/index.js +63 -42
  136. package/es/Lazyload/styles/index.js +3 -4
  137. package/es/Menu/Item.js +275 -236
  138. package/es/Menu/List.js +75 -67
  139. package/es/Menu/Root.js +372 -334
  140. package/es/Menu/context.js +18 -12
  141. package/es/Menu/index.js +3 -5
  142. package/es/Menu/styles/index.js +3 -4
  143. package/es/Message/Container.js +155 -119
  144. package/es/Message/index.js +42 -30
  145. package/es/Message/messager.js +29 -33
  146. package/es/Message/styles/index.js +3 -4
  147. package/es/Modal/Modal.js +80 -60
  148. package/es/Modal/Panel.js +258 -234
  149. package/es/Modal/context.js +15 -15
  150. package/es/Modal/events.js +213 -182
  151. package/es/Modal/index.js +12 -14
  152. package/es/Modal/styles/index.js +3 -4
  153. package/es/Pagination/Item.js +46 -32
  154. package/es/Pagination/Jumper.js +79 -66
  155. package/es/Pagination/Links.js +110 -82
  156. package/es/Pagination/Next.js +52 -31
  157. package/es/Pagination/PageSizeList.js +57 -40
  158. package/es/Pagination/Pagination.js +78 -54
  159. package/es/Pagination/Prev.js +49 -30
  160. package/es/Pagination/Simple.js +32 -18
  161. package/es/Pagination/index.js +68 -41
  162. package/es/Pagination/styles/index.js +3 -4
  163. package/es/Popover/Confirm.js +107 -64
  164. package/es/Popover/Panel.js +284 -231
  165. package/es/Popover/context.js +15 -12
  166. package/es/Popover/events.js +80 -86
  167. package/es/Popover/index.js +12 -14
  168. package/es/Popover/styles/index.js +3 -4
  169. package/es/Progress/Circle.js +70 -59
  170. package/es/Progress/Line.js +51 -39
  171. package/es/Progress/Popup.js +42 -24
  172. package/es/Progress/analyzeColor.js +18 -9
  173. package/es/Progress/index.js +13 -15
  174. package/es/Progress/styles/index.js +3 -4
  175. package/es/Radio/Group.js +105 -94
  176. package/es/Radio/Radio.js +2 -3
  177. package/es/Radio/index.js +15 -17
  178. package/es/Radio/styles/index.js +1 -1
  179. package/es/Rate/Rate.js +216 -167
  180. package/es/Rate/index.js +17 -10
  181. package/es/Rate/styles/index.js +3 -4
  182. package/es/Rule/convert.js +48 -57
  183. package/es/Rule/index.js +63 -40
  184. package/es/Rule/length.js +53 -38
  185. package/es/Rule/regExp.js +23 -14
  186. package/es/Rule/required.js +26 -18
  187. package/es/Rule/styles/index.js +1 -1
  188. package/es/Rule/type.js +26 -18
  189. package/es/Scroll/Bar.js +145 -117
  190. package/es/Scroll/Scroll.js +277 -217
  191. package/es/Scroll/context.js +20 -13
  192. package/es/Scroll/fixedLength.js +33 -24
  193. package/es/Scroll/index.js +89 -55
  194. package/es/Scroll/styles/index.js +3 -4
  195. package/es/Select/BoxList.js +218 -189
  196. package/es/Select/BoxOption.js +64 -38
  197. package/es/Select/FlexBox.js +107 -75
  198. package/es/Select/FlexResult.js +65 -49
  199. package/es/Select/Input.js +137 -113
  200. package/es/Select/More.js +124 -121
  201. package/es/Select/Option.js +73 -52
  202. package/es/Select/OptionList.js +236 -200
  203. package/es/Select/OptionTree.js +111 -96
  204. package/es/Select/Result.js +297 -271
  205. package/es/Select/Select.js +517 -491
  206. package/es/Select/filter.js +221 -148
  207. package/es/Select/group.js +74 -45
  208. package/es/Select/index.js +32 -31
  209. package/es/Select/styles/index.js +3 -4
  210. package/es/Slider/Container.js +145 -132
  211. package/es/Slider/Indicator.js +28 -13
  212. package/es/Slider/Slider.js +132 -103
  213. package/es/Slider/index.js +5 -8
  214. package/es/Slider/styles/index.js +3 -4
  215. package/es/Slider/utils.js +26 -30
  216. package/es/Spin/Multiple.js +153 -109
  217. package/es/Spin/Simple.js +33 -22
  218. package/es/Spin/Spin.js +29 -29
  219. package/es/Spin/index.js +66 -84
  220. package/es/Spin/styles/index.js +27 -30
  221. package/es/Sticky/context.js +12 -10
  222. package/es/Sticky/index.js +255 -194
  223. package/es/Sticky/styles/index.js +1 -1
  224. package/es/Switch/Switch.js +2 -3
  225. package/es/Switch/index.js +8 -14
  226. package/es/Table/Checkbox.js +68 -39
  227. package/es/Table/CheckboxAll.js +121 -64
  228. package/es/Table/Colgroup.js +72 -47
  229. package/es/Table/Expand.js +63 -43
  230. package/es/Table/SeperateTable.js +594 -444
  231. package/es/Table/SimpleTable.js +215 -136
  232. package/es/Table/Sorter.js +83 -62
  233. package/es/Table/Table.js +157 -157
  234. package/es/Table/Tbody.js +240 -176
  235. package/es/Table/Td.js +169 -130
  236. package/es/Table/Thead.js +206 -177
  237. package/es/Table/Tr.js +249 -205
  238. package/es/Table/TreeExpand.js +151 -116
  239. package/es/Table/context.js +15 -15
  240. package/es/Table/fixedAuto.js +82 -59
  241. package/es/Table/index.js +309 -228
  242. package/es/Table/resizable.js +89 -56
  243. package/es/Table/select.js +238 -215
  244. package/es/Table/styles/index.js +3 -4
  245. package/es/Tabs/Header.js +203 -160
  246. package/es/Tabs/Link.js +46 -28
  247. package/es/Tabs/Panel.js +49 -33
  248. package/es/Tabs/Tab.js +97 -79
  249. package/es/Tabs/Tabs.js +211 -177
  250. package/es/Tabs/Wrapper.js +37 -17
  251. package/es/Tabs/index.js +7 -10
  252. package/es/Tabs/styles/index.js +3 -4
  253. package/es/Tag/Input.js +70 -54
  254. package/es/Tag/Tag.js +198 -156
  255. package/es/Tag/index.js +5 -8
  256. package/es/Tag/styles/index.js +3 -4
  257. package/es/Textarea/Textarea.js +139 -118
  258. package/es/Textarea/index.js +10 -19
  259. package/es/Tooltip/Container.js +140 -127
  260. package/es/Tooltip/events.js +49 -55
  261. package/es/Tooltip/index.js +5 -8
  262. package/es/Tooltip/styles/index.js +3 -4
  263. package/es/Transfer/Card.js +212 -177
  264. package/es/Transfer/Transfer.js +160 -153
  265. package/es/Transfer/btns.js +97 -80
  266. package/es/Transfer/context.js +2 -3
  267. package/es/Transfer/filter.js +65 -35
  268. package/es/Transfer/index.js +9 -13
  269. package/es/Transfer/item.js +66 -41
  270. package/es/Transfer/select.js +15 -16
  271. package/es/Transfer/styles/index.js +3 -4
  272. package/es/Tree/Checkbox.js +72 -50
  273. package/es/Tree/Content.js +136 -95
  274. package/es/Tree/List.js +82 -53
  275. package/es/Tree/Node.js +237 -202
  276. package/es/Tree/Root.js +23 -19
  277. package/es/Tree/Tree.js +262 -197
  278. package/es/Tree/index.js +6 -9
  279. package/es/Tree/styles/index.js +3 -4
  280. package/es/Tree/toggle.js +89 -51
  281. package/es/TreeSelect/Input.js +73 -60
  282. package/es/TreeSelect/Result.js +213 -181
  283. package/es/TreeSelect/TreeSelect.js +327 -312
  284. package/es/TreeSelect/datum.js +56 -44
  285. package/es/TreeSelect/filter.js +134 -96
  286. package/es/TreeSelect/index.js +15 -23
  287. package/es/TreeSelect/styles/index.js +3 -4
  288. package/es/TreeSelect/tiled.js +143 -106
  289. package/es/Upload/Dragger.js +63 -39
  290. package/es/Upload/Drop.js +79 -57
  291. package/es/Upload/File.js +61 -48
  292. package/es/Upload/FileInput.js +53 -40
  293. package/es/Upload/Image.js +158 -115
  294. package/es/Upload/ImageFile.js +63 -43
  295. package/es/Upload/ImageResult.js +139 -114
  296. package/es/Upload/Progress.js +117 -105
  297. package/es/Upload/RemoveConfirm.js +58 -42
  298. package/es/Upload/Result.js +73 -58
  299. package/es/Upload/Upload.js +649 -490
  300. package/es/Upload/accept.js +33 -13
  301. package/es/Upload/context.js +12 -10
  302. package/es/Upload/index.js +16 -20
  303. package/es/Upload/request.js +48 -46
  304. package/es/Upload/styles/index.js +3 -4
  305. package/es/component.js +45 -24
  306. package/es/config.js +27 -19
  307. package/es/context/implementation.js +132 -94
  308. package/es/context/index.js +3 -4
  309. package/es/hoc/coin.js +118 -81
  310. package/es/hoc/config.js +31 -17
  311. package/es/hoc/delay.js +99 -55
  312. package/es/hoc/draggable.js +90 -80
  313. package/es/hoc/fetch.js +56 -33
  314. package/es/hoc/hidable.js +119 -98
  315. package/es/hoc/inputBorder.js +158 -158
  316. package/es/hoc/moveable.js +124 -96
  317. package/es/hoc/pagable.js +74 -55
  318. package/es/hoc/resizable.js +132 -100
  319. package/es/hoc/styles/index.js +7 -8
  320. package/es/hoc/trim.js +54 -32
  321. package/es/icons/Caret.js +14 -15
  322. package/es/icons/index.js +31 -85
  323. package/es/index.d.ts +1 -1
  324. package/es/index.js +58 -57
  325. package/es/locale/en_US.js +9 -30
  326. package/es/locale/index.js +13 -14
  327. package/es/locale/zh-CN.js +9 -17
  328. package/es/styles/expose.js +3 -4
  329. package/es/styles/index.js +1 -1
  330. package/es/utils/accept.js +15 -12
  331. package/es/utils/classname.js +23 -12
  332. package/es/utils/cleanProps.js +9 -21
  333. package/es/utils/clone.js +34 -27
  334. package/es/utils/color.js +310 -276
  335. package/es/utils/css-accessors.js +94 -45
  336. package/es/utils/dom/detect.js +29 -29
  337. package/es/utils/dom/document.js +23 -19
  338. package/es/utils/dom/element.js +139 -105
  339. package/es/utils/dom/getDataset.js +9 -9
  340. package/es/utils/dom/isDOMElement.js +3 -5
  341. package/es/utils/dom/normalizeWheel.js +32 -28
  342. package/es/utils/dom/popContainer.js +12 -13
  343. package/es/utils/dom/popover.js +79 -59
  344. package/es/utils/dom/ready.js +5 -6
  345. package/es/utils/dom/translate.js +10 -12
  346. package/es/utils/errors.js +47 -28
  347. package/es/utils/expose.js +97 -58
  348. package/es/utils/flat.js +122 -107
  349. package/es/utils/func.js +38 -20
  350. package/es/utils/hash.js +24 -20
  351. package/es/utils/index.js +24 -49
  352. package/es/utils/is.js +91 -70
  353. package/es/utils/lazyload.js +104 -86
  354. package/es/utils/notification.js +34 -20
  355. package/es/utils/numbers.js +61 -51
  356. package/es/utils/objects.js +221 -140
  357. package/es/utils/proptypes.js +21 -34
  358. package/es/utils/shallowEqual.js +46 -42
  359. package/es/utils/strings.js +50 -32
  360. package/es/utils/transform.js +24 -9
  361. package/es/utils/tree.js +78 -63
  362. package/es/utils/uid.js +14 -17
  363. package/es/utils/validate/index.js +71 -50
  364. package/es/utils/validate/isJson.js +7 -10
  365. package/es/utils/validate/nullable.js +10 -9
  366. package/es/utils/validate/range.js +22 -19
  367. package/es/utils/validate/rangeLength.js +19 -16
  368. package/es/utils/validate/regExp.js +10 -10
  369. package/es/utils/validate/required.js +11 -8
  370. package/es/utils/validate/type.js +56 -59
  371. package/es/utils/vars-inject.js +3420 -4248
  372. package/lib/DatePicker/utils.js +1 -1
  373. package/lib/Form/Field.js +8 -4
  374. package/lib/Form/Form.js +3 -0
  375. package/lib/Form/Item.js +1 -1
  376. package/lib/Form/index.d.ts +1 -0
  377. package/lib/Form/inputable.js +1 -1
  378. package/lib/Pagination/Jumper.js +3 -0
  379. package/lib/index.d.ts +1 -1
  380. package/lib/index.js +1 -1
  381. package/package.json +3 -2
@@ -1,542 +1,700 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
- import classnames from 'classnames'
4
- import immer from 'immer'
5
- import Gap from '../Gap'
6
- import { PureComponent } from '../component'
7
- import { getUidStr } from '../utils/uid'
8
- import { FormError } from '../utils/errors'
9
- import { uploadClass } from './styles'
10
- import defaultRequest, { ERROR, UPLOADING } from './request'
11
- import FileInput from './FileInput'
12
- import File from './File'
13
- import ImageFile from './ImageFile'
14
- import Result from './Result'
15
- import ImageResult from './ImageResult'
16
- import { Provider } from './context'
17
- import Drop from './Drop'
18
- import attrAccept from '../utils/accept'
19
- import { isFunc } from '../utils/is'
20
- import { getLocale } from '../locale'
21
- import acceptHOC from './accept'
22
- import getDataset from '../utils/dom/getDataset'
23
-
24
- const VALIDATORITEMS = [
25
- { key: 'size', param: blob => blob.size },
26
- {
27
- key: 'ext',
28
- param: blob => {
29
- const exts = blob.name.split('.')
30
- return exts[exts.length - 1]
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
- getCanDelete(item, index) {
69
- const { canDelete } = this.props
70
- if (isFunc(canDelete)) {
71
- return canDelete(item, index)
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
- getAction(file) {
77
- const { action } = this.props
78
- if (typeof action === 'string') return action
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
- validatorHandle(error, file) {
84
- const { validatorHandle: vth } = this.props
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
- if (typeof vth === 'function') return vth(error, file)
60
+ var Upload =
61
+ /*#__PURE__*/
62
+ function (_PureComponent) {
63
+ _inheritsLoose(Upload, _PureComponent);
87
64
 
88
- return vth
89
- }
65
+ function Upload(props) {
66
+ var _this;
90
67
 
91
- bindElement(input) {
92
- this.input = input
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
- handleAddClick() {
96
- const { disabled } = this.props
97
- if (disabled) return
98
- this.input.click()
99
- }
87
+ var _proto = Upload.prototype;
100
88
 
101
- validate() {
102
- const { files } = this.state
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
- removeFile(id) {
110
- const { onErrorRemove } = this.props
111
- const file = this.state.files[id]
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
- immer(draft => {
117
- delete draft.files[id]
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
- removeValue(index) {
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
- recoverValue(index, value) {
152
- const { disabled } = this.props
153
- if (disabled) return
154
- this.props.onChange(
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
- async useValidator(blob) {
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
- if (forceAccept) {
173
- const acceptRes = attrAccept(blob, accept)
174
- if (!acceptRes) return new Error(forceAcceptErrorMsg || getLocale('invalidAccept'))
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
- while (VALIDATORITEMS[i]) {
178
- const item = VALIDATORITEMS[i]
179
- if (typeof validator[item.key] === 'function') {
180
- try {
181
- // eslint-disable-next-line no-await-in-loop
182
- await promised(validator[item.key], item.param(blob), files)
183
- } catch (err) {
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
- if (error instanceof Error) return error
187
- }
188
- i += 1
262
+ }, _callee, this, [[11, 16]]);
263
+ }));
264
+
265
+ function useValidator(_x) {
266
+ return _useValidator.apply(this, arguments);
189
267
  }
190
268
 
191
- return null
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
- async addFile(e) {
195
- const { beforeUpload, value, limit, filesFilter } = this.props
196
- // eslint-disable-next-line
197
- const files = { ...this.state.files }
198
- let finishedCode = false
199
- let fileList = e.fromDragger && e.files ? e.files : e.target.files
200
- if (filesFilter) fileList = filesFilter(Array.from(fileList)) || []
201
- const addLength = limit - value.length - Object.keys(this.state.files).length
202
- if (addLength <= 0) return
203
- const list = Array.from({ length: Math.min(fileList.length, addLength) })
204
- for (let i = 0; i < list.length; i++) {
205
- const blob = fileList[i]
206
- const id = getUidStr()
207
- const file = {
208
- name: blob.name,
209
- process: -1,
210
- status: UPLOADING,
211
- blob,
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
- files[id] = file
215
- // eslint-disable-next-line no-await-in-loop
216
- const error = await this.useValidator(blob)
217
- if (error instanceof Error) {
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
- file.message = error.message
224
- file.status = ERROR
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
- .catch(() => true)
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
- continue
243
- }
433
+ }, _callee2, this);
434
+ }));
244
435
 
245
- if (beforeUpload) {
246
- beforeUpload(blob, this.validatorHandle)
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
- uploadFile(id, file, data) {
281
- const {
282
- onSuccess,
283
- name,
284
- htmlName,
285
- cors,
286
- params,
287
- withCredentials,
288
- headers,
289
- request,
290
- onProgress,
291
- onStart,
292
- responseType,
293
- } = this.props
294
-
295
- const req = request || defaultRequest
296
- let throttle = false
297
-
298
- const options = {
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
- onStart,
309
-
310
- onProgress: (e, msg) => {
311
- const percent = typeof e.percent === 'number' ? e.percent : (e.loaded / e.total) * 100
312
- if (throttle) return
313
- throttle = true
314
- setTimeout(() => {
315
- throttle = false
316
- }, 16)
317
-
318
- if (this.state.files[id]) {
319
- this.setState(
320
- immer(draft => {
321
- draft.files[id].process = percent
322
- if (msg) draft.files[id].message = msg
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
- onSuccess,
335
-
336
- onLoad: xhr => {
490
+ onSuccess: onSuccess,
491
+ onLoad: function onLoad(xhr) {
337
492
  if (!/^2|1223/.test(xhr.status)) {
338
- this.handleError(id, xhr, file)
339
- return
493
+ _this4.handleError(id, xhr, file);
494
+
495
+ return;
340
496
  }
341
497
 
342
- let value
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
- this.setState(
352
- immer(draft => {
353
- draft.files[id].status = ERROR
354
- draft.files[id].name = file.name
355
- draft.files[id].message = value.message
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
- this.setState(
360
- immer(draft => {
361
- delete draft.files[id]
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
- return req(options)
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
- handleError(id, xhr, file) {
393
- const { onError, onHttpError } = this.props
394
-
395
- let message = xhr.statusText
396
- if (onError) message = onError(xhr, file)
397
- if (onHttpError) message = onHttpError(xhr, file) || message
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
- const dragProps = {
414
- multiple,
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
- <Drop
423
- drop={drop}
424
- accept={accept}
425
- disabled={disabled}
426
- onDrop={this.handleFileDrop}
427
- multiple={multiple || limit > 1}
428
- >
429
- <span className={uploadClass('handle', disabled && 'disabled')} onClick={this.handleAddClick}>
430
- <Provider value={dragProps}>{children}</Provider>
431
- <FileInput
432
- webkitdirectory={webkitdirectory}
433
- accept={accept}
434
- ref={this.bindElement}
435
- multiple={multiple}
436
- onChange={this.addFile}
437
- />
438
- </span>
439
- </Drop>
440
- )
441
- }
442
-
443
- render() {
444
- const {
445
- limit,
446
- value,
447
- renderResult,
448
- style,
449
- imageStyle,
450
- recoverAble,
451
- showUploadList,
452
- customResult: CustomResult,
453
- disabled,
454
- renderContent,
455
- accept,
456
- drop,
457
- leftHandler,
458
- onPreview,
459
- removeConfirm,
460
- GapProps,
461
- } = this.props
462
- const { files, recycle } = this.state
463
- const fileDrop = drop && !imageStyle
464
-
465
- const className = classnames(
466
- uploadClass('_', disabled && 'disabled', showUploadList === false && 'hide-list', fileDrop && 'file-drop'),
467
- this.props.className
468
- )
469
- const FileComponent = imageStyle ? ImageFile : File
470
- const ResultComponent = imageStyle ? ImageResult : Result
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
- <div className={className} style={style}>
475
- {this.renderHandle()}
476
- <CustomResult value={value} files={files} onValueRemove={this.removeValue} onFileRemove={this.removeFile} />
477
- </div>
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
- const Wrapper = imageStyle ? Gap : React.Fragment
482
-
483
- return (
484
- <div className={className} style={style} {...getDataset(this.props)}>
485
- <Wrapper {...(imageStyle ? GapProps : null)}>
486
- {!imageStyle && this.renderHandle()}
487
- {imageStyle && leftHandler && this.renderHandle()}
488
- {showUploadList &&
489
- value.map((v, i) => (
490
- <Drop
491
- drop={drop}
492
- multiple={false}
493
- key={i}
494
- accept={accept}
495
- dropData={i}
496
- disabled={disabled}
497
- onDrop={this.handleReplace}
498
- >
499
- <ResultComponent
500
- renderContent={renderContent}
501
- value={v}
502
- values={value}
503
- index={i}
504
- style={imageStyle}
505
- renderResult={renderResult}
506
- onRemove={this.getCanDelete(v, i) ? this.removeValue : undefined}
507
- removeConfirm={removeConfirm}
508
- onPreview={onPreview}
509
- />
510
- </Drop>
511
- ))}
512
-
513
- {showUploadList &&
514
- Object.keys(files).map(id => (
515
- <FileComponent {...files[id]} key={id} id={id} style={imageStyle} onRemove={this.removeFile} />
516
- ))}
517
-
518
- {imageStyle && !leftHandler && this.renderHandle()}
519
-
520
- {recoverAble &&
521
- recycle.map((v, i) => (
522
- <ResultComponent
523
- renderContent={renderContent}
524
- key={i}
525
- value={v}
526
- values={recycle}
527
- index={i}
528
- renderResult={renderResult}
529
- recoverAble={!!recoverAble}
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: { column: 12, row: 12 },
600
- }
601
-
602
- export default acceptHOC(Upload)
756
+ GapProps: {
757
+ column: 12,
758
+ row: 12
759
+ }
760
+ };
761
+ export default acceptHOC(Upload);