|
@@ -1,4290 +0,0 @@
|
|
|
-(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Uppy = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
|
-
|
|
|
-},{}],2:[function(require,module,exports){
|
|
|
-
|
|
|
-/**
|
|
|
- * Expose `Emitter`.
|
|
|
- */
|
|
|
-
|
|
|
-module.exports = Emitter;
|
|
|
-
|
|
|
-/**
|
|
|
- * Initialize a new `Emitter`.
|
|
|
- *
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-function Emitter(obj) {
|
|
|
- if (obj) return mixin(obj);
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Mixin the emitter properties.
|
|
|
- *
|
|
|
- * @param {Object} obj
|
|
|
- * @return {Object}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function mixin(obj) {
|
|
|
- for (var key in Emitter.prototype) {
|
|
|
- obj[key] = Emitter.prototype[key];
|
|
|
- }
|
|
|
- return obj;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Listen on the given `event` with `fn`.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Emitter}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Emitter.prototype.on =
|
|
|
-Emitter.prototype.addEventListener = function(event, fn){
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
- (this._callbacks[event] = this._callbacks[event] || [])
|
|
|
- .push(fn);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Adds an `event` listener that will be invoked a single
|
|
|
- * time then automatically removed.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Emitter}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Emitter.prototype.once = function(event, fn){
|
|
|
- var self = this;
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
-
|
|
|
- function on() {
|
|
|
- self.off(event, on);
|
|
|
- fn.apply(this, arguments);
|
|
|
- }
|
|
|
-
|
|
|
- on.fn = fn;
|
|
|
- this.on(event, on);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Remove the given callback for `event` or all
|
|
|
- * registered callbacks.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Emitter}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Emitter.prototype.off =
|
|
|
-Emitter.prototype.removeListener =
|
|
|
-Emitter.prototype.removeAllListeners =
|
|
|
-Emitter.prototype.removeEventListener = function(event, fn){
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
-
|
|
|
- // all
|
|
|
- if (0 == arguments.length) {
|
|
|
- this._callbacks = {};
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- // specific event
|
|
|
- var callbacks = this._callbacks[event];
|
|
|
- if (!callbacks) return this;
|
|
|
-
|
|
|
- // remove all handlers
|
|
|
- if (1 == arguments.length) {
|
|
|
- delete this._callbacks[event];
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- // remove specific handler
|
|
|
- var cb;
|
|
|
- for (var i = 0; i < callbacks.length; i++) {
|
|
|
- cb = callbacks[i];
|
|
|
- if (cb === fn || cb.fn === fn) {
|
|
|
- callbacks.splice(i, 1);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Emit `event` with the given args.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @param {Mixed} ...
|
|
|
- * @return {Emitter}
|
|
|
- */
|
|
|
-
|
|
|
-Emitter.prototype.emit = function(event){
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
- var args = [].slice.call(arguments, 1)
|
|
|
- , callbacks = this._callbacks[event];
|
|
|
-
|
|
|
- if (callbacks) {
|
|
|
- callbacks = callbacks.slice(0);
|
|
|
- for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
|
- callbacks[i].apply(this, args);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Return array of callbacks for `event`.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @return {Array}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Emitter.prototype.listeners = function(event){
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
- return this._callbacks[event] || [];
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Check if this emitter has `event` handlers.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @return {Boolean}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Emitter.prototype.hasListeners = function(event){
|
|
|
- return !! this.listeners(event).length;
|
|
|
-};
|
|
|
-
|
|
|
-},{}],3:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-// istanbul ignore next
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-// istanbul ignore next
|
|
|
-
|
|
|
-function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
|
|
-
|
|
|
-var _handlebarsBase = require('./handlebars/base');
|
|
|
-
|
|
|
-var base = _interopRequireWildcard(_handlebarsBase);
|
|
|
-
|
|
|
-// Each of these augment the Handlebars object. No need to setup here.
|
|
|
-// (This is done to easily share code between commonjs and browse envs)
|
|
|
-
|
|
|
-var _handlebarsSafeString = require('./handlebars/safe-string');
|
|
|
-
|
|
|
-var _handlebarsSafeString2 = _interopRequireDefault(_handlebarsSafeString);
|
|
|
-
|
|
|
-var _handlebarsException = require('./handlebars/exception');
|
|
|
-
|
|
|
-var _handlebarsException2 = _interopRequireDefault(_handlebarsException);
|
|
|
-
|
|
|
-var _handlebarsUtils = require('./handlebars/utils');
|
|
|
-
|
|
|
-var Utils = _interopRequireWildcard(_handlebarsUtils);
|
|
|
-
|
|
|
-var _handlebarsRuntime = require('./handlebars/runtime');
|
|
|
-
|
|
|
-var runtime = _interopRequireWildcard(_handlebarsRuntime);
|
|
|
-
|
|
|
-var _handlebarsNoConflict = require('./handlebars/no-conflict');
|
|
|
-
|
|
|
-var _handlebarsNoConflict2 = _interopRequireDefault(_handlebarsNoConflict);
|
|
|
-
|
|
|
-// For compatibility and usage outside of module systems, make the Handlebars object a namespace
|
|
|
-function create() {
|
|
|
- var hb = new base.HandlebarsEnvironment();
|
|
|
-
|
|
|
- Utils.extend(hb, base);
|
|
|
- hb.SafeString = _handlebarsSafeString2['default'];
|
|
|
- hb.Exception = _handlebarsException2['default'];
|
|
|
- hb.Utils = Utils;
|
|
|
- hb.escapeExpression = Utils.escapeExpression;
|
|
|
-
|
|
|
- hb.VM = runtime;
|
|
|
- hb.template = function (spec) {
|
|
|
- return runtime.template(spec, hb);
|
|
|
- };
|
|
|
-
|
|
|
- return hb;
|
|
|
-}
|
|
|
-
|
|
|
-var inst = create();
|
|
|
-inst.create = create;
|
|
|
-
|
|
|
-_handlebarsNoConflict2['default'](inst);
|
|
|
-
|
|
|
-inst['default'] = inst;
|
|
|
-
|
|
|
-exports['default'] = inst;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{"./handlebars/base":4,"./handlebars/exception":7,"./handlebars/no-conflict":17,"./handlebars/runtime":18,"./handlebars/safe-string":19,"./handlebars/utils":20}],4:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-exports.HandlebarsEnvironment = HandlebarsEnvironment;
|
|
|
-// istanbul ignore next
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-var _utils = require('./utils');
|
|
|
-
|
|
|
-var _exception = require('./exception');
|
|
|
-
|
|
|
-var _exception2 = _interopRequireDefault(_exception);
|
|
|
-
|
|
|
-var _helpers = require('./helpers');
|
|
|
-
|
|
|
-var _decorators = require('./decorators');
|
|
|
-
|
|
|
-var _logger = require('./logger');
|
|
|
-
|
|
|
-var _logger2 = _interopRequireDefault(_logger);
|
|
|
-
|
|
|
-var VERSION = '4.0.5';
|
|
|
-exports.VERSION = VERSION;
|
|
|
-var COMPILER_REVISION = 7;
|
|
|
-
|
|
|
-exports.COMPILER_REVISION = COMPILER_REVISION;
|
|
|
-var REVISION_CHANGES = {
|
|
|
- 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
|
|
|
- 2: '== 1.0.0-rc.3',
|
|
|
- 3: '== 1.0.0-rc.4',
|
|
|
- 4: '== 1.x.x',
|
|
|
- 5: '== 2.0.0-alpha.x',
|
|
|
- 6: '>= 2.0.0-beta.1',
|
|
|
- 7: '>= 4.0.0'
|
|
|
-};
|
|
|
-
|
|
|
-exports.REVISION_CHANGES = REVISION_CHANGES;
|
|
|
-var objectType = '[object Object]';
|
|
|
-
|
|
|
-function HandlebarsEnvironment(helpers, partials, decorators) {
|
|
|
- this.helpers = helpers || {};
|
|
|
- this.partials = partials || {};
|
|
|
- this.decorators = decorators || {};
|
|
|
-
|
|
|
- _helpers.registerDefaultHelpers(this);
|
|
|
- _decorators.registerDefaultDecorators(this);
|
|
|
-}
|
|
|
-
|
|
|
-HandlebarsEnvironment.prototype = {
|
|
|
- constructor: HandlebarsEnvironment,
|
|
|
-
|
|
|
- logger: _logger2['default'],
|
|
|
- log: _logger2['default'].log,
|
|
|
-
|
|
|
- registerHelper: function registerHelper(name, fn) {
|
|
|
- if (_utils.toString.call(name) === objectType) {
|
|
|
- if (fn) {
|
|
|
- throw new _exception2['default']('Arg not supported with multiple helpers');
|
|
|
- }
|
|
|
- _utils.extend(this.helpers, name);
|
|
|
- } else {
|
|
|
- this.helpers[name] = fn;
|
|
|
- }
|
|
|
- },
|
|
|
- unregisterHelper: function unregisterHelper(name) {
|
|
|
- delete this.helpers[name];
|
|
|
- },
|
|
|
-
|
|
|
- registerPartial: function registerPartial(name, partial) {
|
|
|
- if (_utils.toString.call(name) === objectType) {
|
|
|
- _utils.extend(this.partials, name);
|
|
|
- } else {
|
|
|
- if (typeof partial === 'undefined') {
|
|
|
- throw new _exception2['default']('Attempting to register a partial called "' + name + '" as undefined');
|
|
|
- }
|
|
|
- this.partials[name] = partial;
|
|
|
- }
|
|
|
- },
|
|
|
- unregisterPartial: function unregisterPartial(name) {
|
|
|
- delete this.partials[name];
|
|
|
- },
|
|
|
-
|
|
|
- registerDecorator: function registerDecorator(name, fn) {
|
|
|
- if (_utils.toString.call(name) === objectType) {
|
|
|
- if (fn) {
|
|
|
- throw new _exception2['default']('Arg not supported with multiple decorators');
|
|
|
- }
|
|
|
- _utils.extend(this.decorators, name);
|
|
|
- } else {
|
|
|
- this.decorators[name] = fn;
|
|
|
- }
|
|
|
- },
|
|
|
- unregisterDecorator: function unregisterDecorator(name) {
|
|
|
- delete this.decorators[name];
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-var log = _logger2['default'].log;
|
|
|
-
|
|
|
-exports.log = log;
|
|
|
-exports.createFrame = _utils.createFrame;
|
|
|
-exports.logger = _logger2['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{"./decorators":5,"./exception":7,"./helpers":8,"./logger":16,"./utils":20}],5:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-exports.registerDefaultDecorators = registerDefaultDecorators;
|
|
|
-// istanbul ignore next
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-var _decoratorsInline = require('./decorators/inline');
|
|
|
-
|
|
|
-var _decoratorsInline2 = _interopRequireDefault(_decoratorsInline);
|
|
|
-
|
|
|
-function registerDefaultDecorators(instance) {
|
|
|
- _decoratorsInline2['default'](instance);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-},{"./decorators/inline":6}],6:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-
|
|
|
-var _utils = require('../utils');
|
|
|
-
|
|
|
-exports['default'] = function (instance) {
|
|
|
- instance.registerDecorator('inline', function (fn, props, container, options) {
|
|
|
- var ret = fn;
|
|
|
- if (!props.partials) {
|
|
|
- props.partials = {};
|
|
|
- ret = function (context, options) {
|
|
|
- // Create a new partials stack frame prior to exec.
|
|
|
- var original = container.partials;
|
|
|
- container.partials = _utils.extend({}, original, props.partials);
|
|
|
- var ret = fn(context, options);
|
|
|
- container.partials = original;
|
|
|
- return ret;
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- props.partials[options.args[0]] = options.fn;
|
|
|
-
|
|
|
- return ret;
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{"../utils":20}],7:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-
|
|
|
-var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
|
|
-
|
|
|
-function Exception(message, node) {
|
|
|
- var loc = node && node.loc,
|
|
|
- line = undefined,
|
|
|
- column = undefined;
|
|
|
- if (loc) {
|
|
|
- line = loc.start.line;
|
|
|
- column = loc.start.column;
|
|
|
-
|
|
|
- message += ' - ' + line + ':' + column;
|
|
|
- }
|
|
|
-
|
|
|
- var tmp = Error.prototype.constructor.call(this, message);
|
|
|
-
|
|
|
- // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
|
|
|
- for (var idx = 0; idx < errorProps.length; idx++) {
|
|
|
- this[errorProps[idx]] = tmp[errorProps[idx]];
|
|
|
- }
|
|
|
-
|
|
|
- /* istanbul ignore else */
|
|
|
- if (Error.captureStackTrace) {
|
|
|
- Error.captureStackTrace(this, Exception);
|
|
|
- }
|
|
|
-
|
|
|
- if (loc) {
|
|
|
- this.lineNumber = line;
|
|
|
- this.column = column;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-Exception.prototype = new Error();
|
|
|
-
|
|
|
-exports['default'] = Exception;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{}],8:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-exports.registerDefaultHelpers = registerDefaultHelpers;
|
|
|
-// istanbul ignore next
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-var _helpersBlockHelperMissing = require('./helpers/block-helper-missing');
|
|
|
-
|
|
|
-var _helpersBlockHelperMissing2 = _interopRequireDefault(_helpersBlockHelperMissing);
|
|
|
-
|
|
|
-var _helpersEach = require('./helpers/each');
|
|
|
-
|
|
|
-var _helpersEach2 = _interopRequireDefault(_helpersEach);
|
|
|
-
|
|
|
-var _helpersHelperMissing = require('./helpers/helper-missing');
|
|
|
-
|
|
|
-var _helpersHelperMissing2 = _interopRequireDefault(_helpersHelperMissing);
|
|
|
-
|
|
|
-var _helpersIf = require('./helpers/if');
|
|
|
-
|
|
|
-var _helpersIf2 = _interopRequireDefault(_helpersIf);
|
|
|
-
|
|
|
-var _helpersLog = require('./helpers/log');
|
|
|
-
|
|
|
-var _helpersLog2 = _interopRequireDefault(_helpersLog);
|
|
|
-
|
|
|
-var _helpersLookup = require('./helpers/lookup');
|
|
|
-
|
|
|
-var _helpersLookup2 = _interopRequireDefault(_helpersLookup);
|
|
|
-
|
|
|
-var _helpersWith = require('./helpers/with');
|
|
|
-
|
|
|
-var _helpersWith2 = _interopRequireDefault(_helpersWith);
|
|
|
-
|
|
|
-function registerDefaultHelpers(instance) {
|
|
|
- _helpersBlockHelperMissing2['default'](instance);
|
|
|
- _helpersEach2['default'](instance);
|
|
|
- _helpersHelperMissing2['default'](instance);
|
|
|
- _helpersIf2['default'](instance);
|
|
|
- _helpersLog2['default'](instance);
|
|
|
- _helpersLookup2['default'](instance);
|
|
|
- _helpersWith2['default'](instance);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-},{"./helpers/block-helper-missing":9,"./helpers/each":10,"./helpers/helper-missing":11,"./helpers/if":12,"./helpers/log":13,"./helpers/lookup":14,"./helpers/with":15}],9:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-
|
|
|
-var _utils = require('../utils');
|
|
|
-
|
|
|
-exports['default'] = function (instance) {
|
|
|
- instance.registerHelper('blockHelperMissing', function (context, options) {
|
|
|
- var inverse = options.inverse,
|
|
|
- fn = options.fn;
|
|
|
-
|
|
|
- if (context === true) {
|
|
|
- return fn(this);
|
|
|
- } else if (context === false || context == null) {
|
|
|
- return inverse(this);
|
|
|
- } else if (_utils.isArray(context)) {
|
|
|
- if (context.length > 0) {
|
|
|
- if (options.ids) {
|
|
|
- options.ids = [options.name];
|
|
|
- }
|
|
|
-
|
|
|
- return instance.helpers.each(context, options);
|
|
|
- } else {
|
|
|
- return inverse(this);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (options.data && options.ids) {
|
|
|
- var data = _utils.createFrame(options.data);
|
|
|
- data.contextPath = _utils.appendContextPath(options.data.contextPath, options.name);
|
|
|
- options = { data: data };
|
|
|
- }
|
|
|
-
|
|
|
- return fn(context, options);
|
|
|
- }
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{"../utils":20}],10:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-// istanbul ignore next
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-var _utils = require('../utils');
|
|
|
-
|
|
|
-var _exception = require('../exception');
|
|
|
-
|
|
|
-var _exception2 = _interopRequireDefault(_exception);
|
|
|
-
|
|
|
-exports['default'] = function (instance) {
|
|
|
- instance.registerHelper('each', function (context, options) {
|
|
|
- if (!options) {
|
|
|
- throw new _exception2['default']('Must pass iterator to #each');
|
|
|
- }
|
|
|
-
|
|
|
- var fn = options.fn,
|
|
|
- inverse = options.inverse,
|
|
|
- i = 0,
|
|
|
- ret = '',
|
|
|
- data = undefined,
|
|
|
- contextPath = undefined;
|
|
|
-
|
|
|
- if (options.data && options.ids) {
|
|
|
- contextPath = _utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.';
|
|
|
- }
|
|
|
-
|
|
|
- if (_utils.isFunction(context)) {
|
|
|
- context = context.call(this);
|
|
|
- }
|
|
|
-
|
|
|
- if (options.data) {
|
|
|
- data = _utils.createFrame(options.data);
|
|
|
- }
|
|
|
-
|
|
|
- function execIteration(field, index, last) {
|
|
|
- if (data) {
|
|
|
- data.key = field;
|
|
|
- data.index = index;
|
|
|
- data.first = index === 0;
|
|
|
- data.last = !!last;
|
|
|
-
|
|
|
- if (contextPath) {
|
|
|
- data.contextPath = contextPath + field;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- ret = ret + fn(context[field], {
|
|
|
- data: data,
|
|
|
- blockParams: _utils.blockParams([context[field], field], [contextPath + field, null])
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- if (context && typeof context === 'object') {
|
|
|
- if (_utils.isArray(context)) {
|
|
|
- for (var j = context.length; i < j; i++) {
|
|
|
- if (i in context) {
|
|
|
- execIteration(i, i, i === context.length - 1);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- var priorKey = undefined;
|
|
|
-
|
|
|
- for (var key in context) {
|
|
|
- if (context.hasOwnProperty(key)) {
|
|
|
- // We're running the iterations one step out of sync so we can detect
|
|
|
- // the last iteration without have to scan the object twice and create
|
|
|
- // an itermediate keys array.
|
|
|
- if (priorKey !== undefined) {
|
|
|
- execIteration(priorKey, i - 1);
|
|
|
- }
|
|
|
- priorKey = key;
|
|
|
- i++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (priorKey !== undefined) {
|
|
|
- execIteration(priorKey, i - 1, true);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (i === 0) {
|
|
|
- ret = inverse(this);
|
|
|
- }
|
|
|
-
|
|
|
- return ret;
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{"../exception":7,"../utils":20}],11:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-// istanbul ignore next
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-var _exception = require('../exception');
|
|
|
-
|
|
|
-var _exception2 = _interopRequireDefault(_exception);
|
|
|
-
|
|
|
-exports['default'] = function (instance) {
|
|
|
- instance.registerHelper('helperMissing', function () /* [args, ]options */{
|
|
|
- if (arguments.length === 1) {
|
|
|
- // A missing field in a {{foo}} construct.
|
|
|
- return undefined;
|
|
|
- } else {
|
|
|
- // Someone is actually trying to call something, blow up.
|
|
|
- throw new _exception2['default']('Missing helper: "' + arguments[arguments.length - 1].name + '"');
|
|
|
- }
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{"../exception":7}],12:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-
|
|
|
-var _utils = require('../utils');
|
|
|
-
|
|
|
-exports['default'] = function (instance) {
|
|
|
- instance.registerHelper('if', function (conditional, options) {
|
|
|
- if (_utils.isFunction(conditional)) {
|
|
|
- conditional = conditional.call(this);
|
|
|
- }
|
|
|
-
|
|
|
- // Default behavior is to render the positive path if the value is truthy and not empty.
|
|
|
- // The `includeZero` option may be set to treat the condtional as purely not empty based on the
|
|
|
- // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
|
|
|
- if (!options.hash.includeZero && !conditional || _utils.isEmpty(conditional)) {
|
|
|
- return options.inverse(this);
|
|
|
- } else {
|
|
|
- return options.fn(this);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- instance.registerHelper('unless', function (conditional, options) {
|
|
|
- return instance.helpers['if'].call(this, conditional, { fn: options.inverse, inverse: options.fn, hash: options.hash });
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{"../utils":20}],13:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-
|
|
|
-exports['default'] = function (instance) {
|
|
|
- instance.registerHelper('log', function () /* message, options */{
|
|
|
- var args = [undefined],
|
|
|
- options = arguments[arguments.length - 1];
|
|
|
- for (var i = 0; i < arguments.length - 1; i++) {
|
|
|
- args.push(arguments[i]);
|
|
|
- }
|
|
|
-
|
|
|
- var level = 1;
|
|
|
- if (options.hash.level != null) {
|
|
|
- level = options.hash.level;
|
|
|
- } else if (options.data && options.data.level != null) {
|
|
|
- level = options.data.level;
|
|
|
- }
|
|
|
- args[0] = level;
|
|
|
-
|
|
|
- instance.log.apply(instance, args);
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{}],14:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-
|
|
|
-exports['default'] = function (instance) {
|
|
|
- instance.registerHelper('lookup', function (obj, field) {
|
|
|
- return obj && obj[field];
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{}],15:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-
|
|
|
-var _utils = require('../utils');
|
|
|
-
|
|
|
-exports['default'] = function (instance) {
|
|
|
- instance.registerHelper('with', function (context, options) {
|
|
|
- if (_utils.isFunction(context)) {
|
|
|
- context = context.call(this);
|
|
|
- }
|
|
|
-
|
|
|
- var fn = options.fn;
|
|
|
-
|
|
|
- if (!_utils.isEmpty(context)) {
|
|
|
- var data = options.data;
|
|
|
- if (options.data && options.ids) {
|
|
|
- data = _utils.createFrame(options.data);
|
|
|
- data.contextPath = _utils.appendContextPath(options.data.contextPath, options.ids[0]);
|
|
|
- }
|
|
|
-
|
|
|
- return fn(context, {
|
|
|
- data: data,
|
|
|
- blockParams: _utils.blockParams([context], [data && data.contextPath])
|
|
|
- });
|
|
|
- } else {
|
|
|
- return options.inverse(this);
|
|
|
- }
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{"../utils":20}],16:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-
|
|
|
-var _utils = require('./utils');
|
|
|
-
|
|
|
-var logger = {
|
|
|
- methodMap: ['debug', 'info', 'warn', 'error'],
|
|
|
- level: 'info',
|
|
|
-
|
|
|
- // Maps a given level value to the `methodMap` indexes above.
|
|
|
- lookupLevel: function lookupLevel(level) {
|
|
|
- if (typeof level === 'string') {
|
|
|
- var levelMap = _utils.indexOf(logger.methodMap, level.toLowerCase());
|
|
|
- if (levelMap >= 0) {
|
|
|
- level = levelMap;
|
|
|
- } else {
|
|
|
- level = parseInt(level, 10);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return level;
|
|
|
- },
|
|
|
-
|
|
|
- // Can be overridden in the host environment
|
|
|
- log: function log(level) {
|
|
|
- level = logger.lookupLevel(level);
|
|
|
-
|
|
|
- if (typeof console !== 'undefined' && logger.lookupLevel(logger.level) <= level) {
|
|
|
- var method = logger.methodMap[level];
|
|
|
- if (!console[method]) {
|
|
|
- // eslint-disable-line no-console
|
|
|
- method = 'log';
|
|
|
- }
|
|
|
-
|
|
|
- for (var _len = arguments.length, message = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
|
- message[_key - 1] = arguments[_key];
|
|
|
- }
|
|
|
-
|
|
|
- console[method].apply(console, message); // eslint-disable-line no-console
|
|
|
- }
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-exports['default'] = logger;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{"./utils":20}],17:[function(require,module,exports){
|
|
|
-(function (global){
|
|
|
-/* global window */
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-
|
|
|
-exports['default'] = function (Handlebars) {
|
|
|
- /* istanbul ignore next */
|
|
|
- var root = typeof global !== 'undefined' ? global : window,
|
|
|
- $Handlebars = root.Handlebars;
|
|
|
- /* istanbul ignore next */
|
|
|
- Handlebars.noConflict = function () {
|
|
|
- if (root.Handlebars === Handlebars) {
|
|
|
- root.Handlebars = $Handlebars;
|
|
|
- }
|
|
|
- return Handlebars;
|
|
|
- };
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
|
-},{}],18:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-exports.checkRevision = checkRevision;
|
|
|
-exports.template = template;
|
|
|
-exports.wrapProgram = wrapProgram;
|
|
|
-exports.resolvePartial = resolvePartial;
|
|
|
-exports.invokePartial = invokePartial;
|
|
|
-exports.noop = noop;
|
|
|
-// istanbul ignore next
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-// istanbul ignore next
|
|
|
-
|
|
|
-function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
|
|
-
|
|
|
-var _utils = require('./utils');
|
|
|
-
|
|
|
-var Utils = _interopRequireWildcard(_utils);
|
|
|
-
|
|
|
-var _exception = require('./exception');
|
|
|
-
|
|
|
-var _exception2 = _interopRequireDefault(_exception);
|
|
|
-
|
|
|
-var _base = require('./base');
|
|
|
-
|
|
|
-function checkRevision(compilerInfo) {
|
|
|
- var compilerRevision = compilerInfo && compilerInfo[0] || 1,
|
|
|
- currentRevision = _base.COMPILER_REVISION;
|
|
|
-
|
|
|
- if (compilerRevision !== currentRevision) {
|
|
|
- if (compilerRevision < currentRevision) {
|
|
|
- var runtimeVersions = _base.REVISION_CHANGES[currentRevision],
|
|
|
- compilerVersions = _base.REVISION_CHANGES[compilerRevision];
|
|
|
- throw new _exception2['default']('Template was precompiled with an older version of Handlebars than the current runtime. ' + 'Please update your precompiler to a newer version (' + runtimeVersions + ') or downgrade your runtime to an older version (' + compilerVersions + ').');
|
|
|
- } else {
|
|
|
- // Use the embedded version info since the runtime doesn't know about this revision yet
|
|
|
- throw new _exception2['default']('Template was precompiled with a newer version of Handlebars than the current runtime. ' + 'Please update your runtime to a newer version (' + compilerInfo[1] + ').');
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function template(templateSpec, env) {
|
|
|
- /* istanbul ignore next */
|
|
|
- if (!env) {
|
|
|
- throw new _exception2['default']('No environment passed to template');
|
|
|
- }
|
|
|
- if (!templateSpec || !templateSpec.main) {
|
|
|
- throw new _exception2['default']('Unknown template object: ' + typeof templateSpec);
|
|
|
- }
|
|
|
-
|
|
|
- templateSpec.main.decorator = templateSpec.main_d;
|
|
|
-
|
|
|
- // Note: Using env.VM references rather than local var references throughout this section to allow
|
|
|
- // for external users to override these as psuedo-supported APIs.
|
|
|
- env.VM.checkRevision(templateSpec.compiler);
|
|
|
-
|
|
|
- function invokePartialWrapper(partial, context, options) {
|
|
|
- if (options.hash) {
|
|
|
- context = Utils.extend({}, context, options.hash);
|
|
|
- if (options.ids) {
|
|
|
- options.ids[0] = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- partial = env.VM.resolvePartial.call(this, partial, context, options);
|
|
|
- var result = env.VM.invokePartial.call(this, partial, context, options);
|
|
|
-
|
|
|
- if (result == null && env.compile) {
|
|
|
- options.partials[options.name] = env.compile(partial, templateSpec.compilerOptions, env);
|
|
|
- result = options.partials[options.name](context, options);
|
|
|
- }
|
|
|
- if (result != null) {
|
|
|
- if (options.indent) {
|
|
|
- var lines = result.split('\n');
|
|
|
- for (var i = 0, l = lines.length; i < l; i++) {
|
|
|
- if (!lines[i] && i + 1 === l) {
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- lines[i] = options.indent + lines[i];
|
|
|
- }
|
|
|
- result = lines.join('\n');
|
|
|
- }
|
|
|
- return result;
|
|
|
- } else {
|
|
|
- throw new _exception2['default']('The partial ' + options.name + ' could not be compiled when running in runtime-only mode');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Just add water
|
|
|
- var container = {
|
|
|
- strict: function strict(obj, name) {
|
|
|
- if (!(name in obj)) {
|
|
|
- throw new _exception2['default']('"' + name + '" not defined in ' + obj);
|
|
|
- }
|
|
|
- return obj[name];
|
|
|
- },
|
|
|
- lookup: function lookup(depths, name) {
|
|
|
- var len = depths.length;
|
|
|
- for (var i = 0; i < len; i++) {
|
|
|
- if (depths[i] && depths[i][name] != null) {
|
|
|
- return depths[i][name];
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- lambda: function lambda(current, context) {
|
|
|
- return typeof current === 'function' ? current.call(context) : current;
|
|
|
- },
|
|
|
-
|
|
|
- escapeExpression: Utils.escapeExpression,
|
|
|
- invokePartial: invokePartialWrapper,
|
|
|
-
|
|
|
- fn: function fn(i) {
|
|
|
- var ret = templateSpec[i];
|
|
|
- ret.decorator = templateSpec[i + '_d'];
|
|
|
- return ret;
|
|
|
- },
|
|
|
-
|
|
|
- programs: [],
|
|
|
- program: function program(i, data, declaredBlockParams, blockParams, depths) {
|
|
|
- var programWrapper = this.programs[i],
|
|
|
- fn = this.fn(i);
|
|
|
- if (data || depths || blockParams || declaredBlockParams) {
|
|
|
- programWrapper = wrapProgram(this, i, fn, data, declaredBlockParams, blockParams, depths);
|
|
|
- } else if (!programWrapper) {
|
|
|
- programWrapper = this.programs[i] = wrapProgram(this, i, fn);
|
|
|
- }
|
|
|
- return programWrapper;
|
|
|
- },
|
|
|
-
|
|
|
- data: function data(value, depth) {
|
|
|
- while (value && depth--) {
|
|
|
- value = value._parent;
|
|
|
- }
|
|
|
- return value;
|
|
|
- },
|
|
|
- merge: function merge(param, common) {
|
|
|
- var obj = param || common;
|
|
|
-
|
|
|
- if (param && common && param !== common) {
|
|
|
- obj = Utils.extend({}, common, param);
|
|
|
- }
|
|
|
-
|
|
|
- return obj;
|
|
|
- },
|
|
|
-
|
|
|
- noop: env.VM.noop,
|
|
|
- compilerInfo: templateSpec.compiler
|
|
|
- };
|
|
|
-
|
|
|
- function ret(context) {
|
|
|
- var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
|
|
-
|
|
|
- var data = options.data;
|
|
|
-
|
|
|
- ret._setup(options);
|
|
|
- if (!options.partial && templateSpec.useData) {
|
|
|
- data = initData(context, data);
|
|
|
- }
|
|
|
- var depths = undefined,
|
|
|
- blockParams = templateSpec.useBlockParams ? [] : undefined;
|
|
|
- if (templateSpec.useDepths) {
|
|
|
- if (options.depths) {
|
|
|
- depths = context !== options.depths[0] ? [context].concat(options.depths) : options.depths;
|
|
|
- } else {
|
|
|
- depths = [context];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function main(context /*, options*/) {
|
|
|
- return '' + templateSpec.main(container, context, container.helpers, container.partials, data, blockParams, depths);
|
|
|
- }
|
|
|
- main = executeDecorators(templateSpec.main, main, container, options.depths || [], data, blockParams);
|
|
|
- return main(context, options);
|
|
|
- }
|
|
|
- ret.isTop = true;
|
|
|
-
|
|
|
- ret._setup = function (options) {
|
|
|
- if (!options.partial) {
|
|
|
- container.helpers = container.merge(options.helpers, env.helpers);
|
|
|
-
|
|
|
- if (templateSpec.usePartial) {
|
|
|
- container.partials = container.merge(options.partials, env.partials);
|
|
|
- }
|
|
|
- if (templateSpec.usePartial || templateSpec.useDecorators) {
|
|
|
- container.decorators = container.merge(options.decorators, env.decorators);
|
|
|
- }
|
|
|
- } else {
|
|
|
- container.helpers = options.helpers;
|
|
|
- container.partials = options.partials;
|
|
|
- container.decorators = options.decorators;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- ret._child = function (i, data, blockParams, depths) {
|
|
|
- if (templateSpec.useBlockParams && !blockParams) {
|
|
|
- throw new _exception2['default']('must pass block params');
|
|
|
- }
|
|
|
- if (templateSpec.useDepths && !depths) {
|
|
|
- throw new _exception2['default']('must pass parent depths');
|
|
|
- }
|
|
|
-
|
|
|
- return wrapProgram(container, i, templateSpec[i], data, 0, blockParams, depths);
|
|
|
- };
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-function wrapProgram(container, i, fn, data, declaredBlockParams, blockParams, depths) {
|
|
|
- function prog(context) {
|
|
|
- var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
|
|
-
|
|
|
- var currentDepths = depths;
|
|
|
- if (depths && context !== depths[0]) {
|
|
|
- currentDepths = [context].concat(depths);
|
|
|
- }
|
|
|
-
|
|
|
- return fn(container, context, container.helpers, container.partials, options.data || data, blockParams && [options.blockParams].concat(blockParams), currentDepths);
|
|
|
- }
|
|
|
-
|
|
|
- prog = executeDecorators(fn, prog, container, depths, data, blockParams);
|
|
|
-
|
|
|
- prog.program = i;
|
|
|
- prog.depth = depths ? depths.length : 0;
|
|
|
- prog.blockParams = declaredBlockParams || 0;
|
|
|
- return prog;
|
|
|
-}
|
|
|
-
|
|
|
-function resolvePartial(partial, context, options) {
|
|
|
- if (!partial) {
|
|
|
- if (options.name === '@partial-block') {
|
|
|
- partial = options.data['partial-block'];
|
|
|
- } else {
|
|
|
- partial = options.partials[options.name];
|
|
|
- }
|
|
|
- } else if (!partial.call && !options.name) {
|
|
|
- // This is a dynamic partial that returned a string
|
|
|
- options.name = partial;
|
|
|
- partial = options.partials[partial];
|
|
|
- }
|
|
|
- return partial;
|
|
|
-}
|
|
|
-
|
|
|
-function invokePartial(partial, context, options) {
|
|
|
- options.partial = true;
|
|
|
- if (options.ids) {
|
|
|
- options.data.contextPath = options.ids[0] || options.data.contextPath;
|
|
|
- }
|
|
|
-
|
|
|
- var partialBlock = undefined;
|
|
|
- if (options.fn && options.fn !== noop) {
|
|
|
- options.data = _base.createFrame(options.data);
|
|
|
- partialBlock = options.data['partial-block'] = options.fn;
|
|
|
-
|
|
|
- if (partialBlock.partials) {
|
|
|
- options.partials = Utils.extend({}, options.partials, partialBlock.partials);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (partial === undefined && partialBlock) {
|
|
|
- partial = partialBlock;
|
|
|
- }
|
|
|
-
|
|
|
- if (partial === undefined) {
|
|
|
- throw new _exception2['default']('The partial ' + options.name + ' could not be found');
|
|
|
- } else if (partial instanceof Function) {
|
|
|
- return partial(context, options);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function noop() {
|
|
|
- return '';
|
|
|
-}
|
|
|
-
|
|
|
-function initData(context, data) {
|
|
|
- if (!data || !('root' in data)) {
|
|
|
- data = data ? _base.createFrame(data) : {};
|
|
|
- data.root = context;
|
|
|
- }
|
|
|
- return data;
|
|
|
-}
|
|
|
-
|
|
|
-function executeDecorators(fn, prog, container, depths, data, blockParams) {
|
|
|
- if (fn.decorator) {
|
|
|
- var props = {};
|
|
|
- prog = fn.decorator(prog, props, container, depths && depths[0], data, blockParams, depths);
|
|
|
- Utils.extend(prog, props);
|
|
|
- }
|
|
|
- return prog;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-},{"./base":4,"./exception":7,"./utils":20}],19:[function(require,module,exports){
|
|
|
-// Build out our basic SafeString type
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-function SafeString(string) {
|
|
|
- this.string = string;
|
|
|
-}
|
|
|
-
|
|
|
-SafeString.prototype.toString = SafeString.prototype.toHTML = function () {
|
|
|
- return '' + this.string;
|
|
|
-};
|
|
|
-
|
|
|
-exports['default'] = SafeString;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-
|
|
|
-},{}],20:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-exports.__esModule = true;
|
|
|
-exports.extend = extend;
|
|
|
-exports.indexOf = indexOf;
|
|
|
-exports.escapeExpression = escapeExpression;
|
|
|
-exports.isEmpty = isEmpty;
|
|
|
-exports.createFrame = createFrame;
|
|
|
-exports.blockParams = blockParams;
|
|
|
-exports.appendContextPath = appendContextPath;
|
|
|
-var escape = {
|
|
|
- '&': '&',
|
|
|
- '<': '<',
|
|
|
- '>': '>',
|
|
|
- '"': '"',
|
|
|
- "'": ''',
|
|
|
- '`': '`',
|
|
|
- '=': '='
|
|
|
-};
|
|
|
-
|
|
|
-var badChars = /[&<>"'`=]/g,
|
|
|
- possible = /[&<>"'`=]/;
|
|
|
-
|
|
|
-function escapeChar(chr) {
|
|
|
- return escape[chr];
|
|
|
-}
|
|
|
-
|
|
|
-function extend(obj /* , ...source */) {
|
|
|
- for (var i = 1; i < arguments.length; i++) {
|
|
|
- for (var key in arguments[i]) {
|
|
|
- if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
|
|
|
- obj[key] = arguments[i][key];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return obj;
|
|
|
-}
|
|
|
-
|
|
|
-var toString = Object.prototype.toString;
|
|
|
-
|
|
|
-exports.toString = toString;
|
|
|
-// Sourced from lodash
|
|
|
-// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
|
|
|
-/* eslint-disable func-style */
|
|
|
-var isFunction = function isFunction(value) {
|
|
|
- return typeof value === 'function';
|
|
|
-};
|
|
|
-// fallback for older versions of Chrome and Safari
|
|
|
-/* istanbul ignore next */
|
|
|
-if (isFunction(/x/)) {
|
|
|
- exports.isFunction = isFunction = function (value) {
|
|
|
- return typeof value === 'function' && toString.call(value) === '[object Function]';
|
|
|
- };
|
|
|
-}
|
|
|
-exports.isFunction = isFunction;
|
|
|
-
|
|
|
-/* eslint-enable func-style */
|
|
|
-
|
|
|
-/* istanbul ignore next */
|
|
|
-var isArray = Array.isArray || function (value) {
|
|
|
- return value && typeof value === 'object' ? toString.call(value) === '[object Array]' : false;
|
|
|
-};
|
|
|
-
|
|
|
-exports.isArray = isArray;
|
|
|
-// Older IE versions do not directly support indexOf so we must implement our own, sadly.
|
|
|
-
|
|
|
-function indexOf(array, value) {
|
|
|
- for (var i = 0, len = array.length; i < len; i++) {
|
|
|
- if (array[i] === value) {
|
|
|
- return i;
|
|
|
- }
|
|
|
- }
|
|
|
- return -1;
|
|
|
-}
|
|
|
-
|
|
|
-function escapeExpression(string) {
|
|
|
- if (typeof string !== 'string') {
|
|
|
- // don't escape SafeStrings, since they're already safe
|
|
|
- if (string && string.toHTML) {
|
|
|
- return string.toHTML();
|
|
|
- } else if (string == null) {
|
|
|
- return '';
|
|
|
- } else if (!string) {
|
|
|
- return string + '';
|
|
|
- }
|
|
|
-
|
|
|
- // Force a string conversion as this will be done by the append regardless and
|
|
|
- // the regex test will do this transparently behind the scenes, causing issues if
|
|
|
- // an object's to string has escaped characters in it.
|
|
|
- string = '' + string;
|
|
|
- }
|
|
|
-
|
|
|
- if (!possible.test(string)) {
|
|
|
- return string;
|
|
|
- }
|
|
|
- return string.replace(badChars, escapeChar);
|
|
|
-}
|
|
|
-
|
|
|
-function isEmpty(value) {
|
|
|
- if (!value && value !== 0) {
|
|
|
- return true;
|
|
|
- } else if (isArray(value) && value.length === 0) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function createFrame(object) {
|
|
|
- var frame = extend({}, object);
|
|
|
- frame._parent = object;
|
|
|
- return frame;
|
|
|
-}
|
|
|
-
|
|
|
-function blockParams(params, ids) {
|
|
|
- params.path = ids;
|
|
|
- return params;
|
|
|
-}
|
|
|
-
|
|
|
-function appendContextPath(contextPath, id) {
|
|
|
- return (contextPath ? contextPath + '.' : '') + id;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-},{}],21:[function(require,module,exports){
|
|
|
-// Create a simple path alias to allow browserify to resolve
|
|
|
-// the runtime on a supported path.
|
|
|
-module.exports = require('./dist/cjs/handlebars.runtime')['default'];
|
|
|
-
|
|
|
-},{"./dist/cjs/handlebars.runtime":3}],22:[function(require,module,exports){
|
|
|
-module.exports = require("handlebars/runtime")["default"];
|
|
|
-
|
|
|
-},{"handlebars/runtime":21}],23:[function(require,module,exports){
|
|
|
-
|
|
|
-/**
|
|
|
- * Reduce `arr` with `fn`.
|
|
|
- *
|
|
|
- * @param {Array} arr
|
|
|
- * @param {Function} fn
|
|
|
- * @param {Mixed} initial
|
|
|
- *
|
|
|
- * TODO: combatible error handling?
|
|
|
- */
|
|
|
-
|
|
|
-module.exports = function(arr, fn, initial){
|
|
|
- var idx = 0;
|
|
|
- var len = arr.length;
|
|
|
- var curr = arguments.length == 3
|
|
|
- ? initial
|
|
|
- : arr[idx++];
|
|
|
-
|
|
|
- while (idx < len) {
|
|
|
- curr = fn.call(null, curr, arr[idx], ++idx, arr);
|
|
|
- }
|
|
|
-
|
|
|
- return curr;
|
|
|
-};
|
|
|
-},{}],24:[function(require,module,exports){
|
|
|
-/**
|
|
|
- * Module dependencies.
|
|
|
- */
|
|
|
-
|
|
|
-var Emitter = require('emitter');
|
|
|
-var reduce = require('reduce');
|
|
|
-
|
|
|
-/**
|
|
|
- * Root reference for iframes.
|
|
|
- */
|
|
|
-
|
|
|
-var root;
|
|
|
-if (typeof window !== 'undefined') { // Browser window
|
|
|
- root = window;
|
|
|
-} else if (typeof self !== 'undefined') { // Web Worker
|
|
|
- root = self;
|
|
|
-} else { // Other environments
|
|
|
- root = this;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Noop.
|
|
|
- */
|
|
|
-
|
|
|
-function noop(){};
|
|
|
-
|
|
|
-/**
|
|
|
- * Check if `obj` is a host object,
|
|
|
- * we don't want to serialize these :)
|
|
|
- *
|
|
|
- * TODO: future proof, move to compoent land
|
|
|
- *
|
|
|
- * @param {Object} obj
|
|
|
- * @return {Boolean}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function isHost(obj) {
|
|
|
- var str = {}.toString.call(obj);
|
|
|
-
|
|
|
- switch (str) {
|
|
|
- case '[object File]':
|
|
|
- case '[object Blob]':
|
|
|
- case '[object FormData]':
|
|
|
- return true;
|
|
|
- default:
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Determine XHR.
|
|
|
- */
|
|
|
-
|
|
|
-request.getXHR = function () {
|
|
|
- if (root.XMLHttpRequest
|
|
|
- && (!root.location || 'file:' != root.location.protocol
|
|
|
- || !root.ActiveXObject)) {
|
|
|
- return new XMLHttpRequest;
|
|
|
- } else {
|
|
|
- try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {}
|
|
|
- try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {}
|
|
|
- try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {}
|
|
|
- try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {}
|
|
|
- }
|
|
|
- return false;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Removes leading and trailing whitespace, added to support IE.
|
|
|
- *
|
|
|
- * @param {String} s
|
|
|
- * @return {String}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-var trim = ''.trim
|
|
|
- ? function(s) { return s.trim(); }
|
|
|
- : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
|
|
|
-
|
|
|
-/**
|
|
|
- * Check if `obj` is an object.
|
|
|
- *
|
|
|
- * @param {Object} obj
|
|
|
- * @return {Boolean}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function isObject(obj) {
|
|
|
- return obj === Object(obj);
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Serialize the given `obj`.
|
|
|
- *
|
|
|
- * @param {Object} obj
|
|
|
- * @return {String}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function serialize(obj) {
|
|
|
- if (!isObject(obj)) return obj;
|
|
|
- var pairs = [];
|
|
|
- for (var key in obj) {
|
|
|
- if (null != obj[key]) {
|
|
|
- pushEncodedKeyValuePair(pairs, key, obj[key]);
|
|
|
- }
|
|
|
- }
|
|
|
- return pairs.join('&');
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Helps 'serialize' with serializing arrays.
|
|
|
- * Mutates the pairs array.
|
|
|
- *
|
|
|
- * @param {Array} pairs
|
|
|
- * @param {String} key
|
|
|
- * @param {Mixed} val
|
|
|
- */
|
|
|
-
|
|
|
-function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
- if (Array.isArray(val)) {
|
|
|
- return val.forEach(function(v) {
|
|
|
- pushEncodedKeyValuePair(pairs, key, v);
|
|
|
- });
|
|
|
- }
|
|
|
- pairs.push(encodeURIComponent(key)
|
|
|
- + '=' + encodeURIComponent(val));
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Expose serialization method.
|
|
|
- */
|
|
|
-
|
|
|
- request.serializeObject = serialize;
|
|
|
-
|
|
|
- /**
|
|
|
- * Parse the given x-www-form-urlencoded `str`.
|
|
|
- *
|
|
|
- * @param {String} str
|
|
|
- * @return {Object}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function parseString(str) {
|
|
|
- var obj = {};
|
|
|
- var pairs = str.split('&');
|
|
|
- var parts;
|
|
|
- var pair;
|
|
|
-
|
|
|
- for (var i = 0, len = pairs.length; i < len; ++i) {
|
|
|
- pair = pairs[i];
|
|
|
- parts = pair.split('=');
|
|
|
- obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
|
|
|
- }
|
|
|
-
|
|
|
- return obj;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Expose parser.
|
|
|
- */
|
|
|
-
|
|
|
-request.parseString = parseString;
|
|
|
-
|
|
|
-/**
|
|
|
- * Default MIME type map.
|
|
|
- *
|
|
|
- * superagent.types.xml = 'application/xml';
|
|
|
- *
|
|
|
- */
|
|
|
-
|
|
|
-request.types = {
|
|
|
- html: 'text/html',
|
|
|
- json: 'application/json',
|
|
|
- xml: 'application/xml',
|
|
|
- urlencoded: 'application/x-www-form-urlencoded',
|
|
|
- 'form': 'application/x-www-form-urlencoded',
|
|
|
- 'form-data': 'application/x-www-form-urlencoded'
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Default serialization map.
|
|
|
- *
|
|
|
- * superagent.serialize['application/xml'] = function(obj){
|
|
|
- * return 'generated xml here';
|
|
|
- * };
|
|
|
- *
|
|
|
- */
|
|
|
-
|
|
|
- request.serialize = {
|
|
|
- 'application/x-www-form-urlencoded': serialize,
|
|
|
- 'application/json': JSON.stringify
|
|
|
- };
|
|
|
-
|
|
|
- /**
|
|
|
- * Default parsers.
|
|
|
- *
|
|
|
- * superagent.parse['application/xml'] = function(str){
|
|
|
- * return { object parsed from str };
|
|
|
- * };
|
|
|
- *
|
|
|
- */
|
|
|
-
|
|
|
-request.parse = {
|
|
|
- 'application/x-www-form-urlencoded': parseString,
|
|
|
- 'application/json': JSON.parse
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Parse the given header `str` into
|
|
|
- * an object containing the mapped fields.
|
|
|
- *
|
|
|
- * @param {String} str
|
|
|
- * @return {Object}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function parseHeader(str) {
|
|
|
- var lines = str.split(/\r?\n/);
|
|
|
- var fields = {};
|
|
|
- var index;
|
|
|
- var line;
|
|
|
- var field;
|
|
|
- var val;
|
|
|
-
|
|
|
- lines.pop(); // trailing CRLF
|
|
|
-
|
|
|
- for (var i = 0, len = lines.length; i < len; ++i) {
|
|
|
- line = lines[i];
|
|
|
- index = line.indexOf(':');
|
|
|
- field = line.slice(0, index).toLowerCase();
|
|
|
- val = trim(line.slice(index + 1));
|
|
|
- fields[field] = val;
|
|
|
- }
|
|
|
-
|
|
|
- return fields;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Return the mime type for the given `str`.
|
|
|
- *
|
|
|
- * @param {String} str
|
|
|
- * @return {String}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function type(str){
|
|
|
- return str.split(/ *; */).shift();
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Return header field parameters.
|
|
|
- *
|
|
|
- * @param {String} str
|
|
|
- * @return {Object}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function params(str){
|
|
|
- return reduce(str.split(/ *; */), function(obj, str){
|
|
|
- var parts = str.split(/ *= */)
|
|
|
- , key = parts.shift()
|
|
|
- , val = parts.shift();
|
|
|
-
|
|
|
- if (key && val) obj[key] = val;
|
|
|
- return obj;
|
|
|
- }, {});
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Initialize a new `Response` with the given `xhr`.
|
|
|
- *
|
|
|
- * - set flags (.ok, .error, etc)
|
|
|
- * - parse header
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * Aliasing `superagent` as `request` is nice:
|
|
|
- *
|
|
|
- * request = superagent;
|
|
|
- *
|
|
|
- * We can use the promise-like API, or pass callbacks:
|
|
|
- *
|
|
|
- * request.get('/').end(function(res){});
|
|
|
- * request.get('/', function(res){});
|
|
|
- *
|
|
|
- * Sending data can be chained:
|
|
|
- *
|
|
|
- * request
|
|
|
- * .post('/user')
|
|
|
- * .send({ name: 'tj' })
|
|
|
- * .end(function(res){});
|
|
|
- *
|
|
|
- * Or passed to `.send()`:
|
|
|
- *
|
|
|
- * request
|
|
|
- * .post('/user')
|
|
|
- * .send({ name: 'tj' }, function(res){});
|
|
|
- *
|
|
|
- * Or passed to `.post()`:
|
|
|
- *
|
|
|
- * request
|
|
|
- * .post('/user', { name: 'tj' })
|
|
|
- * .end(function(res){});
|
|
|
- *
|
|
|
- * Or further reduced to a single call for simple cases:
|
|
|
- *
|
|
|
- * request
|
|
|
- * .post('/user', { name: 'tj' }, function(res){});
|
|
|
- *
|
|
|
- * @param {XMLHTTPRequest} xhr
|
|
|
- * @param {Object} options
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function Response(req, options) {
|
|
|
- options = options || {};
|
|
|
- this.req = req;
|
|
|
- this.xhr = this.req.xhr;
|
|
|
- // responseText is accessible only if responseType is '' or 'text' and on older browsers
|
|
|
- this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined')
|
|
|
- ? this.xhr.responseText
|
|
|
- : null;
|
|
|
- this.statusText = this.req.xhr.statusText;
|
|
|
- this.setStatusProperties(this.xhr.status);
|
|
|
- this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
|
|
- // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
|
|
|
- // getResponseHeader still works. so we get content-type even if getting
|
|
|
- // other headers fails.
|
|
|
- this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
|
|
- this.setHeaderProperties(this.header);
|
|
|
- this.body = this.req.method != 'HEAD'
|
|
|
- ? this.parseBody(this.text ? this.text : this.xhr.response)
|
|
|
- : null;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Get case-insensitive `field` value.
|
|
|
- *
|
|
|
- * @param {String} field
|
|
|
- * @return {String}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Response.prototype.get = function(field){
|
|
|
- return this.header[field.toLowerCase()];
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Set header related properties:
|
|
|
- *
|
|
|
- * - `.type` the content type without params
|
|
|
- *
|
|
|
- * A response of "Content-Type: text/plain; charset=utf-8"
|
|
|
- * will provide you with a `.type` of "text/plain".
|
|
|
- *
|
|
|
- * @param {Object} header
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-Response.prototype.setHeaderProperties = function(header){
|
|
|
- // content-type
|
|
|
- var ct = this.header['content-type'] || '';
|
|
|
- this.type = type(ct);
|
|
|
-
|
|
|
- // params
|
|
|
- var obj = params(ct);
|
|
|
- for (var key in obj) this[key] = obj[key];
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Parse the given body `str`.
|
|
|
- *
|
|
|
- * Used for auto-parsing of bodies. Parsers
|
|
|
- * are defined on the `superagent.parse` object.
|
|
|
- *
|
|
|
- * @param {String} str
|
|
|
- * @return {Mixed}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-Response.prototype.parseBody = function(str){
|
|
|
- var parse = request.parse[this.type];
|
|
|
- return parse && str && (str.length || str instanceof Object)
|
|
|
- ? parse(str)
|
|
|
- : null;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Set flags such as `.ok` based on `status`.
|
|
|
- *
|
|
|
- * For example a 2xx response will give you a `.ok` of __true__
|
|
|
- * whereas 5xx will be __false__ and `.error` will be __true__. The
|
|
|
- * `.clientError` and `.serverError` are also available to be more
|
|
|
- * specific, and `.statusType` is the class of error ranging from 1..5
|
|
|
- * sometimes useful for mapping respond colors etc.
|
|
|
- *
|
|
|
- * "sugar" properties are also defined for common cases. Currently providing:
|
|
|
- *
|
|
|
- * - .noContent
|
|
|
- * - .badRequest
|
|
|
- * - .unauthorized
|
|
|
- * - .notAcceptable
|
|
|
- * - .notFound
|
|
|
- *
|
|
|
- * @param {Number} status
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-Response.prototype.setStatusProperties = function(status){
|
|
|
- // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
|
|
- if (status === 1223) {
|
|
|
- status = 204;
|
|
|
- }
|
|
|
-
|
|
|
- var type = status / 100 | 0;
|
|
|
-
|
|
|
- // status / class
|
|
|
- this.status = this.statusCode = status;
|
|
|
- this.statusType = type;
|
|
|
-
|
|
|
- // basics
|
|
|
- this.info = 1 == type;
|
|
|
- this.ok = 2 == type;
|
|
|
- this.clientError = 4 == type;
|
|
|
- this.serverError = 5 == type;
|
|
|
- this.error = (4 == type || 5 == type)
|
|
|
- ? this.toError()
|
|
|
- : false;
|
|
|
-
|
|
|
- // sugar
|
|
|
- this.accepted = 202 == status;
|
|
|
- this.noContent = 204 == status;
|
|
|
- this.badRequest = 400 == status;
|
|
|
- this.unauthorized = 401 == status;
|
|
|
- this.notAcceptable = 406 == status;
|
|
|
- this.notFound = 404 == status;
|
|
|
- this.forbidden = 403 == status;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Return an `Error` representative of this response.
|
|
|
- *
|
|
|
- * @return {Error}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Response.prototype.toError = function(){
|
|
|
- var req = this.req;
|
|
|
- var method = req.method;
|
|
|
- var url = req.url;
|
|
|
-
|
|
|
- var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')';
|
|
|
- var err = new Error(msg);
|
|
|
- err.status = this.status;
|
|
|
- err.method = method;
|
|
|
- err.url = url;
|
|
|
-
|
|
|
- return err;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Expose `Response`.
|
|
|
- */
|
|
|
-
|
|
|
-request.Response = Response;
|
|
|
-
|
|
|
-/**
|
|
|
- * Initialize a new `Request` with the given `method` and `url`.
|
|
|
- *
|
|
|
- * @param {String} method
|
|
|
- * @param {String} url
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-function Request(method, url) {
|
|
|
- var self = this;
|
|
|
- Emitter.call(this);
|
|
|
- this._query = this._query || [];
|
|
|
- this.method = method;
|
|
|
- this.url = url;
|
|
|
- this.header = {};
|
|
|
- this._header = {};
|
|
|
- this.on('end', function(){
|
|
|
- var err = null;
|
|
|
- var res = null;
|
|
|
-
|
|
|
- try {
|
|
|
- res = new Response(self);
|
|
|
- } catch(e) {
|
|
|
- err = new Error('Parser is unable to parse the response');
|
|
|
- err.parse = true;
|
|
|
- err.original = e;
|
|
|
- return self.callback(err);
|
|
|
- }
|
|
|
-
|
|
|
- self.emit('response', res);
|
|
|
-
|
|
|
- if (err) {
|
|
|
- return self.callback(err, res);
|
|
|
- }
|
|
|
-
|
|
|
- if (res.status >= 200 && res.status < 300) {
|
|
|
- return self.callback(err, res);
|
|
|
- }
|
|
|
-
|
|
|
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
|
|
- new_err.original = err;
|
|
|
- new_err.response = res;
|
|
|
- new_err.status = res.status;
|
|
|
-
|
|
|
- self.callback(new_err, res);
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Mixin `Emitter`.
|
|
|
- */
|
|
|
-
|
|
|
-Emitter(Request.prototype);
|
|
|
-
|
|
|
-/**
|
|
|
- * Allow for extension
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.use = function(fn) {
|
|
|
- fn(this);
|
|
|
- return this;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Set timeout to `ms`.
|
|
|
- *
|
|
|
- * @param {Number} ms
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.timeout = function(ms){
|
|
|
- this._timeout = ms;
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Clear previous timeout.
|
|
|
- *
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.clearTimeout = function(){
|
|
|
- this._timeout = 0;
|
|
|
- clearTimeout(this._timer);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Abort the request, and clear potential timeout.
|
|
|
- *
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.abort = function(){
|
|
|
- if (this.aborted) return;
|
|
|
- this.aborted = true;
|
|
|
- this.xhr.abort();
|
|
|
- this.clearTimeout();
|
|
|
- this.emit('abort');
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Set header `field` to `val`, or multiple fields with one object.
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * req.get('/')
|
|
|
- * .set('Accept', 'application/json')
|
|
|
- * .set('X-API-Key', 'foobar')
|
|
|
- * .end(callback);
|
|
|
- *
|
|
|
- * req.get('/')
|
|
|
- * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
|
- * .end(callback);
|
|
|
- *
|
|
|
- * @param {String|Object} field
|
|
|
- * @param {String} val
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.set = function(field, val){
|
|
|
- if (isObject(field)) {
|
|
|
- for (var key in field) {
|
|
|
- this.set(key, field[key]);
|
|
|
- }
|
|
|
- return this;
|
|
|
- }
|
|
|
- this._header[field.toLowerCase()] = val;
|
|
|
- this.header[field] = val;
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Remove header `field`.
|
|
|
- *
|
|
|
- * Example:
|
|
|
- *
|
|
|
- * req.get('/')
|
|
|
- * .unset('User-Agent')
|
|
|
- * .end(callback);
|
|
|
- *
|
|
|
- * @param {String} field
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.unset = function(field){
|
|
|
- delete this._header[field.toLowerCase()];
|
|
|
- delete this.header[field];
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Get case-insensitive header `field` value.
|
|
|
- *
|
|
|
- * @param {String} field
|
|
|
- * @return {String}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.getHeader = function(field){
|
|
|
- return this._header[field.toLowerCase()];
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Set Content-Type to `type`, mapping values from `request.types`.
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * superagent.types.xml = 'application/xml';
|
|
|
- *
|
|
|
- * request.post('/')
|
|
|
- * .type('xml')
|
|
|
- * .send(xmlstring)
|
|
|
- * .end(callback);
|
|
|
- *
|
|
|
- * request.post('/')
|
|
|
- * .type('application/xml')
|
|
|
- * .send(xmlstring)
|
|
|
- * .end(callback);
|
|
|
- *
|
|
|
- * @param {String} type
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.type = function(type){
|
|
|
- this.set('Content-Type', request.types[type] || type);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Force given parser
|
|
|
- *
|
|
|
- * Sets the body parser no matter type.
|
|
|
- *
|
|
|
- * @param {Function}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.parse = function(fn){
|
|
|
- this._parser = fn;
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Set Accept to `type`, mapping values from `request.types`.
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * superagent.types.json = 'application/json';
|
|
|
- *
|
|
|
- * request.get('/agent')
|
|
|
- * .accept('json')
|
|
|
- * .end(callback);
|
|
|
- *
|
|
|
- * request.get('/agent')
|
|
|
- * .accept('application/json')
|
|
|
- * .end(callback);
|
|
|
- *
|
|
|
- * @param {String} accept
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.accept = function(type){
|
|
|
- this.set('Accept', request.types[type] || type);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Set Authorization field value with `user` and `pass`.
|
|
|
- *
|
|
|
- * @param {String} user
|
|
|
- * @param {String} pass
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.auth = function(user, pass){
|
|
|
- var str = btoa(user + ':' + pass);
|
|
|
- this.set('Authorization', 'Basic ' + str);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
-* Add query-string `val`.
|
|
|
-*
|
|
|
-* Examples:
|
|
|
-*
|
|
|
-* request.get('/shoes')
|
|
|
-* .query('size=10')
|
|
|
-* .query({ color: 'blue' })
|
|
|
-*
|
|
|
-* @param {Object|String} val
|
|
|
-* @return {Request} for chaining
|
|
|
-* @api public
|
|
|
-*/
|
|
|
-
|
|
|
-Request.prototype.query = function(val){
|
|
|
- if ('string' != typeof val) val = serialize(val);
|
|
|
- if (val) this._query.push(val);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Write the field `name` and `val` for "multipart/form-data"
|
|
|
- * request bodies.
|
|
|
- *
|
|
|
- * ``` js
|
|
|
- * request.post('/upload')
|
|
|
- * .field('foo', 'bar')
|
|
|
- * .end(callback);
|
|
|
- * ```
|
|
|
- *
|
|
|
- * @param {String} name
|
|
|
- * @param {String|Blob|File} val
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.field = function(name, val){
|
|
|
- if (!this._formData) this._formData = new root.FormData();
|
|
|
- this._formData.append(name, val);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Queue the given `file` as an attachment to the specified `field`,
|
|
|
- * with optional `filename`.
|
|
|
- *
|
|
|
- * ``` js
|
|
|
- * request.post('/upload')
|
|
|
- * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
|
- * .end(callback);
|
|
|
- * ```
|
|
|
- *
|
|
|
- * @param {String} field
|
|
|
- * @param {Blob|File} file
|
|
|
- * @param {String} filename
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.attach = function(field, file, filename){
|
|
|
- if (!this._formData) this._formData = new root.FormData();
|
|
|
- this._formData.append(field, file, filename);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Send `data`, defaulting the `.type()` to "json" when
|
|
|
- * an object is given.
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * // querystring
|
|
|
- * request.get('/search')
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // multiple data "writes"
|
|
|
- * request.get('/search')
|
|
|
- * .send({ search: 'query' })
|
|
|
- * .send({ range: '1..5' })
|
|
|
- * .send({ order: 'desc' })
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // manual json
|
|
|
- * request.post('/user')
|
|
|
- * .type('json')
|
|
|
- * .send('{"name":"tj"}')
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // auto json
|
|
|
- * request.post('/user')
|
|
|
- * .send({ name: 'tj' })
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // manual x-www-form-urlencoded
|
|
|
- * request.post('/user')
|
|
|
- * .type('form')
|
|
|
- * .send('name=tj')
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // auto x-www-form-urlencoded
|
|
|
- * request.post('/user')
|
|
|
- * .type('form')
|
|
|
- * .send({ name: 'tj' })
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // defaults to x-www-form-urlencoded
|
|
|
- * request.post('/user')
|
|
|
- * .send('name=tobi')
|
|
|
- * .send('species=ferret')
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * @param {String|Object} data
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.send = function(data){
|
|
|
- var obj = isObject(data);
|
|
|
- var type = this.getHeader('Content-Type');
|
|
|
-
|
|
|
- // merge
|
|
|
- if (obj && isObject(this._data)) {
|
|
|
- for (var key in data) {
|
|
|
- this._data[key] = data[key];
|
|
|
- }
|
|
|
- } else if ('string' == typeof data) {
|
|
|
- if (!type) this.type('form');
|
|
|
- type = this.getHeader('Content-Type');
|
|
|
- if ('application/x-www-form-urlencoded' == type) {
|
|
|
- this._data = this._data
|
|
|
- ? this._data + '&' + data
|
|
|
- : data;
|
|
|
- } else {
|
|
|
- this._data = (this._data || '') + data;
|
|
|
- }
|
|
|
- } else {
|
|
|
- this._data = data;
|
|
|
- }
|
|
|
-
|
|
|
- if (!obj || isHost(data)) return this;
|
|
|
- if (!type) this.type('json');
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Invoke the callback with `err` and `res`
|
|
|
- * and handle arity check.
|
|
|
- *
|
|
|
- * @param {Error} err
|
|
|
- * @param {Response} res
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.callback = function(err, res){
|
|
|
- var fn = this._callback;
|
|
|
- this.clearTimeout();
|
|
|
- fn(err, res);
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Invoke callback with x-domain error.
|
|
|
- *
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.crossDomainError = function(){
|
|
|
- var err = new Error('Origin is not allowed by Access-Control-Allow-Origin');
|
|
|
- err.crossDomain = true;
|
|
|
- this.callback(err);
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Invoke callback with timeout error.
|
|
|
- *
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.timeoutError = function(){
|
|
|
- var timeout = this._timeout;
|
|
|
- var err = new Error('timeout of ' + timeout + 'ms exceeded');
|
|
|
- err.timeout = timeout;
|
|
|
- this.callback(err);
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Enable transmission of cookies with x-domain requests.
|
|
|
- *
|
|
|
- * Note that for this to work the origin must not be
|
|
|
- * using "Access-Control-Allow-Origin" with a wildcard,
|
|
|
- * and also must set "Access-Control-Allow-Credentials"
|
|
|
- * to "true".
|
|
|
- *
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.withCredentials = function(){
|
|
|
- this._withCredentials = true;
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Initiate request, invoking callback `fn(res)`
|
|
|
- * with an instanceof `Response`.
|
|
|
- *
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.end = function(fn){
|
|
|
- var self = this;
|
|
|
- var xhr = this.xhr = request.getXHR();
|
|
|
- var query = this._query.join('&');
|
|
|
- var timeout = this._timeout;
|
|
|
- var data = this._formData || this._data;
|
|
|
-
|
|
|
- // store callback
|
|
|
- this._callback = fn || noop;
|
|
|
-
|
|
|
- // state change
|
|
|
- xhr.onreadystatechange = function(){
|
|
|
- if (4 != xhr.readyState) return;
|
|
|
-
|
|
|
- // In IE9, reads to any property (e.g. status) off of an aborted XHR will
|
|
|
- // result in the error "Could not complete the operation due to error c00c023f"
|
|
|
- var status;
|
|
|
- try { status = xhr.status } catch(e) { status = 0; }
|
|
|
-
|
|
|
- if (0 == status) {
|
|
|
- if (self.timedout) return self.timeoutError();
|
|
|
- if (self.aborted) return;
|
|
|
- return self.crossDomainError();
|
|
|
- }
|
|
|
- self.emit('end');
|
|
|
- };
|
|
|
-
|
|
|
- // progress
|
|
|
- var handleProgress = function(e){
|
|
|
- if (e.total > 0) {
|
|
|
- e.percent = e.loaded / e.total * 100;
|
|
|
- }
|
|
|
- self.emit('progress', e);
|
|
|
- };
|
|
|
- if (this.hasListeners('progress')) {
|
|
|
- xhr.onprogress = handleProgress;
|
|
|
- }
|
|
|
- try {
|
|
|
- if (xhr.upload && this.hasListeners('progress')) {
|
|
|
- xhr.upload.onprogress = handleProgress;
|
|
|
- }
|
|
|
- } catch(e) {
|
|
|
- // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist.
|
|
|
- // Reported here:
|
|
|
- // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context
|
|
|
- }
|
|
|
-
|
|
|
- // timeout
|
|
|
- if (timeout && !this._timer) {
|
|
|
- this._timer = setTimeout(function(){
|
|
|
- self.timedout = true;
|
|
|
- self.abort();
|
|
|
- }, timeout);
|
|
|
- }
|
|
|
-
|
|
|
- // querystring
|
|
|
- if (query) {
|
|
|
- query = request.serializeObject(query);
|
|
|
- this.url += ~this.url.indexOf('?')
|
|
|
- ? '&' + query
|
|
|
- : '?' + query;
|
|
|
- }
|
|
|
-
|
|
|
- // initiate request
|
|
|
- xhr.open(this.method, this.url, true);
|
|
|
-
|
|
|
- // CORS
|
|
|
- if (this._withCredentials) xhr.withCredentials = true;
|
|
|
-
|
|
|
- // body
|
|
|
- if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
|
|
|
- // serialize stuff
|
|
|
- var contentType = this.getHeader('Content-Type');
|
|
|
- var serialize = this._parser || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
|
|
- if (serialize) data = serialize(data);
|
|
|
- }
|
|
|
-
|
|
|
- // set header fields
|
|
|
- for (var field in this.header) {
|
|
|
- if (null == this.header[field]) continue;
|
|
|
- xhr.setRequestHeader(field, this.header[field]);
|
|
|
- }
|
|
|
-
|
|
|
- // send stuff
|
|
|
- this.emit('request', this);
|
|
|
-
|
|
|
- // IE11 xhr.send(undefined) sends 'undefined' string as POST payload (instead of nothing)
|
|
|
- // We need null here if data is undefined
|
|
|
- xhr.send(typeof data !== 'undefined' ? data : null);
|
|
|
- return this;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Faux promise support
|
|
|
- *
|
|
|
- * @param {Function} fulfill
|
|
|
- * @param {Function} reject
|
|
|
- * @return {Request}
|
|
|
- */
|
|
|
-
|
|
|
-Request.prototype.then = function (fulfill, reject) {
|
|
|
- return this.end(function(err, res) {
|
|
|
- err ? reject(err) : fulfill(res);
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Expose `Request`.
|
|
|
- */
|
|
|
-
|
|
|
-request.Request = Request;
|
|
|
-
|
|
|
-/**
|
|
|
- * Issue a request:
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * request('GET', '/users').end(callback)
|
|
|
- * request('/users').end(callback)
|
|
|
- * request('/users', callback)
|
|
|
- *
|
|
|
- * @param {String} method
|
|
|
- * @param {String|Function} url or callback
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-function request(method, url) {
|
|
|
- // callback
|
|
|
- if ('function' == typeof url) {
|
|
|
- return new Request('GET', method).end(url);
|
|
|
- }
|
|
|
-
|
|
|
- // url first
|
|
|
- if (1 == arguments.length) {
|
|
|
- return new Request('GET', method);
|
|
|
- }
|
|
|
-
|
|
|
- return new Request(method, url);
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * GET `url` with optional callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed|Function} data or fn
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-request.get = function(url, data, fn){
|
|
|
- var req = request('GET', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.query(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * HEAD `url` with optional callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed|Function} data or fn
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-request.head = function(url, data, fn){
|
|
|
- var req = request('HEAD', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.send(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * DELETE `url` with optional callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-function del(url, fn){
|
|
|
- var req = request('DELETE', url);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
-
|
|
|
-request.del = del;
|
|
|
-request.delete = del;
|
|
|
-
|
|
|
-/**
|
|
|
- * PATCH `url` with optional `data` and callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed} data
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-request.patch = function(url, data, fn){
|
|
|
- var req = request('PATCH', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.send(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * POST `url` with optional `data` and callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed} data
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-request.post = function(url, data, fn){
|
|
|
- var req = request('POST', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.send(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * PUT `url` with optional `data` and callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed|Function} data or fn
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
-
|
|
|
-request.put = function(url, data, fn){
|
|
|
- var req = request('PUT', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.send(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * Expose `request`.
|
|
|
- */
|
|
|
-
|
|
|
-module.exports = request;
|
|
|
-
|
|
|
-},{"emitter":2,"reduce":23}],25:[function(require,module,exports){
|
|
|
-(function (global){
|
|
|
-(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.tus = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
|
|
|
-"use strict";
|
|
|
-
|
|
|
-Object.defineProperty(exports, "__esModule", {
|
|
|
- value: true
|
|
|
-});
|
|
|
-exports.default = fingerprint;
|
|
|
-/**
|
|
|
- * Generate a fingerprint for a file which will be used the store the endpoint
|
|
|
- *
|
|
|
- * @param {File} file
|
|
|
- * @return {String}
|
|
|
- */
|
|
|
-function fingerprint(file) {
|
|
|
- return ["tus", file.name, file.type, file.size, file.lastModified].join("-");
|
|
|
-}
|
|
|
-
|
|
|
-},{}],2:[function(_dereq_,module,exports){
|
|
|
-"use strict";
|
|
|
-
|
|
|
-var _upload = _dereq_("./upload");
|
|
|
-
|
|
|
-var _upload2 = _interopRequireDefault(_upload);
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
-
|
|
|
-var defaultOptions = _upload2.default.defaultOptions; /* global window */
|
|
|
-
|
|
|
-var _window = window;
|
|
|
-var XMLHttpRequest = _window.XMLHttpRequest;
|
|
|
-var localStorage = _window.localStorage;
|
|
|
-var Blob = _window.Blob;
|
|
|
-
|
|
|
-var isSupported = XMLHttpRequest && localStorage && Blob && typeof Blob.prototype.slice === "function";
|
|
|
-
|
|
|
-module.exports = {
|
|
|
- Upload: _upload2.default,
|
|
|
- isSupported: isSupported,
|
|
|
- defaultOptions: defaultOptions
|
|
|
-};
|
|
|
-
|
|
|
-},{"./upload":3}],3:[function(_dereq_,module,exports){
|
|
|
-"use strict";
|
|
|
-
|
|
|
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); /* global window, XMLHttpRequest */
|
|
|
-
|
|
|
-Object.defineProperty(exports, "__esModule", {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _fingerprint = _dereq_("./fingerprint");
|
|
|
-
|
|
|
-var _fingerprint2 = _interopRequireDefault(_fingerprint);
|
|
|
-
|
|
|
-var _extend = _dereq_("extend");
|
|
|
-
|
|
|
-var _extend2 = _interopRequireDefault(_extend);
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
-
|
|
|
-var _window = window;
|
|
|
-var localStorage = _window.localStorage;
|
|
|
-var btoa = _window.btoa;
|
|
|
-
|
|
|
-var defaultOptions = {
|
|
|
- endpoint: "",
|
|
|
- fingerprint: _fingerprint2.default,
|
|
|
- resume: true,
|
|
|
- onProgress: null,
|
|
|
- onChunkComplete: null,
|
|
|
- onSuccess: null,
|
|
|
- onError: null,
|
|
|
- headers: {},
|
|
|
- chunkSize: Infinity,
|
|
|
- withCredentials: false
|
|
|
-};
|
|
|
-
|
|
|
-var Upload = (function () {
|
|
|
- function Upload(file, options) {
|
|
|
- _classCallCheck(this, Upload);
|
|
|
-
|
|
|
- this.options = (0, _extend2.default)(true, {}, defaultOptions, options);
|
|
|
-
|
|
|
- // The underlying File/Blob object
|
|
|
- this.file = file;
|
|
|
-
|
|
|
- // The URL against which the file will be uploaded
|
|
|
- this.url = null;
|
|
|
-
|
|
|
- // The underlying XHR object for the current PATCH request
|
|
|
- this._xhr = null;
|
|
|
-
|
|
|
- // The fingerpinrt for the current file (set after start())
|
|
|
- this._fingerprint = null;
|
|
|
-
|
|
|
- // The offset used in the current PATCH request
|
|
|
- this._offset = null;
|
|
|
-
|
|
|
- // True if the current PATCH request has been aborted
|
|
|
- this._aborted = false;
|
|
|
- }
|
|
|
-
|
|
|
- _createClass(Upload, [{
|
|
|
- key: "start",
|
|
|
- value: function start() {
|
|
|
- var file = this.file;
|
|
|
-
|
|
|
- if (!file) {
|
|
|
- this._emitError(new Error("tus: no file to upload provided"));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!this.options.endpoint) {
|
|
|
- this._emitError(new Error("tus: no endpoint provided"));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // A URL has manually been specified, so we try to resume
|
|
|
- if (this.url !== null) {
|
|
|
- this._resumeUpload();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Try to find the endpoint for the file in the localStorage
|
|
|
- if (this.options.resume) {
|
|
|
- this._fingerprint = this.options.fingerprint(file);
|
|
|
- var resumedUrl = localStorage.getItem(this._fingerprint);
|
|
|
-
|
|
|
- if (resumedUrl != null) {
|
|
|
- this.url = resumedUrl;
|
|
|
- this._resumeUpload();
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // An upload has not started for the file yet, so we start a new one
|
|
|
- this._createUpload();
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: "abort",
|
|
|
- value: function abort() {
|
|
|
- if (this._xhr !== null) {
|
|
|
- this._xhr.abort();
|
|
|
- this._aborted = true;
|
|
|
- }
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: "_emitXhrError",
|
|
|
- value: function _emitXhrError(xhr, err) {
|
|
|
- err.originalRequest = xhr;
|
|
|
- this._emitError(err);
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: "_emitError",
|
|
|
- value: function _emitError(err) {
|
|
|
- if (typeof this.options.onError === "function") {
|
|
|
- this.options.onError(err);
|
|
|
- } else {
|
|
|
- throw err;
|
|
|
- }
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: "_emitSuccess",
|
|
|
- value: function _emitSuccess() {
|
|
|
- if (typeof this.options.onSuccess === "function") {
|
|
|
- this.options.onSuccess();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Publishes notification when data has been sent to the server. This
|
|
|
- * data may not have been accepted by the server yet.
|
|
|
- * @param {number} bytesSent Number of bytes sent to the server.
|
|
|
- * @param {number} bytesTotal Total number of bytes to be sent to the server.
|
|
|
- */
|
|
|
-
|
|
|
- }, {
|
|
|
- key: "_emitProgress",
|
|
|
- value: function _emitProgress(bytesSent, bytesTotal) {
|
|
|
- if (typeof this.options.onProgress === "function") {
|
|
|
- this.options.onProgress(bytesSent, bytesTotal);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Publishes notification when a chunk of data has been sent to the server
|
|
|
- * and accepted by the server.
|
|
|
- * @param {number} chunkSize Size of the chunk that was accepted by the
|
|
|
- * server.
|
|
|
- * @param {number} bytesAccepted Total number of bytes that have been
|
|
|
- * accepted by the server.
|
|
|
- * @param {number} bytesTotal Total number of bytes to be sent to the server.
|
|
|
- */
|
|
|
-
|
|
|
- }, {
|
|
|
- key: "_emitChunkComplete",
|
|
|
- value: function _emitChunkComplete(chunkSize, bytesAccepted, bytesTotal) {
|
|
|
- if (typeof this.options.onChunkComplete === "function") {
|
|
|
- this.options.onChunkComplete(chunkSize, bytesAccepted, bytesTotal);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Set the headers used in the request and the withCredentials property
|
|
|
- * as defined in the options
|
|
|
- *
|
|
|
- * @param {XMLHttpRequest} xhr
|
|
|
- */
|
|
|
-
|
|
|
- }, {
|
|
|
- key: "_setupXHR",
|
|
|
- value: function _setupXHR(xhr) {
|
|
|
- xhr.setRequestHeader("Tus-Resumable", "1.0.0");
|
|
|
- var headers = this.options.headers;
|
|
|
-
|
|
|
- for (var name in headers) {
|
|
|
- xhr.setRequestHeader(name, headers[name]);
|
|
|
- }
|
|
|
-
|
|
|
- xhr.withCredentials = this.options.withCredentials;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Create a new upload using the creation extension by sending a POST
|
|
|
- * request to the endpoint. After successful creation the file will be
|
|
|
- * uploaded
|
|
|
- *
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
- }, {
|
|
|
- key: "_createUpload",
|
|
|
- value: function _createUpload() {
|
|
|
- var _this = this;
|
|
|
-
|
|
|
- var xhr = new XMLHttpRequest();
|
|
|
- xhr.open("POST", this.options.endpoint, true);
|
|
|
-
|
|
|
- xhr.onload = function () {
|
|
|
- if (!(xhr.status >= 200 && xhr.status < 300)) {
|
|
|
- _this._emitXhrError(xhr, new Error("tus: unexpected response while creating upload"));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- _this.url = xhr.getResponseHeader("Location");
|
|
|
-
|
|
|
- if (_this.options.resume) {
|
|
|
- localStorage.setItem(_this._fingerprint, _this.url);
|
|
|
- }
|
|
|
-
|
|
|
- _this._offset = 0;
|
|
|
- _this._startUpload();
|
|
|
- };
|
|
|
-
|
|
|
- xhr.onerror = function () {
|
|
|
- _this._emitXhrError(xhr, new Error("tus: failed to create upload"));
|
|
|
- };
|
|
|
-
|
|
|
- this._setupXHR(xhr);
|
|
|
- xhr.setRequestHeader("Upload-Length", this.file.size);
|
|
|
-
|
|
|
- // Add metadata if values have been added
|
|
|
- var metadata = encodeMetadata(this.options.metadata);
|
|
|
- if (metadata !== "") {
|
|
|
- xhr.setRequestHeader("Upload-Metadata", metadata);
|
|
|
- }
|
|
|
-
|
|
|
- xhr.send(null);
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * Try to resume an existing upload. First a HEAD request will be sent
|
|
|
- * to retrieve the offset. If the request fails a new upload will be
|
|
|
- * created. In the case of a successful response the file will be uploaded.
|
|
|
- *
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
- }, {
|
|
|
- key: "_resumeUpload",
|
|
|
- value: function _resumeUpload() {
|
|
|
- var _this2 = this;
|
|
|
-
|
|
|
- var xhr = new XMLHttpRequest();
|
|
|
- xhr.open("HEAD", this.url, true);
|
|
|
-
|
|
|
- xhr.onload = function () {
|
|
|
- if (!(xhr.status >= 200 && xhr.status < 300)) {
|
|
|
- if (_this2.options.resume) {
|
|
|
- // Remove stored fingerprint and corresponding endpoint,
|
|
|
- // since the file can not be found
|
|
|
- localStorage.removeItem(_this2._fingerprint);
|
|
|
- }
|
|
|
-
|
|
|
- // Try to create a new upload
|
|
|
- _this2.url = null;
|
|
|
- _this2._createUpload();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var offset = parseInt(xhr.getResponseHeader("Upload-Offset"), 10);
|
|
|
- if (isNaN(offset)) {
|
|
|
- _this2._emitXhrError(xhr, new Error("tus: invalid or missing offset value"));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- _this2._offset = offset;
|
|
|
- _this2._startUpload();
|
|
|
- };
|
|
|
-
|
|
|
- xhr.onerror = function () {
|
|
|
- _this2._emitXhrError(xhr, new Error("tus: failed to resume upload"));
|
|
|
- };
|
|
|
-
|
|
|
- this._setupXHR(xhr);
|
|
|
- xhr.send(null);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Start uploading the file using PATCH requests. The file while be divided
|
|
|
- * into chunks as specified in the chunkSize option. During the upload
|
|
|
- * the onProgress event handler may be invoked multiple times.
|
|
|
- *
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
- }, {
|
|
|
- key: "_startUpload",
|
|
|
- value: function _startUpload() {
|
|
|
- var _this3 = this;
|
|
|
-
|
|
|
- var xhr = this._xhr = new XMLHttpRequest();
|
|
|
- xhr.open("PATCH", this.url, true);
|
|
|
-
|
|
|
- xhr.onload = function () {
|
|
|
- if (!(xhr.status >= 200 && xhr.status < 300)) {
|
|
|
- _this3._emitXhrError(xhr, new Error("tus: unexpected response while creating upload"));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- var offset = parseInt(xhr.getResponseHeader("Upload-Offset"), 10);
|
|
|
- if (isNaN(offset)) {
|
|
|
- _this3._emitXhrError(xhr, new Error("tus: invalid or missing offset value"));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- _this3._emitChunkComplete(offset - _this3._offset, offset, _this3.file.size);
|
|
|
-
|
|
|
- _this3._offset = offset;
|
|
|
-
|
|
|
- if (offset == _this3.file.size) {
|
|
|
- // Yay, finally done :)
|
|
|
- // Emit a last progress event
|
|
|
- _this3._emitProgress(offset, offset);
|
|
|
- _this3._emitSuccess();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- _this3._startUpload();
|
|
|
- };
|
|
|
-
|
|
|
- xhr.onerror = function () {
|
|
|
- // Don't emit an error if the upload was aborted manually
|
|
|
- if (_this3._aborted) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- _this3._emitXhrError(xhr, new Error("tus: failed to upload chunk at offset " + _this3._offset));
|
|
|
- };
|
|
|
-
|
|
|
- // Test support for progress events before attaching an event listener
|
|
|
- if ("upload" in xhr) {
|
|
|
- xhr.upload.onprogress = function (e) {
|
|
|
- if (!e.lengthComputable) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- _this3._emitProgress(start + e.loaded, _this3.file.size);
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- this._setupXHR(xhr);
|
|
|
-
|
|
|
- xhr.setRequestHeader("Upload-Offset", this._offset);
|
|
|
- xhr.setRequestHeader("Content-Type", "application/offset+octet-stream");
|
|
|
-
|
|
|
- var start = this._offset;
|
|
|
- var end = this._offset + this.options.chunkSize;
|
|
|
-
|
|
|
- if (end === Infinity) {
|
|
|
- end = this.file.size;
|
|
|
- }
|
|
|
-
|
|
|
- xhr.send(this.file.slice(start, end));
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return Upload;
|
|
|
-})();
|
|
|
-
|
|
|
-function encodeMetadata(metadata) {
|
|
|
- if (!("btoa" in window)) {
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
- var encoded = [];
|
|
|
-
|
|
|
- for (var key in metadata) {
|
|
|
- encoded.push(key + " " + btoa(unescape(encodeURIComponent(metadata[key]))));
|
|
|
- }
|
|
|
-
|
|
|
- return encoded.join(",");
|
|
|
-}
|
|
|
-
|
|
|
-Upload.defaultOptions = defaultOptions;
|
|
|
-
|
|
|
-exports.default = Upload;
|
|
|
-
|
|
|
-},{"./fingerprint":1,"extend":4}],4:[function(_dereq_,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-var hasOwn = Object.prototype.hasOwnProperty;
|
|
|
-var toStr = Object.prototype.toString;
|
|
|
-
|
|
|
-var isArray = function isArray(arr) {
|
|
|
- if (typeof Array.isArray === 'function') {
|
|
|
- return Array.isArray(arr);
|
|
|
- }
|
|
|
-
|
|
|
- return toStr.call(arr) === '[object Array]';
|
|
|
-};
|
|
|
-
|
|
|
-var isPlainObject = function isPlainObject(obj) {
|
|
|
- if (!obj || toStr.call(obj) !== '[object Object]') {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- var hasOwnConstructor = hasOwn.call(obj, 'constructor');
|
|
|
- var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
|
|
|
- // Not own constructor property must be Object
|
|
|
- if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Own properties are enumerated firstly, so to speed up,
|
|
|
- // if last one is own, then all properties are own.
|
|
|
- var key;
|
|
|
- for (key in obj) {/**/}
|
|
|
-
|
|
|
- return typeof key === 'undefined' || hasOwn.call(obj, key);
|
|
|
-};
|
|
|
-
|
|
|
-module.exports = function extend() {
|
|
|
- var options, name, src, copy, copyIsArray, clone,
|
|
|
- target = arguments[0],
|
|
|
- i = 1,
|
|
|
- length = arguments.length,
|
|
|
- deep = false;
|
|
|
-
|
|
|
- // Handle a deep copy situation
|
|
|
- if (typeof target === 'boolean') {
|
|
|
- deep = target;
|
|
|
- target = arguments[1] || {};
|
|
|
- // skip the boolean and the target
|
|
|
- i = 2;
|
|
|
- } else if ((typeof target !== 'object' && typeof target !== 'function') || target == null) {
|
|
|
- target = {};
|
|
|
- }
|
|
|
-
|
|
|
- for (; i < length; ++i) {
|
|
|
- options = arguments[i];
|
|
|
- // Only deal with non-null/undefined values
|
|
|
- if (options != null) {
|
|
|
- // Extend the base object
|
|
|
- for (name in options) {
|
|
|
- src = target[name];
|
|
|
- copy = options[name];
|
|
|
-
|
|
|
- // Prevent never-ending loop
|
|
|
- if (target !== copy) {
|
|
|
- // Recurse if we're merging plain objects or arrays
|
|
|
- if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
|
|
|
- if (copyIsArray) {
|
|
|
- copyIsArray = false;
|
|
|
- clone = src && isArray(src) ? src : [];
|
|
|
- } else {
|
|
|
- clone = src && isPlainObject(src) ? src : {};
|
|
|
- }
|
|
|
-
|
|
|
- // Never move original objects, clone them
|
|
|
- target[name] = extend(deep, clone, copy);
|
|
|
-
|
|
|
- // Don't bring in undefined values
|
|
|
- } else if (typeof copy !== 'undefined') {
|
|
|
- target[name] = copy;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Return the modified object
|
|
|
- return target;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-},{}]},{},[2])(2)
|
|
|
-});
|
|
|
-}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
|
-},{}],26:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
-
|
|
|
-var _coreUtils = require('../core/Utils');
|
|
|
-
|
|
|
-var _coreUtils2 = _interopRequireDefault(_coreUtils);
|
|
|
-
|
|
|
-var _fs = require('fs');
|
|
|
-
|
|
|
-var _fs2 = _interopRequireDefault(_fs);
|
|
|
-
|
|
|
-var _coreTranslator = require('../core/Translator');
|
|
|
-
|
|
|
-var _coreTranslator2 = _interopRequireDefault(_coreTranslator);
|
|
|
-
|
|
|
-/**
|
|
|
-* Main Uppy core
|
|
|
-*
|
|
|
-* @param {object} opts general options, like locale, to show modal or not to show
|
|
|
-*/
|
|
|
-
|
|
|
-var Core = (function () {
|
|
|
- function Core(opts) {
|
|
|
- _classCallCheck(this, Core);
|
|
|
-
|
|
|
- // set default options
|
|
|
- var defaultOptions = {
|
|
|
- // load English as the default locale
|
|
|
- locale: require('../locale/en_US.js')
|
|
|
- };
|
|
|
-
|
|
|
- // Merge default options with the ones set by user
|
|
|
- this.opts = Object.assign({}, defaultOptions, opts);
|
|
|
-
|
|
|
- // Dictates in what order different plugin types are ran:
|
|
|
- this.types = ['presetter', 'selecter', 'uploader'];
|
|
|
-
|
|
|
- this.type = 'core';
|
|
|
-
|
|
|
- // Container for different types of plugins
|
|
|
- this.plugins = {};
|
|
|
-
|
|
|
- this.translator = new _coreTranslator2['default']({ locale: this.opts.locale });
|
|
|
- console.log(this.translator.t('filesChosen', { smart_count: 3 }));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Registers a plugin with Core
|
|
|
- *
|
|
|
- * @param {Class} Plugin object
|
|
|
- * @param {object} options object that will be passed to Plugin later
|
|
|
- * @return {object} self for chaining
|
|
|
- */
|
|
|
-
|
|
|
- _createClass(Core, [{
|
|
|
- key: 'use',
|
|
|
- value: function use(Plugin, opts) {
|
|
|
- // Instantiate
|
|
|
- var plugin = new Plugin(this, opts);
|
|
|
- this.plugins[plugin.type] = this.plugins[plugin.type] || [];
|
|
|
- this.plugins[plugin.type].push(plugin);
|
|
|
-
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets plugin’s progress, like for uploads
|
|
|
- *
|
|
|
- * @param {object} plugin that wants to set progress
|
|
|
- * @param {integer} percentage
|
|
|
- * @return {object} self for chaining
|
|
|
- */
|
|
|
- }, {
|
|
|
- key: 'setProgress',
|
|
|
- value: function setProgress(plugin, percentage) {
|
|
|
- // Any plugin can call this via `this.core.setProgress(this, precentage)`
|
|
|
- console.log(plugin.type + ' plugin ' + plugin.name + ' set the progress to ' + percentage);
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Runs all plugins of the same type in parallel
|
|
|
- *
|
|
|
- * @param {string} type that wants to set progress
|
|
|
- * @param {array} files
|
|
|
- * @return {Promise} of all methods
|
|
|
- */
|
|
|
- }, {
|
|
|
- key: 'runType',
|
|
|
- value: function runType(type, files) {
|
|
|
- var methods = this.plugins[type].map(function (plugin) {
|
|
|
- return plugin.run(files);
|
|
|
- });
|
|
|
-
|
|
|
- return Promise.all(methods);
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'compileTemplate',
|
|
|
- value: function compileTemplate(templatePath, options) {
|
|
|
- var template = _fs2['default'].readFileSync('../templates/' + templatePath, 'utf-8');
|
|
|
- return ejs.render(template, options);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Runs a waterfall of runType plugin packs, like so:
|
|
|
- * All preseters(data) --> All selecters(data) --> All uploaders(data) --> done
|
|
|
- */
|
|
|
- }, {
|
|
|
- key: 'run',
|
|
|
- value: function run() {
|
|
|
- var _this = this;
|
|
|
-
|
|
|
- console.log({
|
|
|
- 'class': 'Core',
|
|
|
- method: 'run'
|
|
|
- });
|
|
|
-
|
|
|
- // First we select only plugins of current type,
|
|
|
- // then create an array of runType methods of this plugins
|
|
|
- var typeMethods = this.types.filter(function (type) {
|
|
|
- return _this.plugins[type];
|
|
|
- }).map(function (type) {
|
|
|
- return _this.runType.bind(_this, type);
|
|
|
- });
|
|
|
-
|
|
|
- _coreUtils2['default'].promiseWaterfall(typeMethods).then(function (result) {
|
|
|
- return console.log(result);
|
|
|
- })['catch'](function (error) {
|
|
|
- return console.error(error);
|
|
|
- });
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return Core;
|
|
|
-})();
|
|
|
-
|
|
|
-exports['default'] = Core;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"../core/Translator":27,"../core/Utils":28,"../locale/en_US.js":31,"fs":1}],27:[function(require,module,exports){
|
|
|
-/**
|
|
|
-* Translates strings with interpolation & pluralization support.Extensible with custom dictionaries
|
|
|
-* and pluralization functions.
|
|
|
-*
|
|
|
-* Borrows heavily from and inspired by Polyglot https://github.com/airbnb/polyglot.js,
|
|
|
-* basically a stripped-down version of it. Differences: pluralization functions are not hardcoded
|
|
|
-* and can be easily added among with dictionaries, nested objects are used for pluralization
|
|
|
-* as opposed to `||||` delimeter
|
|
|
-*
|
|
|
-* Usage example: `translator.t('files_chosen', {smart_count: 3})`
|
|
|
-*
|
|
|
-* @param {object} opts
|
|
|
-*/
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
-
|
|
|
-var Translator = (function () {
|
|
|
- function Translator(opts) {
|
|
|
- _classCallCheck(this, Translator);
|
|
|
-
|
|
|
- var defaultOptions = {};
|
|
|
- this.opts = Object.assign({}, defaultOptions, opts);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Takes a string with placeholder variables like `%{smart_count} file selected`
|
|
|
- * and replaces it with values from options `{smart_count: 5}`
|
|
|
- *
|
|
|
- * @license https://github.com/airbnb/polyglot.js/blob/master/LICENSE
|
|
|
- * taken from https://github.com/airbnb/polyglot.js/blob/master/lib/polyglot.js#L299
|
|
|
- *
|
|
|
- * @param {string} phrase that needs interpolation, with placeholders
|
|
|
- * @param {object} options with values that will be used to replace placeholders
|
|
|
- * @return {string} interpolated
|
|
|
- */
|
|
|
-
|
|
|
- _createClass(Translator, [{
|
|
|
- key: 'interpolate',
|
|
|
- value: function interpolate(phrase, options) {
|
|
|
- var replace = String.prototype.replace;
|
|
|
- var dollarRegex = /\$/g;
|
|
|
- var dollarBillsYall = '$$$$';
|
|
|
-
|
|
|
- for (var arg in options) {
|
|
|
- if (arg !== '_' && options.hasOwnProperty(arg)) {
|
|
|
- // Ensure replacement value is escaped to prevent special $-prefixed
|
|
|
- // regex replace tokens. the "$$$$" is needed because each "$" needs to
|
|
|
- // be escaped with "$" itself, and we need two in the resulting output.
|
|
|
- var replacement = options[arg];
|
|
|
- if (typeof replacement === 'string') {
|
|
|
- replacement = replace.call(options[arg], dollarRegex, dollarBillsYall);
|
|
|
- }
|
|
|
- // We create a new `RegExp` each time instead of using a more-efficient
|
|
|
- // string replace so that the same argument can be replaced multiple times
|
|
|
- // in the same phrase.
|
|
|
- phrase = replace.call(phrase, new RegExp('%\\{' + arg + '\\}', 'g'), replacement);
|
|
|
- }
|
|
|
- }
|
|
|
- return phrase;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Public translate method
|
|
|
- *
|
|
|
- * @param {string} key
|
|
|
- * @param {object} options with values that will be used later to replace placeholders in string
|
|
|
- * @return {string} translated (and interpolated)
|
|
|
- */
|
|
|
- }, {
|
|
|
- key: 't',
|
|
|
- value: function t(key, options) {
|
|
|
- if (options && options.smart_count) {
|
|
|
- var plural = this.opts.locale.pluralize(options.smart_count);
|
|
|
- return this.interpolate(this.opts.locale.strings[key][plural], options);
|
|
|
- }
|
|
|
-
|
|
|
- return this.interpolate(this.opts.locale.strings[key], options);
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return Translator;
|
|
|
-})();
|
|
|
-
|
|
|
-exports['default'] = Translator;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{}],28:[function(require,module,exports){
|
|
|
-/**
|
|
|
- * A collection of small utility functions that help with dom manipulation, adding listeners,
|
|
|
- * promises and other good things.
|
|
|
- *
|
|
|
- * @module Utils
|
|
|
- */
|
|
|
-
|
|
|
-/**
|
|
|
- * Runs a waterfall of promises: calls each task, passing the result
|
|
|
- * from the previous one as an argument. The first task is run with an empty array.
|
|
|
- *
|
|
|
- * @memberof Utils
|
|
|
- * @param {array} methods of Promises to run waterfall on
|
|
|
- * @return {Promise} of the final task
|
|
|
- */
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
|
|
-
|
|
|
-function promiseWaterfall(methods) {
|
|
|
- var _methods = _toArray(methods);
|
|
|
-
|
|
|
- var resolvedPromise = _methods[0];
|
|
|
-
|
|
|
- var tasks = _methods.slice(1);
|
|
|
-
|
|
|
- var finalTaskPromise = tasks.reduce(function (prevTaskPromise, task) {
|
|
|
- return prevTaskPromise.then(task);
|
|
|
- }, resolvedPromise([])); // initial value
|
|
|
-
|
|
|
- return finalTaskPromise;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Toggles a class on a DOM element
|
|
|
- * This is how we roll $('.element').toggleClass in a non-jQuery world
|
|
|
- *
|
|
|
- * @memberof Utils
|
|
|
- * @param {String} el selector
|
|
|
- * @param {String} className to toggle
|
|
|
- * @return {String}
|
|
|
- */
|
|
|
-function toggleClass(el, className) {
|
|
|
- if (el.classList) {
|
|
|
- el.classList.toggle(className);
|
|
|
- } else {
|
|
|
- var classes = el.className.split(' ');
|
|
|
- var existingIndex = classes.indexOf(className);
|
|
|
-
|
|
|
- if (existingIndex >= 0) {
|
|
|
- classes.splice(existingIndex, 1);
|
|
|
- } else {
|
|
|
- classes.push(className);
|
|
|
- el.className = classes.join(' ');
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Adds a class to a DOM element
|
|
|
- *
|
|
|
- * @memberof Utils
|
|
|
- * @param {String} el selector
|
|
|
- * @param {String} className to add
|
|
|
- * @return {String}
|
|
|
- */
|
|
|
-function addClass(el, className) {
|
|
|
- if (el.classList) {
|
|
|
- el.classList.add(className);
|
|
|
- } else {
|
|
|
- el.className += ' ' + className;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Removes a class to a DOM element
|
|
|
- *
|
|
|
- * @memberof Utils
|
|
|
- * @param {String} el selector
|
|
|
- * @param {String} className to remove
|
|
|
- * @return {String}
|
|
|
- */
|
|
|
-function removeClass(el, className) {
|
|
|
- if (el.classList) {
|
|
|
- el.classList.remove(className);
|
|
|
- } else {
|
|
|
- var patClasses = className.split(' ').join('|');
|
|
|
- var pattern = new RegExp('(^|\\b)' + patClasses + '(\\b|$)', 'gi');
|
|
|
-
|
|
|
- el.className = el.className.replace(pattern, ' ');
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Adds multiple listeners to to a DOM element
|
|
|
- * Equvalent to jQuery’s `$form.on('drag dragstart dragend dragover dragenter dragleave drop')`.
|
|
|
- *
|
|
|
- * @memberof Utils
|
|
|
- * @param {String} el selector
|
|
|
- * @param {String} events to add, like `drag dragstart dragend dragover dragenter dragleave drop`
|
|
|
- * @param {requestCallback} cb
|
|
|
- * @return {String}
|
|
|
- */
|
|
|
-function addListenerMulti(el, events, cb) {
|
|
|
- var eventsArray = events.split(' ');
|
|
|
- for (var _event in eventsArray) {
|
|
|
- el.addEventListener(eventsArray[_event], cb, false);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-exports['default'] = {
|
|
|
- promiseWaterfall: promiseWaterfall,
|
|
|
- toggleClass: toggleClass,
|
|
|
- addClass: addClass,
|
|
|
- removeClass: removeClass,
|
|
|
- addListenerMulti: addListenerMulti
|
|
|
-};
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{}],29:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-var _Core = require('./Core');
|
|
|
-
|
|
|
-var _Core2 = _interopRequireDefault(_Core);
|
|
|
-
|
|
|
-exports['default'] = _Core2['default'];
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"./Core":26}],30:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-var _core = require('./core');
|
|
|
-
|
|
|
-var _core2 = _interopRequireDefault(_core);
|
|
|
-
|
|
|
-var _plugins = require('./plugins');
|
|
|
-
|
|
|
-var _plugins2 = _interopRequireDefault(_plugins);
|
|
|
-
|
|
|
-var locale = {};
|
|
|
-
|
|
|
-exports['default'] = {
|
|
|
- Core: _core2['default'],
|
|
|
- plugins: _plugins2['default'],
|
|
|
- locale: locale
|
|
|
-};
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"./core":29,"./plugins":39}],31:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-var en_US = {};
|
|
|
-
|
|
|
-en_US.strings = {
|
|
|
- chooseFile: 'Choose a file',
|
|
|
- youHaveChosen: 'You have chosen: %{fileName}',
|
|
|
- orDragDrop: 'or drag it here',
|
|
|
- filesChosen: {
|
|
|
- 0: '%{smart_count} file selected',
|
|
|
- 1: '%{smart_count} files selected'
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-en_US.pluralize = function (n) {
|
|
|
- if (n === 1) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
- return 1;
|
|
|
-};
|
|
|
-
|
|
|
-if (typeof window.Uppy !== 'undefined') {
|
|
|
- window.Uppy.locale.en_US = en_US;
|
|
|
-}
|
|
|
-
|
|
|
-exports['default'] = en_US;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{}],32:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
-
|
|
|
-var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
-
|
|
|
-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 _coreUtils = require('../core/Utils');
|
|
|
-
|
|
|
-var _coreUtils2 = _interopRequireDefault(_coreUtils);
|
|
|
-
|
|
|
-var _Plugin2 = require('./Plugin');
|
|
|
-
|
|
|
-var _Plugin3 = _interopRequireDefault(_Plugin2);
|
|
|
-
|
|
|
-var _templatesDragdropHbs = require('../templates/dragdrop.hbs');
|
|
|
-
|
|
|
-var _templatesDragdropHbs2 = _interopRequireDefault(_templatesDragdropHbs);
|
|
|
-
|
|
|
-/**
|
|
|
-* Drag & Drop plugin
|
|
|
-*
|
|
|
-*/
|
|
|
-
|
|
|
-var DragDrop = (function (_Plugin) {
|
|
|
- _inherits(DragDrop, _Plugin);
|
|
|
-
|
|
|
- function DragDrop(core, opts) {
|
|
|
- _classCallCheck(this, DragDrop);
|
|
|
-
|
|
|
- _get(Object.getPrototypeOf(DragDrop.prototype), 'constructor', this).call(this, core, opts);
|
|
|
- this.type = 'selecter';
|
|
|
-
|
|
|
- // set default options
|
|
|
- var defaultOptions = {
|
|
|
- bla: 'blabla',
|
|
|
- autoSubmit: true,
|
|
|
- modal: true
|
|
|
- };
|
|
|
-
|
|
|
- // merge default options with the ones set by user
|
|
|
- this.opts = defaultOptions;
|
|
|
- Object.assign(this.opts, opts);
|
|
|
-
|
|
|
- // get the element where the Drag & Drop event will occur
|
|
|
- this.dropzone = document.querySelectorAll(this.opts.selector)[0];
|
|
|
- this.dropzoneInput = document.querySelectorAll('.UppyDragDrop-input')[0];
|
|
|
-
|
|
|
- this.status = document.querySelectorAll('.UppyDragDrop-status')[0];
|
|
|
-
|
|
|
- this.isDragDropSupported = this.checkDragDropSupport();
|
|
|
-
|
|
|
- // crazy stuff so that ‘this’ will behave in class
|
|
|
- this.listenForEvents = this.listenForEvents.bind(this);
|
|
|
- this.handleDrop = this.handleDrop.bind(this);
|
|
|
- this.checkDragDropSupport = this.checkDragDropSupport.bind(this);
|
|
|
- this.handleInputChange = this.handleInputChange.bind(this);
|
|
|
-
|
|
|
- console.log((0, _templatesDragdropHbs2['default'])({
|
|
|
- chooseFile: 'smth',
|
|
|
- orDragDrop: 'going on here'
|
|
|
- }));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Checks if the browser supports Drag & Drop
|
|
|
- * @return {Boolean} true if supported, false otherwise
|
|
|
- */
|
|
|
-
|
|
|
- _createClass(DragDrop, [{
|
|
|
- key: 'checkDragDropSupport',
|
|
|
- value: function checkDragDropSupport() {
|
|
|
- var div = document.createElement('div');
|
|
|
-
|
|
|
- if (!('draggable' in div) || !('ondragstart' in div && 'ondrop' in div)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!('FormData' in window)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if (!('FileReader' in window)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'listenForEvents',
|
|
|
- value: function listenForEvents() {
|
|
|
- var _this = this;
|
|
|
-
|
|
|
- console.log('waiting for some files to be dropped on ' + this.opts.selector);
|
|
|
-
|
|
|
- if (this.isDragDropSupported) {
|
|
|
- _coreUtils2['default'].addClass(this.dropzone, 'is-dragdrop-supported');
|
|
|
- }
|
|
|
-
|
|
|
- // prevent default actions for all drag & drop events
|
|
|
- var strEvents = 'drag dragstart dragend dragover dragenter dragleave drop';
|
|
|
- _coreUtils2['default'].addListenerMulti(this.dropzone, strEvents, function (e) {
|
|
|
- e.preventDefault();
|
|
|
- e.stopPropagation();
|
|
|
- });
|
|
|
-
|
|
|
- // Toggle is-dragover state when files are dragged over or dropped
|
|
|
- _coreUtils2['default'].addListenerMulti(this.dropzone, 'dragover dragenter', function (e) {
|
|
|
- _coreUtils2['default'].addClass(_this.dropzone, 'is-dragover');
|
|
|
- });
|
|
|
-
|
|
|
- _coreUtils2['default'].addListenerMulti(this.dropzone, 'dragleave dragend drop', function (e) {
|
|
|
- _coreUtils2['default'].removeClass(_this.dropzone, 'is-dragover');
|
|
|
- });
|
|
|
-
|
|
|
- var onDrop = new Promise(function (resolve, reject) {
|
|
|
- _this.dropzone.addEventListener('drop', function (e) {
|
|
|
- resolve(_this.handleDrop.bind(null, e));
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- var onInput = new Promise(function (resolve, reject) {
|
|
|
- _this.dropzoneInput.addEventListener('change', function (e) {
|
|
|
- resolve(_this.handleInputChange.bind(null, e));
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- return Promise.race([onDrop, onInput]).then(function (handler) {
|
|
|
- return handler();
|
|
|
- });
|
|
|
-
|
|
|
- // this.dropzone.addEventListener('drop', this.handleDrop);
|
|
|
- // this.dropzoneInput.addEventListener('change', this.handleInputChange);
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'displayStatus',
|
|
|
- value: function displayStatus(status) {
|
|
|
- this.status.innerHTML = status;
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'handleDrop',
|
|
|
- value: function handleDrop(e) {
|
|
|
- console.log('all right, someone dropped something here...');
|
|
|
- var files = e.dataTransfer.files;
|
|
|
- // files = Array.from(files);
|
|
|
-
|
|
|
- // const formData = new FormData(this.dropzone);
|
|
|
- // console.log('pizza', formData);
|
|
|
-
|
|
|
- // for (var i = 0; i < files.length; i++) {
|
|
|
- // formData.append('file', files[i]);
|
|
|
- // console.log('pizza', files[i]);
|
|
|
- // }
|
|
|
-
|
|
|
- return Promise.resolve({ from: 'DragDrop', files: files });
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'handleInputChange',
|
|
|
- value: function handleInputChange() {
|
|
|
- // const fileInput = document.querySelectorAll('.UppyDragDrop-input')[0];
|
|
|
- var formData = new FormData(this.dropzone);
|
|
|
-
|
|
|
- console.log('@todo: No support for formData yet', formData);
|
|
|
- var files = [];
|
|
|
-
|
|
|
- return Promise.resolve({ from: 'DragDrop', files: files });
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'run',
|
|
|
- value: function run(results) {
|
|
|
- console.log({
|
|
|
- 'class': 'DragDrop',
|
|
|
- method: 'run',
|
|
|
- results: results
|
|
|
- });
|
|
|
-
|
|
|
- return this.listenForEvents();
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return DragDrop;
|
|
|
-})(_Plugin3['default']);
|
|
|
-
|
|
|
-exports['default'] = DragDrop;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"../core/Utils":28,"../templates/dragdrop.hbs":40,"./Plugin":36}],33:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
-
|
|
|
-var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
-
|
|
|
-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 _Plugin2 = require('./Plugin');
|
|
|
-
|
|
|
-var _Plugin3 = _interopRequireDefault(_Plugin2);
|
|
|
-
|
|
|
-var _superagent = require('superagent');
|
|
|
-
|
|
|
-var _superagent2 = _interopRequireDefault(_superagent);
|
|
|
-
|
|
|
-var Dropbox = (function (_Plugin) {
|
|
|
- _inherits(Dropbox, _Plugin);
|
|
|
-
|
|
|
- function Dropbox(core, opts) {
|
|
|
- _classCallCheck(this, Dropbox);
|
|
|
-
|
|
|
- _get(Object.getPrototypeOf(Dropbox.prototype), 'constructor', this).call(this, core, opts);
|
|
|
- this.type = 'selecter';
|
|
|
- this.authenticate = this.authenticate.bind(this);
|
|
|
- this.connect = this.connect.bind(this);
|
|
|
- this.render = this.render.bind(this);
|
|
|
- this.files = [];
|
|
|
- this.currentDir = '/';
|
|
|
- }
|
|
|
-
|
|
|
- _createClass(Dropbox, [{
|
|
|
- key: 'connect',
|
|
|
- value: function connect(target) {
|
|
|
- this._target = document.getElementById(target);
|
|
|
-
|
|
|
- this.client = new Dropbox.Client({ key: 'b7dzc9ei5dv5hcv', token: '' });
|
|
|
- this.client.authDriver(new Dropbox.AuthDriver.Redirect());
|
|
|
- this.authenticate();
|
|
|
-
|
|
|
- if (this.client.credentials().token) {
|
|
|
- this.getDirectory();
|
|
|
- }
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'authenticate',
|
|
|
- value: function authenticate() {
|
|
|
- this.client.authenticate();
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'addFile',
|
|
|
- value: function addFile() {}
|
|
|
- }, {
|
|
|
- key: 'getDirectory',
|
|
|
- value: function getDirectory() {
|
|
|
- var _this = this;
|
|
|
-
|
|
|
- _superagent2['default'].get('https://api18.dropbox.com/1/metadata/auto').query({
|
|
|
- client_id: 'b7dzc9ei5dv5hcv',
|
|
|
- token: this.client.credentials().token
|
|
|
- }).set('Content-Type', 'application/json').end(function (err, res) {
|
|
|
- if (err) {
|
|
|
- console.error(err);
|
|
|
- // return showError(err)
|
|
|
- }
|
|
|
- console.log(res);
|
|
|
- });
|
|
|
-
|
|
|
- return this.client.readdir(this.currentDir, function (error, entries, stat, statFiles) {
|
|
|
- if (error) {
|
|
|
- console.error(error);
|
|
|
- // return showError(error) // Something went wrong.
|
|
|
- }
|
|
|
- return _this.render(statFiles);
|
|
|
- });
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'run',
|
|
|
- value: function run(results) {}
|
|
|
- }, {
|
|
|
- key: 'render',
|
|
|
- value: function render(files) {
|
|
|
- var _this2 = this;
|
|
|
-
|
|
|
- // for each file in the directory, create a list item element
|
|
|
- var elems = files.map(function (file, i) {
|
|
|
- var icon = file.isFolder ? 'folder' : 'file';
|
|
|
- return '<li data-type="' + icon + '" data-name="' + file.name + '">\n <span>' + icon + ' : </span>\n <span> ' + file.name + '</span>\n </li>';
|
|
|
- });
|
|
|
-
|
|
|
- // appends the list items to the target
|
|
|
- this._target.innerHTML = elems.sort().join('');
|
|
|
-
|
|
|
- if (this.currentDir.length > 1) {
|
|
|
- var _parent = document.createElement('LI');
|
|
|
- _parent.setAttribute('data-type', 'parent');
|
|
|
- _parent.innerHTML = '<span>...</span>';
|
|
|
- this._target.appendChild(_parent);
|
|
|
- }
|
|
|
-
|
|
|
- // add an onClick to each list item
|
|
|
- var fileElems = this._target.querySelectorAll('li');
|
|
|
-
|
|
|
- Array.prototype.forEach.call(fileElems, function (element) {
|
|
|
- var type = element.getAttribute('data-type');
|
|
|
-
|
|
|
- if (type === 'file') {
|
|
|
- element.addEventListener('click', function () {
|
|
|
- _this2.files.push(element.getAttribute('data-name'));
|
|
|
- console.log('files: ' + _this2.files);
|
|
|
- });
|
|
|
- } else {
|
|
|
- element.addEventListener('dblclick', function () {
|
|
|
- var length = _this2.currentDir.split('/').length;
|
|
|
-
|
|
|
- if (type === 'folder') {
|
|
|
- _this2.currentDir = '' + _this2.currentDir + element.getAttribute('data-name') + '/';
|
|
|
- } else if (type === 'parent') {
|
|
|
- _this2.currentDir = _this2.currentDir.split('/').slice(0, length - 2).join('/') + '/';
|
|
|
- }
|
|
|
- console.log(_this2.currentDir);
|
|
|
- _this2.getDirectory();
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return Dropbox;
|
|
|
-})(_Plugin3['default']);
|
|
|
-
|
|
|
-exports['default'] = Dropbox;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"./Plugin":36,"superagent":24}],34:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
-
|
|
|
-var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
-
|
|
|
-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 _Plugin2 = require('./Plugin');
|
|
|
-
|
|
|
-var _Plugin3 = _interopRequireDefault(_Plugin2);
|
|
|
-
|
|
|
-var Formtag = (function (_Plugin) {
|
|
|
- _inherits(Formtag, _Plugin);
|
|
|
-
|
|
|
- function Formtag(core, opts) {
|
|
|
- _classCallCheck(this, Formtag);
|
|
|
-
|
|
|
- _get(Object.getPrototypeOf(Formtag.prototype), 'constructor', this).call(this, core, opts);
|
|
|
- this.type = 'selecter';
|
|
|
- }
|
|
|
-
|
|
|
- _createClass(Formtag, [{
|
|
|
- key: 'run',
|
|
|
- value: function run(results) {
|
|
|
- console.log({
|
|
|
- 'class': 'Formtag',
|
|
|
- method: 'run',
|
|
|
- results: results
|
|
|
- });
|
|
|
-
|
|
|
- this.setProgress(0);
|
|
|
-
|
|
|
- var button = document.querySelector(this.opts.doneButtonSelector);
|
|
|
- var self = this;
|
|
|
-
|
|
|
- return new Promise(function (resolve, reject) {
|
|
|
- button.addEventListener('click', function (e) {
|
|
|
- var fields = document.querySelectorAll(self.opts.selector);
|
|
|
- var selected = [];
|
|
|
-
|
|
|
- [].forEach.call(fields, function (field, i) {
|
|
|
- [].forEach.call(field.files, function (file, j) {
|
|
|
- selected.push({
|
|
|
- from: 'Formtag',
|
|
|
- file: file
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- // console.log(fields.length);
|
|
|
- // for (var i in fields) {
|
|
|
- // console.log('i');
|
|
|
- // // console.log('i: ', i);
|
|
|
- // for (var j in fields[i].files) {
|
|
|
- // console.log('j');
|
|
|
- // // console.log('i, j', i, j);
|
|
|
- // console.log(fields[i].files);
|
|
|
- // var file = fields[i].files.item(j);
|
|
|
- // if (file) {
|
|
|
- // selected.push({
|
|
|
- // from: 'Formtag',
|
|
|
- // file: fields[i].files.item(j)
|
|
|
- // });
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- self.setProgress(100);
|
|
|
- console.log({
|
|
|
- selected: selected,
|
|
|
- fields: fields
|
|
|
- });
|
|
|
- resolve(selected);
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return Formtag;
|
|
|
-})(_Plugin3['default']);
|
|
|
-
|
|
|
-exports['default'] = Formtag;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"./Plugin":36}],35:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
-
|
|
|
-var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
-
|
|
|
-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 _Plugin2 = require('./Plugin');
|
|
|
-
|
|
|
-var _Plugin3 = _interopRequireDefault(_Plugin2);
|
|
|
-
|
|
|
-var Multipart = (function (_Plugin) {
|
|
|
- _inherits(Multipart, _Plugin);
|
|
|
-
|
|
|
- function Multipart(core, opts) {
|
|
|
- _classCallCheck(this, Multipart);
|
|
|
-
|
|
|
- _get(Object.getPrototypeOf(Multipart.prototype), 'constructor', this).call(this, core, opts);
|
|
|
- this.type = 'uploader';
|
|
|
- if (!this.opts.fieldName === undefined) {
|
|
|
- this.opts.fieldName = 'files[]';
|
|
|
- }
|
|
|
- if (this.opts.bundle === undefined) {
|
|
|
- this.opts.bundle = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- _createClass(Multipart, [{
|
|
|
- key: 'run',
|
|
|
- value: function run(results) {
|
|
|
- console.log({
|
|
|
- 'class': 'Multipart',
|
|
|
- method: 'run',
|
|
|
- results: results
|
|
|
- });
|
|
|
-
|
|
|
- var files = this.extractFiles(results);
|
|
|
-
|
|
|
- this.setProgress(0);
|
|
|
- var uploaders = [];
|
|
|
-
|
|
|
- if (this.opts.bundle) {
|
|
|
- uploaders.push(this.upload(files, 0, files.length));
|
|
|
- } else {
|
|
|
- for (var i in files) {
|
|
|
- uploaders.push(this.upload(files, i, files.length));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return Promise.all(uploaders);
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'upload',
|
|
|
- value: function upload(files, current, total) {
|
|
|
- var _this = this;
|
|
|
-
|
|
|
- var formPost = new FormData();
|
|
|
-
|
|
|
- // turn file into an array so we can use bundle
|
|
|
- if (!this.opts.bundle) {
|
|
|
- files = [files[current]];
|
|
|
- }
|
|
|
-
|
|
|
- for (var i in files) {
|
|
|
- formPost.append(this.opts.fieldName, files[i]);
|
|
|
- }
|
|
|
-
|
|
|
- var xhr = new XMLHttpRequest();
|
|
|
- xhr.open('POST', this.opts.endpoint, true);
|
|
|
-
|
|
|
- xhr.addEventListener('progress', function (e) {
|
|
|
- var percentage = (e.loaded / e.total * 100).toFixed(2);
|
|
|
- _this.setProgress(percentage, current, total);
|
|
|
- });
|
|
|
-
|
|
|
- xhr.addEventListener('load', function () {
|
|
|
- var upload = {};
|
|
|
- if (_this.opts.bundle) {
|
|
|
- upload = { files: files };
|
|
|
- } else {
|
|
|
- upload = { file: files[current] };
|
|
|
- }
|
|
|
- return Promise.resolve(upload);
|
|
|
- });
|
|
|
-
|
|
|
- xhr.addEventListener('error', function () {
|
|
|
- return Promise.reject('fucking error!');
|
|
|
- });
|
|
|
-
|
|
|
- xhr.send(formPost);
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return Multipart;
|
|
|
-})(_Plugin3['default']);
|
|
|
-
|
|
|
-exports['default'] = Multipart;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"./Plugin":36}],36:[function(require,module,exports){
|
|
|
-/**
|
|
|
-* Boilerplate that all Plugins share - and should not be used
|
|
|
-* directly. It also shows which methods final plugins should implement/override,
|
|
|
-* this deciding on structure.
|
|
|
-*
|
|
|
-* @param {object} main Uppy core object
|
|
|
-* @param {object} object with plugin options
|
|
|
-* @return {array | string} files or success/fail message
|
|
|
-*/
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
-
|
|
|
-var Plugin = (function () {
|
|
|
- function Plugin(core, opts) {
|
|
|
- _classCallCheck(this, Plugin);
|
|
|
-
|
|
|
- this.core = core;
|
|
|
- this.opts = opts;
|
|
|
- this.type = 'none';
|
|
|
- this.name = this.constructor.name;
|
|
|
- }
|
|
|
-
|
|
|
- _createClass(Plugin, [{
|
|
|
- key: 'setProgress',
|
|
|
- value: function setProgress(percentage, current, total) {
|
|
|
- var finalPercentage = percentage;
|
|
|
-
|
|
|
- // if (current !== undefined && total !== undefined) {
|
|
|
- // var percentageOfTotal = (percentage / total);
|
|
|
- // // finalPercentage = percentageOfTotal;
|
|
|
- // if (current > 1) {
|
|
|
- // finalPercentage = percentage + (100 / (total * current));
|
|
|
- // } else {
|
|
|
- // finalPercentage = percentage;
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- this.core.setProgress(this, finalPercentage);
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'extractFiles',
|
|
|
- value: function extractFiles(results) {
|
|
|
- console.log({
|
|
|
- 'class': 'Plugin',
|
|
|
- method: 'extractFiles',
|
|
|
- results: results
|
|
|
- });
|
|
|
-
|
|
|
- var files = [];
|
|
|
- results.forEach(function (result) {
|
|
|
- Array.from(result.files).forEach(function (file) {
|
|
|
- return files.push(file);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- // const files = [];
|
|
|
- // for (let i in results) {
|
|
|
- // // console.log('yo12131');
|
|
|
- // // console.log(results[i].files);
|
|
|
- // for (let j in results[i].files) {
|
|
|
- // console.log(results[i].files.item(j));
|
|
|
- // // files.push(results[i].files.item(j));
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // return Array.from(fileList);
|
|
|
- return files;
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'run',
|
|
|
- value: function run(results) {
|
|
|
- return results;
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return Plugin;
|
|
|
-})();
|
|
|
-
|
|
|
-exports['default'] = Plugin;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{}],37:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
-
|
|
|
-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 _Plugin2 = require('./Plugin');
|
|
|
-
|
|
|
-var _Plugin3 = _interopRequireDefault(_Plugin2);
|
|
|
-
|
|
|
-var _DragDrop = require('./DragDrop');
|
|
|
-
|
|
|
-var _DragDrop2 = _interopRequireDefault(_DragDrop);
|
|
|
-
|
|
|
-var _Tus10 = require('./Tus10');
|
|
|
-
|
|
|
-var _Tus102 = _interopRequireDefault(_Tus10);
|
|
|
-
|
|
|
-var TransloaditBasic = (function (_Plugin) {
|
|
|
- _inherits(TransloaditBasic, _Plugin);
|
|
|
-
|
|
|
- function TransloaditBasic(core, opts) {
|
|
|
- _classCallCheck(this, TransloaditBasic);
|
|
|
-
|
|
|
- _get(Object.getPrototypeOf(TransloaditBasic.prototype), 'constructor', this).call(this, core, opts);
|
|
|
- this.type = 'presetter';
|
|
|
- this.core.use(_DragDrop2['default'], { modal: true, wait: true }).use(_Tus102['default'], { endpoint: 'http://master.tus.io:8080' });
|
|
|
- }
|
|
|
-
|
|
|
- return TransloaditBasic;
|
|
|
-})(_Plugin3['default']);
|
|
|
-
|
|
|
-exports['default'] = TransloaditBasic;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"./DragDrop":32,"./Plugin":36,"./Tus10":38}],38:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
-
|
|
|
-var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
-
|
|
|
-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 _Plugin2 = require('./Plugin');
|
|
|
-
|
|
|
-var _Plugin3 = _interopRequireDefault(_Plugin2);
|
|
|
-
|
|
|
-var _tusJsClient = require('tus-js-client');
|
|
|
-
|
|
|
-var _tusJsClient2 = _interopRequireDefault(_tusJsClient);
|
|
|
-
|
|
|
-/**
|
|
|
-* Tus resumable file uploader
|
|
|
-*
|
|
|
-*/
|
|
|
-
|
|
|
-var Tus10 = (function (_Plugin) {
|
|
|
- _inherits(Tus10, _Plugin);
|
|
|
-
|
|
|
- function Tus10(core, opts) {
|
|
|
- _classCallCheck(this, Tus10);
|
|
|
-
|
|
|
- _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts);
|
|
|
- this.type = 'uploader';
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Add files to an array of `upload()` calles, passing the current and total file count numbers
|
|
|
- *
|
|
|
- * @param {array | object} results
|
|
|
- * @returns {Promise} of parallel uploads `Promise.all(uploaders)`
|
|
|
- */
|
|
|
-
|
|
|
- _createClass(Tus10, [{
|
|
|
- key: 'run',
|
|
|
- value: function run(results) {
|
|
|
- console.log({
|
|
|
- 'class': 'Tus10',
|
|
|
- method: 'run',
|
|
|
- results: results
|
|
|
- });
|
|
|
-
|
|
|
- var files = this.extractFiles(results);
|
|
|
-
|
|
|
- // console.log(files);
|
|
|
-
|
|
|
- this.setProgress(0);
|
|
|
- // var uploaded = [];
|
|
|
- var uploaders = [];
|
|
|
- for (var i in files) {
|
|
|
- var file = files[i];
|
|
|
- var current = parseInt(i, 10) + 1;
|
|
|
- var total = files.length;
|
|
|
- uploaders.push(this.upload(file, current, total));
|
|
|
- }
|
|
|
-
|
|
|
- return Promise.all(uploaders);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Create a new Tus upload
|
|
|
- *
|
|
|
- * @param {object} file for use with upload
|
|
|
- * @param {integer} current file in a queue
|
|
|
- * @param {integer} total number of files in a queue
|
|
|
- * @returns {Promise}
|
|
|
- */
|
|
|
- }, {
|
|
|
- key: 'upload',
|
|
|
- value: function upload(file, current, total) {
|
|
|
- console.log('uploading ' + current + ' of ' + total);
|
|
|
- // Create a new tus upload
|
|
|
- var self = this;
|
|
|
- var upload = new _tusJsClient2['default'].Upload(file, {
|
|
|
- endpoint: this.opts.endpoint,
|
|
|
- onError: function onError(error) {
|
|
|
- return Promise.reject('Failed because: ' + error);
|
|
|
- },
|
|
|
- onProgress: function onProgress(bytesUploaded, bytesTotal) {
|
|
|
- var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
|
|
|
- percentage = Math.round(percentage);
|
|
|
- self.setProgress(percentage, current, total);
|
|
|
- },
|
|
|
- onSuccess: function onSuccess() {
|
|
|
- console.log('Download ' + upload.file.name + ' from ' + upload.url);
|
|
|
- return Promise.resolve(upload);
|
|
|
- }
|
|
|
- });
|
|
|
- // Start the upload
|
|
|
- upload.start();
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return Tus10;
|
|
|
-})(_Plugin3['default']);
|
|
|
-
|
|
|
-exports['default'] = Tus10;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"./Plugin":36,"tus-js-client":25}],39:[function(require,module,exports){
|
|
|
-// Parent
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-var _Plugin = require('./Plugin');
|
|
|
-
|
|
|
-var _Plugin2 = _interopRequireDefault(_Plugin);
|
|
|
-
|
|
|
-// Selecters
|
|
|
-
|
|
|
-var _DragDrop = require('./DragDrop');
|
|
|
-
|
|
|
-var _DragDrop2 = _interopRequireDefault(_DragDrop);
|
|
|
-
|
|
|
-var _Dropbox = require('./Dropbox');
|
|
|
-
|
|
|
-var _Dropbox2 = _interopRequireDefault(_Dropbox);
|
|
|
-
|
|
|
-var _Formtag = require('./Formtag');
|
|
|
-
|
|
|
-var _Formtag2 = _interopRequireDefault(_Formtag);
|
|
|
-
|
|
|
-// Uploaders
|
|
|
-
|
|
|
-var _Tus10 = require('./Tus10');
|
|
|
-
|
|
|
-var _Tus102 = _interopRequireDefault(_Tus10);
|
|
|
-
|
|
|
-var _Multipart = require('./Multipart');
|
|
|
-
|
|
|
-var _Multipart2 = _interopRequireDefault(_Multipart);
|
|
|
-
|
|
|
-// Presetters
|
|
|
-
|
|
|
-var _TransloaditBasic = require('./TransloaditBasic');
|
|
|
-
|
|
|
-var _TransloaditBasic2 = _interopRequireDefault(_TransloaditBasic);
|
|
|
-
|
|
|
-exports['default'] = {
|
|
|
- Plugin: _Plugin2['default'],
|
|
|
- DragDrop: _DragDrop2['default'],
|
|
|
- Dropbox: _Dropbox2['default'],
|
|
|
- Formtag: _Formtag2['default'],
|
|
|
- Tus10: _Tus102['default'],
|
|
|
- Multipart: _Multipart2['default'],
|
|
|
- TransloaditBasic: _TransloaditBasic2['default']
|
|
|
-};
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"./DragDrop":32,"./Dropbox":33,"./Formtag":34,"./Multipart":35,"./Plugin":36,"./TransloaditBasic":37,"./Tus10":38}],40:[function(require,module,exports){
|
|
|
-// hbsfy compiled Handlebars template
|
|
|
-var HandlebarsCompiler = require('hbsfy/runtime');
|
|
|
-module.exports = HandlebarsCompiler.template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
|
|
|
- var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
|
|
|
-
|
|
|
- return "<form class=\"UppyDragDrop-form\"\n method=\"post\"\n action=\"/\"\n enctype=\"multipart/form-data\">\n <img class=\"UppyDragDrop-puppy\" src=\"/images/uppy.svg\">\n <input class=\"UppyDragDrop-input\"\n type=\"file\"\n name=\"files[]\"\n data-multiple-caption=\"{count} files selected\"\n multiple />\n <label class=\"UppyDragDrop-label\" for=\"UppyDragDrop-input\">\n <strong>"
|
|
|
- + alias4(((helper = (helper = helpers.chooseFile || (depth0 != null ? depth0.chooseFile : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"chooseFile","hash":{},"data":data}) : helper)))
|
|
|
- + "</strong>\n <span class=\"UppyDragDrop-dragText\">"
|
|
|
- + alias4(((helper = (helper = helpers.orDragDrop || (depth0 != null ? depth0.orDragDrop : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"orDragDrop","hash":{},"data":data}) : helper)))
|
|
|
- + "</span>.\n </label>\n <button class=\"UppyDragDrop-btn\" type=\"submit\">Upload</button>\n <div class=\"UppyDragDrop-status\"></div>\n</form>\n";
|
|
|
-},"useData":true});
|
|
|
-
|
|
|
-},{"hbsfy/runtime":22}]},{},[30])(30)
|
|
|
-});
|