UNPKG

uppy

Version:

Almost as cute as a Puppy :dog:

145 lines (108 loc) 5.48 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'); module.exports = function (_Plugin) { _inherits(Google, _Plugin); function Google(core, opts) { _classCallCheck(this, Google); var _this // Visual // set default options = _possibleConstructorReturn(this, _Plugin.call(this, core, opts)); _this.type = 'acquirer'; _this.id = 'GoogleDrive'; _this.title = 'Google Drive'; _this.stateId = 'googleDrive'; _this.icon = function () { var _path, _uppyIcon; return _uppyIcon = document.createElementNS(_svgNamespace, 'svg'), _uppyIcon.setAttribute('aria-hidden', 'true'), _uppyIcon.setAttribute('width', '28'), _uppyIcon.setAttribute('height', '28'), _uppyIcon.setAttribute('viewBox', '0 0 16 16'), _uppyIcon.setAttribute('class', 'UppyIcon UppyModalTab-icon'), _appendChild(_uppyIcon, [' ', (_path = document.createElementNS(_svgNamespace, 'path'), _path.setAttribute('d', 'M2.955 14.93l2.667-4.62H16l-2.667 4.62H2.955zm2.378-4.62l-2.666 4.62L0 10.31l5.19-8.99 2.666 4.62-2.523 4.37zm10.523-.25h-5.333l-5.19-8.99h5.334l5.19 8.99z'), _path), ' ']), _uppyIcon; }; // writing out the key explicitly for readability the key used to store // the provider instance must be equal to this.id. _this.GoogleDrive = new Provider(core, { host: _this.opts.host, provider: 'drive', authProvider: 'google' }); _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; } Google.prototype.install = function install() { this.view = new View(this); // Set default state for Google Drive this.core.setState({ // writing out the key explicitly for readability the key used to store // the plugin state must be equal to this.stateId. googleDrive: { authenticated: false, files: [], folders: [], directories: [], activeRow: -1, filterInput: '', isSearchVisible: false } }); var target = this.opts.target; var plugin = this; this.target = this.mount(target, plugin); }; Google.prototype.uninstall = function uninstall() { this.unmount(); }; Google.prototype.onAuth = function onAuth(authenticated) { this.view.updateState({ authenticated: authenticated }); if (authenticated) { this.view.getFolder('root'); } }; Google.prototype.isFolder = function isFolder(item) { return item.mimeType === 'application/vnd.google-apps.folder'; }; Google.prototype.getItemData = function getItemData(item) { return _extends({}, item, { size: parseFloat(item.fileSize) }); }; Google.prototype.getItemIcon = function getItemIcon(item) { var _img; return _img = document.createElement('img'), _img.setAttribute('src', '' + String(item.iconLink) + ''), _img; }; Google.prototype.getItemSubList = function getItemSubList(item) { var _this2 = this; return item.items.filter(function (i) { return _this2.isFolder(i) || !i.mimeType.startsWith('application/vnd.google'); }); }; Google.prototype.getItemName = function getItemName(item) { return item.title ? item.title : '/'; }; Google.prototype.getMimeType = function getMimeType(item) { return item.mimeType; }; Google.prototype.getItemId = function getItemId(item) { return item.id; }; Google.prototype.getItemRequestPath = function getItemRequestPath(item) { return this.getItemId(item); }; Google.prototype.getItemModifiedDate = function getItemModifiedDate(item) { return item.modifiedByMeDate; }; Google.prototype.getItemThumbnailUrl = function getItemThumbnailUrl(item) { return this.opts.host + '/' + this.GoogleDrive.id + '/thumbnail/' + this.getItemRequestPath(item); }; Google.prototype.render = function render(state) { return this.view.render(state); }; return Google; }(Plugin); //# sourceMappingURL=index.js.map