Comparing version 1.0.2 to 1.1.0
117
lib/index.js
@@ -1,8 +0,8 @@ | ||
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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return 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; } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
@@ -21,4 +21,4 @@ var _require = require('@uppy/core'), | ||
var UrlUI = require('./UrlUI.js'); | ||
var forEachDroppedOrPastedUrl = require('./utils/forEachDroppedOrPastedUrl'); | ||
/** | ||
@@ -28,22 +28,31 @@ * Url | ||
*/ | ||
module.exports = function (_Plugin) { | ||
_inherits(Url, _Plugin); | ||
module.exports = (_temp = _class = | ||
/*#__PURE__*/ | ||
function (_Plugin) { | ||
_inheritsLoose(Url, _Plugin); | ||
function Url(uppy, opts) { | ||
_classCallCheck(this, Url); | ||
var _this; | ||
var _this = _possibleConstructorReturn(this, _Plugin.call(this, uppy, opts)); | ||
_this = _Plugin.call(this, uppy, opts) || this; | ||
_this.id = _this.opts.id || 'Url'; | ||
_this.title = _this.opts.title || 'Link'; | ||
_this.type = 'acquirer'; | ||
_this.icon = function () { | ||
return h( | ||
'svg', | ||
{ 'aria-hidden': 'true', width: '23', height: '23', viewBox: '0 0 23 23' }, | ||
h('path', { d: 'M20.485 11.236l-2.748 2.737c-.184.182-.367.365-.642.547-1.007.73-2.107 1.095-3.298 1.095-1.65 0-3.298-.73-4.398-2.19-.275-.365-.183-1.003.183-1.277.367-.273 1.008-.182 1.283.183 1.191 1.642 3.482 1.915 5.13.73a.714.714 0 0 0 .367-.365l2.75-2.737c1.373-1.46 1.373-3.74-.093-5.108a3.72 3.72 0 0 0-5.13 0L12.33 6.4a.888.888 0 0 1-1.283 0 .88.88 0 0 1 0-1.277l1.558-1.55a5.38 5.38 0 0 1 7.605 0c2.29 2.006 2.382 5.564.274 7.662zm-8.979 6.294L9.95 19.081a3.72 3.72 0 0 1-5.13 0c-1.467-1.368-1.467-3.74-.093-5.108l2.75-2.737.366-.365c.824-.547 1.74-.82 2.748-.73 1.008.183 1.833.639 2.382 1.46.275.365.917.456 1.283.182.367-.273.458-.912.183-1.277-.916-1.186-2.199-1.915-3.573-2.098-1.374-.273-2.84.091-4.031 1.004l-.55.547-2.749 2.737c-2.107 2.189-2.015 5.655.092 7.753C4.727 21.453 6.101 22 7.475 22c1.374 0 2.749-.547 3.848-1.55l1.558-1.551a.88.88 0 0 0 0-1.278c-.367-.364-1.008-.456-1.375-.09z', fill: '#FF814F', 'fill-rule': 'nonzero' }) | ||
); | ||
}; | ||
return h("svg", { | ||
"aria-hidden": "true", | ||
width: "23", | ||
height: "23", | ||
viewBox: "0 0 23 23" | ||
}, h("path", { | ||
d: "M20.485 11.236l-2.748 2.737c-.184.182-.367.365-.642.547-1.007.73-2.107 1.095-3.298 1.095-1.65 0-3.298-.73-4.398-2.19-.275-.365-.183-1.003.183-1.277.367-.273 1.008-.182 1.283.183 1.191 1.642 3.482 1.915 5.13.73a.714.714 0 0 0 .367-.365l2.75-2.737c1.373-1.46 1.373-3.74-.093-5.108a3.72 3.72 0 0 0-5.13 0L12.33 6.4a.888.888 0 0 1-1.283 0 .88.88 0 0 1 0-1.277l1.558-1.55a5.38 5.38 0 0 1 7.605 0c2.29 2.006 2.382 5.564.274 7.662zm-8.979 6.294L9.95 19.081a3.72 3.72 0 0 1-5.13 0c-1.467-1.368-1.467-3.74-.093-5.108l2.75-2.737.366-.365c.824-.547 1.74-.82 2.748-.73 1.008.183 1.833.639 2.382 1.46.275.365.917.456 1.283.182.367-.273.458-.912.183-1.277-.916-1.186-2.199-1.915-3.573-2.098-1.374-.273-2.84.091-4.031 1.004l-.55.547-2.749 2.737c-2.107 2.189-2.015 5.655.092 7.753C4.727 21.453 6.101 22 7.475 22c1.374 0 2.749-.547 3.848-1.55l1.558-1.551a.88.88 0 0 0 0-1.278c-.367-.364-1.008-.456-1.375-.09z", | ||
fill: "#FF814F", | ||
"fill-rule": "nonzero" | ||
})); | ||
}; // Set default options and locale | ||
// Set default options and locale | ||
_this.defaultLocale = { | ||
@@ -57,12 +66,8 @@ strings: { | ||
}; | ||
var defaultOptions = {}; | ||
_this.opts = _extends({}, defaultOptions, opts); // i18n | ||
_this.opts = _extends({}, defaultOptions, opts); | ||
// i18n | ||
_this.translator = new Translator([_this.defaultLocale, _this.uppy.locale, _this.opts.locale]); | ||
_this.i18n = _this.translator.translate.bind(_this.translator); | ||
_this.i18nArray = _this.translator.translateArray.bind(_this.translator); | ||
_this.hostname = _this.opts.companionUrl; | ||
@@ -72,10 +77,9 @@ | ||
throw new Error('Companion hostname is required, please consult https://uppy.io/docs/companion'); | ||
} | ||
} // Bind all event handlers for referencability | ||
// Bind all event handlers for referencability | ||
_this.getMeta = _this.getMeta.bind(_this); | ||
_this.addFile = _this.addFile.bind(_this); | ||
_this.handleRootDrop = _this.handleRootDrop.bind(_this); | ||
_this.handleRootPaste = _this.handleRootPaste.bind(_this); | ||
_this.getMeta = _this.getMeta.bind(_assertThisInitialized(_this)); | ||
_this.addFile = _this.addFile.bind(_assertThisInitialized(_this)); | ||
_this.handleRootDrop = _this.handleRootDrop.bind(_assertThisInitialized(_this)); | ||
_this.handleRootPaste = _this.handleRootPaste.bind(_assertThisInitialized(_this)); | ||
_this.client = new RequestClient(uppy, { | ||
@@ -88,10 +92,12 @@ companionUrl: _this.opts.companionUrl, | ||
Url.prototype.getFileNameFromUrl = function getFileNameFromUrl(url) { | ||
var _proto = Url.prototype; | ||
_proto.getFileNameFromUrl = function getFileNameFromUrl(url) { | ||
return url.substring(url.lastIndexOf('/') + 1); | ||
}; | ||
Url.prototype.checkIfCorrectURL = function checkIfCorrectURL(url) { | ||
_proto.checkIfCorrectURL = function checkIfCorrectURL(url) { | ||
if (!url) return false; | ||
var protocol = url.match(/^([a-z0-9]+):\/\//)[1]; | ||
var protocol = url.match(/^([a-z0-9]+):\/\//)[1]; | ||
if (protocol !== 'http' && protocol !== 'https') { | ||
@@ -104,5 +110,6 @@ return false; | ||
Url.prototype.addProtocolToURL = function addProtocolToURL(url) { | ||
_proto.addProtocolToURL = function addProtocolToURL(url) { | ||
var protocolRegex = /^[a-z0-9]+:\/\//; | ||
var defaultProtocol = 'http://'; | ||
if (protocolRegex.test(url)) { | ||
@@ -115,11 +122,16 @@ return url; | ||
Url.prototype.getMeta = function getMeta(url) { | ||
_proto.getMeta = function getMeta(url) { | ||
var _this2 = this; | ||
return this.client.post('url/meta', { url: url }).then(function (res) { | ||
return this.client.post('url/meta', { | ||
url: url | ||
}).then(function (res) { | ||
if (res.error) { | ||
_this2.uppy.log('[URL] Error:'); | ||
_this2.uppy.log(res.error); | ||
throw new Error('Failed to fetch the file'); | ||
} | ||
return res; | ||
@@ -129,8 +141,9 @@ }); | ||
Url.prototype.addFile = function addFile(url) { | ||
_proto.addFile = function addFile(url) { | ||
var _this3 = this; | ||
url = this.addProtocolToURL(url); | ||
if (!this.checkIfCorrectURL(url)) { | ||
this.uppy.log('[URL] Incorrect URL entered: ' + url); | ||
this.uppy.log("[URL] Incorrect URL entered: " + url); | ||
this.uppy.info(this.i18n('enterCorrectUrl'), 'error', 4000); | ||
@@ -154,3 +167,3 @@ return; | ||
companionUrl: _this3.opts.companionUrl, | ||
url: _this3.hostname + '/url/get', | ||
url: _this3.hostname + "/url/get", | ||
body: { | ||
@@ -166,9 +179,8 @@ fileId: url, | ||
_this3.uppy.log('[Url] Adding remote file'); | ||
try { | ||
_this3.uppy.addFile(tagFile); | ||
} catch (err) { | ||
// Nothing, restriction errors handled in Core | ||
} catch (err) {// Nothing, restriction errors handled in Core | ||
} | ||
}).then(function () { | ||
// Close the Dashboard panel if plugin is installed | ||
}).then(function () {// Close the Dashboard panel if plugin is installed | ||
// into Dashboard (could be other parent UI plugin) | ||
@@ -180,2 +192,3 @@ // if (this.parent && this.parent.hideAllPanels) { | ||
_this3.uppy.log(err); | ||
_this3.uppy.info({ | ||
@@ -188,7 +201,8 @@ message: _this3.i18n('failedToFetch'), | ||
Url.prototype.handleRootDrop = function handleRootDrop(e) { | ||
_proto.handleRootDrop = function handleRootDrop(e) { | ||
var _this4 = this; | ||
forEachDroppedOrPastedUrl(e.dataTransfer, 'drop', function (url) { | ||
_this4.uppy.log('[URL] Adding file from dropped url: ' + url); | ||
_this4.uppy.log("[URL] Adding file from dropped url: " + url); | ||
_this4.addFile(url); | ||
@@ -198,7 +212,8 @@ }); | ||
Url.prototype.handleRootPaste = function handleRootPaste(e) { | ||
_proto.handleRootPaste = function handleRootPaste(e) { | ||
var _this5 = this; | ||
forEachDroppedOrPastedUrl(e.clipboardData, 'paste', function (url) { | ||
_this5.uppy.log('[URL] Adding file from pasted url: ' + url); | ||
_this5.uppy.log("[URL] Adding file from pasted url: " + url); | ||
_this5.addFile(url); | ||
@@ -208,10 +223,12 @@ }); | ||
Url.prototype.render = function render(state) { | ||
_proto.render = function render(state) { | ||
return h(UrlUI, { | ||
i18n: this.i18n, | ||
addFile: this.addFile }); | ||
addFile: this.addFile | ||
}); | ||
}; | ||
Url.prototype.install = function install() { | ||
_proto.install = function install() { | ||
var target = this.opts.target; | ||
if (target) { | ||
@@ -222,3 +239,3 @@ this.mount(target, this); | ||
Url.prototype.uninstall = function uninstall() { | ||
_proto.uninstall = function uninstall() { | ||
this.unmount(); | ||
@@ -228,2 +245,2 @@ }; | ||
return Url; | ||
}(Plugin); | ||
}(Plugin), _class.VERSION = "1.1.0", _temp); |
@@ -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,29 +9,35 @@ h = _require.h, | ||
var UrlUI = function (_Component) { | ||
_inherits(UrlUI, _Component); | ||
var UrlUI = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inheritsLoose(UrlUI, _Component); | ||
function UrlUI(props) { | ||
_classCallCheck(this, UrlUI); | ||
var _this; | ||
var _this = _possibleConstructorReturn(this, _Component.call(this, props)); | ||
_this.handleKeyPress = _this.handleKeyPress.bind(_this); | ||
_this.handleClick = _this.handleClick.bind(_this); | ||
_this = _Component.call(this, props) || this; | ||
_this.handleKeyPress = _this.handleKeyPress.bind(_assertThisInitialized(_this)); | ||
_this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this)); | ||
return _this; | ||
} | ||
UrlUI.prototype.componentDidMount = function componentDidMount() { | ||
var _proto = UrlUI.prototype; | ||
_proto.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
this.input.value = ''; | ||
// My guess about why browser scrolls to top on focus: | ||
this.input.value = ''; // My guess about why browser scrolls to top on focus: | ||
// Component is mounted right away, but the tab panel might be animating | ||
// still, so input element is positioned outside viewport. This fixes it. | ||
setTimeout(function () { | ||
if (!_this2.input) return; | ||
_this2.input.focus({ preventScroll: true }); | ||
_this2.input.focus({ | ||
preventScroll: true | ||
}); | ||
}, 150); | ||
}; | ||
UrlUI.prototype.handleKeyPress = function handleKeyPress(ev) { | ||
_proto.handleKeyPress = function handleKeyPress(ev) { | ||
if (ev.keyCode === 13) { | ||
@@ -44,30 +48,25 @@ this.props.addFile(this.input.value); | ||
UrlUI.prototype.handleClick = function handleClick() { | ||
_proto.handleClick = function handleClick() { | ||
this.props.addFile(this.input.value); | ||
}; | ||
UrlUI.prototype.render = function render() { | ||
_proto.render = function render() { | ||
var _this3 = this; | ||
return h( | ||
'div', | ||
{ 'class': 'uppy-Url' }, | ||
h('input', { | ||
'class': 'uppy-u-reset uppy-c-textInput uppy-Url-input', | ||
type: 'text', | ||
'aria-label': this.props.i18n('enterUrlToImport'), | ||
placeholder: this.props.i18n('enterUrlToImport'), | ||
onkeyup: this.handleKeyPress, | ||
ref: function ref(input) { | ||
_this3.input = input; | ||
} }), | ||
h( | ||
'button', | ||
{ | ||
'class': 'uppy-u-reset uppy-c-btn uppy-c-btn-primary uppy-Url-importButton', | ||
type: 'button', | ||
onclick: this.handleClick }, | ||
this.props.i18n('import') | ||
) | ||
); | ||
return h("div", { | ||
class: "uppy-Url" | ||
}, h("input", { | ||
class: "uppy-u-reset uppy-c-textInput uppy-Url-input", | ||
type: "text", | ||
"aria-label": this.props.i18n('enterUrlToImport'), | ||
placeholder: this.props.i18n('enterUrlToImport'), | ||
onkeyup: this.handleKeyPress, | ||
ref: function ref(input) { | ||
_this3.input = input; | ||
} | ||
}), h("button", { | ||
class: "uppy-u-reset uppy-c-btn uppy-c-btn-primary uppy-Url-importButton", | ||
type: "button", | ||
onclick: this.handleClick | ||
}, this.props.i18n('import'))); | ||
}; | ||
@@ -74,0 +73,0 @@ |
var toArray = require('@uppy/utils/lib/toArray'); | ||
/* | ||
@@ -51,3 +50,2 @@ SITUATION | ||
*/ | ||
// Finds all links dropped/pasted from one browser window to another. | ||
@@ -57,7 +55,8 @@ // @param {object} dataTransfer - DataTransfer instance, e.g. e.clipboardData, or e.dataTransfer | ||
// @param {function} callback - (urlString) => {} | ||
module.exports = function forEachDroppedOrPastedUrl(dataTransfer, isDropOrPaste, callback) { | ||
var items = toArray(dataTransfer.items); | ||
var urlItems; | ||
var urlItems = void 0; | ||
switch (isDropOrPaste) { | ||
@@ -69,2 +68,3 @@ case 'paste': | ||
}); | ||
if (atLeastOneFileIsDragged) { | ||
@@ -77,4 +77,6 @@ return; | ||
} | ||
break; | ||
} | ||
case 'drop': | ||
@@ -87,5 +89,6 @@ { | ||
} | ||
default: | ||
{ | ||
throw new Error('isDropOrPaste must be either \'drop\' or \'paste\', but it\'s ' + isDropOrPaste); | ||
throw new Error("isDropOrPaste must be either 'drop' or 'paste', but it's " + isDropOrPaste); | ||
} | ||
@@ -92,0 +95,0 @@ } |
{ | ||
"name": "@uppy/url", | ||
"description": "The Url plugin lets users import files from the Internet. Paste any URL and it’ll be added!", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -25,8 +25,8 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/companion-client": "1.0.1", | ||
"@uppy/utils": "1.0.2", | ||
"@uppy/companion-client": "1.1.0", | ||
"@uppy/utils": "1.1.0", | ||
"preact": "8.2.9" | ||
}, | ||
"devDependencies": { | ||
"@uppy/core": "1.0.2" | ||
"@uppy/core": "1.1.0" | ||
}, | ||
@@ -36,3 +36,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "5c9e1a836df858254657a59ab8bd4b90035cf8b4" | ||
"gitHead": "28d235fe2fb57d87a399c20883fd6590aa49f4f4" | ||
} |
@@ -13,2 +13,4 @@ const { Plugin } = require('@uppy/core') | ||
module.exports = class Url extends Plugin { | ||
static VERSION = require('../package.json').version | ||
constructor (uppy, opts) { | ||
@@ -15,0 +17,0 @@ super(uppy, opts) |
646
29148
+ Added@uppy/companion-client@1.1.0(transitive)
+ Added@uppy/utils@1.1.0(transitive)
- Removed@uppy/companion-client@1.0.1(transitive)
- Removed@uppy/utils@1.0.2(transitive)
Updated@uppy/companion-client@1.1.0
Updated@uppy/utils@1.1.0