1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
8 |
|
9 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
10 |
|
11 | var _templateObject = _taggedTemplateLiteral(['\n color: ', ';\n font-family: ', '\n font-weight: 300;\n margin: 0.5em 0;\n'], ['\n color: ', ';\n font-family: ', '\n font-weight: 300;\n margin: 0.5em 0;\n']),
|
12 | _templateObject2 = _taggedTemplateLiteral(['\n margin: 0.75em 0 1.25em 0;\n'], ['\n margin: 0.75em 0 1.25em 0;\n']);
|
13 |
|
14 | var _head = require('lodash/head');
|
15 |
|
16 | var _head2 = _interopRequireDefault(_head);
|
17 |
|
18 | var _isObject = require('lodash/isObject');
|
19 |
|
20 | var _isObject2 = _interopRequireDefault(_isObject);
|
21 |
|
22 | var _styledComponents = require('styled-components');
|
23 |
|
24 | var _styledComponents2 = _interopRequireDefault(_styledComponents);
|
25 |
|
26 | var _react = require('react');
|
27 |
|
28 | var _react2 = _interopRequireDefault(_react);
|
29 |
|
30 | var _dropzone = require('@scrnhq/eurovision-elements/dropzone');
|
31 |
|
32 | var _dropzone2 = _interopRequireDefault(_dropzone);
|
33 |
|
34 | var _fileList = require('./file-list');
|
35 |
|
36 | var _fileList2 = _interopRequireDefault(_fileList);
|
37 |
|
38 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
39 |
|
40 | function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
41 |
|
42 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
43 |
|
44 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
45 |
|
46 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
47 |
|
48 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
49 |
|
50 | function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
51 |
|
52 | var ErrorMessage = _styledComponents2.default.div(_templateObject, function (props) {
|
53 | return props.theme.warning;
|
54 | }, function (props) {
|
55 | return props.theme.fontBase;
|
56 | });
|
57 |
|
58 | var FormDropzone = function (_Component) {
|
59 | _inherits(FormDropzone, _Component);
|
60 |
|
61 | function FormDropzone() {
|
62 | var _ref;
|
63 |
|
64 | var _temp, _this, _ret;
|
65 |
|
66 | _classCallCheck(this, FormDropzone);
|
67 |
|
68 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
69 | args[_key] = arguments[_key];
|
70 | }
|
71 |
|
72 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = FormDropzone.__proto__ || Object.getPrototypeOf(FormDropzone)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
73 | fileList: _this.props.multiple ? [] : null
|
74 | }, _this.onDrop = function (files) {
|
75 | var fileList = _this.props.multiple ? [].concat(_toConsumableArray(_this.state.fileList), _toConsumableArray(files)) : (0, _head2.default)(files) || null;
|
76 |
|
77 | _this.updateFileList(fileList);
|
78 | }, _this.onDelete = function (fileToDelete) {
|
79 | var fileList = _this.props.multiple ? _this.state.fileList.filter(function (file) {
|
80 | return file !== fileToDelete;
|
81 | }) : null;
|
82 |
|
83 | _this.updateFileList(fileList);
|
84 | }, _temp), _possibleConstructorReturn(_this, _ret);
|
85 | }
|
86 |
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | _createClass(FormDropzone, [{
|
109 | key: 'componentWillMount',
|
110 |
|
111 |
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 | value: function componentWillMount() {
|
118 | var value = this.props.input.value;
|
119 |
|
120 | if ((0, _isObject2.default)(value) && value.__typename === 'Asset') {
|
121 | this.setState({
|
122 | fileList: [{
|
123 | type: value.mimeType,
|
124 | preview: value.path
|
125 | }]
|
126 | });
|
127 | }
|
128 | }
|
129 |
|
130 | |
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | }, {
|
146 | key: 'updateFileList',
|
147 |
|
148 |
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 | value: function updateFileList(fileList) {
|
155 | this.setState({ fileList: fileList });
|
156 | this.props.input.onChange(this.props.multiple ? fileList.map(function (file) {
|
157 | return { file: file };
|
158 | }) : { file: fileList });
|
159 | }
|
160 |
|
161 | |
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 | }, {
|
168 | key: 'render',
|
169 | value: function render() {
|
170 | var _props = this.props,
|
171 | input = _props.input,
|
172 | meta = _props.meta,
|
173 | className = _props.className,
|
174 | other = _objectWithoutProperties(_props, ['input', 'meta', 'className']);
|
175 |
|
176 | return _react2.default.createElement(
|
177 | 'div',
|
178 | { className: className },
|
179 | meta.touched && meta.error && _react2.default.createElement(
|
180 | ErrorMessage,
|
181 | null,
|
182 | meta.error.file ? meta.error.file[0] : meta.error[0]
|
183 | ),
|
184 | _react2.default.createElement(_fileList2.default, { files: this.state.fileList, onDelete: this.onDelete }),
|
185 | _react2.default.createElement(_dropzone2.default, _extends({}, input, other, {
|
186 | onChange: function onChange() {},
|
187 | onDrop: this.onDrop
|
188 | }))
|
189 | );
|
190 | }
|
191 | }]);
|
192 |
|
193 | return FormDropzone;
|
194 | }(_react.Component);
|
195 |
|
196 | FormDropzone.propTypes = {
|
197 | multiple: _react.PropTypes.bool,
|
198 | className: _react.PropTypes.string,
|
199 | meta: _react.PropTypes.shape({
|
200 | touched: _react.PropTypes.bool,
|
201 | error: _react.PropTypes.oneOfType([_react.PropTypes.object, _react.PropTypes.array])
|
202 | }).isRequired,
|
203 | input: _react.PropTypes.shape({
|
204 | onChange: _react.PropTypes.func,
|
205 | value: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.object, _react.PropTypes.array]),
|
206 | name: _react.PropTypes.string.isRequired
|
207 | }).isRequired
|
208 | };
|
209 | FormDropzone.defaultProps = {
|
210 | multiple: false
|
211 | };
|
212 | exports.default = (0, _styledComponents2.default)(FormDropzone)(_templateObject2); |
\ | No newline at end of file |