@uppy/provider-views
Advanced tools
Comparing version 0.30.3 to 0.30.4
@@ -7,4 +7,2 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var LoaderView = require('./Loader'); | ||
var _require = require('preact'), | ||
@@ -36,26 +34,26 @@ h = _require.h, | ||
return h( | ||
'div', | ||
{ 'class': 'uppy-Provider-auth' }, | ||
"div", | ||
{ "class": "uppy-Provider-auth" }, | ||
h( | ||
'div', | ||
{ 'class': 'uppy-Provider-authIcon' }, | ||
"div", | ||
{ "class": "uppy-Provider-authIcon" }, | ||
this.props.pluginIcon() | ||
), | ||
h( | ||
'h1', | ||
{ 'class': 'uppy-Provider-authTitle' }, | ||
'Please authenticate with ', | ||
"h1", | ||
{ "class": "uppy-Provider-authTitle" }, | ||
"Please authenticate with ", | ||
h( | ||
'span', | ||
{ 'class': 'uppy-Provider-authTitleName' }, | ||
"span", | ||
{ "class": "uppy-Provider-authTitleName" }, | ||
this.props.pluginName | ||
), | ||
h('br', null), | ||
' to select files' | ||
h("br", null), | ||
" to select files" | ||
), | ||
h( | ||
'button', | ||
"button", | ||
{ | ||
type: 'button', | ||
'class': 'uppy-u-reset uppy-c-btn uppy-c-btn-primary uppy-Provider-authBtn', | ||
type: "button", | ||
"class": "uppy-u-reset uppy-c-btn uppy-c-btn-primary uppy-Provider-authBtn", | ||
onclick: this.props.handleAuth, | ||
@@ -66,9 +64,9 @@ ref: function ref(el) { | ||
}, | ||
'Connect to ', | ||
"Connect to ", | ||
this.props.pluginName | ||
), | ||
this.props.demo && h( | ||
'button', | ||
{ 'class': 'uppy-u-reset uppy-c-btn uppy-c-btn-primary uppy-Provider-authBtn', onclick: this.props.handleDemoAuth }, | ||
'Proceed with Demo Account' | ||
"button", | ||
{ "class": "uppy-u-reset uppy-c-btn uppy-c-btn-primary uppy-Provider-authBtn", onclick: this.props.handleDemoAuth }, | ||
"Proceed with Demo Account" | ||
) | ||
@@ -90,10 +88,3 @@ ); | ||
AuthView.prototype.componentDidMount = function componentDidMount() { | ||
this.props.checkAuth(); | ||
}; | ||
AuthView.prototype.render = function render() { | ||
if (this.props.checkAuthInProgress) { | ||
return h(LoaderView, null); | ||
} | ||
return h(AuthBlock, this.props); | ||
@@ -100,0 +91,0 @@ }; |
@@ -45,3 +45,3 @@ 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; }; | ||
'button', | ||
{ type: 'button', onclick: props.logout, 'class': 'uppy-ProviderBrowser-userLogout' }, | ||
{ type: 'button', onclick: props.logout, 'class': 'uppy-u-reset uppy-ProviderBrowser-userLogout' }, | ||
props.i18n('logOut') | ||
@@ -48,0 +48,0 @@ ) |
103
lib/index.js
@@ -83,3 +83,3 @@ 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; }; | ||
this.logout = this.logout.bind(this); | ||
this.checkAuth = this.checkAuth.bind(this); | ||
this.preFirstRender = this.preFirstRender.bind(this); | ||
this.handleAuth = this.handleAuth.bind(this); | ||
@@ -121,13 +121,11 @@ this.handleDemoAuth = this.handleDemoAuth.bind(this); | ||
ProviderView.prototype.checkAuth = function checkAuth() { | ||
var _this2 = this; | ||
/** | ||
* Called only the first time the provider view is rendered. | ||
* Kind of like an init function. | ||
*/ | ||
this.plugin.setPluginState({ checkAuthInProgress: true }); | ||
this.provider.checkAuth().then(function (authenticated) { | ||
_this2.plugin.setPluginState({ checkAuthInProgress: false }); | ||
_this2.plugin.onAuth(authenticated); | ||
}).catch(function (err) { | ||
_this2.plugin.setPluginState({ checkAuthInProgress: false }); | ||
_this2.handleError(err); | ||
}); | ||
ProviderView.prototype.preFirstRender = function preFirstRender() { | ||
this.plugin.setPluginState({ didFirstRender: true }); | ||
this.plugin.onFirstRender(); | ||
}; | ||
@@ -143,3 +141,3 @@ | ||
ProviderView.prototype.getFolder = function getFolder(id, name) { | ||
var _this3 = this; | ||
var _this2 = this; | ||
@@ -151,3 +149,3 @@ return this._loaderWrapper(this.provider.list(id), function (res) { | ||
var state = _this3.plugin.getPluginState(); | ||
var state = _this2.plugin.getPluginState(); | ||
var index = findIndex(state.directories, function (dir) { | ||
@@ -163,5 +161,5 @@ return id === dir.id; | ||
_this3.username = _this3.username ? _this3.username : res.username; | ||
_this3._updateFilesAndFolders(res, files, folders); | ||
_this3.plugin.setPluginState({ directories: updatedDirectories }); | ||
_this2.username = _this2.username ? _this2.username : res.username; | ||
_this2._updateFilesAndFolders(res, files, folders); | ||
_this2.plugin.setPluginState({ directories: updatedDirectories }); | ||
}, this.handleError); | ||
@@ -233,3 +231,3 @@ }; | ||
ProviderView.prototype.logout = function logout() { | ||
var _this4 = this; | ||
var _this3 = this; | ||
@@ -244,3 +242,3 @@ this.provider.logout(location.href).then(function (res) { | ||
}; | ||
_this4.plugin.setPluginState(newState); | ||
_this3.plugin.setPluginState(newState); | ||
} | ||
@@ -388,3 +386,3 @@ }).catch(this.handleError); | ||
ProviderView.prototype.addFolder = function addFolder(folder) { | ||
var _this5 = this; | ||
var _this4 = this; | ||
@@ -403,10 +401,10 @@ var folderId = this.providerFileToId(folder); | ||
if (!item.isFolder) { | ||
_this5.addFile(item); | ||
files.push(_this5.providerFileToId(item)); | ||
_this4.addFile(item); | ||
files.push(_this4.providerFileToId(item)); | ||
} | ||
}); | ||
state = _this5.plugin.getPluginState(); | ||
state = _this4.plugin.getPluginState(); | ||
state.selectedFolders[folderId] = { loading: false, files: files }; | ||
_this5.plugin.setPluginState({ selectedFolders: folders }); | ||
var dashboard = _this5.plugin.uppy.getPlugin('Dashboard'); | ||
_this4.plugin.setPluginState({ selectedFolders: folders }); | ||
var dashboard = _this4.plugin.uppy.getPlugin('Dashboard'); | ||
var message = void 0; | ||
@@ -420,8 +418,8 @@ if (files.length) { | ||
} | ||
_this5.plugin.uppy.info(message); | ||
_this4.plugin.uppy.info(message); | ||
}).catch(function (e) { | ||
state = _this5.plugin.getPluginState(); | ||
state = _this4.plugin.getPluginState(); | ||
delete state.selectedFolders[folderId]; | ||
_this5.plugin.setPluginState({ selectedFolders: state.selectedFolders }); | ||
_this5.handleError(e); | ||
_this4.plugin.setPluginState({ selectedFolders: state.selectedFolders }); | ||
_this4.handleError(e); | ||
}); | ||
@@ -498,3 +496,3 @@ }; | ||
ProviderView.prototype.handleAuth = function handleAuth() { | ||
var _this6 = this; | ||
var _this5 = this; | ||
@@ -506,4 +504,4 @@ var authState = btoa(JSON.stringify({ origin: location.origin })); | ||
var handleToken = function handleToken(e) { | ||
if (!_this6._isOriginAllowed(e.origin, _this6.plugin.opts.serverPattern) || e.source !== authWindow) { | ||
_this6.plugin.uppy.log('rejecting event from ' + e.origin + ' vs allowed pattern ' + _this6.plugin.opts.serverPattern); | ||
if (!_this5._isOriginAllowed(e.origin, _this5.plugin.opts.serverPattern) || e.source !== authWindow) { | ||
_this5.plugin.uppy.log('rejecting event from ' + e.origin + ' vs allowed pattern ' + _this5.plugin.opts.serverPattern); | ||
return; | ||
@@ -513,4 +511,4 @@ } | ||
window.removeEventListener('message', handleToken); | ||
_this6.provider.setAuthToken(e.data.token); | ||
_this6._loaderWrapper(_this6.provider.checkAuth(), _this6.plugin.onAuth, _this6.handleError); | ||
_this5.provider.setAuthToken(e.data.token); | ||
_this5.preFirstRender(); | ||
}; | ||
@@ -539,4 +537,4 @@ window.addEventListener('message', handleToken); | ||
var uppy = this.plugin.uppy; | ||
var message = uppy.i18n('companionError'); | ||
uppy.log(error.toString()); | ||
var message = uppy.i18n(error.isAuthError ? 'companionAuthError' : 'companionError'); | ||
uppy.info({ message: message, details: error.toString() }, 'error', 5000); | ||
@@ -546,3 +544,3 @@ }; | ||
ProviderView.prototype.handleScroll = function handleScroll(e) { | ||
var _this7 = this; | ||
var _this6 = this; | ||
@@ -554,9 +552,9 @@ var scrollPos = e.target.scrollHeight - (e.target.scrollTop + e.target.offsetHeight); | ||
this.provider.list(path).then(function (res) { | ||
var _plugin$getPluginStat5 = _this7.plugin.getPluginState(), | ||
var _plugin$getPluginStat5 = _this6.plugin.getPluginState(), | ||
files = _plugin$getPluginStat5.files, | ||
folders = _plugin$getPluginStat5.folders; | ||
_this7._updateFilesAndFolders(res, files, folders); | ||
_this6._updateFilesAndFolders(res, files, folders); | ||
}).catch(this.handleError).then(function () { | ||
_this7._isHandlingScroll = false; | ||
_this6._isHandlingScroll = false; | ||
}); // always called | ||
@@ -569,3 +567,3 @@ | ||
ProviderView.prototype.donePicking = function donePicking() { | ||
var _this8 = this; | ||
var _this7 = this; | ||
@@ -577,5 +575,5 @@ var _plugin$getPluginStat6 = this.plugin.getPluginState(), | ||
if (file.isFolder) { | ||
return _this8.addFolder(file); | ||
return _this7.addFolder(file); | ||
} else { | ||
return _this8.addFile(file); | ||
return _this7.addFile(file); | ||
} | ||
@@ -585,3 +583,3 @@ }); | ||
this._loaderWrapper(Promise.all(promises), function () { | ||
_this8.clearSelection(); | ||
_this7.clearSelection(); | ||
}, function () {}); | ||
@@ -605,9 +603,9 @@ }; | ||
ProviderView.prototype._loaderWrapper = function _loaderWrapper(promise, then, catch_) { | ||
var _this9 = this; | ||
var _this8 = this; | ||
promise.then(function (result) { | ||
_this9.plugin.setPluginState({ loading: false }); | ||
_this8.plugin.setPluginState({ loading: false }); | ||
then(result); | ||
}).catch(function (err) { | ||
_this9.plugin.setPluginState({ loading: false }); | ||
_this8.plugin.setPluginState({ loading: false }); | ||
catch_(err); | ||
@@ -621,6 +619,11 @@ }); | ||
authenticated = _plugin$getPluginStat7.authenticated, | ||
checkAuthInProgress = _plugin$getPluginStat7.checkAuthInProgress, | ||
loading = _plugin$getPluginStat7.loading; | ||
didFirstRender = _plugin$getPluginStat7.didFirstRender; | ||
if (loading) { | ||
if (!didFirstRender) { | ||
this.preFirstRender(); | ||
} | ||
// reload pluginState for "loading" attribute because it might | ||
// have changed above. | ||
if (this.plugin.getPluginState().loading) { | ||
return h( | ||
@@ -641,6 +644,4 @@ CloseWrapper, | ||
demo: this.plugin.opts.demo, | ||
checkAuth: this.checkAuth, | ||
handleAuth: this.handleAuth, | ||
handleDemoAuth: this.handleDemoAuth, | ||
checkAuthInProgress: checkAuthInProgress }) | ||
handleDemoAuth: this.handleDemoAuth }) | ||
); | ||
@@ -647,0 +648,0 @@ } |
@@ -76,3 +76,3 @@ var _require = require('preact'), | ||
{ type: 'button', | ||
'class': 'uppy-ProviderBrowserItem-inner', | ||
'class': 'uppy-u-reset uppy-ProviderBrowserItem-inner', | ||
'aria-label': 'Select ' + props.title, | ||
@@ -79,0 +79,0 @@ tabindex: 0, |
{ | ||
"name": "@uppy/provider-views", | ||
"description": "View library for Uppy remote provider plugins.", | ||
"version": "0.30.3", | ||
"version": "0.30.4", | ||
"license": "MIT", | ||
@@ -22,3 +22,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/utils": "0.30.3", | ||
"@uppy/utils": "0.30.4", | ||
"classnames": "^2.2.6", | ||
@@ -28,3 +28,3 @@ "preact": "^8.2.9" | ||
"devDependencies": { | ||
"@uppy/core": "0.30.3" | ||
"@uppy/core": "0.30.4" | ||
}, | ||
@@ -34,3 +34,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "27899d944f0ffb551d0473955236734c24eb4fff" | ||
"gitHead": "7ae8af44abdd42eef71c46b831b2e3dadb00237f" | ||
} |
@@ -1,2 +0,1 @@ | ||
const LoaderView = require('./Loader') | ||
const { h, Component } = require('preact') | ||
@@ -32,10 +31,3 @@ | ||
class AuthView extends Component { | ||
componentDidMount () { | ||
this.props.checkAuth() | ||
} | ||
render () { | ||
if (this.props.checkAuthInProgress) { | ||
return <LoaderView /> | ||
} | ||
return <AuthBlock {...this.props} /> | ||
@@ -42,0 +34,0 @@ } |
@@ -30,3 +30,3 @@ const classNames = require('classnames') | ||
<span class="uppy-ProviderBrowser-user">{props.username}</span> | ||
<button type="button" onclick={props.logout} class="uppy-ProviderBrowser-userLogout"> | ||
<button type="button" onclick={props.logout} class="uppy-u-reset uppy-ProviderBrowser-userLogout"> | ||
{props.i18n('logOut')} | ||
@@ -33,0 +33,0 @@ </button> |
@@ -59,3 +59,3 @@ const { h, Component } = require('preact') | ||
this.logout = this.logout.bind(this) | ||
this.checkAuth = this.checkAuth.bind(this) | ||
this.preFirstRender = this.preFirstRender.bind(this) | ||
this.handleAuth = this.handleAuth.bind(this) | ||
@@ -97,13 +97,9 @@ this.handleDemoAuth = this.handleDemoAuth.bind(this) | ||
checkAuth () { | ||
this.plugin.setPluginState({ checkAuthInProgress: true }) | ||
this.provider.checkAuth() | ||
.then((authenticated) => { | ||
this.plugin.setPluginState({ checkAuthInProgress: false }) | ||
this.plugin.onAuth(authenticated) | ||
}) | ||
.catch((err) => { | ||
this.plugin.setPluginState({ checkAuthInProgress: false }) | ||
this.handleError(err) | ||
}) | ||
/** | ||
* Called only the first time the provider view is rendered. | ||
* Kind of like an init function. | ||
*/ | ||
preFirstRender () { | ||
this.plugin.setPluginState({ didFirstRender: true }) | ||
this.plugin.onFirstRender() | ||
} | ||
@@ -439,3 +435,3 @@ | ||
this.provider.setAuthToken(e.data.token) | ||
this._loaderWrapper(this.provider.checkAuth(), this.plugin.onAuth, this.handleError) | ||
this.preFirstRender() | ||
} | ||
@@ -462,4 +458,4 @@ window.addEventListener('message', handleToken) | ||
const uppy = this.plugin.uppy | ||
const message = uppy.i18n('companionError') | ||
uppy.log(error.toString()) | ||
const message = uppy.i18n(error.isAuthError ? 'companionAuthError' : 'companionError') | ||
uppy.info({message: message, details: error.toString()}, 'error', 5000) | ||
@@ -524,5 +520,10 @@ } | ||
render (state) { | ||
const { authenticated, checkAuthInProgress, loading } = this.plugin.getPluginState() | ||
const { authenticated, didFirstRender } = this.plugin.getPluginState() | ||
if (!didFirstRender) { | ||
this.preFirstRender() | ||
} | ||
if (loading) { | ||
// reload pluginState for "loading" attribute because it might | ||
// have changed above. | ||
if (this.plugin.getPluginState().loading) { | ||
return ( | ||
@@ -542,6 +543,4 @@ <CloseWrapper onUnmount={this.clearSelection}> | ||
demo={this.plugin.opts.demo} | ||
checkAuth={this.checkAuth} | ||
handleAuth={this.handleAuth} | ||
handleDemoAuth={this.handleDemoAuth} | ||
checkAuthInProgress={checkAuthInProgress} /> | ||
handleDemoAuth={this.handleDemoAuth} /> | ||
</CloseWrapper> | ||
@@ -548,0 +547,0 @@ ) |
@@ -63,3 +63,3 @@ const { h } = require('preact') | ||
<button type="button" | ||
class="uppy-ProviderBrowserItem-inner" | ||
class="uppy-u-reset uppy-ProviderBrowserItem-inner" | ||
aria-label={`Select ${props.title}`} | ||
@@ -66,0 +66,0 @@ tabindex={0} |
Sorry, the diff of this file is not supported yet
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
99329
2115
+ Added@uppy/utils@0.30.4(transitive)
- Removed@uppy/utils@0.30.3(transitive)
Updated@uppy/utils@0.30.4