UNPKG

uppy

Version:

Almost as cute as a Puppy :dog:

148 lines (112 loc) 5.7 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; }; var _svgNamespace = 'http://www.w3.org/2000/svg', _appendChild = require('yo-yoify/lib/appendChild'); 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('../Plugin'); var Provider = require('../../uppy-base/src/plugins/Provider'); var View = require('../../generic-provider-views/index'); var icons = require('./icons'); module.exports = function (_Plugin) { _inherits(Dropbox, _Plugin); function Dropbox(core, opts) { _classCallCheck(this, Dropbox); var _this // Visual // set default options = _possibleConstructorReturn(this, _Plugin.call(this, core, opts)); _this.type = 'acquirer'; _this.id = 'Dropbox'; _this.title = 'Dropbox'; _this.stateId = 'dropbox'; _this.icon = function () { var _path, _path2, _path3, _uppyIcon; return _uppyIcon = document.createElementNS(_svgNamespace, 'svg'), _uppyIcon.setAttribute('width', '128'), _uppyIcon.setAttribute('height', '118'), _uppyIcon.setAttribute('viewBox', '0 0 128 118'), _uppyIcon.setAttribute('class', 'UppyIcon'), _appendChild(_uppyIcon, [' ', (_path = document.createElementNS(_svgNamespace, 'path'), _path.setAttribute('d', 'M38.145.777L1.108 24.96l25.608 20.507 37.344-23.06z'), _path), ' ', (_path2 = document.createElementNS(_svgNamespace, 'path'), _path2.setAttribute('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'), _path2), ' ', (_path3 = document.createElementNS(_svgNamespace, 'path'), _path3.setAttribute('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'), _path3), ' ']), _uppyIcon; }; // writing out the key explicitly for readability the key used to store // the provider instance must be equal to this.id. _this.Dropbox = new Provider(core, { host: _this.opts.host, provider: 'dropbox' }); _this.files = []; _this.onAuth = _this.onAuth.bind(_this);_this.render = _this.render.bind(_this);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 this.core.setState({ // writing out the key explicitly for readability the key used to store // the plugin state must be equal to this.stateId. dropbox: { authenticated: false, files: [], folders: [], directories: [], activeRow: -1, filterInput: '', isSearchVisible: false } }); var target = this.opts.target; var plugin = this; this.target = this.mount(target, plugin); }; Dropbox.prototype.uninstall = function uninstall() { this.unmount(); }; Dropbox.prototype.onAuth = function onAuth(authenticated) { this.view.updateState({ authenticated: authenticated }); if (authenticated) { this.view.getFolder(); } }; Dropbox.prototype.isFolder = function isFolder(item) { return item.is_dir; }; Dropbox.prototype.getItemData = function getItemData(item) { return _extends({}, item, { size: item.bytes }); }; Dropbox.prototype.getItemIcon = function getItemIcon(item) { var icon = icons[item.icon]; if (!icon) { if (item.icon.startsWith('folder')) { icon = icons['folder']; } else { icon = icons['page_white']; } } return icon(); }; Dropbox.prototype.getItemSubList = function getItemSubList(item) { return item.contents; }; Dropbox.prototype.getItemName = function getItemName(item) { return item.path.length > 1 ? item.path.substring(1) : item.path; }; Dropbox.prototype.getMimeType = function getMimeType(item) { return item.mime_type; }; Dropbox.prototype.getItemId = function getItemId(item) { return item.rev; }; Dropbox.prototype.getItemRequestPath = function getItemRequestPath(item) { return encodeURIComponent(this.getItemName(item)); }; Dropbox.prototype.getItemModifiedDate = function getItemModifiedDate(item) { return item.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