@scaleflex/widget-attach-dnd 4.4.0 → 4.5.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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
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.1](https://code.scaleflex.cloud/scaleflex/widget/compare/v4.5.0...v4.5.1) (2025-10-14)
7
+
8
+ **Note:** Version bump only for package @scaleflex/widget-attach-dnd
9
+
10
+
11
+
12
+
13
+
14
+ # [4.5.0](https://code.scaleflex.cloud/scaleflex/widget/compare/v4.4.0...v4.5.0) (2025-10-08)
15
+
16
+ **Note:** Version bump only for package @scaleflex/widget-attach-dnd
17
+
18
+
19
+
20
+
21
+
6
22
  # [4.4.0](https://code.scaleflex.cloud/scaleflex/widget/compare/v4.1.0...v4.4.0) (2025-10-07)
7
23
 
8
24
  **Note:** Version bump only for package @scaleflex/widget-attach-dnd
package/lib/index.js ADDED
@@ -0,0 +1,209 @@
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 _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
5
+ 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); } }
6
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
7
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
+ 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); }
9
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
10
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
11
+ function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
12
+ function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); }
13
+ function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); 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
+ 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; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
+ 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); }
20
+ import { createElement } from 'react';
21
+ import { createRoot } from 'react-dom/client';
22
+ import { Plugin } from '@scaleflex/widget-core';
23
+ import Explorer from '@scaleflex/widget-explorer';
24
+ import isDragDropSupported from '@scaleflex/widget-utils/lib/isDragDropSupported';
25
+ import getDroppedFiles from '@scaleflex/widget-utils/lib/getDroppedFiles';
26
+ import findDOMElement from '@scaleflex/widget-utils/lib/findDOMElement';
27
+ import { DropFilesWindow } from '@scaleflex/widget-common';
28
+ import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
29
+ // TODO: find a way to show version of the current plugin
30
+ // why solution below isn't good?
31
+ // first import doesn't work with webpack 5 as it was deprecated
32
+ // second import fixes webpack 5 issue as it was mentioned in their docs
33
+ // but it exposes our package.json to the client and it is mentioned as security rist in mutiple places
34
+ // https://github.com/axelpale/genversion
35
+ // https://stackoverflow.com/questions/64993118/error-should-not-import-the-named-export-version-imported-as-version
36
+ // https://stackoverflow.com/questions/9153571/is-there-a-way-to-get-version-from-package-json-in-nodejs-code/10855054#10855054
37
+ // import { version } from '../package.json'
38
+ // import packageInfo from '../package.json'
39
+ var AttachDragAndDrop = /*#__PURE__*/function (_Plugin) {
40
+ // static VERSION = packageInfo.version
41
+
42
+ function AttachDragAndDrop(filerobot) {
43
+ var _this;
44
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
45
+ _classCallCheck(this, AttachDragAndDrop);
46
+ _this = _callSuper(this, AttachDragAndDrop, [filerobot, opts]);
47
+ _defineProperty(_this, "addFiles", function (files) {
48
+ var descriptors = files.map(function (file) {
49
+ return {
50
+ source: _this.id,
51
+ name: file.name,
52
+ type: file.type,
53
+ data: file,
54
+ meta: {
55
+ relativePath: file.relativePath || null
56
+ }
57
+ };
58
+ });
59
+ try {
60
+ _this.filerobot.addFiles(descriptors);
61
+ } catch (err) {
62
+ _this.filerobot.info(err, 'warning');
63
+ _this.filerobot.log(err);
64
+ }
65
+ });
66
+ _defineProperty(_this, "handleDragEnter", function (event) {
67
+ event.preventDefault();
68
+ event.stopPropagation();
69
+ if (_this.dropHintElement) {
70
+ _this.dropHintElement.style.visibility = 'visible';
71
+ _this._oldTargetPosition = _this.targetElement.style.position || 'initial';
72
+ _this._oldTargetMinHeight = _this.targetElement.style.minHeight || 'initial';
73
+ _this.targetElement.style.position = 'relative';
74
+ _this.targetElement.style.minHeight = '150px';
75
+ }
76
+ _this.targetElement.classList.add('filerobot-common-DropFilesTarget');
77
+ _this._isDragging = true;
78
+ });
79
+ _defineProperty(_this, "handleDragOver", function (event) {
80
+ event.preventDefault();
81
+ event.stopPropagation();
82
+ event.dataTransfer.dropEffect = 'copy';
83
+ });
84
+ _defineProperty(_this, "endDragging", function () {
85
+ if (_this.dropHintElement) {
86
+ _this.dropHintElement.style.visibility = 'hidden';
87
+ _this.targetElement.style.position = _this._oldTargetPosition;
88
+ _this.targetElement.style.minHeight = _this._oldTargetMinHeight;
89
+ }
90
+ _this.targetElement.classList.remove('filerobot-common-DropFilesTarget');
91
+ _this._isDragging = false;
92
+ });
93
+ _defineProperty(_this, "handleDrop", function (event) {
94
+ event.preventDefault();
95
+ event.stopPropagation();
96
+
97
+ // Remove dragover class
98
+ _this.endDragging();
99
+ if (_this.explorerPlugin && !_this.explorerPlugin.opts.inline) {
100
+ _this.explorerPlugin.openModal();
101
+ }
102
+
103
+ // Adding the dropped files
104
+ _this.filerobot.log('[AttachDragAndDrop] Files dropped.');
105
+ var logDropError = function logDropError(error) {
106
+ _this.filerobot.info(error, 'warning');
107
+ _this.filerobot.log(error, 'error');
108
+ };
109
+ getDroppedFiles(event.dataTransfer, {
110
+ logDropError: logDropError
111
+ }).then(function (files) {
112
+ return _this.addFiles(files);
113
+ });
114
+ });
115
+ _defineProperty(_this, "handleDragLeave", function (event) {
116
+ if (_this._isDragging) {
117
+ event.preventDefault();
118
+ _this.endDragging();
119
+ }
120
+ });
121
+ _defineProperty(_this, "handleMouseEnter", function (event) {
122
+ if (_this._isDragging) {
123
+ event.preventDefault();
124
+ _this.endDragging();
125
+ }
126
+ });
127
+ _defineProperty(_this, "addDropHintWindow", function () {
128
+ var newElement = document.createElement('div');
129
+ _this.targetElement.appendChild(newElement);
130
+ var style = {};
131
+ if (_this.opts.fixedDropHint) {
132
+ style.position = 'fixed';
133
+ }
134
+ var DropFilesWindowElem = /*#__PURE__*/createElement(DropFilesWindow, {
135
+ i18n: _this.filerobot.i18n,
136
+ style: style,
137
+ onMount: function onMount() {
138
+ _this.dropHintElement = newElement.lastElementChild;
139
+ }
140
+ });
141
+ _this.root = createRoot(newElement);
142
+ _this.root.render(DropFilesWindowElem);
143
+ });
144
+ _defineProperty(_this, "attachEventsToTargetElement", function () {
145
+ if (!_this.opts.noDropHint) {
146
+ _this.addDropHintWindow();
147
+ }
148
+ document.addEventListener('mouseenter', _this.handleMouseEnter);
149
+ _this.targetElement.addEventListener('dragenter', _this.handleDragEnter);
150
+ _this.targetElement.addEventListener('dragover', _this.handleDragOver);
151
+ _this.targetElement.addEventListener('drop', _this.handleDrop);
152
+ _this.targetElement.addEventListener('dragleave', _this.handleDragLeave);
153
+ });
154
+ _defineProperty(_this, "detachEventsFromTargetElement", function () {
155
+ document.removeEventListener('mouseenter', _this.handleMouseEnter);
156
+ _this.targetElement.removeEventListener('dragenter', _this.handleDragEnter);
157
+ _this.targetElement.removeEventListener('dragover', _this.handleDragOver);
158
+ _this.targetElement.removeEventListener('drop', _this.handleDrop);
159
+ _this.targetElement.removeEventListener('dragleave', _this.handleDragLeave);
160
+ });
161
+ _this.type = 'acquirer';
162
+ _this.id = PLUGINS_IDS.ATTACH_DND;
163
+ _this.invisible = true;
164
+ _this.title = 'Attach Drag & Drop';
165
+ var defaultOptions = {
166
+ target: document.body,
167
+ fixedDropHint: false,
168
+ noDropHint: false
169
+ };
170
+ _this.opts = _objectSpread(_objectSpread({}, defaultOptions), opts);
171
+ _this.targetElement = findDOMElement(_this.opts.target);
172
+ _this._isDragging = false;
173
+
174
+ // Check for browser drag & drop support
175
+ _this.isDragDropSupported = isDragDropSupported(_this.targetElement);
176
+ return _this;
177
+ }
178
+ _inherits(AttachDragAndDrop, _Plugin);
179
+ return _createClass(AttachDragAndDrop, [{
180
+ key: "setOptions",
181
+ value: function setOptions(newOpts) {
182
+ _superPropGet(AttachDragAndDrop, "setOptions", this, 3)([newOpts]);
183
+ }
184
+ }, {
185
+ key: "install",
186
+ value: function install() {
187
+ if (Explorer) {
188
+ this.mount(Explorer, this);
189
+ this.explorerPlugin = this.filerobot.getPlugin(PLUGINS_IDS.EXPLORER);
190
+ }
191
+ }
192
+ }, {
193
+ key: "onMount",
194
+ value: function onMount() {
195
+ if (this.isDragDropSupported) {
196
+ this.attachEventsToTargetElement();
197
+ } else {
198
+ console.warn('The browser/provided element doesn\'t support drag & drop.');
199
+ }
200
+ }
201
+ }, {
202
+ key: "uninstall",
203
+ value: function uninstall() {
204
+ this.detachEventsFromTargetElement();
205
+ this.unmount();
206
+ }
207
+ }]);
208
+ }(Plugin);
209
+ export default AttachDragAndDrop;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleflex/widget-attach-dnd",
3
- "version": "4.4.0",
3
+ "version": "4.5.1",
4
4
  "description": "Attaches drag & drop zone to the specified HTML target, so any file dropped in that target would be uploaded.",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -12,7 +12,7 @@
12
12
  "access": "public"
13
13
  },
14
14
  "dependencies": {
15
- "@scaleflex/widget-utils": "^4.4.0"
15
+ "@scaleflex/widget-utils": "^4.5.1"
16
16
  },
17
17
  "devDependencies": {
18
18
  "react": "^19.0.0",
@@ -25,5 +25,5 @@
25
25
  "react-dom": ">=19.0.0"
26
26
  },
27
27
  "license": "MIT",
28
- "gitHead": "04b8ec545c4f10be89f5a44eed954acf8433360c"
28
+ "gitHead": "b211f9961ad30d3eaa01138f34e190ad5d38fb91"
29
29
  }