@uppy/provider-views
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -1,7 +0,3 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _require = require('preact'), | ||
@@ -11,55 +7,49 @@ h = _require.h, | ||
var AuthBlock = function (_Component) { | ||
_inherits(AuthBlock, _Component); | ||
var AuthBlock = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inheritsLoose(AuthBlock, _Component); | ||
function AuthBlock() { | ||
_classCallCheck(this, AuthBlock); | ||
return _possibleConstructorReturn(this, _Component.apply(this, arguments)); | ||
return _Component.apply(this, arguments) || this; | ||
} | ||
AuthBlock.prototype.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
var _proto = AuthBlock.prototype; | ||
_proto.componentDidMount = function componentDidMount() { | ||
var _this = this; | ||
setTimeout(function () { | ||
if (!_this2.connectButton) return; | ||
_this2.connectButton.focus({ preventScroll: true }); | ||
if (!_this.connectButton) return; | ||
_this.connectButton.focus({ | ||
preventScroll: true | ||
}); | ||
}, 150); | ||
}; | ||
AuthBlock.prototype.render = function render() { | ||
var _this3 = this; | ||
_proto.render = function render() { | ||
var _this2 = this; | ||
var pluginNameComponent = h( | ||
"span", | ||
{ "class": "uppy-Provider-authTitleName" }, | ||
this.props.pluginName, | ||
h("br", null) | ||
); | ||
return h( | ||
"div", | ||
{ "class": "uppy-Provider-auth" }, | ||
h( | ||
"div", | ||
{ "class": "uppy-Provider-authIcon" }, | ||
this.props.pluginIcon() | ||
), | ||
h( | ||
"div", | ||
{ "class": "uppy-Provider-authTitle" }, | ||
this.props.i18nArray('authenticateWithTitle', { pluginName: pluginNameComponent }) | ||
), | ||
h( | ||
"button", | ||
{ | ||
type: "button", | ||
"class": "uppy-u-reset uppy-c-btn uppy-c-btn-primary uppy-Provider-authBtn", | ||
onclick: this.props.handleAuth, | ||
ref: function ref(el) { | ||
_this3.connectButton = el; | ||
} | ||
}, | ||
this.props.i18nArray('authenticateWith', { pluginName: this.props.pluginName }) | ||
) | ||
); | ||
var pluginNameComponent = h("span", { | ||
class: "uppy-Provider-authTitleName" | ||
}, this.props.pluginName, h("br", null)); | ||
return h("div", { | ||
class: "uppy-Provider-auth" | ||
}, h("div", { | ||
class: "uppy-Provider-authIcon" | ||
}, this.props.pluginIcon()), h("div", { | ||
class: "uppy-Provider-authTitle" | ||
}, this.props.i18nArray('authenticateWithTitle', { | ||
pluginName: pluginNameComponent | ||
})), h("button", { | ||
type: "button", | ||
class: "uppy-u-reset uppy-c-btn uppy-c-btn-primary uppy-Provider-authBtn", | ||
onclick: this.props.handleAuth, | ||
ref: function ref(el) { | ||
_this2.connectButton = el; | ||
} | ||
}, this.props.i18nArray('authenticateWith', { | ||
pluginName: this.props.pluginName | ||
}))); | ||
}; | ||
@@ -70,12 +60,14 @@ | ||
var AuthView = function (_Component2) { | ||
_inherits(AuthView, _Component2); | ||
var AuthView = | ||
/*#__PURE__*/ | ||
function (_Component2) { | ||
_inheritsLoose(AuthView, _Component2); | ||
function AuthView() { | ||
_classCallCheck(this, AuthView); | ||
return _possibleConstructorReturn(this, _Component2.apply(this, arguments)); | ||
return _Component2.apply(this, arguments) || this; | ||
} | ||
AuthView.prototype.render = function render() { | ||
var _proto2 = AuthView.prototype; | ||
_proto2.render = function render() { | ||
return h(AuthBlock, this.props); | ||
@@ -82,0 +74,0 @@ }; |
@@ -5,36 +5,23 @@ var _require = require('preact'), | ||
var Breadcrumb = function Breadcrumb(props) { | ||
return h( | ||
"span", | ||
null, | ||
h( | ||
"button", | ||
{ | ||
type: "button", | ||
"class": "uppy-u-reset", | ||
onclick: props.getFolder }, | ||
props.title | ||
), | ||
!props.isLast ? ' / ' : '' | ||
); | ||
return h("span", null, h("button", { | ||
type: "button", | ||
class: "uppy-u-reset", | ||
onclick: props.getFolder | ||
}, props.title), !props.isLast ? ' / ' : ''); | ||
}; | ||
module.exports = function (props) { | ||
return h( | ||
"div", | ||
{ "class": "uppy-Provider-breadcrumbs" }, | ||
h( | ||
"div", | ||
{ "class": "uppy-Provider-breadcrumbsIcon" }, | ||
props.breadcrumbsIcon | ||
), | ||
props.directories.map(function (directory, i) { | ||
return Breadcrumb({ | ||
getFolder: function getFolder() { | ||
return props.getFolder(directory.id); | ||
}, | ||
title: i === 0 ? props.title : directory.title, | ||
isLast: i + 1 === props.directories.length | ||
}); | ||
}) | ||
); | ||
return h("div", { | ||
class: "uppy-Provider-breadcrumbs" | ||
}, h("div", { | ||
class: "uppy-Provider-breadcrumbsIcon" | ||
}, props.breadcrumbsIcon), props.directories.map(function (directory, i) { | ||
return Breadcrumb({ | ||
getFolder: function getFolder() { | ||
return props.getFolder(directory.id); | ||
}, | ||
title: i === 0 ? props.title : directory.title, | ||
isLast: i + 1 === props.directories.length | ||
}); | ||
})); | ||
}; |
@@ -1,7 +0,11 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var classNames = require('classnames'); | ||
var Breadcrumbs = require('./Breadcrumbs'); | ||
var Filter = require('./Filter'); | ||
var Table = require('./ItemList'); | ||
var FooterActions = require('./FooterActions'); | ||
@@ -22,53 +26,41 @@ | ||
var selected = props.currentSelection.length; | ||
return h( | ||
'div', | ||
{ 'class': classNames('uppy-ProviderBrowser', 'uppy-ProviderBrowser-viewType--' + props.viewType) }, | ||
h( | ||
'div', | ||
{ 'class': 'uppy-ProviderBrowser-header' }, | ||
h( | ||
'div', | ||
{ 'class': classNames('uppy-ProviderBrowser-headerBar', !props.showBreadcrumbs && 'uppy-ProviderBrowser-headerBar--simple') }, | ||
props.showBreadcrumbs && Breadcrumbs({ | ||
getFolder: props.getFolder, | ||
directories: props.directories, | ||
breadcrumbsIcon: props.pluginIcon && props.pluginIcon(), | ||
title: props.title | ||
}), | ||
h( | ||
'span', | ||
{ 'class': 'uppy-ProviderBrowser-user' }, | ||
props.username | ||
), | ||
h( | ||
'button', | ||
{ type: 'button', onclick: props.logout, 'class': 'uppy-u-reset uppy-ProviderBrowser-userLogout' }, | ||
props.i18n('logOut') | ||
) | ||
) | ||
), | ||
props.showFilter && h(Filter, props), | ||
h(Table, { | ||
columns: [{ | ||
name: 'Name', | ||
key: 'title' | ||
}], | ||
folders: filteredFolders, | ||
files: filteredFiles, | ||
activeRow: props.isActiveRow, | ||
sortByTitle: props.sortByTitle, | ||
sortByDate: props.sortByDate, | ||
isChecked: props.isChecked, | ||
handleFolderClick: props.getNextFolder, | ||
toggleCheckbox: props.toggleCheckbox, | ||
handleScroll: props.handleScroll, | ||
title: props.title, | ||
showTitles: props.showTitles, | ||
i18n: props.i18n | ||
}), | ||
selected > 0 && h(FooterActions, _extends({ selected: selected }, props)) | ||
); | ||
return h("div", { | ||
class: classNames('uppy-ProviderBrowser', "uppy-ProviderBrowser-viewType--" + props.viewType) | ||
}, h("div", { | ||
class: "uppy-ProviderBrowser-header" | ||
}, h("div", { | ||
class: classNames('uppy-ProviderBrowser-headerBar', !props.showBreadcrumbs && 'uppy-ProviderBrowser-headerBar--simple') | ||
}, props.showBreadcrumbs && Breadcrumbs({ | ||
getFolder: props.getFolder, | ||
directories: props.directories, | ||
breadcrumbsIcon: props.pluginIcon && props.pluginIcon(), | ||
title: props.title | ||
}), h("span", { | ||
class: "uppy-ProviderBrowser-user" | ||
}, props.username), h("button", { | ||
type: "button", | ||
onclick: props.logout, | ||
class: "uppy-u-reset uppy-ProviderBrowser-userLogout" | ||
}, props.i18n('logOut')))), props.showFilter && h(Filter, props), h(Table, { | ||
columns: [{ | ||
name: 'Name', | ||
key: 'title' | ||
}], | ||
folders: filteredFolders, | ||
files: filteredFiles, | ||
activeRow: props.isActiveRow, | ||
sortByTitle: props.sortByTitle, | ||
sortByDate: props.sortByDate, | ||
isChecked: props.isChecked, | ||
handleFolderClick: props.getNextFolder, | ||
toggleCheckbox: props.toggleCheckbox, | ||
handleScroll: props.handleScroll, | ||
title: props.title, | ||
showTitles: props.showTitles, | ||
i18n: props.i18n | ||
}), selected > 0 && h(FooterActions, _extends({ | ||
selected: selected | ||
}, props))); | ||
}; | ||
module.exports = Browser; |
@@ -1,7 +0,5 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _require = require('preact'), | ||
@@ -11,15 +9,18 @@ h = _require.h, | ||
module.exports = function (_Component) { | ||
_inherits(Filter, _Component); | ||
module.exports = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inheritsLoose(Filter, _Component); | ||
function Filter(props) { | ||
_classCallCheck(this, Filter); | ||
var _this; | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
_this.handleKeyPress = _this.handleKeyPress.bind(_this); | ||
_this = _Component.call(this, props) || this; | ||
_this.handleKeyPress = _this.handleKeyPress.bind(_assertThisInitialized(_this)); | ||
return _this; | ||
} | ||
Filter.prototype.handleKeyPress = function handleKeyPress(ev) { | ||
var _proto = Filter.prototype; | ||
_proto.handleKeyPress = function handleKeyPress(ev) { | ||
if (ev.keyCode === 13) { | ||
@@ -30,43 +31,44 @@ ev.stopPropagation(); | ||
} | ||
this.props.filterQuery(ev); | ||
}; | ||
Filter.prototype.render = function render() { | ||
_proto.render = function render() { | ||
var _this2 = this; | ||
return h( | ||
"div", | ||
{ "class": "uppy-ProviderBrowser-search" }, | ||
h("input", { | ||
"class": "uppy-u-reset uppy-ProviderBrowser-searchInput", | ||
type: "text", | ||
placeholder: this.props.i18n('filter'), | ||
"aria-label": this.props.i18n('filter'), | ||
onkeyup: this.handleKeyPress, | ||
onkeydown: this.handleKeyPress, | ||
onkeypress: this.handleKeyPress, | ||
value: this.props.filterInput, | ||
ref: function ref(input) { | ||
_this2.input = input; | ||
} }), | ||
h( | ||
"svg", | ||
{ "aria-hidden": "true", "class": "UppyIcon uppy-ProviderBrowser-searchIcon", width: "12", height: "12", viewBox: "0 0 12 12" }, | ||
h("path", { d: "M8.638 7.99l3.172 3.172a.492.492 0 1 1-.697.697L7.91 8.656a4.977 4.977 0 0 1-2.983.983C2.206 9.639 0 7.481 0 4.819 0 2.158 2.206 0 4.927 0c2.721 0 4.927 2.158 4.927 4.82a4.74 4.74 0 0 1-1.216 3.17zm-3.71.685c2.176 0 3.94-1.726 3.94-3.856 0-2.129-1.764-3.855-3.94-3.855C2.75.964.984 2.69.984 4.819c0 2.13 1.765 3.856 3.942 3.856z" }) | ||
), | ||
this.props.filterInput && h( | ||
"button", | ||
{ | ||
"class": "uppy-u-reset uppy-ProviderBrowser-searchClose", | ||
type: "button", | ||
"aria-label": this.props.i18n('resetFilter'), | ||
title: this.props.i18n('resetFilter'), | ||
onclick: this.props.filterQuery }, | ||
h( | ||
"svg", | ||
{ "aria-hidden": "true", "class": "UppyIcon", viewBox: "0 0 19 19" }, | ||
h("path", { d: "M17.318 17.232L9.94 9.854 9.586 9.5l-.354.354-7.378 7.378h.707l-.62-.62v.706L9.318 9.94l.354-.354-.354-.354L1.94 1.854v.707l.62-.62h-.706l7.378 7.378.354.354.354-.354 7.378-7.378h-.707l.622.62v-.706L9.854 9.232l-.354.354.354.354 7.378 7.378.708-.707-7.38-7.378v.708l7.38-7.38.353-.353-.353-.353-.622-.622-.353-.353-.354.352-7.378 7.38h.708L2.56 1.23 2.208.88l-.353.353-.622.62-.353.355.352.353 7.38 7.38v-.708l-7.38 7.38-.353.353.352.353.622.622.353.353.354-.353 7.38-7.38h-.708l7.38 7.38z" }) | ||
) | ||
) | ||
); | ||
return h("div", { | ||
class: "uppy-ProviderBrowser-search" | ||
}, h("input", { | ||
class: "uppy-u-reset uppy-ProviderBrowser-searchInput", | ||
type: "text", | ||
placeholder: this.props.i18n('filter'), | ||
"aria-label": this.props.i18n('filter'), | ||
onkeyup: this.handleKeyPress, | ||
onkeydown: this.handleKeyPress, | ||
onkeypress: this.handleKeyPress, | ||
value: this.props.filterInput, | ||
ref: function ref(input) { | ||
_this2.input = input; | ||
} | ||
}), h("svg", { | ||
"aria-hidden": "true", | ||
class: "UppyIcon uppy-ProviderBrowser-searchIcon", | ||
width: "12", | ||
height: "12", | ||
viewBox: "0 0 12 12" | ||
}, h("path", { | ||
d: "M8.638 7.99l3.172 3.172a.492.492 0 1 1-.697.697L7.91 8.656a4.977 4.977 0 0 1-2.983.983C2.206 9.639 0 7.481 0 4.819 0 2.158 2.206 0 4.927 0c2.721 0 4.927 2.158 4.927 4.82a4.74 4.74 0 0 1-1.216 3.17zm-3.71.685c2.176 0 3.94-1.726 3.94-3.856 0-2.129-1.764-3.855-3.94-3.855C2.75.964.984 2.69.984 4.819c0 2.13 1.765 3.856 3.942 3.856z" | ||
})), this.props.filterInput && h("button", { | ||
class: "uppy-u-reset uppy-ProviderBrowser-searchClose", | ||
type: "button", | ||
"aria-label": this.props.i18n('resetFilter'), | ||
title: this.props.i18n('resetFilter'), | ||
onclick: this.props.filterQuery | ||
}, h("svg", { | ||
"aria-hidden": "true", | ||
class: "UppyIcon", | ||
viewBox: "0 0 19 19" | ||
}, h("path", { | ||
d: "M17.318 17.232L9.94 9.854 9.586 9.5l-.354.354-7.378 7.378h.707l-.62-.62v.706L9.318 9.94l.354-.354-.354-.354L1.94 1.854v.707l.62-.62h-.706l7.378 7.378.354.354.354-.354 7.378-7.378h-.707l.622.62v-.706L9.854 9.232l-.354.354.354.354 7.378 7.378.708-.707-7.38-7.378v.708l7.38-7.38.353-.353-.353-.353-.622-.622-.353-.353-.354.352-7.378 7.38h.708L2.56 1.23 2.208.88l-.353.353-.622.62-.353.355.352.353 7.38 7.38v-.708l-7.38 7.38-.353.353.352.353.622.622.353.353.354-.353 7.38-7.38h-.708l7.38 7.38z" | ||
})))); | ||
}; | ||
@@ -73,0 +75,0 @@ |
@@ -5,18 +5,13 @@ var _require = require('preact'), | ||
module.exports = function (props) { | ||
return h( | ||
"div", | ||
{ "class": "uppy-ProviderBrowser-footer" }, | ||
h( | ||
"button", | ||
{ "class": "uppy-u-reset uppy-c-btn uppy-c-btn-primary", onclick: props.done }, | ||
props.i18n('selectXFiles', { | ||
smart_count: props.selected | ||
}) | ||
), | ||
h( | ||
"button", | ||
{ "class": "uppy-u-reset uppy-c-btn uppy-c-btn-link", onclick: props.cancel }, | ||
props.i18n('cancel') | ||
) | ||
); | ||
return h("div", { | ||
class: "uppy-ProviderBrowser-footer" | ||
}, h("button", { | ||
class: "uppy-u-reset uppy-c-btn uppy-c-btn-primary", | ||
onclick: props.done | ||
}, props.i18n('selectXFiles', { | ||
smart_count: props.selected | ||
})), h("button", { | ||
class: "uppy-u-reset uppy-c-btn uppy-c-btn-link", | ||
onclick: props.cancel | ||
}, props.i18n('cancel'))); | ||
}; |
460
lib/index.js
@@ -1,9 +0,7 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _class, _temp; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _require = require('preact'), | ||
@@ -14,11 +12,17 @@ h = _require.h, | ||
var AuthView = require('./AuthView'); | ||
var Browser = require('./Browser'); | ||
var LoaderView = require('./Loader'); | ||
var generateFileID = require('@uppy/utils/lib/generateFileID'); | ||
var getFileType = require('@uppy/utils/lib/getFileType'); | ||
var isPreviewSupported = require('@uppy/utils/lib/isPreviewSupported'); | ||
/** | ||
* Array.prototype.findIndex ponyfill for old browsers. | ||
*/ | ||
function findIndex(array, predicate) { | ||
@@ -28,19 +32,31 @@ for (var i = 0; i < array.length; i++) { | ||
} | ||
return -1; | ||
} // location.origin does not exist in IE | ||
function getOrigin() { | ||
if ('origin' in location) { | ||
return location.origin; // eslint-disable-line compat/compat | ||
} | ||
return location.protocol + "//" + location.hostname + (location.port ? ":" + location.port : ''); | ||
} | ||
var CloseWrapper = function (_Component) { | ||
_inherits(CloseWrapper, _Component); | ||
var CloseWrapper = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inheritsLoose(CloseWrapper, _Component); | ||
function CloseWrapper() { | ||
_classCallCheck(this, CloseWrapper); | ||
return _possibleConstructorReturn(this, _Component.apply(this, arguments)); | ||
return _Component.apply(this, arguments) || this; | ||
} | ||
CloseWrapper.prototype.componentWillUnmount = function componentWillUnmount() { | ||
var _proto = CloseWrapper.prototype; | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
this.props.onUnmount(); | ||
}; | ||
CloseWrapper.prototype.render = function render() { | ||
_proto.render = function render() { | ||
return this.props.children[0]; | ||
@@ -51,3 +67,2 @@ }; | ||
}(Component); | ||
/** | ||
@@ -58,3 +73,5 @@ * Class to easily generate generic views for Provider plugins | ||
module.exports = function () { | ||
module.exports = (_temp = _class = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
@@ -64,8 +81,5 @@ * @param {object} instance of the plugin | ||
function ProviderView(plugin, opts) { | ||
_classCallCheck(this, ProviderView); | ||
this.plugin = plugin; | ||
this.provider = opts.provider; | ||
this.provider = opts.provider; // set default options | ||
// set default options | ||
var defaultOptions = { | ||
@@ -75,8 +89,7 @@ viewType: 'list', | ||
showFilter: true, | ||
showBreadcrumbs: true | ||
showBreadcrumbs: true // merge default options with the ones set by user | ||
// merge default options with the ones set by user | ||
};this.opts = _extends({}, defaultOptions, opts); | ||
}; | ||
this.opts = _extends({}, defaultOptions, opts); // Logic | ||
// Logic | ||
this.addFile = this.addFile.bind(this); | ||
@@ -100,15 +113,14 @@ this.filterItems = this.filterItems.bind(this); | ||
this.cancelPicking = this.cancelPicking.bind(this); | ||
this.clearSelection = this.clearSelection.bind(this); | ||
this.clearSelection = this.clearSelection.bind(this); // Visual | ||
// Visual | ||
this.render = this.render.bind(this); | ||
this.clearSelection(); | ||
} | ||
ProviderView.prototype.tearDown = function tearDown() { | ||
// Nothing. | ||
var _proto2 = ProviderView.prototype; | ||
_proto2.tearDown = function tearDown() {// Nothing. | ||
}; | ||
ProviderView.prototype._updateFilesAndFolders = function _updateFilesAndFolders(res, files, folders) { | ||
_proto2._updateFilesAndFolders = function _updateFilesAndFolders(res, files, folders) { | ||
this.nextPagePath = res.nextPagePath; | ||
@@ -122,6 +134,7 @@ res.items.forEach(function (item) { | ||
}); | ||
this.plugin.setPluginState({ folders: folders, files: files }); | ||
}; | ||
this.plugin.setPluginState({ | ||
folders: folders, | ||
files: files | ||
}); | ||
} | ||
/** | ||
@@ -131,9 +144,10 @@ * Called only the first time the provider view is rendered. | ||
*/ | ||
; | ||
ProviderView.prototype.preFirstRender = function preFirstRender() { | ||
this.plugin.setPluginState({ didFirstRender: true }); | ||
_proto2.preFirstRender = function preFirstRender() { | ||
this.plugin.setPluginState({ | ||
didFirstRender: true | ||
}); | ||
this.plugin.onFirstRender(); | ||
}; | ||
} | ||
/** | ||
@@ -144,13 +158,14 @@ * Based on folder ID, fetch a new folder and update it to state | ||
*/ | ||
; | ||
_proto2.getFolder = function getFolder(id, name) { | ||
var _this = this; | ||
ProviderView.prototype.getFolder = function getFolder(id, name) { | ||
var _this2 = this; | ||
return this._loaderWrapper(this.provider.list(id), function (res) { | ||
var folders = []; | ||
var files = []; | ||
var updatedDirectories = void 0; | ||
var updatedDirectories; | ||
var state = _this2.plugin.getPluginState(); | ||
var state = _this.plugin.getPluginState(); | ||
var index = findIndex(state.directories, function (dir) { | ||
@@ -163,11 +178,17 @@ return id === dir.id; | ||
} else { | ||
updatedDirectories = state.directories.concat([{ id: id, title: name }]); | ||
updatedDirectories = state.directories.concat([{ | ||
id: id, | ||
title: name | ||
}]); | ||
} | ||
_this2.username = _this2.username ? _this2.username : res.username; | ||
_this2._updateFilesAndFolders(res, files, folders); | ||
_this2.plugin.setPluginState({ directories: updatedDirectories }); | ||
_this.username = _this.username ? _this.username : res.username; | ||
_this._updateFilesAndFolders(res, files, folders); | ||
_this.plugin.setPluginState({ | ||
directories: updatedDirectories | ||
}); | ||
}, this.handleError); | ||
}; | ||
} | ||
/** | ||
@@ -178,5 +199,5 @@ * Fetches new folder | ||
*/ | ||
; | ||
ProviderView.prototype.getNextFolder = function getNextFolder(folder) { | ||
_proto2.getNextFolder = function getNextFolder(folder) { | ||
this.getFolder(folder.requestPath, folder.name); | ||
@@ -186,3 +207,3 @@ this.lastCheckbox = undefined; | ||
ProviderView.prototype.addFile = function addFile(file) { | ||
_proto2.addFile = function addFile(file) { | ||
var tagFile = { | ||
@@ -200,3 +221,3 @@ id: this.providerFileToId(file), | ||
companionUrl: this.plugin.opts.companionUrl, | ||
url: '' + this.provider.fileUrl(file.requestPath), | ||
url: "" + this.provider.fileUrl(file.requestPath), | ||
body: { | ||
@@ -208,19 +229,19 @@ fileId: file.id | ||
}; | ||
var fileType = getFileType(tagFile); // TODO Should we just always use the thumbnail URL if it exists? | ||
var fileType = getFileType(tagFile); | ||
// TODO Should we just always use the thumbnail URL if it exists? | ||
if (fileType && isPreviewSupported(fileType)) { | ||
tagFile.preview = file.thumbnail; | ||
} | ||
this.plugin.uppy.log('Adding remote file'); | ||
try { | ||
this.plugin.uppy.addFile(tagFile); | ||
} catch (err) { | ||
// Nothing, restriction errors handled in Core | ||
} catch (err) {// Nothing, restriction errors handled in Core | ||
} | ||
}; | ||
ProviderView.prototype.removeFile = function removeFile(id) { | ||
var _plugin$getPluginStat = this.plugin.getPluginState(), | ||
currentSelection = _plugin$getPluginStat.currentSelection; | ||
_proto2.removeFile = function removeFile(id) { | ||
var _this$plugin$getPlugi = this.plugin.getPluginState(), | ||
currentSelection = _this$plugin$getPlugi.currentSelection; | ||
@@ -232,12 +253,11 @@ this.plugin.setPluginState({ | ||
}); | ||
}; | ||
} | ||
/** | ||
* Removes session token on client side. | ||
*/ | ||
; | ||
_proto2.logout = function logout() { | ||
var _this2 = this; | ||
ProviderView.prototype.logout = function logout() { | ||
var _this3 = this; | ||
this.provider.logout(location.href).then(function (res) { | ||
@@ -251,3 +271,4 @@ if (res.ok) { | ||
}; | ||
_this3.plugin.setPluginState(newState); | ||
_this2.plugin.setPluginState(newState); | ||
} | ||
@@ -257,3 +278,3 @@ }).catch(this.handleError); | ||
ProviderView.prototype.filterQuery = function filterQuery(e) { | ||
_proto2.filterQuery = function filterQuery(e) { | ||
var state = this.plugin.getPluginState(); | ||
@@ -265,5 +286,4 @@ this.plugin.setPluginState(_extends({}, state, { | ||
ProviderView.prototype.toggleSearch = function toggleSearch(inputEl) { | ||
_proto2.toggleSearch = function toggleSearch(inputEl) { | ||
var state = this.plugin.getPluginState(); | ||
this.plugin.setPluginState({ | ||
@@ -275,7 +295,9 @@ isSearchVisible: !state.isSearchVisible, | ||
ProviderView.prototype.filterItems = function filterItems(items) { | ||
_proto2.filterItems = function filterItems(items) { | ||
var state = this.plugin.getPluginState(); | ||
if (!state.filterInput || state.filterInput === '') { | ||
return items; | ||
} | ||
return items.filter(function (folder) { | ||
@@ -286,9 +308,8 @@ return folder.name.toLowerCase().indexOf(state.filterInput.toLowerCase()) !== -1; | ||
ProviderView.prototype.sortByTitle = function sortByTitle() { | ||
_proto2.sortByTitle = function sortByTitle() { | ||
var state = _extends({}, this.plugin.getPluginState()); | ||
var files = state.files, | ||
folders = state.folders, | ||
sorting = state.sorting; | ||
var sortedFiles = files.sort(function (fileA, fileB) { | ||
@@ -298,5 +319,5 @@ if (sorting === 'titleDescending') { | ||
} | ||
return fileA.name.localeCompare(fileB.name); | ||
}); | ||
var sortedFolders = folders.sort(function (folderA, folderB) { | ||
@@ -306,5 +327,5 @@ if (sorting === 'titleDescending') { | ||
} | ||
return folderA.name.localeCompare(folderB.name); | ||
}); | ||
this.plugin.setPluginState(_extends({}, state, { | ||
@@ -317,9 +338,8 @@ files: sortedFiles, | ||
ProviderView.prototype.sortByDate = function sortByDate() { | ||
_proto2.sortByDate = function sortByDate() { | ||
var state = _extends({}, this.plugin.getPluginState()); | ||
var files = state.files, | ||
folders = state.folders, | ||
sorting = state.sorting; | ||
var sortedFiles = files.sort(function (fileA, fileB) { | ||
@@ -332,5 +352,5 @@ var a = new Date(fileA.modifiedDate); | ||
} | ||
return a > b ? 1 : a < b ? -1 : 0; | ||
}); | ||
var sortedFolders = folders.sort(function (folderA, folderB) { | ||
@@ -346,3 +366,2 @@ var a = new Date(folderA.modifiedDate); | ||
}); | ||
this.plugin.setPluginState(_extends({}, state, { | ||
@@ -355,9 +374,8 @@ files: sortedFiles, | ||
ProviderView.prototype.sortBySize = function sortBySize() { | ||
_proto2.sortBySize = function sortBySize() { | ||
var state = _extends({}, this.plugin.getPluginState()); | ||
var files = state.files, | ||
sorting = state.sorting; | ||
sorting = state.sorting; // check that plugin supports file sizes | ||
// check that plugin supports file sizes | ||
if (!files.length || !this.plugin.getItemData(files[0]).size) { | ||
@@ -374,5 +392,5 @@ return; | ||
} | ||
return a > b ? 1 : a < b ? -1 : 0; | ||
}); | ||
this.plugin.setPluginState(_extends({}, state, { | ||
@@ -384,9 +402,9 @@ files: sortedFiles, | ||
ProviderView.prototype.isActiveRow = function isActiveRow(file) { | ||
_proto2.isActiveRow = function isActiveRow(file) { | ||
return this.plugin.getPluginState().activeRow === this.plugin.getItemId(file); | ||
}; | ||
ProviderView.prototype.isChecked = function isChecked(file) { | ||
var _plugin$getPluginStat2 = this.plugin.getPluginState(), | ||
currentSelection = _plugin$getPluginStat2.currentSelection; | ||
_proto2.isChecked = function isChecked(file) { | ||
var _this$plugin$getPlugi2 = this.plugin.getPluginState(), | ||
currentSelection = _this$plugin$getPlugi2.currentSelection; | ||
@@ -396,4 +414,3 @@ return currentSelection.some(function (item) { | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -405,15 +422,22 @@ * Adds all files found inside of specified folder. | ||
*/ | ||
; | ||
_proto2.addFolder = function addFolder(folder) { | ||
var _this3 = this; | ||
ProviderView.prototype.addFolder = function addFolder(folder) { | ||
var _this4 = this; | ||
var folderId = this.providerFileToId(folder); | ||
var state = this.plugin.getPluginState(); | ||
var folders = state.selectedFolders || {}; | ||
if (folderId in folders && folders[folderId].loading) { | ||
return; | ||
} | ||
folders[folderId] = { loading: true, files: [] }; | ||
this.plugin.setPluginState({ selectedFolders: folders }); | ||
folders[folderId] = { | ||
loading: true, | ||
files: [] | ||
}; | ||
this.plugin.setPluginState({ | ||
selectedFolders: folders | ||
}); | ||
return this.provider.list(folder.requestPath).then(function (res) { | ||
@@ -423,14 +447,25 @@ var files = []; | ||
if (!item.isFolder) { | ||
_this4.addFile(item); | ||
files.push(_this4.providerFileToId(item)); | ||
_this3.addFile(item); | ||
files.push(_this3.providerFileToId(item)); | ||
} | ||
}); | ||
state = _this4.plugin.getPluginState(); | ||
state.selectedFolders[folderId] = { loading: false, files: files }; | ||
_this4.plugin.setPluginState({ selectedFolders: folders }); | ||
var dashboard = _this4.plugin.uppy.getPlugin('Dashboard'); | ||
var message = void 0; | ||
state = _this3.plugin.getPluginState(); | ||
state.selectedFolders[folderId] = { | ||
loading: false, | ||
files: files | ||
}; | ||
_this3.plugin.setPluginState({ | ||
selectedFolders: folders | ||
}); | ||
var dashboard = _this3.plugin.uppy.getPlugin('Dashboard'); | ||
var message; | ||
if (files.length) { | ||
message = dashboard.i18n('folderAdded', { | ||
smart_count: files.length, folder: folder.name | ||
smart_count: files.length, | ||
folder: folder.name | ||
}); | ||
@@ -440,11 +475,15 @@ } else { | ||
} | ||
_this4.plugin.uppy.info(message); | ||
_this3.plugin.uppy.info(message); | ||
}).catch(function (e) { | ||
state = _this4.plugin.getPluginState(); | ||
state = _this3.plugin.getPluginState(); | ||
delete state.selectedFolders[folderId]; | ||
_this4.plugin.setPluginState({ selectedFolders: state.selectedFolders }); | ||
_this4.handleError(e); | ||
_this3.plugin.setPluginState({ | ||
selectedFolders: state.selectedFolders | ||
}); | ||
_this3.handleError(e); | ||
}); | ||
}; | ||
} | ||
/** | ||
@@ -457,20 +496,21 @@ * Toggles file/folder checkbox to on/off state while updating files list. | ||
*/ | ||
; | ||
ProviderView.prototype.toggleCheckbox = function toggleCheckbox(e, file) { | ||
_proto2.toggleCheckbox = function toggleCheckbox(e, file) { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
var _plugin$getPluginStat3 = this.plugin.getPluginState(), | ||
folders = _plugin$getPluginStat3.folders, | ||
files = _plugin$getPluginStat3.files; | ||
var _this$plugin$getPlugi3 = this.plugin.getPluginState(), | ||
folders = _this$plugin$getPlugi3.folders, | ||
files = _this$plugin$getPlugi3.files; | ||
var items = this.filterItems(folders.concat(files)); | ||
var items = this.filterItems(folders.concat(files)); // Shift-clicking selects a single consecutive list of items | ||
// starting at the previous click and deselects everything else. | ||
// Shift-clicking selects a single consecutive list of items | ||
// starting at the previous click and deselects everything else. | ||
if (this.lastCheckbox && e.shiftKey) { | ||
var _currentSelection = void 0; | ||
var _currentSelection; | ||
var prevIndex = items.indexOf(this.lastCheckbox); | ||
var currentIndex = items.indexOf(file); | ||
if (prevIndex < currentIndex) { | ||
@@ -481,3 +521,6 @@ _currentSelection = items.slice(prevIndex, currentIndex + 1); | ||
} | ||
this.plugin.setPluginState({ currentSelection: _currentSelection }); | ||
this.plugin.setPluginState({ | ||
currentSelection: _currentSelection | ||
}); | ||
return; | ||
@@ -488,4 +531,4 @@ } | ||
var _plugin$getPluginStat4 = this.plugin.getPluginState(), | ||
currentSelection = _plugin$getPluginStat4.currentSelection; | ||
var _this$plugin$getPlugi4 = this.plugin.getPluginState(), | ||
currentSelection = _this$plugin$getPlugi4.currentSelection; | ||
@@ -505,3 +548,3 @@ if (this.isChecked(file)) { | ||
ProviderView.prototype.providerFileToId = function providerFileToId(file) { | ||
_proto2.providerFileToId = function providerFileToId(file) { | ||
return generateFileID({ | ||
@@ -514,23 +557,27 @@ data: file, | ||
ProviderView.prototype.handleAuth = function handleAuth() { | ||
var _this5 = this; | ||
_proto2.handleAuth = function handleAuth() { | ||
var _this4 = this; | ||
var authState = btoa(JSON.stringify({ origin: location.origin })); | ||
// @todo remove this hardcoded version | ||
var authState = btoa(JSON.stringify({ | ||
origin: getOrigin() | ||
})); // @todo remove this hardcoded version | ||
var clientVersion = 'companion-client:1.0.2'; | ||
var link = this.provider.authUrl() + '?state=' + authState + '&uppyVersions=' + clientVersion; | ||
var link = this.provider.authUrl() + "?state=" + authState + "&uppyVersions=" + clientVersion; | ||
var authWindow = window.open(link, '_blank'); | ||
var authWindow = window.open(link, '_blank'); | ||
var handleToken = function handleToken(e) { | ||
if (!_this5._isOriginAllowed(e.origin, _this5.plugin.opts.companionAllowedHosts) || e.source !== authWindow) { | ||
_this5.plugin.uppy.log('rejecting event from ' + e.origin + ' vs allowed pattern ' + _this5.plugin.opts.companionAllowedHosts); | ||
if (!_this4._isOriginAllowed(e.origin, _this4.plugin.opts.companionAllowedHosts) || e.source !== authWindow) { | ||
_this4.plugin.uppy.log("rejecting event from " + e.origin + " vs allowed pattern " + _this4.plugin.opts.companionAllowedHosts); | ||
return; | ||
} | ||
} // Check if it's a string before doing the JSON.parse to maintain support | ||
// for older Companion versions that used object references | ||
// Check if it's a string before doing the JSON.parse to maintain support | ||
// for older Companion versions that used object references | ||
var data = typeof e.data === 'string' ? JSON.parse(e.data) : e.data; | ||
if (!data.token) { | ||
_this5.plugin.uppy.log('did not receive token from auth window'); | ||
_this4.plugin.uppy.log('did not receive token from auth window'); | ||
return; | ||
@@ -541,12 +588,15 @@ } | ||
window.removeEventListener('message', handleToken); | ||
_this5.provider.setAuthToken(data.token); | ||
_this5.preFirstRender(); | ||
_this4.provider.setAuthToken(data.token); | ||
_this4.preFirstRender(); | ||
}; | ||
window.addEventListener('message', handleToken); | ||
}; | ||
ProviderView.prototype._isOriginAllowed = function _isOriginAllowed(origin, allowedOrigin) { | ||
_proto2._isOriginAllowed = function _isOriginAllowed(origin, allowedOrigin) { | ||
var getRegex = function getRegex(value) { | ||
if (typeof value === 'string') { | ||
return new RegExp('^' + value + '$'); | ||
return new RegExp("^" + value + "$"); | ||
} else if (value instanceof RegExp) { | ||
@@ -559,20 +609,26 @@ return value; | ||
return patterns.filter(function (pattern) { | ||
return pattern !== null; | ||
}).some(function (pattern) { | ||
return pattern.test(origin); | ||
}); | ||
return pattern != null; | ||
}) // loose comparison to catch undefined | ||
.some(function (pattern) { | ||
return pattern.test(origin) || pattern.test(origin + "/"); | ||
}); // allowing for trailing '/' | ||
}; | ||
ProviderView.prototype.handleError = function handleError(error) { | ||
_proto2.handleError = function handleError(error) { | ||
var uppy = this.plugin.uppy; | ||
uppy.log(error.toString()); | ||
if (error.isAuthError) { | ||
return; | ||
} | ||
var message = uppy.i18n('companionError'); | ||
uppy.info({ message: message, details: error.toString() }, 'error', 5000); | ||
uppy.info({ | ||
message: message, | ||
details: error.toString() | ||
}, 'error', 5000); | ||
}; | ||
ProviderView.prototype.handleScroll = function handleScroll(e) { | ||
var _this6 = this; | ||
_proto2.handleScroll = function handleScroll(e) { | ||
var _this5 = this; | ||
@@ -584,9 +640,9 @@ var scrollPos = e.target.scrollHeight - (e.target.scrollTop + e.target.offsetHeight); | ||
this.provider.list(path).then(function (res) { | ||
var _plugin$getPluginStat5 = _this6.plugin.getPluginState(), | ||
files = _plugin$getPluginStat5.files, | ||
folders = _plugin$getPluginStat5.folders; | ||
var _this5$plugin$getPlug = _this5.plugin.getPluginState(), | ||
files = _this5$plugin$getPlug.files, | ||
folders = _this5$plugin$getPlug.folders; | ||
_this6._updateFilesAndFolders(res, files, folders); | ||
_this5._updateFilesAndFolders(res, files, folders); | ||
}).catch(this.handleError).then(function () { | ||
_this6._isHandlingScroll = false; | ||
_this5._isHandlingScroll = false; | ||
}); // always called | ||
@@ -598,13 +654,13 @@ | ||
ProviderView.prototype.donePicking = function donePicking() { | ||
var _this7 = this; | ||
_proto2.donePicking = function donePicking() { | ||
var _this6 = this; | ||
var _plugin$getPluginStat6 = this.plugin.getPluginState(), | ||
currentSelection = _plugin$getPluginStat6.currentSelection; | ||
var _this$plugin$getPlugi5 = this.plugin.getPluginState(), | ||
currentSelection = _this$plugin$getPlugi5.currentSelection; | ||
var promises = currentSelection.map(function (file) { | ||
if (file.isFolder) { | ||
return _this7.addFolder(file); | ||
return _this6.addFolder(file); | ||
} else { | ||
return _this7.addFile(file); | ||
return _this6.addFile(file); | ||
} | ||
@@ -614,9 +670,8 @@ }); | ||
this._loaderWrapper(Promise.all(promises), function () { | ||
_this7.clearSelection(); | ||
_this6.clearSelection(); | ||
}, function () {}); | ||
}; | ||
ProviderView.prototype.cancelPicking = function cancelPicking() { | ||
_proto2.cancelPicking = function cancelPicking() { | ||
this.clearSelection(); | ||
var dashboard = this.plugin.uppy.getPlugin('Dashboard'); | ||
@@ -626,52 +681,59 @@ if (dashboard) dashboard.hideAllPanels(); | ||
ProviderView.prototype.clearSelection = function clearSelection() { | ||
this.plugin.setPluginState({ currentSelection: [] }); | ||
}; | ||
_proto2.clearSelection = function clearSelection() { | ||
this.plugin.setPluginState({ | ||
currentSelection: [] | ||
}); | ||
} // displays loader view while asynchronous request is being made. | ||
; | ||
// displays loader view while asynchronous request is being made. | ||
_proto2._loaderWrapper = function _loaderWrapper(promise, then, catch_) { | ||
var _this7 = this; | ||
promise.then(function (result) { | ||
_this7.plugin.setPluginState({ | ||
loading: false | ||
}); | ||
ProviderView.prototype._loaderWrapper = function _loaderWrapper(promise, then, catch_) { | ||
var _this8 = this; | ||
promise.then(function (result) { | ||
_this8.plugin.setPluginState({ loading: false }); | ||
then(result); | ||
}).catch(function (err) { | ||
_this8.plugin.setPluginState({ loading: false }); | ||
_this7.plugin.setPluginState({ | ||
loading: false | ||
}); | ||
catch_(err); | ||
}); | ||
this.plugin.setPluginState({ loading: true }); | ||
this.plugin.setPluginState({ | ||
loading: true | ||
}); | ||
}; | ||
ProviderView.prototype.render = function render(state) { | ||
var _plugin$getPluginStat7 = this.plugin.getPluginState(), | ||
authenticated = _plugin$getPluginStat7.authenticated, | ||
didFirstRender = _plugin$getPluginStat7.didFirstRender; | ||
_proto2.render = function render(state) { | ||
var _this$plugin$getPlugi6 = this.plugin.getPluginState(), | ||
authenticated = _this$plugin$getPlugi6.authenticated, | ||
didFirstRender = _this$plugin$getPlugi6.didFirstRender; | ||
if (!didFirstRender) { | ||
this.preFirstRender(); | ||
} | ||
} // reload pluginState for "loading" attribute because it might | ||
// have changed above. | ||
// reload pluginState for "loading" attribute because it might | ||
// have changed above. | ||
if (this.plugin.getPluginState().loading) { | ||
return h( | ||
CloseWrapper, | ||
{ onUnmount: this.clearSelection }, | ||
h(LoaderView, { i18n: this.plugin.uppy.i18n }) | ||
); | ||
return h(CloseWrapper, { | ||
onUnmount: this.clearSelection | ||
}, h(LoaderView, { | ||
i18n: this.plugin.uppy.i18n | ||
})); | ||
} | ||
if (!authenticated) { | ||
return h( | ||
CloseWrapper, | ||
{ onUnmount: this.clearSelection }, | ||
h(AuthView, { | ||
pluginName: this.plugin.title, | ||
pluginIcon: this.plugin.icon, | ||
handleAuth: this.handleAuth, | ||
i18n: this.plugin.uppy.i18n, | ||
i18nArray: this.plugin.uppy.i18nArray }) | ||
); | ||
return h(CloseWrapper, { | ||
onUnmount: this.clearSelection | ||
}, h(AuthView, { | ||
pluginName: this.plugin.title, | ||
pluginIcon: this.plugin.icon, | ||
handleAuth: this.handleAuth, | ||
i18n: this.plugin.uppy.i18n, | ||
i18nArray: this.plugin.uppy.i18nArray | ||
})); | ||
} | ||
@@ -704,10 +766,8 @@ | ||
return h( | ||
CloseWrapper, | ||
{ onUnmount: this.clearSelection }, | ||
h(Browser, browserProps) | ||
); | ||
return h(CloseWrapper, { | ||
onUnmount: this.clearSelection | ||
}, h(Browser, browserProps)); | ||
}; | ||
return ProviderView; | ||
}(); | ||
}(), _class.VERSION = "1.1.0", _temp); |
116
lib/Item.js
@@ -9,22 +9,39 @@ var _require = require('preact'), | ||
case 'file': | ||
return h( | ||
'svg', | ||
{ 'aria-hidden': 'true', 'class': 'UppyIcon', width: 11, height: 14.5, viewBox: '0 0 44 58' }, | ||
h('path', { d: 'M27.437.517a1 1 0 0 0-.094.03H4.25C2.037.548.217 2.368.217 4.58v48.405c0 2.212 1.82 4.03 4.03 4.03H39.03c2.21 0 4.03-1.818 4.03-4.03V15.61a1 1 0 0 0-.03-.28 1 1 0 0 0 0-.093 1 1 0 0 0-.03-.032 1 1 0 0 0 0-.03 1 1 0 0 0-.032-.063 1 1 0 0 0-.03-.063 1 1 0 0 0-.032 0 1 1 0 0 0-.03-.063 1 1 0 0 0-.032-.03 1 1 0 0 0-.03-.063 1 1 0 0 0-.063-.062l-14.593-14a1 1 0 0 0-.062-.062A1 1 0 0 0 28 .708a1 1 0 0 0-.374-.157 1 1 0 0 0-.156 0 1 1 0 0 0-.03-.03l-.003-.003zM4.25 2.547h22.218v9.97c0 2.21 1.82 4.03 4.03 4.03h10.564v36.438a2.02 2.02 0 0 1-2.032 2.032H4.25c-1.13 0-2.032-.9-2.032-2.032V4.58c0-1.13.902-2.032 2.03-2.032zm24.218 1.345l10.375 9.937.75.718H30.5c-1.13 0-2.032-.9-2.032-2.03V3.89z' }) | ||
); | ||
return h("svg", { | ||
"aria-hidden": "true", | ||
class: "UppyIcon", | ||
width: 11, | ||
height: 14.5, | ||
viewBox: "0 0 44 58" | ||
}, h("path", { | ||
d: "M27.437.517a1 1 0 0 0-.094.03H4.25C2.037.548.217 2.368.217 4.58v48.405c0 2.212 1.82 4.03 4.03 4.03H39.03c2.21 0 4.03-1.818 4.03-4.03V15.61a1 1 0 0 0-.03-.28 1 1 0 0 0 0-.093 1 1 0 0 0-.03-.032 1 1 0 0 0 0-.03 1 1 0 0 0-.032-.063 1 1 0 0 0-.03-.063 1 1 0 0 0-.032 0 1 1 0 0 0-.03-.063 1 1 0 0 0-.032-.03 1 1 0 0 0-.03-.063 1 1 0 0 0-.063-.062l-14.593-14a1 1 0 0 0-.062-.062A1 1 0 0 0 28 .708a1 1 0 0 0-.374-.157 1 1 0 0 0-.156 0 1 1 0 0 0-.03-.03l-.003-.003zM4.25 2.547h22.218v9.97c0 2.21 1.82 4.03 4.03 4.03h10.564v36.438a2.02 2.02 0 0 1-2.032 2.032H4.25c-1.13 0-2.032-.9-2.032-2.032V4.58c0-1.13.902-2.032 2.03-2.032zm24.218 1.345l10.375 9.937.75.718H30.5c-1.13 0-2.032-.9-2.032-2.03V3.89z" | ||
})); | ||
case 'folder': | ||
return h( | ||
'svg', | ||
{ 'aria-hidden': 'true', 'class': 'UppyIcon', style: { width: 16, marginRight: 3 }, viewBox: '0 0 276.157 276.157' }, | ||
h('path', { d: 'M273.08 101.378c-3.3-4.65-8.86-7.32-15.254-7.32h-24.34V67.59c0-10.2-8.3-18.5-18.5-18.5h-85.322c-3.63 0-9.295-2.875-11.436-5.805l-6.386-8.735c-4.982-6.814-15.104-11.954-23.546-11.954H58.73c-9.292 0-18.638 6.608-21.737 15.372l-2.033 5.752c-.958 2.71-4.72 5.37-7.596 5.37H18.5C8.3 49.09 0 57.39 0 67.59v167.07c0 .886.16 1.73.443 2.52.152 3.306 1.18 6.424 3.053 9.064 3.3 4.652 8.86 7.32 15.255 7.32h188.487c11.395 0 23.27-8.425 27.035-19.18l40.677-116.188c2.11-6.035 1.43-12.164-1.87-16.816zM18.5 64.088h8.864c9.295 0 18.64-6.607 21.738-15.37l2.032-5.75c.96-2.712 4.722-5.373 7.597-5.373h29.565c3.63 0 9.295 2.876 11.437 5.806l6.386 8.735c4.982 6.815 15.104 11.954 23.546 11.954h85.322c1.898 0 3.5 1.602 3.5 3.5v26.47H69.34c-11.395 0-23.27 8.423-27.035 19.178L15 191.23V67.59c0-1.898 1.603-3.5 3.5-3.5zm242.29 49.15l-40.676 116.188c-1.674 4.78-7.812 9.135-12.877 9.135H18.75c-1.447 0-2.576-.372-3.02-.997-.442-.625-.422-1.814.057-3.18l40.677-116.19c1.674-4.78 7.812-9.134 12.877-9.134h188.487c1.448 0 2.577.372 3.02.997.443.625.423 1.814-.056 3.18z' }) | ||
); | ||
return h("svg", { | ||
"aria-hidden": "true", | ||
class: "UppyIcon", | ||
style: { | ||
width: 16, | ||
marginRight: 3 | ||
}, | ||
viewBox: "0 0 276.157 276.157" | ||
}, h("path", { | ||
d: "M273.08 101.378c-3.3-4.65-8.86-7.32-15.254-7.32h-24.34V67.59c0-10.2-8.3-18.5-18.5-18.5h-85.322c-3.63 0-9.295-2.875-11.436-5.805l-6.386-8.735c-4.982-6.814-15.104-11.954-23.546-11.954H58.73c-9.292 0-18.638 6.608-21.737 15.372l-2.033 5.752c-.958 2.71-4.72 5.37-7.596 5.37H18.5C8.3 49.09 0 57.39 0 67.59v167.07c0 .886.16 1.73.443 2.52.152 3.306 1.18 6.424 3.053 9.064 3.3 4.652 8.86 7.32 15.255 7.32h188.487c11.395 0 23.27-8.425 27.035-19.18l40.677-116.188c2.11-6.035 1.43-12.164-1.87-16.816zM18.5 64.088h8.864c9.295 0 18.64-6.607 21.738-15.37l2.032-5.75c.96-2.712 4.722-5.373 7.597-5.373h29.565c3.63 0 9.295 2.876 11.437 5.806l6.386 8.735c4.982 6.815 15.104 11.954 23.546 11.954h85.322c1.898 0 3.5 1.602 3.5 3.5v26.47H69.34c-11.395 0-23.27 8.423-27.035 19.178L15 191.23V67.59c0-1.898 1.603-3.5 3.5-3.5zm242.29 49.15l-40.676 116.188c-1.674 4.78-7.812 9.135-12.877 9.135H18.75c-1.447 0-2.576-.372-3.02-.997-.442-.625-.422-1.814.057-3.18l40.677-116.19c1.674-4.78 7.812-9.134 12.877-9.134h188.487c1.448 0 2.577.372 3.02.997.443.625.423 1.814-.056 3.18z" | ||
})); | ||
case 'video': | ||
return h( | ||
'svg', | ||
{ 'aria-hidden': 'true', viewBox: '0 0 58 58' }, | ||
h('path', { d: 'M36.537 28.156l-11-7a1.005 1.005 0 0 0-1.02-.033C24.2 21.3 24 21.635 24 22v14a1 1 0 0 0 1.537.844l11-7a1.002 1.002 0 0 0 0-1.688zM26 34.18V23.82L34.137 29 26 34.18z' }), | ||
h('path', { d: 'M57 6H1a1 1 0 0 0-1 1v44a1 1 0 0 0 1 1h56a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1zM10 28H2v-9h8v9zm-8 2h8v9H2v-9zm10 10V8h34v42H12V40zm44-12h-8v-9h8v9zm-8 2h8v9h-8v-9zm8-22v9h-8V8h8zM2 8h8v9H2V8zm0 42v-9h8v9H2zm54 0h-8v-9h8v9z' }) | ||
); | ||
return h("svg", { | ||
"aria-hidden": "true", | ||
viewBox: "0 0 58 58" | ||
}, h("path", { | ||
d: "M36.537 28.156l-11-7a1.005 1.005 0 0 0-1.02-.033C24.2 21.3 24 21.635 24 22v14a1 1 0 0 0 1.537.844l11-7a1.002 1.002 0 0 0 0-1.688zM26 34.18V23.82L34.137 29 26 34.18z" | ||
}), h("path", { | ||
d: "M57 6H1a1 1 0 0 0-1 1v44a1 1 0 0 0 1 1h56a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1zM10 28H2v-9h8v9zm-8 2h8v9H2v-9zm10 10V8h34v42H12V40zm44-12h-8v-9h8v9zm-8 2h8v9h-8v-9zm8-22v9h-8V8h8zM2 8h8v9H2V8zm0 42v-9h8v9H2zm54 0h-8v-9h8v9z" | ||
})); | ||
default: | ||
return h('img', { src: string }); | ||
return h("img", { | ||
src: string | ||
}); | ||
} | ||
@@ -42,7 +59,8 @@ } | ||
var handleItemClick = function handleItemClick(ev) { | ||
ev.preventDefault(); | ||
// when file is clicked, select it, but when folder is clicked, open it | ||
ev.preventDefault(); // when file is clicked, select it, but when folder is clicked, open it | ||
if (props.type === 'folder') { | ||
return props.handleFolderClick(ev); | ||
} | ||
props.handleClick(ev); | ||
@@ -52,36 +70,28 @@ }; | ||
var itemIcon = props.getItemIcon(); | ||
return h( | ||
'li', | ||
{ 'class': 'uppy-ProviderBrowserItem' + (props.isChecked ? ' uppy-ProviderBrowserItem--selected' : '') + (itemIcon === 'video' ? ' uppy-ProviderBrowserItem--noPreview' : '') }, | ||
h( | ||
'div', | ||
{ 'class': 'uppy-ProviderBrowserItem-checkbox' }, | ||
h('input', { type: 'checkbox', | ||
role: 'option', | ||
tabindex: 0, | ||
'aria-label': 'Select ' + props.title, | ||
id: props.id, | ||
checked: props.isChecked, | ||
disabled: props.isDisabled, | ||
onchange: props.handleClick, | ||
onkeyup: stop, | ||
onkeydown: stop, | ||
onkeypress: stop }), | ||
h('label', { | ||
'for': props.id, | ||
onclick: props.handleClick | ||
}) | ||
), | ||
h( | ||
'button', | ||
{ type: 'button', | ||
'class': 'uppy-u-reset uppy-ProviderBrowserItem-inner', | ||
'aria-label': 'Select ' + props.title, | ||
tabindex: 0, | ||
onclick: handleItemClick }, | ||
mapStringToIcon(props.getItemIcon()), | ||
props.showTitles && props.title | ||
) | ||
); | ||
return h("li", { | ||
class: 'uppy-ProviderBrowserItem' + (props.isChecked ? ' uppy-ProviderBrowserItem--selected' : '') + (itemIcon === 'video' ? ' uppy-ProviderBrowserItem--noPreview' : '') | ||
}, h("div", { | ||
class: "uppy-ProviderBrowserItem-checkbox" | ||
}, h("input", { | ||
type: "checkbox", | ||
role: "option", | ||
tabindex: 0, | ||
"aria-label": "Select " + props.title, | ||
id: props.id, | ||
checked: props.isChecked, | ||
disabled: props.isDisabled, | ||
onchange: props.handleClick, | ||
onkeyup: stop, | ||
onkeydown: stop, | ||
onkeypress: stop | ||
}), h("label", { | ||
for: props.id, | ||
onclick: props.handleClick | ||
})), h("button", { | ||
type: "button", | ||
class: "uppy-u-reset uppy-ProviderBrowserItem-inner", | ||
"aria-label": "Select " + props.title, | ||
tabindex: 0, | ||
onclick: handleItemClick | ||
}, mapStringToIcon(props.getItemIcon()), props.showTitles && props.title)); | ||
}; |
@@ -8,64 +8,59 @@ var Row = require('./Item'); | ||
if (!props.folders.length && !props.files.length) { | ||
return h( | ||
'div', | ||
{ 'class': 'uppy-Provider-empty' }, | ||
props.i18n('noFilesFound') | ||
); | ||
return h("div", { | ||
class: "uppy-Provider-empty" | ||
}, props.i18n('noFilesFound')); | ||
} | ||
return h( | ||
'div', | ||
{ 'class': 'uppy-ProviderBrowser-body' }, | ||
h( | ||
'ul', | ||
{ 'class': 'uppy-ProviderBrowser-list', | ||
onscroll: props.handleScroll, | ||
role: 'listbox', | ||
'aria-label': 'List of files from ' + props.title }, | ||
props.folders.map(function (folder) { | ||
var isDisabled = false; | ||
var isChecked = props.isChecked(folder); | ||
if (isChecked) { | ||
isDisabled = isChecked.loading; | ||
} | ||
return Row({ | ||
title: folder.name, | ||
id: folder.id, | ||
type: 'folder', | ||
// active: props.activeRow(folder), | ||
getItemIcon: function getItemIcon() { | ||
return folder.icon; | ||
}, | ||
isDisabled: isDisabled, | ||
isChecked: isChecked, | ||
handleFolderClick: function handleFolderClick() { | ||
return props.handleFolderClick(folder); | ||
}, | ||
handleClick: function handleClick(e) { | ||
return props.toggleCheckbox(e, folder); | ||
}, | ||
columns: props.columns, | ||
showTitles: props.showTitles | ||
}); | ||
}), | ||
props.files.map(function (file) { | ||
return Row({ | ||
title: file.name, | ||
id: file.id, | ||
type: 'file', | ||
// active: props.activeRow(file), | ||
getItemIcon: function getItemIcon() { | ||
return file.icon; | ||
}, | ||
isDisabled: false, | ||
isChecked: props.isChecked(file), | ||
handleClick: function handleClick(e) { | ||
return props.toggleCheckbox(e, file); | ||
}, | ||
columns: props.columns, | ||
showTitles: props.showTitles | ||
}); | ||
}) | ||
) | ||
); | ||
return h("div", { | ||
class: "uppy-ProviderBrowser-body" | ||
}, h("ul", { | ||
class: "uppy-ProviderBrowser-list", | ||
onscroll: props.handleScroll, | ||
role: "listbox", | ||
"aria-label": "List of files from " + props.title | ||
}, props.folders.map(function (folder) { | ||
var isDisabled = false; | ||
var isChecked = props.isChecked(folder); | ||
if (isChecked) { | ||
isDisabled = isChecked.loading; | ||
} | ||
return Row({ | ||
title: folder.name, | ||
id: folder.id, | ||
type: 'folder', | ||
// active: props.activeRow(folder), | ||
getItemIcon: function getItemIcon() { | ||
return folder.icon; | ||
}, | ||
isDisabled: isDisabled, | ||
isChecked: isChecked, | ||
handleFolderClick: function handleFolderClick() { | ||
return props.handleFolderClick(folder); | ||
}, | ||
handleClick: function handleClick(e) { | ||
return props.toggleCheckbox(e, folder); | ||
}, | ||
columns: props.columns, | ||
showTitles: props.showTitles | ||
}); | ||
}), props.files.map(function (file) { | ||
return Row({ | ||
title: file.name, | ||
id: file.id, | ||
type: 'file', | ||
// active: props.activeRow(file), | ||
getItemIcon: function getItemIcon() { | ||
return file.icon; | ||
}, | ||
isDisabled: false, | ||
isChecked: props.isChecked(file), | ||
handleClick: function handleClick(e) { | ||
return props.toggleCheckbox(e, file); | ||
}, | ||
columns: props.columns, | ||
showTitles: props.showTitles | ||
}); | ||
}))); | ||
}; |
@@ -5,11 +5,5 @@ var _require = require('preact'), | ||
module.exports = function (props) { | ||
return h( | ||
'div', | ||
{ 'class': 'uppy-Provider-loading' }, | ||
h( | ||
'span', | ||
null, | ||
props.i18n('loading') | ||
) | ||
); | ||
return h("div", { | ||
class: "uppy-Provider-loading" | ||
}, h("span", null, props.i18n('loading'))); | ||
}; |
{ | ||
"name": "@uppy/provider-views", | ||
"description": "View library for Uppy remote provider plugins.", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -22,3 +22,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/utils": "1.0.2", | ||
"@uppy/utils": "1.1.0", | ||
"classnames": "^2.2.6", | ||
@@ -28,3 +28,3 @@ "preact": "8.2.9" | ||
"devDependencies": { | ||
"@uppy/core": "1.0.2" | ||
"@uppy/core": "1.1.0" | ||
}, | ||
@@ -34,3 +34,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "5c9e1a836df858254657a59ab8bd4b90035cf8b4" | ||
"gitHead": "28d235fe2fb57d87a399c20883fd6590aa49f4f4" | ||
} |
@@ -19,2 +19,10 @@ const { h, Component } = require('preact') | ||
// location.origin does not exist in IE | ||
function getOrigin () { | ||
if ('origin' in location) { | ||
return location.origin // eslint-disable-line compat/compat | ||
} | ||
return `${location.protocol}//${location.hostname}${location.port ? `:${location.port}` : ''}` | ||
} | ||
class CloseWrapper extends Component { | ||
@@ -34,2 +42,4 @@ componentWillUnmount () { | ||
module.exports = class ProviderView { | ||
static VERSION = require('../package.json').version | ||
/** | ||
@@ -51,3 +61,3 @@ * @param {object} instance of the plugin | ||
// merge default options with the ones set by user | ||
this.opts = Object.assign({}, defaultOptions, opts) | ||
this.opts = { ...defaultOptions, ...opts } | ||
@@ -126,3 +136,3 @@ // Logic | ||
} else { | ||
updatedDirectories = state.directories.concat([{id, title: name}]) | ||
updatedDirectories = state.directories.concat([{ id, title: name }]) | ||
} | ||
@@ -234,3 +244,3 @@ | ||
const state = Object.assign({}, this.plugin.getPluginState()) | ||
const {files, folders, sorting} = state | ||
const { files, folders, sorting } = state | ||
@@ -260,3 +270,3 @@ let sortedFiles = files.sort((fileA, fileB) => { | ||
const state = Object.assign({}, this.plugin.getPluginState()) | ||
const {files, folders, sorting} = state | ||
const { files, folders, sorting } = state | ||
@@ -293,3 +303,3 @@ let sortedFiles = files.sort((fileA, fileB) => { | ||
const state = Object.assign({}, this.plugin.getPluginState()) | ||
const {files, sorting} = state | ||
const { files, sorting } = state | ||
@@ -339,4 +349,4 @@ // check that plugin supports file sizes | ||
} | ||
folders[folderId] = {loading: true, files: []} | ||
this.plugin.setPluginState({selectedFolders: folders}) | ||
folders[folderId] = { loading: true, files: [] } | ||
this.plugin.setPluginState({ selectedFolders: folders }) | ||
return this.provider.list(folder.requestPath).then((res) => { | ||
@@ -351,4 +361,4 @@ let files = [] | ||
state = this.plugin.getPluginState() | ||
state.selectedFolders[folderId] = {loading: false, files: files} | ||
this.plugin.setPluginState({selectedFolders: folders}) | ||
state.selectedFolders[folderId] = { loading: false, files: files } | ||
this.plugin.setPluginState({ selectedFolders: folders }) | ||
const dashboard = this.plugin.uppy.getPlugin('Dashboard') | ||
@@ -367,3 +377,3 @@ let message | ||
delete state.selectedFolders[folderId] | ||
this.plugin.setPluginState({selectedFolders: state.selectedFolders}) | ||
this.plugin.setPluginState({ selectedFolders: state.selectedFolders }) | ||
this.handleError(e) | ||
@@ -423,3 +433,3 @@ }) | ||
handleAuth () { | ||
const authState = btoa(JSON.stringify({ origin: location.origin })) | ||
const authState = btoa(JSON.stringify({ origin: getOrigin() })) | ||
// @todo remove this hardcoded version | ||
@@ -464,4 +474,4 @@ const clientVersion = 'companion-client:1.0.2' | ||
return patterns | ||
.filter((pattern) => pattern !== null) | ||
.some((pattern) => pattern.test(origin)) | ||
.filter((pattern) => pattern != null) // loose comparison to catch undefined | ||
.some((pattern) => pattern.test(origin) || pattern.test(`${origin}/`)) // allowing for trailing '/' | ||
} | ||
@@ -476,3 +486,3 @@ | ||
const message = uppy.i18n('companionError') | ||
uppy.info({message: message, details: error.toString()}, 'error', 5000) | ||
uppy.info({ message: message, details: error.toString() }, 'error', 5000) | ||
} | ||
@@ -479,0 +489,0 @@ |
@@ -60,3 +60,3 @@ const { h } = require('preact') | ||
onclick={props.handleClick} | ||
/> | ||
/> | ||
</div> | ||
@@ -63,0 +63,0 @@ <button type="button" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
2142
97087
+ Added@uppy/utils@1.1.0(transitive)
- Removed@uppy/utils@1.0.2(transitive)
Updated@uppy/utils@1.1.0