@scaleflex/widget-drag-drop 4.4.0 → 4.5.0
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/CHANGELOG.md +8 -0
- package/dist/style.css +84 -0
- package/dist/style.min.css +1 -0
- package/lib/DragDropArea.js +70 -0
- package/lib/common.slice.js +28 -0
- package/lib/defaultLocale.js +9 -0
- package/lib/index.js +217 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.5.0](https://code.scaleflex.cloud/scaleflex/widget/compare/v4.4.0...v4.5.0) (2025-10-08)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @scaleflex/widget-drag-drop
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [4.4.0](https://code.scaleflex.cloud/scaleflex/widget/compare/v4.1.0...v4.4.0) (2025-10-07)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @scaleflex/widget-drag-drop
|
package/dist/style.css
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap");
|
|
2
|
+
.filerobot-DragDrop-container {
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
justify-content: center;
|
|
6
|
+
border-radius: 4px;
|
|
7
|
+
background-color: #F9FBFC;
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
font-family: "Roboto", sans-serif, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
|
10
|
+
max-width: 100%;
|
|
11
|
+
}
|
|
12
|
+
.filerobot-DragDrop-container:hover, .filerobot-DragDrop-container:active {
|
|
13
|
+
background-color: #F3F7FA;
|
|
14
|
+
}
|
|
15
|
+
.filerobot-DragDrop-container::-moz-focus-inner {
|
|
16
|
+
border: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.filerobot-DragDrop-inner {
|
|
20
|
+
margin: 0;
|
|
21
|
+
text-align: center;
|
|
22
|
+
line-height: 1.4;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.filerobot-DragDrop-arrow {
|
|
26
|
+
width: 60px;
|
|
27
|
+
height: 60px;
|
|
28
|
+
fill: rgb(223.5, 223.5, 223.5);
|
|
29
|
+
margin-bottom: 17px;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.filerobot-DragDrop--isDragDropSupported {
|
|
33
|
+
border: 1px dashed #DFE7ED;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.filerobot-DragDrop--isDraggingOver {
|
|
37
|
+
border: 1px dashed #5282DB;
|
|
38
|
+
background: #F3F7FA;
|
|
39
|
+
}
|
|
40
|
+
.filerobot-DragDrop--isDraggingOver .filerobot-DragDrop-arrow {
|
|
41
|
+
fill: #939393;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.filerobot-DragDrop-label {
|
|
45
|
+
display: block;
|
|
46
|
+
font-size: 14px;
|
|
47
|
+
line-height: 20px;
|
|
48
|
+
margin-bottom: 5px;
|
|
49
|
+
font-weight: 400;
|
|
50
|
+
color: #768A9F;
|
|
51
|
+
}
|
|
52
|
+
@media only screen and (min-width: 1601px) {
|
|
53
|
+
.filerobot-DragDrop-label {
|
|
54
|
+
font-size: 16px;
|
|
55
|
+
line-height: 22px;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.filerobot-DragDrop-title {
|
|
60
|
+
display: block;
|
|
61
|
+
font-size: 24px;
|
|
62
|
+
line-height: 28px;
|
|
63
|
+
margin-bottom: 16px;
|
|
64
|
+
}
|
|
65
|
+
@media only screen and (min-width: 1601px) {
|
|
66
|
+
.filerobot-DragDrop-title {
|
|
67
|
+
font-size: 32px;
|
|
68
|
+
line-height: 36px;
|
|
69
|
+
margin-bottom: 28px;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
.filerobot-DragDrop-title span {
|
|
73
|
+
color: #6879EB;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.filerobot-DragDrop-browse {
|
|
77
|
+
color: #5282DB;
|
|
78
|
+
cursor: pointer;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.filerobot-DragDrop-note {
|
|
82
|
+
font-size: 0.8em;
|
|
83
|
+
color: rgb(172.5, 172.5, 172.5);
|
|
84
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap");.filerobot-DragDrop-container{align-items:center;background-color:#f9fbfc;border-radius:4px;cursor:pointer;display:flex;font-family:Roboto,sans-serif,Helvetica,Arial,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;justify-content:center;max-width:100%}.filerobot-DragDrop-container:active,.filerobot-DragDrop-container:hover{background-color:#f3f7fa}.filerobot-DragDrop-container::-moz-focus-inner{border:0}.filerobot-DragDrop-inner{line-height:1.4;margin:0;text-align:center}.filerobot-DragDrop-arrow{height:60px;width:60px;fill:#e0e0e0;margin-bottom:17px}.filerobot-DragDrop--isDragDropSupported{border:1px dashed #dfe7ed}.filerobot-DragDrop--isDraggingOver{background:#f3f7fa;border:1px dashed #5282db}.filerobot-DragDrop--isDraggingOver .filerobot-DragDrop-arrow{fill:#939393}.filerobot-DragDrop-label{color:#768a9f;display:block;font-size:14px;font-weight:400;line-height:20px;margin-bottom:5px}@media only screen and (min-width:1601px){.filerobot-DragDrop-label{font-size:16px;line-height:22px}}.filerobot-DragDrop-title{display:block;font-size:24px;line-height:28px;margin-bottom:16px}@media only screen and (min-width:1601px){.filerobot-DragDrop-title{font-size:32px;line-height:36px;margin-bottom:28px}}.filerobot-DragDrop-title span{color:#6879eb}.filerobot-DragDrop-browse{color:#5282db;cursor:pointer}.filerobot-DragDrop-note{color:#adadad;font-size:.8em}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { useSelector } from 'react-redux';
|
|
3
|
+
import { useCore, usePlugin } from '@scaleflex/widget-core/lib/hooks';
|
|
4
|
+
import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
5
|
+
import { selectIsDraggingOver } from './common.slice';
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
var DragDropArea = function DragDropArea(_ref) {
|
|
8
|
+
var isDragDropSupported = _ref.isDragDropSupported,
|
|
9
|
+
handleDragOver = _ref.handleDragOver,
|
|
10
|
+
handleDragLeave = _ref.handleDragLeave,
|
|
11
|
+
handleDrop = _ref.handleDrop,
|
|
12
|
+
onInputChange = _ref.onInputChange;
|
|
13
|
+
var _useCore = useCore(),
|
|
14
|
+
restrictions = _useCore.opts.restrictions;
|
|
15
|
+
var _usePlugin = usePlugin(PLUGINS_IDS.DRAG_DROP),
|
|
16
|
+
opts = _usePlugin.opts,
|
|
17
|
+
i18n = _usePlugin.i18n;
|
|
18
|
+
var fileInputRef = useRef();
|
|
19
|
+
var isDraggingOver = useSelector(selectIsDraggingOver);
|
|
20
|
+
var width = opts.width,
|
|
21
|
+
height = opts.height,
|
|
22
|
+
inputName = opts.inputName,
|
|
23
|
+
labelSize = opts.labelSize,
|
|
24
|
+
hideNote = opts.hideNote,
|
|
25
|
+
note = opts.note,
|
|
26
|
+
hint = opts.hint;
|
|
27
|
+
var dragDropClass = "filerobot-Root\n filerobot-u-reset\n filerobot-DragDrop-container\n ".concat(isDragDropSupported ? 'filerobot-DragDrop--isDragDropSupported' : '', "\n ").concat(isDraggingOver ? 'filerobot-DragDrop--isDraggingOver' : '', "\n ");
|
|
28
|
+
var dragDropStyle = {
|
|
29
|
+
width: width,
|
|
30
|
+
height: height
|
|
31
|
+
};
|
|
32
|
+
return /*#__PURE__*/_jsxs("button", {
|
|
33
|
+
type: "button",
|
|
34
|
+
className: dragDropClass,
|
|
35
|
+
style: dragDropStyle,
|
|
36
|
+
onDragOver: handleDragOver,
|
|
37
|
+
onDragLeave: handleDragLeave,
|
|
38
|
+
onDrop: handleDrop,
|
|
39
|
+
children: [/*#__PURE__*/_jsx("input", {
|
|
40
|
+
className: "filerobot-DragDrop-input",
|
|
41
|
+
type: "file",
|
|
42
|
+
hidden: true,
|
|
43
|
+
ref: fileInputRef,
|
|
44
|
+
name: inputName,
|
|
45
|
+
multiple: restrictions.maxNumberOfFiles !== 1,
|
|
46
|
+
accept: restrictions.allowedFileTypes,
|
|
47
|
+
onChange: onInputChange
|
|
48
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
49
|
+
className: "filerobot-DragDrop-inner",
|
|
50
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
51
|
+
className: "filerobot-DragDrop-title",
|
|
52
|
+
children: [i18n('dragDropTitle'), ' ', /*#__PURE__*/_jsxs("span", {
|
|
53
|
+
children: [i18n('dragDropBrowseLabel'), ' ']
|
|
54
|
+
}), i18n('dragDropOrLabel'), ' ', /*#__PURE__*/_jsx("span", {
|
|
55
|
+
children: i18n('dragDropImportLabel')
|
|
56
|
+
})]
|
|
57
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
58
|
+
className: "filerobot-DragDrop-label",
|
|
59
|
+
style: {
|
|
60
|
+
fontSize: labelSize
|
|
61
|
+
},
|
|
62
|
+
children: hint || i18n('dragDropHint')
|
|
63
|
+
}), !hideNote && /*#__PURE__*/_jsx("span", {
|
|
64
|
+
className: "filerobot-DragDrop-note",
|
|
65
|
+
children: note || i18n('mutualizedDragDropHereNote')
|
|
66
|
+
})]
|
|
67
|
+
})]
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
export default DragDropArea;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { createSlice } from '@reduxjs/toolkit';
|
|
8
|
+
import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
9
|
+
var initialState = {
|
|
10
|
+
isDraggingOver: false
|
|
11
|
+
};
|
|
12
|
+
var commonSlice = createSlice({
|
|
13
|
+
name: PLUGINS_IDS.DRAG_DROP,
|
|
14
|
+
initialState: initialState,
|
|
15
|
+
reducers: {
|
|
16
|
+
draggingOverUpdated: function draggingOverUpdated(state, action) {
|
|
17
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
18
|
+
isDraggingOver: action.payload
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
var draggingOverUpdated = commonSlice.actions.draggingOverUpdated;
|
|
24
|
+
export { draggingOverUpdated };
|
|
25
|
+
export var selectIsDraggingOver = function selectIsDraggingOver(state) {
|
|
26
|
+
return state[PLUGINS_IDS.DRAG_DROP].isDraggingOver;
|
|
27
|
+
};
|
|
28
|
+
export default commonSlice.reducer;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
dragDropLabel: 'Drag & Drop or click to browse',
|
|
3
|
+
dragDropHint: 'HEIC, JPEG, PNG, or WEBP, max size 5 MB',
|
|
4
|
+
dragDropTitle: 'Drop assets here, paste,',
|
|
5
|
+
dragDropBrowseLabel: 'browse',
|
|
6
|
+
dragDropOrLabel: 'or',
|
|
7
|
+
dragDropImportLabel: 'import',
|
|
8
|
+
mutualizedDragDropHereNote: 'You can drag & drop files right here'
|
|
9
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
6
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
7
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
11
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
12
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
13
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
14
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
15
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
16
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
17
|
+
import { createElement } from 'react';
|
|
18
|
+
import { Plugin } from '@scaleflex/widget-core';
|
|
19
|
+
import Translator from '@scaleflex/widget-utils/lib/Translator';
|
|
20
|
+
import toArray from '@scaleflex/widget-utils/lib/toArray';
|
|
21
|
+
import isDragDropSupported from '@scaleflex/widget-utils/lib/isDragDropSupported';
|
|
22
|
+
import getDroppedFiles from '@scaleflex/widget-utils/lib/getDroppedFiles';
|
|
23
|
+
import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
24
|
+
import defaultLocale from './defaultLocale';
|
|
25
|
+
import dragDropReducer, { draggingOverUpdated } from './common.slice';
|
|
26
|
+
import DragDropArea from './DragDropArea';
|
|
27
|
+
|
|
28
|
+
// TODO: find a way to show version of the current plugin
|
|
29
|
+
// why solution below isn't good?
|
|
30
|
+
// first import doesn't work with webpack 5 as it was deprecated
|
|
31
|
+
// second import fixes webpack 5 issue as it was mentioned in their docs
|
|
32
|
+
// but it exposes our package.json to the client and it is mentioned as security rist in mutiple places
|
|
33
|
+
// https://github.com/axelpale/genversion
|
|
34
|
+
// https://stackoverflow.com/questions/64993118/error-should-not-import-the-named-export-version-imported-as-version
|
|
35
|
+
// https://stackoverflow.com/questions/9153571/is-there-a-way-to-get-version-from-package-json-in-nodejs-code/10855054#10855054
|
|
36
|
+
// import { version } from '../package.json'
|
|
37
|
+
// import packageInfo from '../package.json'
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Drag & Drop plugin
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
var DragDrop = /*#__PURE__*/function (_Plugin) {
|
|
44
|
+
// static VERSION = packageInfo.version
|
|
45
|
+
|
|
46
|
+
function DragDrop(filerobot) {
|
|
47
|
+
var _this;
|
|
48
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
49
|
+
_classCallCheck(this, DragDrop);
|
|
50
|
+
_this = _callSuper(this, DragDrop, [filerobot, opts]);
|
|
51
|
+
_this.type = 'acquirer';
|
|
52
|
+
_this.id = PLUGINS_IDS.DRAG_DROP;
|
|
53
|
+
_this.title = 'Drag & Drop';
|
|
54
|
+
_this.invisible = true;
|
|
55
|
+
_this.defaultLocale = {
|
|
56
|
+
strings: defaultLocale
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Default options
|
|
60
|
+
var defaultOpts = {
|
|
61
|
+
target: null,
|
|
62
|
+
inputName: 'files[]',
|
|
63
|
+
width: '100%',
|
|
64
|
+
height: 'auto',
|
|
65
|
+
note: null,
|
|
66
|
+
iconSize: null,
|
|
67
|
+
labelSize: '',
|
|
68
|
+
hideNote: false,
|
|
69
|
+
hint: null
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Merge default options with the ones set by user
|
|
73
|
+
_this.opts = _objectSpread(_objectSpread({}, defaultOpts), opts);
|
|
74
|
+
|
|
75
|
+
// Check for browser dragDrop support
|
|
76
|
+
_this.isDragDropSupported = isDragDropSupported();
|
|
77
|
+
_this.removeDragOverClassTimeout = null;
|
|
78
|
+
_this.i18nInit();
|
|
79
|
+
|
|
80
|
+
// Bind `this` to class methods
|
|
81
|
+
_this.onInputChange = _this.onInputChange.bind(_this);
|
|
82
|
+
_this.handleDragOver = _this.handleDragOver.bind(_this);
|
|
83
|
+
_this.handleDragLeave = _this.handleDragLeave.bind(_this);
|
|
84
|
+
_this.handleDrop = _this.handleDrop.bind(_this);
|
|
85
|
+
_this.addFiles = _this.addFiles.bind(_this);
|
|
86
|
+
_this.render = _this.render.bind(_this);
|
|
87
|
+
return _this;
|
|
88
|
+
}
|
|
89
|
+
_inherits(DragDrop, _Plugin);
|
|
90
|
+
return _createClass(DragDrop, [{
|
|
91
|
+
key: "i18nInit",
|
|
92
|
+
value: function i18nInit() {
|
|
93
|
+
this.translator = new Translator([this.defaultLocale, this.filerobot.locale, this.opts.locale]);
|
|
94
|
+
this.i18n = this.translator.translate.bind(this.translator);
|
|
95
|
+
this.i18nArray = this.translator.translateArray.bind(this.translator);
|
|
96
|
+
}
|
|
97
|
+
}, {
|
|
98
|
+
key: "addFiles",
|
|
99
|
+
value: function addFiles(files) {
|
|
100
|
+
var _this2 = this;
|
|
101
|
+
var descriptors = files.map(function (file) {
|
|
102
|
+
return {
|
|
103
|
+
source: _this2.id,
|
|
104
|
+
name: file.name,
|
|
105
|
+
type: file.type,
|
|
106
|
+
data: file,
|
|
107
|
+
meta: {
|
|
108
|
+
// path of the file relative to the ancestor directory the user selected.
|
|
109
|
+
// e.g. 'docs/Old Prague/airbnb.pdf'
|
|
110
|
+
relativePath: file.relativePath || null
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
try {
|
|
115
|
+
this.filerobot.addFiles(descriptors);
|
|
116
|
+
} catch (err) {
|
|
117
|
+
this.filerobot.log(err);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "removeFile",
|
|
122
|
+
value: function removeFile(id) {
|
|
123
|
+
this.filerobot.removeFile(id);
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "onInputChange",
|
|
127
|
+
value: function onInputChange(event) {
|
|
128
|
+
this.filerobot.log('[DragDrop] Files selected through input');
|
|
129
|
+
var files = toArray(event.target.files);
|
|
130
|
+
this.addFiles(files);
|
|
131
|
+
|
|
132
|
+
// We clear the input after a file is selected, because otherwise
|
|
133
|
+
// change event is not fired in Chrome and Safari when a file
|
|
134
|
+
// with the same name is selected.
|
|
135
|
+
// ___Why not use value="" on <input/> instead?
|
|
136
|
+
// Because if we use that method of clearing the input,
|
|
137
|
+
// Chrome will not trigger change if we drop the same file twice (Issue #768).
|
|
138
|
+
event.target.value = null;
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
key: "handleDrop",
|
|
142
|
+
value: function handleDrop(event, dropCategory) {
|
|
143
|
+
var _this3 = this;
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
event.stopPropagation();
|
|
146
|
+
clearTimeout(this.removeDragOverClassTimeout);
|
|
147
|
+
|
|
148
|
+
// 2. Remove dragover class
|
|
149
|
+
this.dispatch(draggingOverUpdated(false));
|
|
150
|
+
|
|
151
|
+
// 3. Add all dropped files
|
|
152
|
+
this.filerobot.log('[DragDrop] Files were dropped');
|
|
153
|
+
var logDropError = function logDropError(error) {
|
|
154
|
+
_this3.filerobot.log(error, 'error');
|
|
155
|
+
};
|
|
156
|
+
getDroppedFiles(event.dataTransfer, {
|
|
157
|
+
logDropError: logDropError
|
|
158
|
+
}).then(function (files) {
|
|
159
|
+
return _this3.addFiles(files);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}, {
|
|
163
|
+
key: "handleDragOver",
|
|
164
|
+
value: function handleDragOver(event) {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
event.stopPropagation();
|
|
167
|
+
|
|
168
|
+
// 1. Add a small (+) icon on drop
|
|
169
|
+
// (and prevent browsers from interpreting this as files being moved into the browser)
|
|
170
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
171
|
+
clearTimeout(this.removeDragOverClassTimeout);
|
|
172
|
+
this.dispatch(draggingOverUpdated(true));
|
|
173
|
+
}
|
|
174
|
+
}, {
|
|
175
|
+
key: "handleDragLeave",
|
|
176
|
+
value: function handleDragLeave(event) {
|
|
177
|
+
var _this4 = this;
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
event.stopPropagation();
|
|
180
|
+
clearTimeout(this.removeDragOverClassTimeout);
|
|
181
|
+
// Timeout against flickering, this solution is taken from drag-drop library. Solution with 'pointer-events: none' didn't work across browsers.
|
|
182
|
+
this.removeDragOverClassTimeout = setTimeout(function () {
|
|
183
|
+
_this4.dispatch(draggingOverUpdated(false));
|
|
184
|
+
}, 50);
|
|
185
|
+
}
|
|
186
|
+
}, {
|
|
187
|
+
key: "getPluginReducer",
|
|
188
|
+
value: function getPluginReducer() {
|
|
189
|
+
return dragDropReducer;
|
|
190
|
+
}
|
|
191
|
+
}, {
|
|
192
|
+
key: "render",
|
|
193
|
+
value: function render() {
|
|
194
|
+
return /*#__PURE__*/createElement(DragDropArea, {
|
|
195
|
+
onInputChange: this.onInputChange,
|
|
196
|
+
handleDragOver: this.handleDragOver,
|
|
197
|
+
handleDragLeave: this.handleDragLeave,
|
|
198
|
+
handleDrop: this.handleDrop,
|
|
199
|
+
isDragDropSupported: this.isDragDropSupported
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}, {
|
|
203
|
+
key: "install",
|
|
204
|
+
value: function install() {
|
|
205
|
+
var target = this.opts.target;
|
|
206
|
+
if (target) {
|
|
207
|
+
this.mount(target, this);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}, {
|
|
211
|
+
key: "uninstall",
|
|
212
|
+
value: function uninstall() {
|
|
213
|
+
this.unmount();
|
|
214
|
+
}
|
|
215
|
+
}]);
|
|
216
|
+
}(Plugin);
|
|
217
|
+
export { DragDrop as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleflex/widget-drag-drop",
|
|
3
3
|
"description": "Droppable zone UI for Filrobot filerobot. Drag and drop files into it to upload.",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.5.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"style": "dist/style.min.css",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@scaleflex/icons": "^3.0.0-beta.11",
|
|
19
19
|
"@scaleflex/ui": "^3.0.0-beta.11",
|
|
20
|
-
"@scaleflex/widget-utils": "^4.
|
|
20
|
+
"@scaleflex/widget-utils": "^4.5.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"react": "^19.0.0",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"react-dom": ">=19.0.0",
|
|
31
31
|
"react-redux": "^8.1.1"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "df64ca68034ed6c33e123e7dfa215176aa0a1196"
|
|
34
34
|
}
|