1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = void 0;
|
7 |
|
8 | var _react = _interopRequireWildcard(require("react"));
|
9 |
|
10 | var _CloudUpload = _interopRequireDefault(require("@material-ui/icons/CloudUpload"));
|
11 |
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
13 |
|
14 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
15 |
|
16 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17 |
|
18 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
19 |
|
20 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
21 |
|
22 | 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); } }
|
23 |
|
24 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
25 |
|
26 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
27 |
|
28 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
29 |
|
30 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
31 |
|
32 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
33 |
|
34 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
35 |
|
36 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
37 |
|
38 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
39 |
|
40 | var Dropzone = function (_Component) {
|
41 | _inherits(Dropzone, _Component);
|
42 |
|
43 | var _super = _createSuper(Dropzone);
|
44 |
|
45 | function Dropzone(props) {
|
46 | var _this;
|
47 |
|
48 | _classCallCheck(this, Dropzone);
|
49 |
|
50 | _this = _super.call(this, props);
|
51 | _this.state = {
|
52 | hightlight: false
|
53 | };
|
54 | _this.fileInputRef = _react["default"].createRef();
|
55 | _this.openFileDialog = _this.openFileDialog.bind(_assertThisInitialized(_this));
|
56 | _this.onFilesAdded = _this.onFilesAdded.bind(_assertThisInitialized(_this));
|
57 | _this.onDragOver = _this.onDragOver.bind(_assertThisInitialized(_this));
|
58 | _this.onDragLeave = _this.onDragLeave.bind(_assertThisInitialized(_this));
|
59 | _this.onDrop = _this.onDrop.bind(_assertThisInitialized(_this));
|
60 | _this.strings = {
|
61 | DROP_TEXT: "Dosya Yükle"
|
62 | };
|
63 |
|
64 | if (props.locale == "tr") {
|
65 | _this.strings = {
|
66 | DROP_TEXT: "Dosya Yükle"
|
67 | };
|
68 | }
|
69 |
|
70 | return _this;
|
71 | }
|
72 |
|
73 | _createClass(Dropzone, [{
|
74 | key: "openFileDialog",
|
75 | value: function openFileDialog() {
|
76 | if (this.props.disabled) return;
|
77 | this.fileInputRef.current.click();
|
78 | }
|
79 | }, {
|
80 | key: "onFilesAdded",
|
81 | value: function onFilesAdded(evt) {
|
82 | if (this.props.disabled) return;
|
83 | var files = evt.target.files;
|
84 |
|
85 | if (this.props.onFilesAdded) {
|
86 | var array = this.fileListToArray(files);
|
87 | this.props.onFilesAdded(array);
|
88 | this.fileInputRef.current.value = "";
|
89 | }
|
90 | }
|
91 | }, {
|
92 | key: "onDragOver",
|
93 | value: function onDragOver(event) {
|
94 | event.preventDefault();
|
95 | if (this.props.disabed) return;
|
96 | this.setState({
|
97 | hightlight: true
|
98 | });
|
99 | }
|
100 | }, {
|
101 | key: "onDragLeave",
|
102 | value: function onDragLeave(event) {
|
103 | this.setState({
|
104 | hightlight: false
|
105 | });
|
106 | }
|
107 | }, {
|
108 | key: "onDrop",
|
109 | value: function onDrop(event) {
|
110 | event.preventDefault();
|
111 | if (this.props.disabed) return;
|
112 | var files = event.dataTransfer.files;
|
113 |
|
114 | if (this.props.onFilesAdded) {
|
115 | var array = this.fileListToArray(files);
|
116 | this.props.onFilesAdded(array);
|
117 | }
|
118 |
|
119 | this.setState({
|
120 | hightlight: false
|
121 | });
|
122 | }
|
123 | }, {
|
124 | key: "fileListToArray",
|
125 | value: function fileListToArray(list) {
|
126 | var array = [];
|
127 |
|
128 | for (var i = 0; i < list.length; i++) {
|
129 | array.push({
|
130 | data: list.item(i),
|
131 | status: "unLoaded"
|
132 | });
|
133 | }
|
134 |
|
135 | return array;
|
136 | }
|
137 | }, {
|
138 | key: "render",
|
139 | value: function render() {
|
140 | var dropzoneDivStyle = {
|
141 | height: "250px",
|
142 | width: "150px",
|
143 | "background-color": "#fff",
|
144 | border: "2px dashed rgb(187, 186, 186)",
|
145 |
|
146 | display: "flex",
|
147 | "align-items": "center",
|
148 | "justify-content": "center",
|
149 | "flex-direction": "column",
|
150 | "font-size": "16px",
|
151 | "margin-top": "33%"
|
152 | };
|
153 |
|
154 | if (this.state.hightlight) {
|
155 | dropzoneDivStyle["background-color"] = "rgb(188, 185, 236)";
|
156 | }
|
157 |
|
158 | if (this.props.disabled) {
|
159 | dropzoneDivStyle["cursor"] = "default";
|
160 | } else {
|
161 | dropzoneDivStyle["cursor"] = "pointer";
|
162 | }
|
163 |
|
164 | return _react["default"].createElement("div", {
|
165 | style: dropzoneDivStyle,
|
166 | onDragOver: this.onDragOver,
|
167 | onDragLeave: this.onDragLeave,
|
168 | onDrop: this.onDrop,
|
169 | onClick: this.openFileDialog
|
170 | }, _react["default"].createElement("input", {
|
171 | ref: this.fileInputRef,
|
172 | style: {
|
173 | display: "none"
|
174 | },
|
175 | type: "file",
|
176 | multiple: true,
|
177 | onChange: this.onFilesAdded
|
178 | }), _react["default"].createElement(_CloudUpload["default"], null), _react["default"].createElement("span", null, this.strings["DROP_TEXT"]));
|
179 | }
|
180 | }]);
|
181 |
|
182 | return Dropzone;
|
183 | }(_react.Component);
|
184 |
|
185 | var _default = Dropzone;
|
186 | exports["default"] = _default; |
\ | No newline at end of file |