1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 | import React from 'react';
|
7 | import ConfigProvider from '../config-provider';
|
8 | import { log } from '../util';
|
9 | import { errorCode } from './util';
|
10 | import _transform from './transform';
|
11 | import Upload from './upload';
|
12 | import List from './list';
|
13 | import Card from './card';
|
14 | import Dragger from './dragger';
|
15 | import Selecter from './runtime/selecter';
|
16 | import Uploader from './runtime/uploader';
|
17 |
|
18 | Upload.Card = ConfigProvider.config(Card, { componentName: 'Upload' });
|
19 | Upload.Dragger = ConfigProvider.config(Dragger, { componentName: 'Upload' });
|
20 | Upload.Selecter = Selecter;
|
21 | Upload.Uploader = Uploader;
|
22 | Upload.ErrorCode = errorCode;
|
23 |
|
24 |
|
25 | Upload.ImageUpload = ConfigProvider.config(Card, {
|
26 | componentName: 'Upload',
|
27 | transform: function transform(props, deprecated) {
|
28 | deprecated('Upload.ImageUpload', 'Upload.Card', 'Upload');
|
29 | var newprops = _transform(props, function () {});
|
30 | if (newprops.locale && newprops.locale.image) {
|
31 | newprops.locale.card = newprops.locale.image;
|
32 | }
|
33 |
|
34 | return newprops;
|
35 | }
|
36 | });
|
37 |
|
38 |
|
39 | Upload.DragUpload = ConfigProvider.config(Dragger, {
|
40 | componentName: 'Upload',
|
41 | transform: function transform(props, deprecated) {
|
42 | deprecated('Upload.DragUpload', 'Upload.Dragger', 'Upload');
|
43 | var newprops = _transform(props, function () {});
|
44 | if (!newprops.listType) {
|
45 | newprops.listType = 'card';
|
46 | }
|
47 |
|
48 | return newprops;
|
49 | }
|
50 | });
|
51 |
|
52 |
|
53 |
|
54 | Upload.Core = function (_React$Component) {
|
55 | _inherits(Core, _React$Component);
|
56 |
|
57 | function Core(props) {
|
58 | _classCallCheck(this, Core);
|
59 |
|
60 |
|
61 | var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
|
62 |
|
63 | _this.handleSelect = function (files) {
|
64 | _this.uploader.startUpload(files);
|
65 | };
|
66 |
|
67 | var _this$props = _this.props,
|
68 | action = _this$props.action,
|
69 | name = _this$props.name,
|
70 | method = _this$props.method,
|
71 | beforeUpload = _this$props.beforeUpload,
|
72 | onProgress = _this$props.onProgress,
|
73 | onError = _this$props.onError,
|
74 | withCredentials = _this$props.withCredentials,
|
75 | headers = _this$props.headers,
|
76 | data = _this$props.data,
|
77 | onSuccess = _this$props.onSuccess;
|
78 |
|
79 |
|
80 | _this.uploader = new Uploader({
|
81 | action: action,
|
82 | name: name,
|
83 | method: method,
|
84 | beforeUpload: beforeUpload,
|
85 | onProgress: onProgress,
|
86 | onError: onError,
|
87 | withCredentials: withCredentials,
|
88 | headers: headers,
|
89 | data: data,
|
90 | onSuccess: onSuccess
|
91 | });
|
92 | return _this;
|
93 | }
|
94 |
|
95 | Core.prototype.abort = function abort() {
|
96 | this.uploader.abort();
|
97 | };
|
98 |
|
99 | Core.prototype.render = function render() {
|
100 | log.deprecated('Upload.Core', 'Upload.Selecter and Upload.Uploader', 'Upload');
|
101 |
|
102 |
|
103 |
|
104 | var _props = this.props,
|
105 | action = _props.action,
|
106 | name = _props.name,
|
107 | method = _props.method,
|
108 | beforeUpload = _props.beforeUpload,
|
109 | onProgress = _props.onProgress,
|
110 | onError = _props.onError,
|
111 | withCredentials = _props.withCredentials,
|
112 | headers = _props.headers,
|
113 | data = _props.data,
|
114 | onSuccess = _props.onSuccess,
|
115 | others = _objectWithoutProperties(_props, ['action', 'name', 'method', 'beforeUpload', 'onProgress', 'onError', 'withCredentials', 'headers', 'data', 'onSuccess']);
|
116 |
|
117 | var props = others;
|
118 |
|
119 | return React.createElement(Selecter, _extends({}, _transform(props, function () {}), {
|
120 | onSelect: this.handleSelect
|
121 | }));
|
122 | };
|
123 |
|
124 | return Core;
|
125 | }(React.Component);
|
126 |
|
127 | Upload.List = List;
|
128 |
|
129 |
|
130 |
|
131 | Upload.CropUpload = function () {
|
132 | log.deprecated('Upload.CropUpload', '@alife/bc-next-crop-upload', 'Upload');
|
133 | return null;
|
134 | };
|
135 |
|
136 | export default ConfigProvider.config(Upload, {
|
137 | transform: _transform
|
138 | }); |
\ | No newline at end of file |