UNPKG

uppy

Version:

Extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:

138 lines (107 loc) 4.79 kB
'use strict'; 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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 Plugin = require('../../core/Plugin'); var Provider = require('../Provider'); var View = require('../Provider/view'); var icons = require('./icons'); var _require = require('preact'), h = _require.h; module.exports = function (_Plugin) { _inherits(Dropbox, _Plugin); function Dropbox(uppy, opts) { _classCallCheck(this, Dropbox); var _this = _possibleConstructorReturn(this, _Plugin.call(this, uppy, opts)); _this.type = 'acquirer'; _this.id = _this.opts.id || 'Dropbox'; _this.title = 'Dropbox'; _this.icon = function () { return h( 'svg', { 'class': 'UppyIcon', width: '128', height: '118', viewBox: '0 0 128 118' }, h('path', { d: 'M38.145.777L1.108 24.96l25.608 20.507 37.344-23.06z' }), h('path', { d: 'M1.108 65.975l37.037 24.183L64.06 68.525l-37.343-23.06zM64.06 68.525l25.917 21.633 37.036-24.183-25.61-20.51z' }), h('path', { d: 'M127.014 24.96L89.977.776 64.06 22.407l37.345 23.06zM64.136 73.18l-25.99 21.567-11.122-7.262v8.142l37.112 22.256 37.114-22.256v-8.142l-11.12 7.262z' }) ); }; // writing out the key explicitly for readability the key used to store // the provider instance must be equal to this.id. _this[_this.id] = new Provider(uppy, { host: _this.opts.host, provider: 'dropbox' }); _this.files = []; _this.onAuth = _this.onAuth.bind(_this); _this.render = _this.render.bind(_this); // set default options var defaultOptions = {}; // merge default options with the ones set by user _this.opts = _extends({}, defaultOptions, opts); return _this; } Dropbox.prototype.install = function install() { this.view = new View(this); // Set default state for Dropbox this.setPluginState({ authenticated: false, files: [], folders: [], directories: [], activeRow: -1, filterInput: '', isSearchVisible: false }); var target = this.opts.target; if (target) { this.mount(target, this); } }; Dropbox.prototype.uninstall = function uninstall() { this.view.tearDown(); this.unmount(); }; Dropbox.prototype.onAuth = function onAuth(authenticated) { this.setPluginState({ authenticated: authenticated }); if (authenticated) { this.view.getFolder(); } }; Dropbox.prototype.isFolder = function isFolder(item) { return item['.tag'] === 'folder'; }; Dropbox.prototype.getItemData = function getItemData(item) { return item; }; Dropbox.prototype.getItemIcon = function getItemIcon(item) { return icons[item['.tag']](); }; Dropbox.prototype.getItemSubList = function getItemSubList(item) { return item.entries; }; Dropbox.prototype.getItemName = function getItemName(item) { return item.name || ''; }; Dropbox.prototype.getMimeType = function getMimeType(item) { // mime types aren't supported. return null; }; Dropbox.prototype.getItemId = function getItemId(item) { return item.id; }; Dropbox.prototype.getItemRequestPath = function getItemRequestPath(item) { return encodeURIComponent(item.path_lower); }; Dropbox.prototype.getItemModifiedDate = function getItemModifiedDate(item) { return item.server_modified; }; Dropbox.prototype.getItemThumbnailUrl = function getItemThumbnailUrl(item) { return this.opts.host + '/' + this.Dropbox.id + '/thumbnail/' + this.getItemRequestPath(item); }; Dropbox.prototype.render = function render(state) { return this.view.render(state); }; return Dropbox; }(Plugin); //# sourceMappingURL=index.js.map