@scaleflex/widget-provider-views 4.8.6 → 4.8.7
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/dist/style.css +789 -0
- package/dist/style.min.css +1 -0
- package/lib/ProviderViews.Styled.js +22 -0
- package/lib/components/AuthView.js +35 -0
- package/lib/components/AuthView.styled.js +21 -0
- package/lib/components/Browser.js +58 -0
- package/lib/components/FolderImportProgress/FolderImportProgress.styled.js +50 -0
- package/lib/components/FolderImportProgress/index.js +50 -0
- package/lib/components/Items/AssetsSection/AssetsSectionTableHeader.js +41 -0
- package/lib/components/Items/AssetsSection/AssetsSectionTableRow.js +147 -0
- package/lib/components/Items/AssetsSection/index.js +65 -0
- package/lib/components/Items/FoldersSection/FoldersSectionTableHeader.js +41 -0
- package/lib/components/Items/FoldersSection/FoldersSectionTableRow.js +102 -0
- package/lib/components/Items/FoldersSection/index.js +64 -0
- package/lib/components/Items/Items.styled.js +156 -0
- package/lib/components/Items/List.js +96 -0
- package/lib/components/Items/index.js +172 -0
- package/lib/components/SearchProviderView/FooterActions.js +25 -0
- package/lib/components/SearchProviderView/SearchFilterInput.js +76 -0
- package/lib/components/SearchProviderView/SearchProviderBrowser.js +74 -0
- package/lib/components/SearchProviderView/SearchProviderBrowser.styled.js +65 -0
- package/lib/components/SearchProviderView/SearchProviderView.js +248 -0
- package/lib/components/SearchProviderView/index.js +1 -0
- package/lib/context/index.js +2 -0
- package/lib/hooks/useBrowserContext.js +5 -0
- package/lib/index.js +1139 -0
- package/lib/style/filerobot-ProviderBrowser-layoutType--grid.scss +233 -0
- package/lib/style/filerobot-ProviderBrowser-layoutType--list.scss +190 -0
- package/lib/style/filerobot-ProviderBrowserItem-details.scss +207 -0
- package/lib/style.scss +311 -0
- package/lib/utils/View.js +219 -0
- package/lib/utils/remoteFileObjToLocal.js +13 -0
- package/package.json +36 -36
- package/CHANGELOG.md +0 -8431
package/lib/index.js
ADDED
|
@@ -0,0 +1,1139 @@
|
|
|
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
|
+
var _excluded = ["children"];
|
|
3
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
8
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
9
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
11
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
12
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
13
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
14
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
17
|
+
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); } }
|
|
18
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
19
|
+
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; }
|
|
20
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
21
|
+
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); }
|
|
22
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
23
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
24
|
+
import { useEffect } from 'react';
|
|
25
|
+
import { LoaderView } from '@scaleflex/widget-common';
|
|
26
|
+
import generateFileId from '@scaleflex/widget-utils/lib/generateFileId';
|
|
27
|
+
import isFolder from '@scaleflex/widget-utils/lib/isFolder';
|
|
28
|
+
import { LIST_VIEW_COLS_IDS, LAYOUTS_IDS, LIST_VIEW_FOLDERS_COLS_IDS, PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
29
|
+
import { CheckBoxGroup } from '@scaleflex/ui/core';
|
|
30
|
+
import AuthView from './components/AuthView';
|
|
31
|
+
import Browser from './components/Browser';
|
|
32
|
+
import FolderImportProgress from './components/FolderImportProgress';
|
|
33
|
+
// TODO: find a way to show version of the current plugin
|
|
34
|
+
// why solution below isn't good?
|
|
35
|
+
// first import doesn't work with webpack 5 as it was deprecated
|
|
36
|
+
// second import fixes webpack 5 issue as it was mentioned in their docs
|
|
37
|
+
// but it exposes our package.json to the client and it is mentioned as security rist in mutiple places
|
|
38
|
+
// https://github.com/axelpale/genversion
|
|
39
|
+
// https://stackoverflow.com/questions/64993118/error-should-not-import-the-named-export-version-imported-as-version
|
|
40
|
+
// https://stackoverflow.com/questions/9153571/is-there-a-way-to-get-version-from-package-json-in-nodejs-code/10855054#10855054
|
|
41
|
+
// import { version } from '../package.json'
|
|
42
|
+
// import packageInfo from '../package.json'
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Array.prototype.findIndex ponyfill for old browsers.
|
|
46
|
+
*/
|
|
47
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
48
|
+
function findIndex(array, predicate) {
|
|
49
|
+
for (var i = 0; i < array.length; i++) {
|
|
50
|
+
if (predicate(array[i])) return i;
|
|
51
|
+
}
|
|
52
|
+
return -1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// location.origin does not exist in IE
|
|
56
|
+
function getOrigin() {
|
|
57
|
+
if ('origin' in location) {
|
|
58
|
+
return location.origin; // eslint-disable-line compat/compat
|
|
59
|
+
}
|
|
60
|
+
return "".concat(location.protocol, "//").concat(location.hostname).concat(location.port ? ":".concat(location.port) : '');
|
|
61
|
+
}
|
|
62
|
+
var CloseWrapper = function CloseWrapper(_ref) {
|
|
63
|
+
var children = _ref.children,
|
|
64
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
65
|
+
useEffect(function () {
|
|
66
|
+
return props.onUnmount;
|
|
67
|
+
}, []);
|
|
68
|
+
return children;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Class to easily generate generic views for Provider plugins
|
|
73
|
+
*/
|
|
74
|
+
var ProviderView = /*#__PURE__*/function () {
|
|
75
|
+
// static VERSION = packageInfo.version
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {object} plugin instance of the plugin
|
|
79
|
+
* @param {object} opts
|
|
80
|
+
*/
|
|
81
|
+
function ProviderView(plugin, opts) {
|
|
82
|
+
var _this = this;
|
|
83
|
+
_classCallCheck(this, ProviderView);
|
|
84
|
+
/**
|
|
85
|
+
* Toggles file/folder checkbox to on/off state while updating files list.
|
|
86
|
+
*
|
|
87
|
+
* Note that some extra complexity comes from supporting shift+click to
|
|
88
|
+
* toggle multiple checkboxes at once, which is done by getting all files
|
|
89
|
+
* in between last checked file and current one.
|
|
90
|
+
*/
|
|
91
|
+
_defineProperty(this, "toggleCheckbox", function (e, item) {
|
|
92
|
+
var isMultiple = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
93
|
+
e.stopPropagation();
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
e.currentTarget.focus();
|
|
96
|
+
var _this$plugin$getPlugi = _this.plugin.getPluginCommonState(),
|
|
97
|
+
folders = _this$plugin$getPlugi.folders,
|
|
98
|
+
files = _this$plugin$getPlugi.files;
|
|
99
|
+
var items = _this.filterItems(folders.concat(files));
|
|
100
|
+
var isFolderItem = isFolder(item);
|
|
101
|
+
|
|
102
|
+
// Shift-clicking selects a single consecutive list of items
|
|
103
|
+
// starting at the previous click and deselects everything else.
|
|
104
|
+
if (_this.lastCheckbox && e.shiftKey) {
|
|
105
|
+
var currentSelection;
|
|
106
|
+
var prevIndex = findIndex(items, function (i) {
|
|
107
|
+
return i.id === _this.lastCheckbox;
|
|
108
|
+
});
|
|
109
|
+
var currentIndex = findIndex(items, function (i) {
|
|
110
|
+
return i.id === item.id;
|
|
111
|
+
});
|
|
112
|
+
if (prevIndex < currentIndex) {
|
|
113
|
+
currentSelection = items.slice(prevIndex, currentIndex + 1);
|
|
114
|
+
} else {
|
|
115
|
+
currentSelection = items.slice(currentIndex, prevIndex + 1);
|
|
116
|
+
}
|
|
117
|
+
var _currentSelection$red = currentSelection.reduce(function (selections, currentItem) {
|
|
118
|
+
var key = isFolder(currentItem) ? 'selectedFolders' : 'selectedFiles';
|
|
119
|
+
return _objectSpread(_objectSpread({}, selections), {}, _defineProperty({}, key, [].concat(_toConsumableArray(selections[key]), [currentItem])));
|
|
120
|
+
}, {
|
|
121
|
+
selectedFolders: [],
|
|
122
|
+
selectedFiles: []
|
|
123
|
+
}),
|
|
124
|
+
selectedFolders = _currentSelection$red.selectedFolders,
|
|
125
|
+
selectedFiles = _currentSelection$red.selectedFiles;
|
|
126
|
+
// We need the current files & the file to be added, so that we are subtracting file of the bulk selected ones and reusing it as separate file.
|
|
127
|
+
if (_this.plugin.filerobot.isFileRestrictedToGetAdded(selectedFiles.slice(1), selectedFiles[0], false)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
var _isAllFoldersSelected = _this.checkIfAllSelected(selectedFolders, folders);
|
|
131
|
+
var _isAllFilesSelected = _this.checkIfAllSelected(selectedFiles, files);
|
|
132
|
+
_this.plugin.setPluginCommonState({
|
|
133
|
+
currentSelection: currentSelection,
|
|
134
|
+
isAllFoldersSelected: _isAllFoldersSelected,
|
|
135
|
+
isAllFilesSelected: _isAllFilesSelected
|
|
136
|
+
});
|
|
137
|
+
return currentSelection;
|
|
138
|
+
} else if (isMultiple || e.ctrlKey || e.metaKey) {
|
|
139
|
+
_this.lastCheckbox = item.id;
|
|
140
|
+
var _this$plugin$getPlugi2 = _this.plugin.getPluginCommonState(),
|
|
141
|
+
_currentSelection = _this$plugin$getPlugi2.currentSelection;
|
|
142
|
+
var updatedSelection = _this.isChecked(item) ? _currentSelection.filter(function (i) {
|
|
143
|
+
return item.id !== i.id;
|
|
144
|
+
}) : _currentSelection.concat([item]);
|
|
145
|
+
var updates = {
|
|
146
|
+
currentSelection: updatedSelection
|
|
147
|
+
};
|
|
148
|
+
if (isFolderItem) {
|
|
149
|
+
updates.isAllFoldersSelected = _this.checkIfAllSelected(updatedSelection.filter(function (item) {
|
|
150
|
+
return isFolder(item);
|
|
151
|
+
}), folders);
|
|
152
|
+
} else {
|
|
153
|
+
if (_this.plugin.filerobot.isFileRestrictedToGetAdded(_currentSelection, item, false)) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
updates.isAllFilesSelected = _this.checkIfAllSelected(updatedSelection.filter(function (item) {
|
|
157
|
+
return !isFolder(item);
|
|
158
|
+
}), files);
|
|
159
|
+
}
|
|
160
|
+
_this.plugin.setPluginCommonState(updates);
|
|
161
|
+
return updatedSelection;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// If only 1 file/folder is available and it's selected means we have selected all the files/folders.
|
|
165
|
+
var isAllFoldersSelected = false;
|
|
166
|
+
var isAllFilesSelected = false;
|
|
167
|
+
if (isFolderItem && folders.length === 1) {
|
|
168
|
+
isAllFoldersSelected = true;
|
|
169
|
+
} else if (!isFolderItem && files.length === 1) {
|
|
170
|
+
isAllFilesSelected = true;
|
|
171
|
+
}
|
|
172
|
+
if (!isFolderItem && _this.plugin.filerobot.isFileRestrictedToGetAdded([], item, false)) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
_this.lastCheckbox = item.id;
|
|
176
|
+
_this.plugin.setPluginCommonState({
|
|
177
|
+
currentSelection: [item],
|
|
178
|
+
disableDownloadButton: !!isFolderItem,
|
|
179
|
+
isAllFoldersSelected: isAllFoldersSelected,
|
|
180
|
+
isAllFilesSelected: isAllFilesSelected
|
|
181
|
+
});
|
|
182
|
+
return [item];
|
|
183
|
+
});
|
|
184
|
+
_defineProperty(this, "toggleAllFilesSelection", function () {
|
|
185
|
+
var _this$plugin$getPlugi3 = _this.plugin.getPluginCommonState(),
|
|
186
|
+
_this$plugin$getPlugi4 = _this$plugin$getPlugi3.currentSelection,
|
|
187
|
+
currentSelection = _this$plugin$getPlugi4 === void 0 ? [] : _this$plugin$getPlugi4,
|
|
188
|
+
files = _this$plugin$getPlugi3.files,
|
|
189
|
+
_this$plugin$getPlugi5 = _this$plugin$getPlugi3.isAllFilesSelected,
|
|
190
|
+
isAllFilesSelected = _this$plugin$getPlugi5 === void 0 ? false : _this$plugin$getPlugi5;
|
|
191
|
+
var selectedFolders = currentSelection.filter(function (item) {
|
|
192
|
+
return isFolder(item);
|
|
193
|
+
});
|
|
194
|
+
var newSelections = isAllFilesSelected ? selectedFolders : selectedFolders.concat(files);
|
|
195
|
+
_this.plugin.setPluginCommonState({
|
|
196
|
+
currentSelection: newSelections,
|
|
197
|
+
isAllFilesSelected: !isAllFilesSelected
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
_defineProperty(this, "toggleAllFoldersSelection", function () {
|
|
201
|
+
var _this$plugin$getPlugi6 = _this.plugin.getPluginCommonState(),
|
|
202
|
+
_this$plugin$getPlugi7 = _this$plugin$getPlugi6.currentSelection,
|
|
203
|
+
currentSelection = _this$plugin$getPlugi7 === void 0 ? [] : _this$plugin$getPlugi7,
|
|
204
|
+
folders = _this$plugin$getPlugi6.folders,
|
|
205
|
+
_this$plugin$getPlugi8 = _this$plugin$getPlugi6.isAllFoldersSelected,
|
|
206
|
+
isAllFoldersSelected = _this$plugin$getPlugi8 === void 0 ? false : _this$plugin$getPlugi8;
|
|
207
|
+
var selectedFiles = currentSelection.filter(function (item) {
|
|
208
|
+
return !isFolder(item);
|
|
209
|
+
});
|
|
210
|
+
var newSelections = isAllFoldersSelected ? selectedFiles : selectedFiles.concat(folders);
|
|
211
|
+
_this.plugin.setPluginCommonState({
|
|
212
|
+
currentSelection: newSelections,
|
|
213
|
+
isAllFoldersSelected: !isAllFoldersSelected
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
_defineProperty(this, "checkIfAllSelected", function (currentSelection, items) {
|
|
217
|
+
return currentSelection.length === items.length;
|
|
218
|
+
});
|
|
219
|
+
/**
|
|
220
|
+
* Validates restrictions during import that require backend requests
|
|
221
|
+
*/
|
|
222
|
+
_defineProperty(this, "validateDuringImport", function (fileCount, totalSize, depth) {
|
|
223
|
+
var folderCount = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
224
|
+
if (_this.importState.shouldStop) {
|
|
225
|
+
return false; // Already stopped due to previous restriction
|
|
226
|
+
}
|
|
227
|
+
var _this$plugin$filerobo = _this.plugin.filerobot.opts.restrictions,
|
|
228
|
+
remoteMaxFolderImportCount = _this$plugin$filerobo.remoteMaxFolderImportCount,
|
|
229
|
+
remoteMaxFolderImportSize = _this$plugin$filerobo.remoteMaxFolderImportSize,
|
|
230
|
+
remoteMaxFolderDepth = _this$plugin$filerobo.remoteMaxFolderDepth,
|
|
231
|
+
remoteMaxFolderCount = _this$plugin$filerobo.remoteMaxFolderCount;
|
|
232
|
+
var _this$plugin$getPlugi9 = _this.plugin.getPluginCommonState(),
|
|
233
|
+
shouldIncludeSubFolders = _this$plugin$getPlugi9.shouldIncludeSubFolders;
|
|
234
|
+
|
|
235
|
+
// Update tracking state
|
|
236
|
+
_this.importState.totalFilesImported += fileCount;
|
|
237
|
+
_this.importState.totalFoldersImported += folderCount;
|
|
238
|
+
_this.importState.totalSizeImported += totalSize;
|
|
239
|
+
_this.importState.currentDepth = Math.max(_this.importState.currentDepth, depth);
|
|
240
|
+
|
|
241
|
+
// Check file count restriction
|
|
242
|
+
if (remoteMaxFolderImportCount && _this.importState.totalFilesImported > remoteMaxFolderImportCount) {
|
|
243
|
+
_this.importState.shouldStop = true;
|
|
244
|
+
throw new Error(_this.plugin.filerobot.i18n('remoteUploadTooManyFilesSelectedError', {
|
|
245
|
+
limit: remoteMaxFolderImportCount
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Check total file size restriction
|
|
250
|
+
if (remoteMaxFolderImportSize && _this.importState.totalSizeImported > remoteMaxFolderImportSize) {
|
|
251
|
+
_this.importState.shouldStop = true;
|
|
252
|
+
var maxSizeGB = Math.round(remoteMaxFolderImportSize / (1024 * 1024 * 1024));
|
|
253
|
+
throw new Error(_this.plugin.filerobot.i18n('remoteUploadTotalFileSizeTooBigError', {
|
|
254
|
+
limit: "".concat(maxSizeGB, " GB")
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Check total folder count restriction during import (only for recursive imports)
|
|
259
|
+
if (shouldIncludeSubFolders && remoteMaxFolderCount && _this.importState.totalFoldersImported > remoteMaxFolderCount) {
|
|
260
|
+
_this.importState.shouldStop = true;
|
|
261
|
+
throw new Error(_this.plugin.filerobot.i18n('remoteUploadTooManyFoldersSelectedError', {
|
|
262
|
+
limit: remoteMaxFolderCount
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Check folder depth restriction (only for recursive imports)
|
|
267
|
+
if (shouldIncludeSubFolders && remoteMaxFolderDepth && _this.importState.currentDepth > remoteMaxFolderDepth) {
|
|
268
|
+
_this.importState.shouldStop = true;
|
|
269
|
+
throw new Error(_this.plugin.filerobot.i18n('remoteUploadPathTooLongError', {
|
|
270
|
+
limit: remoteMaxFolderDepth
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
return true; // Continue importing
|
|
274
|
+
});
|
|
275
|
+
this.id = PLUGINS_IDS.PROVIDER_VIEWS;
|
|
276
|
+
this.plugin = plugin;
|
|
277
|
+
this.provider = opts.provider;
|
|
278
|
+
|
|
279
|
+
// set default options
|
|
280
|
+
var defaultOptions = {
|
|
281
|
+
layoutType: LAYOUTS_IDS.LIST,
|
|
282
|
+
showTitles: true,
|
|
283
|
+
showFilter: false,
|
|
284
|
+
showBreadcrumbs: true,
|
|
285
|
+
showSort: false,
|
|
286
|
+
is3rdPartyData: true,
|
|
287
|
+
showLogout: true,
|
|
288
|
+
showUsername: true,
|
|
289
|
+
selectedListViewCols: [LIST_VIEW_COLS_IDS.TYPE, LIST_VIEW_COLS_IDS.VISIBILITY,
|
|
290
|
+
// LIST_VIEW_COLS_IDS.STATUS,
|
|
291
|
+
LIST_VIEW_COLS_IDS.TAGS, LIST_VIEW_COLS_IDS.LABELS, LIST_VIEW_COLS_IDS.LAST_MODIFY],
|
|
292
|
+
selectedListViewFoldersCols: [LIST_VIEW_FOLDERS_COLS_IDS.VISIBILITY, LIST_VIEW_FOLDERS_COLS_IDS.AMOUNT, LIST_VIEW_FOLDERS_COLS_IDS.LAST_MODIFY]
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// merge default options with the ones set by user
|
|
296
|
+
this.opts = _objectSpread(_objectSpread({}, defaultOptions), opts);
|
|
297
|
+
|
|
298
|
+
// Logic
|
|
299
|
+
this.addFile = this.addFile.bind(this);
|
|
300
|
+
this.enqueueFile = this.enqueueFile.bind(this);
|
|
301
|
+
this.addFolder = this.addFolder.bind(this);
|
|
302
|
+
this.filterItems = this.filterItems.bind(this);
|
|
303
|
+
this.filterQuery = this.filterQuery.bind(this);
|
|
304
|
+
this.toggleSearch = this.toggleSearch.bind(this);
|
|
305
|
+
this.getFolder = this.getFolder.bind(this);
|
|
306
|
+
this.getNextFolder = this.getNextFolder.bind(this);
|
|
307
|
+
this.logout = this.logout.bind(this);
|
|
308
|
+
this.preFirstRender = this.preFirstRender.bind(this);
|
|
309
|
+
this.handleAuth = this.handleAuth.bind(this);
|
|
310
|
+
this.sortByTitle = this.sortByTitle.bind(this);
|
|
311
|
+
this.sortByDate = this.sortByDate.bind(this);
|
|
312
|
+
this.isActiveRow = this.isActiveRow.bind(this);
|
|
313
|
+
this.isChecked = this.isChecked.bind(this);
|
|
314
|
+
this.toggleCheckbox = this.toggleCheckbox.bind(this);
|
|
315
|
+
this.handleError = this.handleError.bind(this);
|
|
316
|
+
this.handleScroll = this.handleScroll.bind(this);
|
|
317
|
+
this.list = this.list.bind(this);
|
|
318
|
+
this.cancelPicking = this.cancelPicking.bind(this);
|
|
319
|
+
this.clearSelection = this.clearSelection.bind(this);
|
|
320
|
+
this.addSelectedItems = this.addSelectedItems.bind(this);
|
|
321
|
+
this.renderPanelUploadActionButtons = this.renderPanelUploadActionButtons.bind(this);
|
|
322
|
+
|
|
323
|
+
// Visual
|
|
324
|
+
this.render = this.render.bind(this);
|
|
325
|
+
this.clearSelection();
|
|
326
|
+
|
|
327
|
+
// Set default state for the plugin
|
|
328
|
+
this.plugin.setPluginCommonState({
|
|
329
|
+
authenticated: false,
|
|
330
|
+
files: [],
|
|
331
|
+
folders: [],
|
|
332
|
+
openedFolders: [],
|
|
333
|
+
selectedFolders: {},
|
|
334
|
+
activeRow: -1,
|
|
335
|
+
filterInput: '',
|
|
336
|
+
isSearchVisible: false
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
return _createClass(ProviderView, [{
|
|
340
|
+
key: "_updateFilesAndFolders",
|
|
341
|
+
value: function _updateFilesAndFolders(res, files, folders) {
|
|
342
|
+
this.nextPagePath = res.nextPagePath;
|
|
343
|
+
res.items.forEach(function (item) {
|
|
344
|
+
if (item.isFolder) {
|
|
345
|
+
folders.push(item);
|
|
346
|
+
} else {
|
|
347
|
+
files.push(item);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
this.plugin.setPluginCommonState({
|
|
351
|
+
folders: folders,
|
|
352
|
+
files: files
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Called only the first time the provider view is rendered.
|
|
358
|
+
* Kind of like an init function.
|
|
359
|
+
*/
|
|
360
|
+
}, {
|
|
361
|
+
key: "preFirstRender",
|
|
362
|
+
value: function preFirstRender() {
|
|
363
|
+
this.plugin.setPluginCommonState({
|
|
364
|
+
didFirstRender: true
|
|
365
|
+
});
|
|
366
|
+
this.plugin.onFirstRender();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Based on folder ID, fetch a new folder and update it to state
|
|
371
|
+
* used from the companion-client
|
|
372
|
+
*
|
|
373
|
+
* @param {string} id Folder id
|
|
374
|
+
* @returns {Promise} Folders/files in folder
|
|
375
|
+
*/
|
|
376
|
+
}, {
|
|
377
|
+
key: "getFolder",
|
|
378
|
+
value: function getFolder(id, name) {
|
|
379
|
+
var _this2 = this;
|
|
380
|
+
return this._loaderWrapper(this.provider.list(id), function (res) {
|
|
381
|
+
var folders = [];
|
|
382
|
+
var files = [];
|
|
383
|
+
var openedFolders;
|
|
384
|
+
var state = _this2.plugin.getPluginCommonState();
|
|
385
|
+
var index = findIndex(state.openedFolders, function (folder) {
|
|
386
|
+
return id === folder.id;
|
|
387
|
+
});
|
|
388
|
+
if (index !== -1) {
|
|
389
|
+
openedFolders = state.openedFolders.slice(0, index + 1);
|
|
390
|
+
} else {
|
|
391
|
+
openedFolders = state.openedFolders.concat([{
|
|
392
|
+
id: id,
|
|
393
|
+
title: name
|
|
394
|
+
}]);
|
|
395
|
+
}
|
|
396
|
+
_this2.username = _this2.username ? _this2.username : res.username;
|
|
397
|
+
_this2._updateFilesAndFolders(res, files, folders);
|
|
398
|
+
_this2.plugin.setPluginCommonState({
|
|
399
|
+
openedFolders: openedFolders
|
|
400
|
+
});
|
|
401
|
+
}, this.handleError);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Fetches new folder
|
|
406
|
+
*
|
|
407
|
+
* @param {object} folder
|
|
408
|
+
*/
|
|
409
|
+
}, {
|
|
410
|
+
key: "getNextFolder",
|
|
411
|
+
value: function getNextFolder(folder) {
|
|
412
|
+
if (folder) {
|
|
413
|
+
this.getFolder(folder.requestPath || folder.id, folder.name || folder.title);
|
|
414
|
+
this.lastCheckbox = undefined;
|
|
415
|
+
if (this.opts.is3rdPartyData) {
|
|
416
|
+
this.plugin.setPluginCommonState({
|
|
417
|
+
currentSelection: []
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}, {
|
|
423
|
+
key: "enqueueFile",
|
|
424
|
+
value: function enqueueFile(file) {
|
|
425
|
+
var _this$importState;
|
|
426
|
+
// Check if we should stop due to previous restriction hits
|
|
427
|
+
if ((_this$importState = this.importState) !== null && _this$importState !== void 0 && _this$importState.shouldStop) {
|
|
428
|
+
return; // Stop processing
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// For individual files (not from folders), validate restrictions during import
|
|
432
|
+
if (this.importState && !file.relativePath) {
|
|
433
|
+
try {
|
|
434
|
+
this.validateDuringImport(1, file.size || 0, 0);
|
|
435
|
+
} catch (error) {
|
|
436
|
+
this.importState.shouldStop = true;
|
|
437
|
+
throw error;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
this.importState.filesQueue.push(file);
|
|
441
|
+
}
|
|
442
|
+
}, {
|
|
443
|
+
key: "addFile",
|
|
444
|
+
value: function addFile(file) {
|
|
445
|
+
var tagFile = _objectSpread(_objectSpread({
|
|
446
|
+
id: this.providerFileToId(file),
|
|
447
|
+
source: this.plugin.id,
|
|
448
|
+
data: file,
|
|
449
|
+
name: file.name || file.id,
|
|
450
|
+
type: file.mimeType,
|
|
451
|
+
isRemote: true,
|
|
452
|
+
body: {
|
|
453
|
+
fileId: file.id
|
|
454
|
+
}
|
|
455
|
+
}, file.relativePath && {
|
|
456
|
+
info: {
|
|
457
|
+
relativePath: "".concat(file.relativePath).concat(file.name)
|
|
458
|
+
}
|
|
459
|
+
}), {}, {
|
|
460
|
+
remote: {
|
|
461
|
+
companionUrl: this.plugin.provider.companionUrl,
|
|
462
|
+
url: "".concat(this.provider.fileUrl(file.requestPath)),
|
|
463
|
+
body: {
|
|
464
|
+
fileId: file.id
|
|
465
|
+
},
|
|
466
|
+
providerOptions: this.provider.opts
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
if (file.thumbnail || file.preview) {
|
|
470
|
+
tagFile.preview = file.thumbnail || file.preview;
|
|
471
|
+
}
|
|
472
|
+
this.plugin.filerobot.log('Adding remote file');
|
|
473
|
+
try {
|
|
474
|
+
this.plugin.filerobot.addFile(tagFile);
|
|
475
|
+
} catch (err) {
|
|
476
|
+
if (!err.isRestriction) {
|
|
477
|
+
this.plugin.filerobot.log(err);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}, {
|
|
482
|
+
key: "removeFile",
|
|
483
|
+
value: function removeFile(id) {
|
|
484
|
+
var _this$plugin$getPlugi10 = this.plugin.getPluginCommonState(),
|
|
485
|
+
currentSelection = _this$plugin$getPlugi10.currentSelection;
|
|
486
|
+
this.plugin.setPluginCommonState({
|
|
487
|
+
currentSelection: currentSelection.filter(function (file) {
|
|
488
|
+
return file.id !== id;
|
|
489
|
+
})
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Removes session token on client side.
|
|
495
|
+
*/
|
|
496
|
+
}, {
|
|
497
|
+
key: "logout",
|
|
498
|
+
value: function logout() {
|
|
499
|
+
var _this3 = this;
|
|
500
|
+
this.provider.logout().then(function (res) {
|
|
501
|
+
if (res.ok) {
|
|
502
|
+
if (!res.revoked) {
|
|
503
|
+
var message = _this3.plugin.filerobot.i18n('providerViewCompanionUnauthorizeMessage', {
|
|
504
|
+
provider: _this3.plugin.title,
|
|
505
|
+
url: res.manual_revoke_url
|
|
506
|
+
});
|
|
507
|
+
_this3.plugin.filerobot.info(message, 'info', 7000);
|
|
508
|
+
}
|
|
509
|
+
var newState = {
|
|
510
|
+
authenticated: false,
|
|
511
|
+
files: [],
|
|
512
|
+
folders: [],
|
|
513
|
+
openedFolders: []
|
|
514
|
+
};
|
|
515
|
+
_this3.plugin.setPluginCommonState(newState);
|
|
516
|
+
}
|
|
517
|
+
})["catch"](this.handleError);
|
|
518
|
+
}
|
|
519
|
+
}, {
|
|
520
|
+
key: "filterQuery",
|
|
521
|
+
value: function filterQuery(e) {
|
|
522
|
+
var state = this.plugin.getPluginCommonState();
|
|
523
|
+
this.plugin.setPluginCommonState(_extends({}, state, {
|
|
524
|
+
filterInput: e ? e.target.value : ''
|
|
525
|
+
}));
|
|
526
|
+
}
|
|
527
|
+
}, {
|
|
528
|
+
key: "toggleSearch",
|
|
529
|
+
value: function toggleSearch(inputEl) {
|
|
530
|
+
var state = this.plugin.getPluginCommonState();
|
|
531
|
+
this.plugin.setPluginCommonState({
|
|
532
|
+
isSearchVisible: !state.isSearchVisible,
|
|
533
|
+
filterInput: ''
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}, {
|
|
537
|
+
key: "filterItems",
|
|
538
|
+
value: function filterItems(items) {
|
|
539
|
+
var state = this.plugin.getPluginCommonState();
|
|
540
|
+
if (!state.filterInput || state.filterInput === '') {
|
|
541
|
+
return items;
|
|
542
|
+
}
|
|
543
|
+
return items.filter(function (folder) {
|
|
544
|
+
return folder.name.toLowerCase().indexOf(state.filterInput.toLowerCase()) !== -1;
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
}, {
|
|
548
|
+
key: "sortByTitle",
|
|
549
|
+
value: function sortByTitle() {
|
|
550
|
+
var state = _extends({}, this.plugin.getPluginCommonState());
|
|
551
|
+
var files = state.files,
|
|
552
|
+
folders = state.folders,
|
|
553
|
+
sorting = state.sorting;
|
|
554
|
+
var sortedFiles = files.sort(function (fileA, fileB) {
|
|
555
|
+
if (sorting === 'titleDescending') {
|
|
556
|
+
return fileB.name.localeCompare(fileA.name);
|
|
557
|
+
}
|
|
558
|
+
return fileA.name.localeCompare(fileB.name);
|
|
559
|
+
});
|
|
560
|
+
var sortedFolders = folders.sort(function (folderA, folderB) {
|
|
561
|
+
if (sorting === 'titleDescending') {
|
|
562
|
+
return folderB.name.localeCompare(folderA.name);
|
|
563
|
+
}
|
|
564
|
+
return folderA.name.localeCompare(folderB.name);
|
|
565
|
+
});
|
|
566
|
+
this.plugin.setPluginCommonState(_extends({}, state, {
|
|
567
|
+
files: sortedFiles,
|
|
568
|
+
folders: sortedFolders,
|
|
569
|
+
sorting: sorting === 'titleDescending' ? 'titleAscending' : 'titleDescending'
|
|
570
|
+
}));
|
|
571
|
+
}
|
|
572
|
+
}, {
|
|
573
|
+
key: "sortByDate",
|
|
574
|
+
value: function sortByDate() {
|
|
575
|
+
var state = _extends({}, this.plugin.getPluginCommonState());
|
|
576
|
+
var files = state.files,
|
|
577
|
+
folders = state.folders,
|
|
578
|
+
sorting = state.sorting;
|
|
579
|
+
var sortedFiles = files.sort(function (fileA, fileB) {
|
|
580
|
+
var a = new Date(fileA.modifiedDate);
|
|
581
|
+
var b = new Date(fileB.modifiedDate);
|
|
582
|
+
if (sorting === 'dateDescending') {
|
|
583
|
+
return a > b ? -1 : a < b ? 1 : 0;
|
|
584
|
+
}
|
|
585
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
586
|
+
});
|
|
587
|
+
var sortedFolders = folders.sort(function (folderA, folderB) {
|
|
588
|
+
var a = new Date(folderA.modifiedDate);
|
|
589
|
+
var b = new Date(folderB.modifiedDate);
|
|
590
|
+
if (sorting === 'dateDescending') {
|
|
591
|
+
return a > b ? -1 : a < b ? 1 : 0;
|
|
592
|
+
}
|
|
593
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
594
|
+
});
|
|
595
|
+
this.plugin.setPluginCommonState(_extends({}, state, {
|
|
596
|
+
files: sortedFiles,
|
|
597
|
+
folders: sortedFolders,
|
|
598
|
+
sorting: sorting === 'dateDescending' ? 'dateAscending' : 'dateDescending'
|
|
599
|
+
}));
|
|
600
|
+
}
|
|
601
|
+
}, {
|
|
602
|
+
key: "sortBySize",
|
|
603
|
+
value: function sortBySize() {
|
|
604
|
+
var state = _extends({}, this.plugin.getPluginCommonState());
|
|
605
|
+
var files = state.files,
|
|
606
|
+
sorting = state.sorting;
|
|
607
|
+
|
|
608
|
+
// check that plugin supports file sizes
|
|
609
|
+
if (!files.length || !this.plugin.getItemData(files[0]).size) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
var sortedFiles = files.sort(function (fileA, fileB) {
|
|
613
|
+
var a = fileA.size;
|
|
614
|
+
var b = fileB.size;
|
|
615
|
+
if (sorting === 'sizeDescending') {
|
|
616
|
+
return a > b ? -1 : a < b ? 1 : 0;
|
|
617
|
+
}
|
|
618
|
+
return a > b ? 1 : a < b ? -1 : 0;
|
|
619
|
+
});
|
|
620
|
+
this.plugin.setPluginCommonState(_extends({}, state, {
|
|
621
|
+
files: sortedFiles,
|
|
622
|
+
sorting: sorting === 'sizeDescending' ? 'sizeAscending' : 'sizeDescending'
|
|
623
|
+
}));
|
|
624
|
+
}
|
|
625
|
+
}, {
|
|
626
|
+
key: "isActiveRow",
|
|
627
|
+
value: function isActiveRow(file) {
|
|
628
|
+
return this.plugin.getPluginCommonState().activeRow === this.plugin.getItemId(file);
|
|
629
|
+
}
|
|
630
|
+
}, {
|
|
631
|
+
key: "isChecked",
|
|
632
|
+
value: function isChecked(file) {
|
|
633
|
+
var _this$plugin$getPlugi11 = this.plugin.getPluginCommonState(),
|
|
634
|
+
currentSelection = _this$plugin$getPlugi11.currentSelection;
|
|
635
|
+
// comparing id instead of the file object, because the reference to the object
|
|
636
|
+
// changes when we switch folders, and the file list is updated
|
|
637
|
+
return currentSelection.some(function (item) {
|
|
638
|
+
return item.id === file.id;
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Adds all files found inside of specified folder.
|
|
644
|
+
*
|
|
645
|
+
* Uses separated state while folder contents are being fetched and
|
|
646
|
+
* mantains list of selected folders, which are separated from files.
|
|
647
|
+
*/
|
|
648
|
+
}, {
|
|
649
|
+
key: "addFolder",
|
|
650
|
+
value: function addFolder(folder) {
|
|
651
|
+
var _this$importState2,
|
|
652
|
+
_this4 = this;
|
|
653
|
+
var parentRelativePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
654
|
+
var currentDepth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
655
|
+
// Check if we should stop due to previous restriction hits
|
|
656
|
+
if ((_this$importState2 = this.importState) !== null && _this$importState2 !== void 0 && _this$importState2.shouldStop) {
|
|
657
|
+
return Promise.resolve();
|
|
658
|
+
}
|
|
659
|
+
var folderId = this.providerFileToId(folder);
|
|
660
|
+
var folders = _objectSpread({}, this.plugin.getPluginCommonState().selectedFolders);
|
|
661
|
+
if (folderId in folders && folders[folderId].loading) {
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
folders[folderId] = {
|
|
665
|
+
loading: true,
|
|
666
|
+
files: []
|
|
667
|
+
};
|
|
668
|
+
this.plugin.setPluginCommonState({
|
|
669
|
+
selectedFolders: folders
|
|
670
|
+
});
|
|
671
|
+
var _this$plugin$getPlugi12 = this.plugin.getPluginCommonState(),
|
|
672
|
+
shouldIncludeSubFolders = _this$plugin$getPlugi12.shouldIncludeSubFolders;
|
|
673
|
+
var relativePath = "".concat(parentRelativePath || folder.relativePath || '').concat(folder.name, "/");
|
|
674
|
+
return this.list(folder.requestPath).then(function (_ref2) {
|
|
675
|
+
var _this4$importState, _this4$importState2;
|
|
676
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
677
|
+
files = _ref3[0],
|
|
678
|
+
_ref3$ = _ref3[1],
|
|
679
|
+
subFolders = _ref3$ === void 0 ? [] : _ref3$;
|
|
680
|
+
// Check if we should stop due to restriction hit during list operation
|
|
681
|
+
if ((_this4$importState = _this4.importState) !== null && _this4$importState !== void 0 && _this4$importState.shouldStop) {
|
|
682
|
+
return Promise.resolve();
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// Calculate total size of files in this folder
|
|
686
|
+
var totalSize = files.reduce(function (sum, file) {
|
|
687
|
+
return sum + (file.size || 0);
|
|
688
|
+
}, 0);
|
|
689
|
+
|
|
690
|
+
// Validate restrictions during import (this may throw and stop the process)
|
|
691
|
+
try {
|
|
692
|
+
_this4.validateDuringImport(files.length, totalSize, currentDepth, 1); // Count this folder as 1
|
|
693
|
+
} catch (error) {
|
|
694
|
+
// Stop the import process and propagate the error
|
|
695
|
+
_this4.importState.shouldStop = true;
|
|
696
|
+
return Promise.reject(error);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// Update progress during import
|
|
700
|
+
_this4.updateImportProgress(1, files.length);
|
|
701
|
+
files.forEach(function (file) {
|
|
702
|
+
// Add relativePath for recursive folder structure replication
|
|
703
|
+
_this4.enqueueFile(_objectSpread(_objectSpread({}, file), {}, {
|
|
704
|
+
relativePath: relativePath
|
|
705
|
+
}));
|
|
706
|
+
});
|
|
707
|
+
var ids = files.map(_this4.providerFileToId);
|
|
708
|
+
folders = _objectSpread(_objectSpread({}, _this4.plugin.getPluginCommonState().selectedFolders), {}, _defineProperty({}, folderId, {
|
|
709
|
+
loading: false,
|
|
710
|
+
files: ids
|
|
711
|
+
}));
|
|
712
|
+
_this4.plugin.setPluginCommonState({
|
|
713
|
+
selectedFolders: folders
|
|
714
|
+
});
|
|
715
|
+
var message;
|
|
716
|
+
if (files.length) {
|
|
717
|
+
message = _this4.plugin.filerobot.i18n('filerobotFolderAddedMessage', {
|
|
718
|
+
smart_count: files.length,
|
|
719
|
+
folder: folder.name
|
|
720
|
+
});
|
|
721
|
+
} else {
|
|
722
|
+
message = _this4.plugin.filerobot.i18n('filerobotEmptyFolderAddedMessage');
|
|
723
|
+
}
|
|
724
|
+
_this4.plugin.filerobot.info(message);
|
|
725
|
+
|
|
726
|
+
// Process subfolders if recursion is enabled and we haven't hit any restrictions
|
|
727
|
+
if (shouldIncludeSubFolders && !((_this4$importState2 = _this4.importState) !== null && _this4$importState2 !== void 0 && _this4$importState2.shouldStop)) {
|
|
728
|
+
return Promise.all(subFolders.map(function (subFolder) {
|
|
729
|
+
return _this4.addFolder(_objectSpread(_objectSpread({}, subFolder), {}, {
|
|
730
|
+
relativePath: relativePath
|
|
731
|
+
}), relativePath, currentDepth + 1);
|
|
732
|
+
}));
|
|
733
|
+
}
|
|
734
|
+
})["catch"](function (e) {
|
|
735
|
+
folders = _objectSpread({}, _this4.plugin.getPluginCommonState().selectedFolders);
|
|
736
|
+
delete folders[folderId];
|
|
737
|
+
_this4.plugin.setPluginCommonState({
|
|
738
|
+
selectedFolders: folders
|
|
739
|
+
});
|
|
740
|
+
_this4.handleError(e);
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Updates the progressive loading UI with current import progress
|
|
746
|
+
*/
|
|
747
|
+
}, {
|
|
748
|
+
key: "updateImportProgress",
|
|
749
|
+
value: function updateImportProgress(foldersCount, filesCount) {
|
|
750
|
+
var _state$folderImportPr;
|
|
751
|
+
var state = this.plugin.getPluginCommonState();
|
|
752
|
+
if ((_state$folderImportPr = state.folderImportProgress) !== null && _state$folderImportPr !== void 0 && _state$folderImportPr.isVisible) {
|
|
753
|
+
var currentProgress = state.folderImportProgress;
|
|
754
|
+
this.plugin.setPluginCommonState({
|
|
755
|
+
folderImportProgress: _objectSpread(_objectSpread({}, currentProgress), {}, {
|
|
756
|
+
foldersCount: (currentProgress.foldersCount || 0) + foldersCount,
|
|
757
|
+
filesCount: (currentProgress.filesCount || 0) + filesCount
|
|
758
|
+
})
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}, {
|
|
763
|
+
key: "providerFileToId",
|
|
764
|
+
value: function providerFileToId(file) {
|
|
765
|
+
return generateFileId({
|
|
766
|
+
data: file,
|
|
767
|
+
name: file.name || file.id,
|
|
768
|
+
type: file.mimeType
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
}, {
|
|
772
|
+
key: "handleAuth",
|
|
773
|
+
value: function handleAuth() {
|
|
774
|
+
var _this5 = this;
|
|
775
|
+
var authState = btoa(JSON.stringify({
|
|
776
|
+
origin: getOrigin()
|
|
777
|
+
}));
|
|
778
|
+
var clientVersion = encodeURIComponent("@scaleflex/widget-provider-views=".concat(ProviderView.VERSION));
|
|
779
|
+
var link = "".concat(this.provider.authUrl(), "?state=").concat(authState, "&filerobotVersions=").concat(clientVersion);
|
|
780
|
+
var authWindow = window.open(link, '_blank');
|
|
781
|
+
var _handleToken = function handleToken(e) {
|
|
782
|
+
if (e.source !== authWindow) {
|
|
783
|
+
_this5.plugin.filerobot.log("rejecting event from ".concat(e.origin));
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Check if it's a string before doing the JSON.parse to maintain support
|
|
788
|
+
// for older Companion versions that used object references
|
|
789
|
+
var data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data;
|
|
790
|
+
if (!data.token) {
|
|
791
|
+
_this5.plugin.filerobot.log('did not receive token from auth window');
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
authWindow.close();
|
|
795
|
+
window.removeEventListener('message', _handleToken);
|
|
796
|
+
_this5.provider.setAuthToken(data.token);
|
|
797
|
+
_this5.preFirstRender();
|
|
798
|
+
};
|
|
799
|
+
window.addEventListener('message', _handleToken);
|
|
800
|
+
}
|
|
801
|
+
}, {
|
|
802
|
+
key: "handleError",
|
|
803
|
+
value: function handleError(error) {
|
|
804
|
+
var filerobot = this.plugin.filerobot;
|
|
805
|
+
filerobot.log(error.toString());
|
|
806
|
+
if (error.isAuthError) {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
var message = error.message || error.toString() || filerobot.i18n('providerViewCompanionError');
|
|
810
|
+
filerobot.info({
|
|
811
|
+
message: message
|
|
812
|
+
}, 'error', 5000);
|
|
813
|
+
}
|
|
814
|
+
}, {
|
|
815
|
+
key: "handleScroll",
|
|
816
|
+
value: function handleScroll(e) {
|
|
817
|
+
var _this6 = this;
|
|
818
|
+
var scrollPos = e.target.scrollHeight - (e.target.scrollTop + e.target.offsetHeight);
|
|
819
|
+
var path = this.nextPagePath || null;
|
|
820
|
+
if (scrollPos < 50 && path && !this._isHandlingScroll) {
|
|
821
|
+
this.provider.list(path).then(function (res) {
|
|
822
|
+
var _this6$plugin$getPlug = _this6.plugin.getPluginCommonState(),
|
|
823
|
+
files = _this6$plugin$getPlug.files,
|
|
824
|
+
folders = _this6$plugin$getPlug.folders;
|
|
825
|
+
_this6._updateFilesAndFolders(res, files, folders);
|
|
826
|
+
})["catch"](this.handleError).then(function () {
|
|
827
|
+
_this6._isHandlingScroll = false;
|
|
828
|
+
}); // always called
|
|
829
|
+
|
|
830
|
+
this._isHandlingScroll = true;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}, {
|
|
834
|
+
key: "list",
|
|
835
|
+
value: function list(path) {
|
|
836
|
+
var _this7 = this;
|
|
837
|
+
var files = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
838
|
+
var folders = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
839
|
+
files = files || [];
|
|
840
|
+
folders = folders || [];
|
|
841
|
+
return new Promise(function (resolve, reject) {
|
|
842
|
+
_this7.provider.list(path).then(function (res) {
|
|
843
|
+
res.items.forEach(function (item) {
|
|
844
|
+
if (item.isFolder) {
|
|
845
|
+
folders.push(item);
|
|
846
|
+
} else {
|
|
847
|
+
files.push(item);
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
var nextPagePath = res.nextPagePath || null;
|
|
851
|
+
if (nextPagePath) {
|
|
852
|
+
return _this7.list(nextPagePath, files, folders).then(function (_ref4) {
|
|
853
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
854
|
+
files = _ref5[0],
|
|
855
|
+
folders = _ref5[1];
|
|
856
|
+
return resolve([files, folders]);
|
|
857
|
+
})["catch"](function (e) {
|
|
858
|
+
return reject(e);
|
|
859
|
+
});
|
|
860
|
+
} else {
|
|
861
|
+
return resolve([files, folders]);
|
|
862
|
+
}
|
|
863
|
+
})["catch"](function (e) {
|
|
864
|
+
return reject(e);
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* gets all the current selection items adds them to the uploading panel
|
|
871
|
+
* if folder it would retrieve its files
|
|
872
|
+
* if files they would be added directly
|
|
873
|
+
*
|
|
874
|
+
*/
|
|
875
|
+
}, {
|
|
876
|
+
key: "addSelectedItems",
|
|
877
|
+
value: async function addSelectedItems() {
|
|
878
|
+
var _this8 = this;
|
|
879
|
+
try {
|
|
880
|
+
var _this$plugin$getPlugi13 = this.plugin.getPluginCommonState(),
|
|
881
|
+
currentSelection = _this$plugin$getPlugi13.currentSelection;
|
|
882
|
+
var remoteMaxFolderCount = this.plugin.filerobot.opts.restrictions.remoteMaxFolderCount;
|
|
883
|
+
|
|
884
|
+
// Pre-validate only restrictions that don't need backend requests
|
|
885
|
+
this.validatePreImportRestrictions(currentSelection, {
|
|
886
|
+
remoteMaxFolderCount: remoteMaxFolderCount
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
// Initialize import tracking state
|
|
890
|
+
this.importState = {
|
|
891
|
+
totalFilesImported: 0,
|
|
892
|
+
totalFoldersImported: 0,
|
|
893
|
+
totalSizeImported: 0,
|
|
894
|
+
filesQueue: [],
|
|
895
|
+
currentDepth: 0,
|
|
896
|
+
shouldStop: false
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
// Set up progressive loading state
|
|
900
|
+
this.plugin.setPluginCommonState({
|
|
901
|
+
folderImportProgress: {
|
|
902
|
+
isVisible: true,
|
|
903
|
+
foldersCount: 0,
|
|
904
|
+
filesCount: 0
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
var promises = currentSelection.map(function (file) {
|
|
908
|
+
if (file.isFolder) {
|
|
909
|
+
return _this8.addFolder(file, '', 1); // Start at depth 1
|
|
910
|
+
} else {
|
|
911
|
+
return _this8.enqueueFile(file);
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
Promise.all(promises).then(function () {
|
|
915
|
+
var _this8$importState, _this8$importState2;
|
|
916
|
+
_this8.plugin.setPluginCommonState({
|
|
917
|
+
folderImportProgress: {
|
|
918
|
+
isVisible: false
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
if (!((_this8$importState = _this8.importState) !== null && _this8$importState !== void 0 && _this8$importState.shouldStop) && ((_this8$importState2 = _this8.importState) === null || _this8$importState2 === void 0 ? void 0 : _this8$importState2.filesQueue.length) > 0) {
|
|
922
|
+
_this8.importState.filesQueue.forEach(function (file) {
|
|
923
|
+
return _this8.addFile(file);
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
_this8.importState = null;
|
|
927
|
+
})["catch"](function (error) {
|
|
928
|
+
_this8.plugin.setPluginCommonState({
|
|
929
|
+
folderImportProgress: {
|
|
930
|
+
isVisible: false
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
_this8.handleImportError(error);
|
|
934
|
+
_this8.importState = null;
|
|
935
|
+
});
|
|
936
|
+
} catch (error) {
|
|
937
|
+
// Hide any loading state and maintain selection
|
|
938
|
+
this.plugin.setPluginCommonState({
|
|
939
|
+
folderImportProgress: {
|
|
940
|
+
isVisible: false
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
|
|
944
|
+
// Show error message without clearing selection
|
|
945
|
+
this.plugin.filerobot.info(error.message, 'error', 5000);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Validates restrictions that don't require backend requests
|
|
951
|
+
*/
|
|
952
|
+
}, {
|
|
953
|
+
key: "validatePreImportRestrictions",
|
|
954
|
+
value: function validatePreImportRestrictions(currentSelection, restrictions) {
|
|
955
|
+
var _this$plugin$getPlugi14 = this.plugin.getPluginCommonState(),
|
|
956
|
+
shouldIncludeSubFolders = _this$plugin$getPlugi14.shouldIncludeSubFolders;
|
|
957
|
+
var remoteMaxFolderCount = restrictions.remoteMaxFolderCount;
|
|
958
|
+
var folders = currentSelection.filter(function (item) {
|
|
959
|
+
return item.isFolder;
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
// Check folder count restriction (no backend request needed)
|
|
963
|
+
if (shouldIncludeSubFolders && remoteMaxFolderCount && folders.length > remoteMaxFolderCount) {
|
|
964
|
+
throw new Error(this.plugin.filerobot.i18n('remoteUploadTooManyFoldersSelectedError', {
|
|
965
|
+
limit: remoteMaxFolderCount
|
|
966
|
+
}));
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}, {
|
|
970
|
+
key: "handleImportError",
|
|
971
|
+
value:
|
|
972
|
+
/**
|
|
973
|
+
* Handles import errors by cleaning up state
|
|
974
|
+
*/
|
|
975
|
+
function handleImportError(error) {
|
|
976
|
+
var _this9 = this;
|
|
977
|
+
// Remove any partially imported files from this session
|
|
978
|
+
var files = this.plugin.filerobot.getUploads();
|
|
979
|
+
Object.keys(files).forEach(function (fileId) {
|
|
980
|
+
if (files[fileId].source === _this9.plugin.id) {
|
|
981
|
+
_this9.plugin.filerobot.removeFile(fileId);
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
// Clear any folder loading states
|
|
986
|
+
this.plugin.setPluginCommonState({
|
|
987
|
+
selectedFolders: {}
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
// Show error message without clearing selection (so user can adjust and try again)
|
|
991
|
+
this.plugin.filerobot.info(error.message, 'error', 5000);
|
|
992
|
+
}
|
|
993
|
+
}, {
|
|
994
|
+
key: "cancelPicking",
|
|
995
|
+
value: function cancelPicking() {
|
|
996
|
+
var clearSelection = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
997
|
+
if (clearSelection) {
|
|
998
|
+
this.clearSelection();
|
|
999
|
+
}
|
|
1000
|
+
this.plugin.setPluginCommonState({
|
|
1001
|
+
folderImportProgress: {
|
|
1002
|
+
isVisible: false
|
|
1003
|
+
},
|
|
1004
|
+
selectedFolders: {}
|
|
1005
|
+
});
|
|
1006
|
+
this.importState = null;
|
|
1007
|
+
this.provider.cancel();
|
|
1008
|
+
}
|
|
1009
|
+
}, {
|
|
1010
|
+
key: "clearSelection",
|
|
1011
|
+
value: function clearSelection() {
|
|
1012
|
+
this.plugin.setPluginCommonState({
|
|
1013
|
+
isAllFoldersSelected: false,
|
|
1014
|
+
isAllFilesSelected: false,
|
|
1015
|
+
currentSelection: []
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
// displays loader view while asynchronous request is being made.
|
|
1020
|
+
}, {
|
|
1021
|
+
key: "_loaderWrapper",
|
|
1022
|
+
value: function _loaderWrapper(promise, then, catch_) {
|
|
1023
|
+
var _this10 = this;
|
|
1024
|
+
this.plugin.setPluginCommonState({
|
|
1025
|
+
loading: true
|
|
1026
|
+
});
|
|
1027
|
+
return promise.then(function (result) {
|
|
1028
|
+
_this10.plugin.setPluginCommonState({
|
|
1029
|
+
loading: false
|
|
1030
|
+
});
|
|
1031
|
+
then(result);
|
|
1032
|
+
})["catch"](function (err) {
|
|
1033
|
+
_this10.plugin.setPluginCommonState({
|
|
1034
|
+
loading: false
|
|
1035
|
+
});
|
|
1036
|
+
catch_(err);
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
}, {
|
|
1040
|
+
key: "renderPanelUploadActionButtons",
|
|
1041
|
+
value: function renderPanelUploadActionButtons() {
|
|
1042
|
+
var _this11 = this;
|
|
1043
|
+
if (!this.plugin.filerobot.opts.enableRemoteRecursiveUpload) {
|
|
1044
|
+
return null;
|
|
1045
|
+
}
|
|
1046
|
+
var _this$plugin$getPlugi15 = this.plugin.getPluginCommonState(),
|
|
1047
|
+
shouldIncludeSubFolders = _this$plugin$getPlugi15.shouldIncludeSubFolders;
|
|
1048
|
+
var handleToggleIncludeSubfoldersOption = function handleToggleIncludeSubfoldersOption() {
|
|
1049
|
+
return _this11.plugin.setPluginCommonState({
|
|
1050
|
+
shouldIncludeSubFolders: !shouldIncludeSubFolders
|
|
1051
|
+
});
|
|
1052
|
+
};
|
|
1053
|
+
return /*#__PURE__*/_jsx(CheckBoxGroup, {
|
|
1054
|
+
checked: shouldIncludeSubFolders,
|
|
1055
|
+
label: this.plugin.filerobot.i18n('remoteUploadIncludeSubFoldersCheckbox'),
|
|
1056
|
+
labelPosition: "after",
|
|
1057
|
+
onChange: handleToggleIncludeSubfoldersOption,
|
|
1058
|
+
size: "sm",
|
|
1059
|
+
type: "checkbox"
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
}, {
|
|
1063
|
+
key: "render",
|
|
1064
|
+
value: function render(state) {
|
|
1065
|
+
var _this12 = this;
|
|
1066
|
+
var viewOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1067
|
+
var _this$plugin$getPlugi16 = this.plugin.getPluginCommonState(),
|
|
1068
|
+
authenticated = _this$plugin$getPlugi16.authenticated,
|
|
1069
|
+
didFirstRender = _this$plugin$getPlugi16.didFirstRender,
|
|
1070
|
+
folderImportProgress = _this$plugin$getPlugi16.folderImportProgress;
|
|
1071
|
+
if (!didFirstRender) {
|
|
1072
|
+
this.preFirstRender();
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
// reload pluginState for "loading" attribute because it might
|
|
1076
|
+
// have changed above.
|
|
1077
|
+
if (this.plugin.getPluginCommonState().loading) {
|
|
1078
|
+
return /*#__PURE__*/_jsx(CloseWrapper, {
|
|
1079
|
+
onUnmount: this.cancelPicking,
|
|
1080
|
+
children: /*#__PURE__*/_jsx(LoaderView, {
|
|
1081
|
+
loaderLabel: this.plugin.filerobot.i18n('loaderLoadingLabel')
|
|
1082
|
+
})
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
if (!authenticated) {
|
|
1086
|
+
return /*#__PURE__*/_jsx(CloseWrapper, {
|
|
1087
|
+
onUnmount: this.cancelPicking,
|
|
1088
|
+
children: /*#__PURE__*/_jsx(AuthView, {
|
|
1089
|
+
pluginName: this.plugin.title,
|
|
1090
|
+
pluginIcon: this.plugin.icon,
|
|
1091
|
+
handleAuth: this.handleAuth,
|
|
1092
|
+
i18n: this.plugin.filerobot.i18n,
|
|
1093
|
+
i18nArray: this.plugin.filerobot.i18nArray
|
|
1094
|
+
})
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
var targetViewOptions = _objectSpread(_objectSpread({}, this.opts), viewOptions);
|
|
1098
|
+
var browserProps = _extends({}, this.plugin.getPluginCommonState(), _objectSpread(_objectSpread({}, targetViewOptions), {}, {
|
|
1099
|
+
username: this.username,
|
|
1100
|
+
getNextFolder: this.getNextFolder,
|
|
1101
|
+
getFolder: this.getFolder,
|
|
1102
|
+
filterItems: this.filterItems,
|
|
1103
|
+
filterQuery: this.filterQuery,
|
|
1104
|
+
toggleSearch: this.toggleSearch,
|
|
1105
|
+
sortByTitle: this.sortByTitle,
|
|
1106
|
+
sortByDate: this.sortByDate,
|
|
1107
|
+
logout: this.logout,
|
|
1108
|
+
isActiveRow: this.isActiveRow,
|
|
1109
|
+
isChecked: this.isChecked,
|
|
1110
|
+
toggleCheckbox: this.toggleCheckbox,
|
|
1111
|
+
handleScroll: this.handleScroll,
|
|
1112
|
+
list: this.list,
|
|
1113
|
+
done: this.addSelectedItems,
|
|
1114
|
+
cancel: this.cancelPicking,
|
|
1115
|
+
title: this.plugin.title,
|
|
1116
|
+
pluginIcon: this.plugin.icon,
|
|
1117
|
+
i18n: this.plugin.filerobot.i18n,
|
|
1118
|
+
updateFilesAndFolders: function updateFilesAndFolders() {
|
|
1119
|
+
return _this12._updateFilesAndFolders.apply(_this12, arguments);
|
|
1120
|
+
},
|
|
1121
|
+
toggleAllFilesSelection: this.toggleAllFilesSelection,
|
|
1122
|
+
toggleAllFoldersSelection: this.toggleAllFoldersSelection
|
|
1123
|
+
}));
|
|
1124
|
+
return /*#__PURE__*/_jsxs(CloseWrapper, {
|
|
1125
|
+
onUnmount: this.cancelPicking,
|
|
1126
|
+
children: [/*#__PURE__*/_jsx(Browser, _objectSpread({}, browserProps)), (folderImportProgress === null || folderImportProgress === void 0 ? void 0 : folderImportProgress.isVisible) && /*#__PURE__*/_jsx(FolderImportProgress, {
|
|
1127
|
+
i18n: this.plugin.filerobot.i18n,
|
|
1128
|
+
foldersCount: folderImportProgress.foldersCount || 0,
|
|
1129
|
+
filesCount: folderImportProgress.filesCount || 0,
|
|
1130
|
+
message: this.plugin.filerobot.i18n('remoteUploadFolderImportProgressMessage'),
|
|
1131
|
+
cancel: function cancel() {
|
|
1132
|
+
return _this12.cancelPicking(false);
|
|
1133
|
+
}
|
|
1134
|
+
})]
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
}]);
|
|
1138
|
+
}();
|
|
1139
|
+
export { ProviderView as default };
|