@scaleflex/widget-drag-drop 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 scaleflex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @scaleflex/widget-drag-drop
2
+
3
+ [![Plugins][plugins-image]](#plugins)
4
+ [![Website][filerobot-image]][sfx-url]
5
+ [![Version][filerobot-version]][version-url]
6
+ [![Scaleflex team][made-by-image]][sfx-url]
7
+ [![License][license-image]][license-url]
8
+ [![CodeSandbox][codeSandbox-image]][codeSandbox-url]
9
+
10
+
11
+ <div align='center'>
12
+ <img title="Scaleflex Widget logo" alt="Scaleflex Widget logo" src="https://cdn.scaleflex.com/plugins/filerobot-widget/assets/filerobot_widget_logo_with_fire.png?vh=b2ff09" width="140"/>
13
+ </div>
14
+
15
+ Drag drop container. On Drop it opens [Scaleflex Media Asset Widget](https://www.npmjs.com/package/@scaleflex/widget-core) as a modal.
16
+
17
+ ## Usage
18
+
19
+ ### NPM
20
+
21
+ ```bash
22
+ npm install --save @scaleflex/widget-drag-drop
23
+ ```
24
+ ### YARN
25
+
26
+ ```bash
27
+ yarn add @scaleflex/widget-drag-drop
28
+ ```
29
+ then
30
+
31
+ ```js
32
+ import DragDrop from '@scaleflex/widget-drag-drop'
33
+ ...
34
+ ...
35
+ ...
36
+ scaleflexWidget.use(DragDrop, propertiesObject)
37
+ ```
38
+
39
+ ### CDN
40
+
41
+ The plugin from CDN is found inside `Scaleflex` global object `Scaleflex.DragDrop`
42
+
43
+ ```js
44
+ const DragDrop = window.ScaleflexWidget.DragDrop
45
+ ...
46
+ ...
47
+ ...
48
+ scaleflexWidget.use(DragDrop, propertiesObject)
49
+ ```
50
+ <!-- TODO(docs): add properties -->
51
+
52
+
53
+ <!-- Variables -->
54
+
55
+ [npm-url]: https://www.npmjs.com/package/@scaleflex/widget-drag-drop
56
+ [license-url]: https://opensource.org/licenses/MIT
57
+ [sfx-url]: https://www.scaleflex.com/
58
+ [version-url]: https://www.npmjs.com/package/@scaleflex/widget-drag-drop
59
+ [codeSandbox-url]: https://codesandbox.io/s/filerobot-widget-v3-c5l9th
60
+
61
+
62
+ [npm-image]: https://img.shields.io/npm/v/@telus/remark-config.svg?style=for-the-badge&logo=npm
63
+ [license-image]: https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge
64
+ [made-by-image]: https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-the%20Scaleflex%20team-6986fa.svg?style=for-the-badge
65
+ [plugins-image]: https://img.shields.io/static/v1?label=Scaleflex&message=Plugins&color=yellow&style=for-the-badge
66
+ [filerobot-image]: https://img.shields.io/static/v1?label=Scaleflex&message=website&color=orange&style=for-the-badge
67
+ [filerobot-version]: https://img.shields.io/npm/v/@scaleflex/widget-drag-drop?label=Version&style=for-the-badge&logo=npm
68
+ [codeSandbox-image]: https://img.shields.io/badge/CodeSandbox-black?style=for-the-badge&logo=CodeSandbox
package/dist/style.css ADDED
@@ -0,0 +1,67 @@
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
+ .filerobot-DragDrop-container:hover, .filerobot-DragDrop-container:active {
12
+ background-color: #F3F7FA; }
13
+ .filerobot-DragDrop-container::-moz-focus-inner {
14
+ border: 0; }
15
+
16
+ .filerobot-DragDrop-inner {
17
+ margin: 0;
18
+ text-align: center;
19
+ line-height: 1.4; }
20
+
21
+ .filerobot-DragDrop-arrow {
22
+ width: 60px;
23
+ height: 60px;
24
+ fill: #e0e0e0;
25
+ margin-bottom: 17px; }
26
+
27
+ .filerobot-DragDrop--isDragDropSupported {
28
+ border: 1px dashed #DFE7ED; }
29
+
30
+ .filerobot-DragDrop--isDraggingOver {
31
+ border: 1px dashed #5282DB;
32
+ background: #F3F7FA; }
33
+ .filerobot-DragDrop--isDraggingOver .filerobot-DragDrop-arrow {
34
+ fill: #939393; }
35
+
36
+ .filerobot-DragDrop-label {
37
+ display: block;
38
+ font-size: 14px;
39
+ line-height: 20px;
40
+ margin-bottom: 5px;
41
+ font-weight: 400;
42
+ color: #768A9F; }
43
+ @media only screen and (min-width: 1601px) {
44
+ .filerobot-DragDrop-label {
45
+ font-size: 16px;
46
+ line-height: 22px; } }
47
+
48
+ .filerobot-DragDrop-title {
49
+ display: block;
50
+ font-size: 24px;
51
+ line-height: 28px;
52
+ margin-bottom: 16px; }
53
+ @media only screen and (min-width: 1601px) {
54
+ .filerobot-DragDrop-title {
55
+ font-size: 32px;
56
+ line-height: 36px;
57
+ margin-bottom: 28px; } }
58
+ .filerobot-DragDrop-title span {
59
+ color: #6879EB; }
60
+
61
+ .filerobot-DragDrop-browse {
62
+ color: #5282DB;
63
+ cursor: pointer; }
64
+
65
+ .filerobot-DragDrop-note {
66
+ font-size: 0.8em;
67
+ color: #adadad; }
@@ -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/lib/style.scss ADDED
@@ -0,0 +1,90 @@
1
+ // packages/@scaleflex/widget-drag-drop/src/index.jsx
2
+ @import '@scaleflex/widget-core/lib/_utils.scss';
3
+ @import '@scaleflex/widget-core/lib/_variables.scss';
4
+
5
+ .filerobot-DragDrop-container {
6
+ display: flex;
7
+ align-items: center;
8
+ justify-content: center;
9
+ border-radius: 4px;
10
+ background-color: $background-light-hover;
11
+ cursor: pointer;
12
+ font-family: $font-family-base;
13
+ max-width: 100%;
14
+
15
+ &:hover, &:active {
16
+ background-color: $background-light-active;
17
+ }
18
+
19
+ // firefox fix: removes thin dotted outline
20
+ &::-moz-focus-inner {
21
+ border: 0;
22
+ }
23
+ }
24
+
25
+ .filerobot-DragDrop-inner {
26
+ margin: 0;
27
+ text-align: center;
28
+ line-height: 1.4;
29
+ }
30
+
31
+ .filerobot-DragDrop-arrow {
32
+ width: 60px;
33
+ height: 60px;
34
+ fill: lighten($gray-500, 30%);
35
+ margin-bottom: 17px;
36
+ }
37
+
38
+ .filerobot-DragDrop--isDragDropSupported {
39
+ border: 1px dashed $border;
40
+ }
41
+
42
+ .filerobot-DragDrop--isDraggingOver {
43
+ border: 1px dashed $blue;
44
+ background: $background-light-active;
45
+
46
+ .filerobot-DragDrop-arrow {
47
+ fill: $gray-500;
48
+ }
49
+ }
50
+
51
+ .filerobot-DragDrop-label {
52
+ display: block;
53
+ font-size: 14px;
54
+ line-height: 20px;
55
+ margin-bottom: 5px;
56
+ font-weight: 400;
57
+ color: #768A9F;
58
+
59
+ @media #{$screen-xxl} {
60
+ font-size: 16px;
61
+ line-height: 22px;
62
+ }
63
+ }
64
+
65
+ .filerobot-DragDrop-title {
66
+ display: block;
67
+ font-size: 24px;
68
+ line-height: 28px;
69
+ margin-bottom: 16px;
70
+
71
+ @media #{$screen-xxl} {
72
+ font-size: 32px;
73
+ line-height: 36px;
74
+ margin-bottom: 28px;
75
+ }
76
+
77
+ span {
78
+ color: #6879EB;
79
+ }
80
+ }
81
+
82
+ .filerobot-DragDrop-browse {
83
+ color: $blue;
84
+ cursor: pointer;
85
+ }
86
+
87
+ .filerobot-DragDrop-note {
88
+ font-size: 0.8em;
89
+ color: lighten($gray-500, 10%);
90
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@scaleflex/widget-drag-drop",
3
+ "description": "Droppable zone UI for Filrobot filerobot. Drag and drop files into it to upload.",
4
+ "version": "0.0.1",
5
+ "license": "MIT",
6
+ "main": "lib/index.js",
7
+ "style": "dist/style.min.css",
8
+ "types": "types/index.d.ts",
9
+ "files": [
10
+ "/dist",
11
+ "/lib",
12
+ "/types"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "dependencies": {
18
+ "@scaleflex/icons": "^3.0.0-beta.11",
19
+ "@scaleflex/ui": "^3.0.0-beta.11",
20
+ "@scaleflex/widget-utils": "^0.0.1"
21
+ },
22
+ "devDependencies": {
23
+ "react": "^19.0.0",
24
+ "react-dom": "^19.0.0"
25
+ },
26
+ "peerDependencies": {
27
+ "@reduxjs/toolkit": "^1.9.5",
28
+ "@scaleflex/widget-core": "^0.0.0",
29
+ "react": ">=19.0.0",
30
+ "react-dom": ">=19.0.0",
31
+ "react-redux": "^8.1.1"
32
+ },
33
+ "gitHead": "64ea82e745b7deda36d6794863350e6671e9010d"
34
+ }
@@ -0,0 +1,22 @@
1
+ import Filerobot = require("@scaleflex/widget-core");
2
+ import DragDropLocale = require("./generatedLocale");
3
+
4
+ declare module DragDrop {
5
+ interface DragDropOptions extends Filerobot.PluginOptions {
6
+ replaceTargetContent?: boolean;
7
+ target?: Filerobot.PluginTarget;
8
+ inputName?: string;
9
+ width?: string | number;
10
+ height?: string | number;
11
+ note?: string;
12
+ hint?: string;
13
+ locale?: DragDropLocale;
14
+ labelSize?: number | string;
15
+ hideNote?: boolean;
16
+ iconSize?: number | string;
17
+ }
18
+ }
19
+
20
+ declare class DragDrop extends Filerobot.Plugin<DragDrop.DragDropOptions> {}
21
+
22
+ export = DragDrop;