vueonrails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +21 -0
- data/README.md +7 -7
- data/lib/generators/generator_templates/forms/index.vue.erb +45 -0
- data/lib/generators/generator_templates/packs/index.js +13 -13
- data/lib/generators/generator_templates/packs/index.vue +3 -3
- data/lib/generators/generator_templates/packs/pack.js.erb +3 -3
- data/lib/generators/generator_templates/sfc/single-file-component.vue +3 -3
- data/lib/generators/generator_templates/tests/unit.test.js.erb +2 -2
- data/lib/generators/generator_templates/turbolinks/turbolinks-pack.js.erb +3 -3
- data/lib/generators/options/child.rb +6 -0
- data/lib/generators/options/click.rb +0 -1
- data/lib/generators/options/form.rb +1 -19
- data/lib/generators/options/list.rb +0 -1
- data/lib/generators/options/modal.rb +0 -1
- data/lib/generators/options/parent.rb +3 -0
- data/lib/generators/options/seperate.rb +0 -1
- data/lib/generators/options/single.rb +0 -1
- data/lib/generators/options/table.rb +0 -1
- data/lib/generators/options/test.rb +1 -2
- data/lib/generators/options/turbolinks-seperate.rb +0 -1
- data/lib/generators/options/turbolinks-single.rb +0 -1
- data/lib/generators/options/vuex.rb +0 -1
- data/lib/generators/vue/vue_generator.rb +76 -18
- data/lib/install/setup.rb +4 -5
- data/lib/install/spv.rb +0 -1
- data/lib/install/test.rb +0 -3
- data/lib/install/ui.rb +0 -3
- data/lib/vueonrails/post_message.rb +1 -1
- data/lib/vueonrails/version.rb +1 -1
- metadata +10 -23
- data/vendor/assets/javascripts/axios.js +0 -1545
- data/vendor/assets/javascripts/axios.map +0 -1
- data/vendor/assets/javascripts/element-ui.js +0 -12
- data/vendor/assets/javascripts/vue-resource.js +0 -1531
- data/vendor/assets/javascripts/vue-router.js +0 -2709
- data/vendor/assets/javascripts/vue-router2.js +0 -2284
- data/vendor/assets/javascripts/vue-validator.js +0 -910
- data/vendor/assets/javascripts/vue-validator2.js +0 -2615
- data/vendor/assets/javascripts/vue-validator3.js +0 -2054
- data/vendor/assets/javascripts/vue.js +0 -10237
- data/vendor/assets/javascripts/vue.min.js +0 -9
- data/vendor/assets/javascripts/vue2.js +0 -8568
- data/vendor/assets/javascripts/vue2.min.js +0 -8
- data/vendor/assets/javascripts/vueonrails.js +0 -39
- data/vendor/assets/javascripts/vuex.js +0 -722
- data/vendor/assets/javascripts/vuex2.js +0 -805
- data/vendor/assets/stylesheets/element-ui.css +0 -1
@@ -1,1531 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
* vue-resource v1.2.0
|
3
|
-
* https://github.com/pagekit/vue-resource
|
4
|
-
* Released under the MIT License.
|
5
|
-
*/
|
6
|
-
|
7
|
-
(function (global, factory) {
|
8
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
9
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
10
|
-
(global.VueResource = factory());
|
11
|
-
}(this, (function () { 'use strict';
|
12
|
-
|
13
|
-
/**
|
14
|
-
* Promises/A+ polyfill v1.1.4 (https://github.com/bramstein/promis)
|
15
|
-
*/
|
16
|
-
|
17
|
-
var RESOLVED = 0;
|
18
|
-
var REJECTED = 1;
|
19
|
-
var PENDING = 2;
|
20
|
-
|
21
|
-
function Promise$1(executor) {
|
22
|
-
|
23
|
-
this.state = PENDING;
|
24
|
-
this.value = undefined;
|
25
|
-
this.deferred = [];
|
26
|
-
|
27
|
-
var promise = this;
|
28
|
-
|
29
|
-
try {
|
30
|
-
executor(function (x) {
|
31
|
-
promise.resolve(x);
|
32
|
-
}, function (r) {
|
33
|
-
promise.reject(r);
|
34
|
-
});
|
35
|
-
} catch (e) {
|
36
|
-
promise.reject(e);
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
Promise$1.reject = function (r) {
|
41
|
-
return new Promise$1(function (resolve, reject) {
|
42
|
-
reject(r);
|
43
|
-
});
|
44
|
-
};
|
45
|
-
|
46
|
-
Promise$1.resolve = function (x) {
|
47
|
-
return new Promise$1(function (resolve, reject) {
|
48
|
-
resolve(x);
|
49
|
-
});
|
50
|
-
};
|
51
|
-
|
52
|
-
Promise$1.all = function all(iterable) {
|
53
|
-
return new Promise$1(function (resolve, reject) {
|
54
|
-
var count = 0, result = [];
|
55
|
-
|
56
|
-
if (iterable.length === 0) {
|
57
|
-
resolve(result);
|
58
|
-
}
|
59
|
-
|
60
|
-
function resolver(i) {
|
61
|
-
return function (x) {
|
62
|
-
result[i] = x;
|
63
|
-
count += 1;
|
64
|
-
|
65
|
-
if (count === iterable.length) {
|
66
|
-
resolve(result);
|
67
|
-
}
|
68
|
-
};
|
69
|
-
}
|
70
|
-
|
71
|
-
for (var i = 0; i < iterable.length; i += 1) {
|
72
|
-
Promise$1.resolve(iterable[i]).then(resolver(i), reject);
|
73
|
-
}
|
74
|
-
});
|
75
|
-
};
|
76
|
-
|
77
|
-
Promise$1.race = function race(iterable) {
|
78
|
-
return new Promise$1(function (resolve, reject) {
|
79
|
-
for (var i = 0; i < iterable.length; i += 1) {
|
80
|
-
Promise$1.resolve(iterable[i]).then(resolve, reject);
|
81
|
-
}
|
82
|
-
});
|
83
|
-
};
|
84
|
-
|
85
|
-
var p$1 = Promise$1.prototype;
|
86
|
-
|
87
|
-
p$1.resolve = function resolve(x) {
|
88
|
-
var promise = this;
|
89
|
-
|
90
|
-
if (promise.state === PENDING) {
|
91
|
-
if (x === promise) {
|
92
|
-
throw new TypeError('Promise settled with itself.');
|
93
|
-
}
|
94
|
-
|
95
|
-
var called = false;
|
96
|
-
|
97
|
-
try {
|
98
|
-
var then = x && x['then'];
|
99
|
-
|
100
|
-
if (x !== null && typeof x === 'object' && typeof then === 'function') {
|
101
|
-
then.call(x, function (x) {
|
102
|
-
if (!called) {
|
103
|
-
promise.resolve(x);
|
104
|
-
}
|
105
|
-
called = true;
|
106
|
-
|
107
|
-
}, function (r) {
|
108
|
-
if (!called) {
|
109
|
-
promise.reject(r);
|
110
|
-
}
|
111
|
-
called = true;
|
112
|
-
});
|
113
|
-
return;
|
114
|
-
}
|
115
|
-
} catch (e) {
|
116
|
-
if (!called) {
|
117
|
-
promise.reject(e);
|
118
|
-
}
|
119
|
-
return;
|
120
|
-
}
|
121
|
-
|
122
|
-
promise.state = RESOLVED;
|
123
|
-
promise.value = x;
|
124
|
-
promise.notify();
|
125
|
-
}
|
126
|
-
};
|
127
|
-
|
128
|
-
p$1.reject = function reject(reason) {
|
129
|
-
var promise = this;
|
130
|
-
|
131
|
-
if (promise.state === PENDING) {
|
132
|
-
if (reason === promise) {
|
133
|
-
throw new TypeError('Promise settled with itself.');
|
134
|
-
}
|
135
|
-
|
136
|
-
promise.state = REJECTED;
|
137
|
-
promise.value = reason;
|
138
|
-
promise.notify();
|
139
|
-
}
|
140
|
-
};
|
141
|
-
|
142
|
-
p$1.notify = function notify() {
|
143
|
-
var promise = this;
|
144
|
-
|
145
|
-
nextTick(function () {
|
146
|
-
if (promise.state !== PENDING) {
|
147
|
-
while (promise.deferred.length) {
|
148
|
-
var deferred = promise.deferred.shift(),
|
149
|
-
onResolved = deferred[0],
|
150
|
-
onRejected = deferred[1],
|
151
|
-
resolve = deferred[2],
|
152
|
-
reject = deferred[3];
|
153
|
-
|
154
|
-
try {
|
155
|
-
if (promise.state === RESOLVED) {
|
156
|
-
if (typeof onResolved === 'function') {
|
157
|
-
resolve(onResolved.call(undefined, promise.value));
|
158
|
-
} else {
|
159
|
-
resolve(promise.value);
|
160
|
-
}
|
161
|
-
} else if (promise.state === REJECTED) {
|
162
|
-
if (typeof onRejected === 'function') {
|
163
|
-
resolve(onRejected.call(undefined, promise.value));
|
164
|
-
} else {
|
165
|
-
reject(promise.value);
|
166
|
-
}
|
167
|
-
}
|
168
|
-
} catch (e) {
|
169
|
-
reject(e);
|
170
|
-
}
|
171
|
-
}
|
172
|
-
}
|
173
|
-
});
|
174
|
-
};
|
175
|
-
|
176
|
-
p$1.then = function then(onResolved, onRejected) {
|
177
|
-
var promise = this;
|
178
|
-
|
179
|
-
return new Promise$1(function (resolve, reject) {
|
180
|
-
promise.deferred.push([onResolved, onRejected, resolve, reject]);
|
181
|
-
promise.notify();
|
182
|
-
});
|
183
|
-
};
|
184
|
-
|
185
|
-
p$1.catch = function (onRejected) {
|
186
|
-
return this.then(undefined, onRejected);
|
187
|
-
};
|
188
|
-
|
189
|
-
/**
|
190
|
-
* Promise adapter.
|
191
|
-
*/
|
192
|
-
|
193
|
-
if (typeof Promise === 'undefined') {
|
194
|
-
window.Promise = Promise$1;
|
195
|
-
}
|
196
|
-
|
197
|
-
function PromiseObj(executor, context) {
|
198
|
-
|
199
|
-
if (executor instanceof Promise) {
|
200
|
-
this.promise = executor;
|
201
|
-
} else {
|
202
|
-
this.promise = new Promise(executor.bind(context));
|
203
|
-
}
|
204
|
-
|
205
|
-
this.context = context;
|
206
|
-
}
|
207
|
-
|
208
|
-
PromiseObj.all = function (iterable, context) {
|
209
|
-
return new PromiseObj(Promise.all(iterable), context);
|
210
|
-
};
|
211
|
-
|
212
|
-
PromiseObj.resolve = function (value, context) {
|
213
|
-
return new PromiseObj(Promise.resolve(value), context);
|
214
|
-
};
|
215
|
-
|
216
|
-
PromiseObj.reject = function (reason, context) {
|
217
|
-
return new PromiseObj(Promise.reject(reason), context);
|
218
|
-
};
|
219
|
-
|
220
|
-
PromiseObj.race = function (iterable, context) {
|
221
|
-
return new PromiseObj(Promise.race(iterable), context);
|
222
|
-
};
|
223
|
-
|
224
|
-
var p = PromiseObj.prototype;
|
225
|
-
|
226
|
-
p.bind = function (context) {
|
227
|
-
this.context = context;
|
228
|
-
return this;
|
229
|
-
};
|
230
|
-
|
231
|
-
p.then = function (fulfilled, rejected) {
|
232
|
-
|
233
|
-
if (fulfilled && fulfilled.bind && this.context) {
|
234
|
-
fulfilled = fulfilled.bind(this.context);
|
235
|
-
}
|
236
|
-
|
237
|
-
if (rejected && rejected.bind && this.context) {
|
238
|
-
rejected = rejected.bind(this.context);
|
239
|
-
}
|
240
|
-
|
241
|
-
return new PromiseObj(this.promise.then(fulfilled, rejected), this.context);
|
242
|
-
};
|
243
|
-
|
244
|
-
p.catch = function (rejected) {
|
245
|
-
|
246
|
-
if (rejected && rejected.bind && this.context) {
|
247
|
-
rejected = rejected.bind(this.context);
|
248
|
-
}
|
249
|
-
|
250
|
-
return new PromiseObj(this.promise.catch(rejected), this.context);
|
251
|
-
};
|
252
|
-
|
253
|
-
p.finally = function (callback) {
|
254
|
-
|
255
|
-
return this.then(function (value) {
|
256
|
-
callback.call(this);
|
257
|
-
return value;
|
258
|
-
}, function (reason) {
|
259
|
-
callback.call(this);
|
260
|
-
return Promise.reject(reason);
|
261
|
-
}
|
262
|
-
);
|
263
|
-
};
|
264
|
-
|
265
|
-
/**
|
266
|
-
* Utility functions.
|
267
|
-
*/
|
268
|
-
|
269
|
-
var debug = false;
|
270
|
-
var util = {};
|
271
|
-
var ref = {};
|
272
|
-
var hasOwnProperty = ref.hasOwnProperty;
|
273
|
-
|
274
|
-
var ref$1 = [];
|
275
|
-
var slice = ref$1.slice;
|
276
|
-
|
277
|
-
var inBrowser = typeof window !== 'undefined';
|
278
|
-
|
279
|
-
var Util = function (Vue) {
|
280
|
-
util = Vue.util;
|
281
|
-
debug = Vue.config.debug || !Vue.config.silent;
|
282
|
-
};
|
283
|
-
|
284
|
-
function warn(msg) {
|
285
|
-
if (typeof console !== 'undefined' && debug) {
|
286
|
-
console.warn('[VueResource warn]: ' + msg);
|
287
|
-
}
|
288
|
-
}
|
289
|
-
|
290
|
-
function error(msg) {
|
291
|
-
if (typeof console !== 'undefined') {
|
292
|
-
console.error(msg);
|
293
|
-
}
|
294
|
-
}
|
295
|
-
|
296
|
-
function nextTick(cb, ctx) {
|
297
|
-
return util.nextTick(cb, ctx);
|
298
|
-
}
|
299
|
-
|
300
|
-
function trim(str) {
|
301
|
-
return str ? str.replace(/^\s*|\s*$/g, '') : '';
|
302
|
-
}
|
303
|
-
|
304
|
-
function toLower(str) {
|
305
|
-
return str ? str.toLowerCase() : '';
|
306
|
-
}
|
307
|
-
|
308
|
-
function toUpper(str) {
|
309
|
-
return str ? str.toUpperCase() : '';
|
310
|
-
}
|
311
|
-
|
312
|
-
var isArray = Array.isArray;
|
313
|
-
|
314
|
-
function isString(val) {
|
315
|
-
return typeof val === 'string';
|
316
|
-
}
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
function isFunction(val) {
|
321
|
-
return typeof val === 'function';
|
322
|
-
}
|
323
|
-
|
324
|
-
function isObject(obj) {
|
325
|
-
return obj !== null && typeof obj === 'object';
|
326
|
-
}
|
327
|
-
|
328
|
-
function isPlainObject(obj) {
|
329
|
-
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype;
|
330
|
-
}
|
331
|
-
|
332
|
-
function isBlob(obj) {
|
333
|
-
return typeof Blob !== 'undefined' && obj instanceof Blob;
|
334
|
-
}
|
335
|
-
|
336
|
-
function isFormData(obj) {
|
337
|
-
return typeof FormData !== 'undefined' && obj instanceof FormData;
|
338
|
-
}
|
339
|
-
|
340
|
-
function when(value, fulfilled, rejected) {
|
341
|
-
|
342
|
-
var promise = PromiseObj.resolve(value);
|
343
|
-
|
344
|
-
if (arguments.length < 2) {
|
345
|
-
return promise;
|
346
|
-
}
|
347
|
-
|
348
|
-
return promise.then(fulfilled, rejected);
|
349
|
-
}
|
350
|
-
|
351
|
-
function options(fn, obj, opts) {
|
352
|
-
|
353
|
-
opts = opts || {};
|
354
|
-
|
355
|
-
if (isFunction(opts)) {
|
356
|
-
opts = opts.call(obj);
|
357
|
-
}
|
358
|
-
|
359
|
-
return merge(fn.bind({$vm: obj, $options: opts}), fn, {$options: opts});
|
360
|
-
}
|
361
|
-
|
362
|
-
function each(obj, iterator) {
|
363
|
-
|
364
|
-
var i, key;
|
365
|
-
|
366
|
-
if (isArray(obj)) {
|
367
|
-
for (i = 0; i < obj.length; i++) {
|
368
|
-
iterator.call(obj[i], obj[i], i);
|
369
|
-
}
|
370
|
-
} else if (isObject(obj)) {
|
371
|
-
for (key in obj) {
|
372
|
-
if (hasOwnProperty.call(obj, key)) {
|
373
|
-
iterator.call(obj[key], obj[key], key);
|
374
|
-
}
|
375
|
-
}
|
376
|
-
}
|
377
|
-
|
378
|
-
return obj;
|
379
|
-
}
|
380
|
-
|
381
|
-
var assign = Object.assign || _assign;
|
382
|
-
|
383
|
-
function merge(target) {
|
384
|
-
|
385
|
-
var args = slice.call(arguments, 1);
|
386
|
-
|
387
|
-
args.forEach(function (source) {
|
388
|
-
_merge(target, source, true);
|
389
|
-
});
|
390
|
-
|
391
|
-
return target;
|
392
|
-
}
|
393
|
-
|
394
|
-
function defaults(target) {
|
395
|
-
|
396
|
-
var args = slice.call(arguments, 1);
|
397
|
-
|
398
|
-
args.forEach(function (source) {
|
399
|
-
|
400
|
-
for (var key in source) {
|
401
|
-
if (target[key] === undefined) {
|
402
|
-
target[key] = source[key];
|
403
|
-
}
|
404
|
-
}
|
405
|
-
|
406
|
-
});
|
407
|
-
|
408
|
-
return target;
|
409
|
-
}
|
410
|
-
|
411
|
-
function _assign(target) {
|
412
|
-
|
413
|
-
var args = slice.call(arguments, 1);
|
414
|
-
|
415
|
-
args.forEach(function (source) {
|
416
|
-
_merge(target, source);
|
417
|
-
});
|
418
|
-
|
419
|
-
return target;
|
420
|
-
}
|
421
|
-
|
422
|
-
function _merge(target, source, deep) {
|
423
|
-
for (var key in source) {
|
424
|
-
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
|
425
|
-
if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
|
426
|
-
target[key] = {};
|
427
|
-
}
|
428
|
-
if (isArray(source[key]) && !isArray(target[key])) {
|
429
|
-
target[key] = [];
|
430
|
-
}
|
431
|
-
_merge(target[key], source[key], deep);
|
432
|
-
} else if (source[key] !== undefined) {
|
433
|
-
target[key] = source[key];
|
434
|
-
}
|
435
|
-
}
|
436
|
-
}
|
437
|
-
|
438
|
-
/**
|
439
|
-
* Root Prefix Transform.
|
440
|
-
*/
|
441
|
-
|
442
|
-
var root = function (options$$1, next) {
|
443
|
-
|
444
|
-
var url = next(options$$1);
|
445
|
-
|
446
|
-
if (isString(options$$1.root) && !url.match(/^(https?:)?\//)) {
|
447
|
-
url = options$$1.root + '/' + url;
|
448
|
-
}
|
449
|
-
|
450
|
-
return url;
|
451
|
-
};
|
452
|
-
|
453
|
-
/**
|
454
|
-
* Query Parameter Transform.
|
455
|
-
*/
|
456
|
-
|
457
|
-
var query = function (options$$1, next) {
|
458
|
-
|
459
|
-
var urlParams = Object.keys(Url.options.params), query = {}, url = next(options$$1);
|
460
|
-
|
461
|
-
each(options$$1.params, function (value, key) {
|
462
|
-
if (urlParams.indexOf(key) === -1) {
|
463
|
-
query[key] = value;
|
464
|
-
}
|
465
|
-
});
|
466
|
-
|
467
|
-
query = Url.params(query);
|
468
|
-
|
469
|
-
if (query) {
|
470
|
-
url += (url.indexOf('?') == -1 ? '?' : '&') + query;
|
471
|
-
}
|
472
|
-
|
473
|
-
return url;
|
474
|
-
};
|
475
|
-
|
476
|
-
/**
|
477
|
-
* URL Template v2.0.6 (https://github.com/bramstein/url-template)
|
478
|
-
*/
|
479
|
-
|
480
|
-
function expand(url, params, variables) {
|
481
|
-
|
482
|
-
var tmpl = parse(url), expanded = tmpl.expand(params);
|
483
|
-
|
484
|
-
if (variables) {
|
485
|
-
variables.push.apply(variables, tmpl.vars);
|
486
|
-
}
|
487
|
-
|
488
|
-
return expanded;
|
489
|
-
}
|
490
|
-
|
491
|
-
function parse(template) {
|
492
|
-
|
493
|
-
var operators = ['+', '#', '.', '/', ';', '?', '&'], variables = [];
|
494
|
-
|
495
|
-
return {
|
496
|
-
vars: variables,
|
497
|
-
expand: function expand(context) {
|
498
|
-
return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) {
|
499
|
-
if (expression) {
|
500
|
-
|
501
|
-
var operator = null, values = [];
|
502
|
-
|
503
|
-
if (operators.indexOf(expression.charAt(0)) !== -1) {
|
504
|
-
operator = expression.charAt(0);
|
505
|
-
expression = expression.substr(1);
|
506
|
-
}
|
507
|
-
|
508
|
-
expression.split(/,/g).forEach(function (variable) {
|
509
|
-
var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
|
510
|
-
values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3]));
|
511
|
-
variables.push(tmp[1]);
|
512
|
-
});
|
513
|
-
|
514
|
-
if (operator && operator !== '+') {
|
515
|
-
|
516
|
-
var separator = ',';
|
517
|
-
|
518
|
-
if (operator === '?') {
|
519
|
-
separator = '&';
|
520
|
-
} else if (operator !== '#') {
|
521
|
-
separator = operator;
|
522
|
-
}
|
523
|
-
|
524
|
-
return (values.length !== 0 ? operator : '') + values.join(separator);
|
525
|
-
} else {
|
526
|
-
return values.join(',');
|
527
|
-
}
|
528
|
-
|
529
|
-
} else {
|
530
|
-
return encodeReserved(literal);
|
531
|
-
}
|
532
|
-
});
|
533
|
-
}
|
534
|
-
};
|
535
|
-
}
|
536
|
-
|
537
|
-
function getValues(context, operator, key, modifier) {
|
538
|
-
|
539
|
-
var value = context[key], result = [];
|
540
|
-
|
541
|
-
if (isDefined(value) && value !== '') {
|
542
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
543
|
-
value = value.toString();
|
544
|
-
|
545
|
-
if (modifier && modifier !== '*') {
|
546
|
-
value = value.substring(0, parseInt(modifier, 10));
|
547
|
-
}
|
548
|
-
|
549
|
-
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
|
550
|
-
} else {
|
551
|
-
if (modifier === '*') {
|
552
|
-
if (Array.isArray(value)) {
|
553
|
-
value.filter(isDefined).forEach(function (value) {
|
554
|
-
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null));
|
555
|
-
});
|
556
|
-
} else {
|
557
|
-
Object.keys(value).forEach(function (k) {
|
558
|
-
if (isDefined(value[k])) {
|
559
|
-
result.push(encodeValue(operator, value[k], k));
|
560
|
-
}
|
561
|
-
});
|
562
|
-
}
|
563
|
-
} else {
|
564
|
-
var tmp = [];
|
565
|
-
|
566
|
-
if (Array.isArray(value)) {
|
567
|
-
value.filter(isDefined).forEach(function (value) {
|
568
|
-
tmp.push(encodeValue(operator, value));
|
569
|
-
});
|
570
|
-
} else {
|
571
|
-
Object.keys(value).forEach(function (k) {
|
572
|
-
if (isDefined(value[k])) {
|
573
|
-
tmp.push(encodeURIComponent(k));
|
574
|
-
tmp.push(encodeValue(operator, value[k].toString()));
|
575
|
-
}
|
576
|
-
});
|
577
|
-
}
|
578
|
-
|
579
|
-
if (isKeyOperator(operator)) {
|
580
|
-
result.push(encodeURIComponent(key) + '=' + tmp.join(','));
|
581
|
-
} else if (tmp.length !== 0) {
|
582
|
-
result.push(tmp.join(','));
|
583
|
-
}
|
584
|
-
}
|
585
|
-
}
|
586
|
-
} else {
|
587
|
-
if (operator === ';') {
|
588
|
-
result.push(encodeURIComponent(key));
|
589
|
-
} else if (value === '' && (operator === '&' || operator === '?')) {
|
590
|
-
result.push(encodeURIComponent(key) + '=');
|
591
|
-
} else if (value === '') {
|
592
|
-
result.push('');
|
593
|
-
}
|
594
|
-
}
|
595
|
-
|
596
|
-
return result;
|
597
|
-
}
|
598
|
-
|
599
|
-
function isDefined(value) {
|
600
|
-
return value !== undefined && value !== null;
|
601
|
-
}
|
602
|
-
|
603
|
-
function isKeyOperator(operator) {
|
604
|
-
return operator === ';' || operator === '&' || operator === '?';
|
605
|
-
}
|
606
|
-
|
607
|
-
function encodeValue(operator, value, key) {
|
608
|
-
|
609
|
-
value = (operator === '+' || operator === '#') ? encodeReserved(value) : encodeURIComponent(value);
|
610
|
-
|
611
|
-
if (key) {
|
612
|
-
return encodeURIComponent(key) + '=' + value;
|
613
|
-
} else {
|
614
|
-
return value;
|
615
|
-
}
|
616
|
-
}
|
617
|
-
|
618
|
-
function encodeReserved(str) {
|
619
|
-
return str.split(/(%[0-9A-Fa-f]{2})/g).map(function (part) {
|
620
|
-
if (!/%[0-9A-Fa-f]/.test(part)) {
|
621
|
-
part = encodeURI(part);
|
622
|
-
}
|
623
|
-
return part;
|
624
|
-
}).join('');
|
625
|
-
}
|
626
|
-
|
627
|
-
/**
|
628
|
-
* URL Template (RFC 6570) Transform.
|
629
|
-
*/
|
630
|
-
|
631
|
-
var template = function (options) {
|
632
|
-
|
633
|
-
var variables = [], url = expand(options.url, options.params, variables);
|
634
|
-
|
635
|
-
variables.forEach(function (key) {
|
636
|
-
delete options.params[key];
|
637
|
-
});
|
638
|
-
|
639
|
-
return url;
|
640
|
-
};
|
641
|
-
|
642
|
-
/**
|
643
|
-
* Service for URL templating.
|
644
|
-
*/
|
645
|
-
|
646
|
-
function Url(url, params) {
|
647
|
-
|
648
|
-
var self = this || {}, options$$1 = url, transform;
|
649
|
-
|
650
|
-
if (isString(url)) {
|
651
|
-
options$$1 = {url: url, params: params};
|
652
|
-
}
|
653
|
-
|
654
|
-
options$$1 = merge({}, Url.options, self.$options, options$$1);
|
655
|
-
|
656
|
-
Url.transforms.forEach(function (handler) {
|
657
|
-
transform = factory(handler, transform, self.$vm);
|
658
|
-
});
|
659
|
-
|
660
|
-
return transform(options$$1);
|
661
|
-
}
|
662
|
-
|
663
|
-
/**
|
664
|
-
* Url options.
|
665
|
-
*/
|
666
|
-
|
667
|
-
Url.options = {
|
668
|
-
url: '',
|
669
|
-
root: null,
|
670
|
-
params: {}
|
671
|
-
};
|
672
|
-
|
673
|
-
/**
|
674
|
-
* Url transforms.
|
675
|
-
*/
|
676
|
-
|
677
|
-
Url.transforms = [template, query, root];
|
678
|
-
|
679
|
-
/**
|
680
|
-
* Encodes a Url parameter string.
|
681
|
-
*
|
682
|
-
* @param {Object} obj
|
683
|
-
*/
|
684
|
-
|
685
|
-
Url.params = function (obj) {
|
686
|
-
|
687
|
-
var params = [], escape = encodeURIComponent;
|
688
|
-
|
689
|
-
params.add = function (key, value) {
|
690
|
-
|
691
|
-
if (isFunction(value)) {
|
692
|
-
value = value();
|
693
|
-
}
|
694
|
-
|
695
|
-
if (value === null) {
|
696
|
-
value = '';
|
697
|
-
}
|
698
|
-
|
699
|
-
this.push(escape(key) + '=' + escape(value));
|
700
|
-
};
|
701
|
-
|
702
|
-
serialize(params, obj);
|
703
|
-
|
704
|
-
return params.join('&').replace(/%20/g, '+');
|
705
|
-
};
|
706
|
-
|
707
|
-
/**
|
708
|
-
* Parse a URL and return its components.
|
709
|
-
*
|
710
|
-
* @param {String} url
|
711
|
-
*/
|
712
|
-
|
713
|
-
Url.parse = function (url) {
|
714
|
-
|
715
|
-
var el = document.createElement('a');
|
716
|
-
|
717
|
-
if (document.documentMode) {
|
718
|
-
el.href = url;
|
719
|
-
url = el.href;
|
720
|
-
}
|
721
|
-
|
722
|
-
el.href = url;
|
723
|
-
|
724
|
-
return {
|
725
|
-
href: el.href,
|
726
|
-
protocol: el.protocol ? el.protocol.replace(/:$/, '') : '',
|
727
|
-
port: el.port,
|
728
|
-
host: el.host,
|
729
|
-
hostname: el.hostname,
|
730
|
-
pathname: el.pathname.charAt(0) === '/' ? el.pathname : '/' + el.pathname,
|
731
|
-
search: el.search ? el.search.replace(/^\?/, '') : '',
|
732
|
-
hash: el.hash ? el.hash.replace(/^#/, '') : ''
|
733
|
-
};
|
734
|
-
};
|
735
|
-
|
736
|
-
function factory(handler, next, vm) {
|
737
|
-
return function (options$$1) {
|
738
|
-
return handler.call(vm, options$$1, next);
|
739
|
-
};
|
740
|
-
}
|
741
|
-
|
742
|
-
function serialize(params, obj, scope) {
|
743
|
-
|
744
|
-
var array = isArray(obj), plain = isPlainObject(obj), hash;
|
745
|
-
|
746
|
-
each(obj, function (value, key) {
|
747
|
-
|
748
|
-
hash = isObject(value) || isArray(value);
|
749
|
-
|
750
|
-
if (scope) {
|
751
|
-
key = scope + '[' + (plain || hash ? key : '') + ']';
|
752
|
-
}
|
753
|
-
|
754
|
-
if (!scope && array) {
|
755
|
-
params.add(value.name, value.value);
|
756
|
-
} else if (hash) {
|
757
|
-
serialize(params, value, key);
|
758
|
-
} else {
|
759
|
-
params.add(key, value);
|
760
|
-
}
|
761
|
-
});
|
762
|
-
}
|
763
|
-
|
764
|
-
/**
|
765
|
-
* XDomain client (Internet Explorer).
|
766
|
-
*/
|
767
|
-
|
768
|
-
var xdrClient = function (request) {
|
769
|
-
return new PromiseObj(function (resolve) {
|
770
|
-
|
771
|
-
var xdr = new XDomainRequest(), handler = function (ref) {
|
772
|
-
var type = ref.type;
|
773
|
-
|
774
|
-
|
775
|
-
var status = 0;
|
776
|
-
|
777
|
-
if (type === 'load') {
|
778
|
-
status = 200;
|
779
|
-
} else if (type === 'error') {
|
780
|
-
status = 500;
|
781
|
-
}
|
782
|
-
|
783
|
-
resolve(request.respondWith(xdr.responseText, {status: status}));
|
784
|
-
};
|
785
|
-
|
786
|
-
request.abort = function () { return xdr.abort(); };
|
787
|
-
|
788
|
-
xdr.open(request.method, request.getUrl());
|
789
|
-
|
790
|
-
if (request.timeout) {
|
791
|
-
xdr.timeout = request.timeout;
|
792
|
-
}
|
793
|
-
|
794
|
-
xdr.onload = handler;
|
795
|
-
xdr.onabort = handler;
|
796
|
-
xdr.onerror = handler;
|
797
|
-
xdr.ontimeout = handler;
|
798
|
-
xdr.onprogress = function () {};
|
799
|
-
xdr.send(request.getBody());
|
800
|
-
});
|
801
|
-
};
|
802
|
-
|
803
|
-
/**
|
804
|
-
* CORS Interceptor.
|
805
|
-
*/
|
806
|
-
|
807
|
-
var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest();
|
808
|
-
|
809
|
-
var cors = function (request, next) {
|
810
|
-
|
811
|
-
if (inBrowser) {
|
812
|
-
|
813
|
-
var orgUrl = Url.parse(location.href);
|
814
|
-
var reqUrl = Url.parse(request.getUrl());
|
815
|
-
|
816
|
-
if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) {
|
817
|
-
|
818
|
-
request.crossOrigin = true;
|
819
|
-
request.emulateHTTP = false;
|
820
|
-
|
821
|
-
if (!SUPPORTS_CORS) {
|
822
|
-
request.client = xdrClient;
|
823
|
-
}
|
824
|
-
}
|
825
|
-
}
|
826
|
-
|
827
|
-
next();
|
828
|
-
};
|
829
|
-
|
830
|
-
/**
|
831
|
-
* Body Interceptor.
|
832
|
-
*/
|
833
|
-
|
834
|
-
var body = function (request, next) {
|
835
|
-
|
836
|
-
if (isFormData(request.body)) {
|
837
|
-
|
838
|
-
request.headers.delete('Content-Type');
|
839
|
-
|
840
|
-
} else if (isObject(request.body) || isArray(request.body)) {
|
841
|
-
|
842
|
-
if (request.emulateJSON) {
|
843
|
-
request.body = Url.params(request.body);
|
844
|
-
request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
|
845
|
-
} else {
|
846
|
-
request.body = JSON.stringify(request.body);
|
847
|
-
}
|
848
|
-
}
|
849
|
-
|
850
|
-
next(function (response) {
|
851
|
-
|
852
|
-
Object.defineProperty(response, 'data', {
|
853
|
-
|
854
|
-
get: function get() {
|
855
|
-
return this.body;
|
856
|
-
},
|
857
|
-
|
858
|
-
set: function set(body) {
|
859
|
-
this.body = body;
|
860
|
-
}
|
861
|
-
|
862
|
-
});
|
863
|
-
|
864
|
-
return response.bodyText ? when(response.text(), function (text) {
|
865
|
-
|
866
|
-
var type = response.headers.get('Content-Type') || '';
|
867
|
-
|
868
|
-
if (type.indexOf('application/json') === 0 || isJson(text)) {
|
869
|
-
|
870
|
-
try {
|
871
|
-
response.body = JSON.parse(text);
|
872
|
-
} catch (e) {
|
873
|
-
response.body = null;
|
874
|
-
}
|
875
|
-
|
876
|
-
} else {
|
877
|
-
response.body = text;
|
878
|
-
}
|
879
|
-
|
880
|
-
return response;
|
881
|
-
|
882
|
-
}) : response;
|
883
|
-
|
884
|
-
});
|
885
|
-
};
|
886
|
-
|
887
|
-
function isJson(str) {
|
888
|
-
|
889
|
-
var start = str.match(/^\[|^\{(?!\{)/), end = {'[': /]$/, '{': /}$/};
|
890
|
-
|
891
|
-
return start && end[start[0]].test(str);
|
892
|
-
}
|
893
|
-
|
894
|
-
/**
|
895
|
-
* JSONP client (Browser).
|
896
|
-
*/
|
897
|
-
|
898
|
-
var jsonpClient = function (request) {
|
899
|
-
return new PromiseObj(function (resolve) {
|
900
|
-
|
901
|
-
var name = request.jsonp || 'callback', callback = request.jsonpCallback || '_jsonp' + Math.random().toString(36).substr(2), body = null, handler, script;
|
902
|
-
|
903
|
-
handler = function (ref) {
|
904
|
-
var type = ref.type;
|
905
|
-
|
906
|
-
|
907
|
-
var status = 0;
|
908
|
-
|
909
|
-
if (type === 'load' && body !== null) {
|
910
|
-
status = 200;
|
911
|
-
} else if (type === 'error') {
|
912
|
-
status = 500;
|
913
|
-
}
|
914
|
-
|
915
|
-
if (status && window[callback]) {
|
916
|
-
delete window[callback];
|
917
|
-
document.body.removeChild(script);
|
918
|
-
}
|
919
|
-
|
920
|
-
resolve(request.respondWith(body, {status: status}));
|
921
|
-
};
|
922
|
-
|
923
|
-
window[callback] = function (result) {
|
924
|
-
body = JSON.stringify(result);
|
925
|
-
};
|
926
|
-
|
927
|
-
request.abort = function () {
|
928
|
-
handler({type: 'abort'});
|
929
|
-
};
|
930
|
-
|
931
|
-
request.params[name] = callback;
|
932
|
-
|
933
|
-
if (request.timeout) {
|
934
|
-
setTimeout(request.abort, request.timeout);
|
935
|
-
}
|
936
|
-
|
937
|
-
script = document.createElement('script');
|
938
|
-
script.src = request.getUrl();
|
939
|
-
script.type = 'text/javascript';
|
940
|
-
script.async = true;
|
941
|
-
script.onload = handler;
|
942
|
-
script.onerror = handler;
|
943
|
-
|
944
|
-
document.body.appendChild(script);
|
945
|
-
});
|
946
|
-
};
|
947
|
-
|
948
|
-
/**
|
949
|
-
* JSONP Interceptor.
|
950
|
-
*/
|
951
|
-
|
952
|
-
var jsonp = function (request, next) {
|
953
|
-
|
954
|
-
if (request.method == 'JSONP') {
|
955
|
-
request.client = jsonpClient;
|
956
|
-
}
|
957
|
-
|
958
|
-
next();
|
959
|
-
};
|
960
|
-
|
961
|
-
/**
|
962
|
-
* Before Interceptor.
|
963
|
-
*/
|
964
|
-
|
965
|
-
var before = function (request, next) {
|
966
|
-
|
967
|
-
if (isFunction(request.before)) {
|
968
|
-
request.before.call(this, request);
|
969
|
-
}
|
970
|
-
|
971
|
-
next();
|
972
|
-
};
|
973
|
-
|
974
|
-
/**
|
975
|
-
* HTTP method override Interceptor.
|
976
|
-
*/
|
977
|
-
|
978
|
-
var method = function (request, next) {
|
979
|
-
|
980
|
-
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) {
|
981
|
-
request.headers.set('X-HTTP-Method-Override', request.method);
|
982
|
-
request.method = 'POST';
|
983
|
-
}
|
984
|
-
|
985
|
-
next();
|
986
|
-
};
|
987
|
-
|
988
|
-
/**
|
989
|
-
* Header Interceptor.
|
990
|
-
*/
|
991
|
-
|
992
|
-
var header = function (request, next) {
|
993
|
-
|
994
|
-
var headers = assign({}, Http.headers.common,
|
995
|
-
!request.crossOrigin ? Http.headers.custom : {},
|
996
|
-
Http.headers[toLower(request.method)]
|
997
|
-
);
|
998
|
-
|
999
|
-
each(headers, function (value, name) {
|
1000
|
-
if (!request.headers.has(name)) {
|
1001
|
-
request.headers.set(name, value);
|
1002
|
-
}
|
1003
|
-
});
|
1004
|
-
|
1005
|
-
next();
|
1006
|
-
};
|
1007
|
-
|
1008
|
-
/**
|
1009
|
-
* XMLHttp client (Browser).
|
1010
|
-
*/
|
1011
|
-
|
1012
|
-
var SUPPORTS_BLOB = typeof Blob !== 'undefined' && typeof FileReader !== 'undefined';
|
1013
|
-
|
1014
|
-
var xhrClient = function (request) {
|
1015
|
-
return new PromiseObj(function (resolve) {
|
1016
|
-
|
1017
|
-
var xhr = new XMLHttpRequest(), handler = function (event) {
|
1018
|
-
|
1019
|
-
var response = request.respondWith(
|
1020
|
-
'response' in xhr ? xhr.response : xhr.responseText, {
|
1021
|
-
status: xhr.status === 1223 ? 204 : xhr.status, // IE9 status bug
|
1022
|
-
statusText: xhr.status === 1223 ? 'No Content' : trim(xhr.statusText)
|
1023
|
-
}
|
1024
|
-
);
|
1025
|
-
|
1026
|
-
each(trim(xhr.getAllResponseHeaders()).split('\n'), function (row) {
|
1027
|
-
response.headers.append(row.slice(0, row.indexOf(':')), row.slice(row.indexOf(':') + 1));
|
1028
|
-
});
|
1029
|
-
|
1030
|
-
resolve(response);
|
1031
|
-
};
|
1032
|
-
|
1033
|
-
request.abort = function () { return xhr.abort(); };
|
1034
|
-
|
1035
|
-
if (request.progress) {
|
1036
|
-
if (request.method === 'GET') {
|
1037
|
-
xhr.addEventListener('progress', request.progress);
|
1038
|
-
} else if (/^(POST|PUT)$/i.test(request.method)) {
|
1039
|
-
xhr.upload.addEventListener('progress', request.progress);
|
1040
|
-
}
|
1041
|
-
}
|
1042
|
-
|
1043
|
-
xhr.open(request.method, request.getUrl(), true);
|
1044
|
-
|
1045
|
-
if (request.timeout) {
|
1046
|
-
xhr.timeout = request.timeout;
|
1047
|
-
}
|
1048
|
-
|
1049
|
-
if (request.credentials === true) {
|
1050
|
-
xhr.withCredentials = true;
|
1051
|
-
}
|
1052
|
-
|
1053
|
-
if (!request.crossOrigin) {
|
1054
|
-
request.headers.set('X-Requested-With', 'XMLHttpRequest');
|
1055
|
-
}
|
1056
|
-
|
1057
|
-
if ('responseType' in xhr && SUPPORTS_BLOB) {
|
1058
|
-
xhr.responseType = 'blob';
|
1059
|
-
}
|
1060
|
-
|
1061
|
-
request.headers.forEach(function (value, name) {
|
1062
|
-
xhr.setRequestHeader(name, value);
|
1063
|
-
});
|
1064
|
-
|
1065
|
-
xhr.onload = handler;
|
1066
|
-
xhr.onabort = handler;
|
1067
|
-
xhr.onerror = handler;
|
1068
|
-
xhr.ontimeout = handler;
|
1069
|
-
xhr.send(request.getBody());
|
1070
|
-
});
|
1071
|
-
};
|
1072
|
-
|
1073
|
-
/**
|
1074
|
-
* Http client (Node).
|
1075
|
-
*/
|
1076
|
-
|
1077
|
-
var nodeClient = function (request) {
|
1078
|
-
|
1079
|
-
var client = require('got');
|
1080
|
-
|
1081
|
-
return new PromiseObj(function (resolve) {
|
1082
|
-
|
1083
|
-
var url = request.getUrl();
|
1084
|
-
var body = request.getBody();
|
1085
|
-
var method = request.method;
|
1086
|
-
var headers = {}, handler;
|
1087
|
-
|
1088
|
-
request.headers.forEach(function (value, name) {
|
1089
|
-
headers[name] = value;
|
1090
|
-
});
|
1091
|
-
|
1092
|
-
client(url, {body: body, method: method, headers: headers}).then(handler = function (resp) {
|
1093
|
-
|
1094
|
-
var response = request.respondWith(resp.body, {
|
1095
|
-
status: resp.statusCode,
|
1096
|
-
statusText: trim(resp.statusMessage)
|
1097
|
-
}
|
1098
|
-
);
|
1099
|
-
|
1100
|
-
each(resp.headers, function (value, name) {
|
1101
|
-
response.headers.set(name, value);
|
1102
|
-
});
|
1103
|
-
|
1104
|
-
resolve(response);
|
1105
|
-
|
1106
|
-
}, function (error$$1) { return handler(error$$1.response); });
|
1107
|
-
});
|
1108
|
-
};
|
1109
|
-
|
1110
|
-
/**
|
1111
|
-
* Base client.
|
1112
|
-
*/
|
1113
|
-
|
1114
|
-
var Client = function (context) {
|
1115
|
-
|
1116
|
-
var reqHandlers = [sendRequest], resHandlers = [], handler;
|
1117
|
-
|
1118
|
-
if (!isObject(context)) {
|
1119
|
-
context = null;
|
1120
|
-
}
|
1121
|
-
|
1122
|
-
function Client(request) {
|
1123
|
-
return new PromiseObj(function (resolve) {
|
1124
|
-
|
1125
|
-
function exec() {
|
1126
|
-
|
1127
|
-
handler = reqHandlers.pop();
|
1128
|
-
|
1129
|
-
if (isFunction(handler)) {
|
1130
|
-
handler.call(context, request, next);
|
1131
|
-
} else {
|
1132
|
-
warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function"));
|
1133
|
-
next();
|
1134
|
-
}
|
1135
|
-
}
|
1136
|
-
|
1137
|
-
function next(response) {
|
1138
|
-
|
1139
|
-
if (isFunction(response)) {
|
1140
|
-
|
1141
|
-
resHandlers.unshift(response);
|
1142
|
-
|
1143
|
-
} else if (isObject(response)) {
|
1144
|
-
|
1145
|
-
resHandlers.forEach(function (handler) {
|
1146
|
-
response = when(response, function (response) {
|
1147
|
-
return handler.call(context, response) || response;
|
1148
|
-
});
|
1149
|
-
});
|
1150
|
-
|
1151
|
-
when(response, resolve);
|
1152
|
-
|
1153
|
-
return;
|
1154
|
-
}
|
1155
|
-
|
1156
|
-
exec();
|
1157
|
-
}
|
1158
|
-
|
1159
|
-
exec();
|
1160
|
-
|
1161
|
-
}, context);
|
1162
|
-
}
|
1163
|
-
|
1164
|
-
Client.use = function (handler) {
|
1165
|
-
reqHandlers.push(handler);
|
1166
|
-
};
|
1167
|
-
|
1168
|
-
return Client;
|
1169
|
-
};
|
1170
|
-
|
1171
|
-
function sendRequest(request, resolve) {
|
1172
|
-
|
1173
|
-
var client = request.client || (inBrowser ? xhrClient : nodeClient);
|
1174
|
-
|
1175
|
-
resolve(client(request));
|
1176
|
-
}
|
1177
|
-
|
1178
|
-
/**
|
1179
|
-
* HTTP Headers.
|
1180
|
-
*/
|
1181
|
-
|
1182
|
-
var Headers = function Headers(headers) {
|
1183
|
-
var this$1 = this;
|
1184
|
-
|
1185
|
-
|
1186
|
-
this.map = {};
|
1187
|
-
|
1188
|
-
each(headers, function (value, name) { return this$1.append(name, value); });
|
1189
|
-
};
|
1190
|
-
|
1191
|
-
Headers.prototype.has = function has (name) {
|
1192
|
-
return getName(this.map, name) !== null;
|
1193
|
-
};
|
1194
|
-
|
1195
|
-
Headers.prototype.get = function get (name) {
|
1196
|
-
|
1197
|
-
var list = this.map[getName(this.map, name)];
|
1198
|
-
|
1199
|
-
return list ? list[0] : null;
|
1200
|
-
};
|
1201
|
-
|
1202
|
-
Headers.prototype.getAll = function getAll (name) {
|
1203
|
-
return this.map[getName(this.map, name)] || [];
|
1204
|
-
};
|
1205
|
-
|
1206
|
-
Headers.prototype.set = function set (name, value) {
|
1207
|
-
this.map[normalizeName(getName(this.map, name) || name)] = [trim(value)];
|
1208
|
-
};
|
1209
|
-
|
1210
|
-
Headers.prototype.append = function append (name, value){
|
1211
|
-
|
1212
|
-
var list = this.getAll(name);
|
1213
|
-
|
1214
|
-
if (list.length) {
|
1215
|
-
list.push(trim(value));
|
1216
|
-
} else {
|
1217
|
-
this.set(name, value);
|
1218
|
-
}
|
1219
|
-
};
|
1220
|
-
|
1221
|
-
Headers.prototype.delete = function delete$1 (name){
|
1222
|
-
delete this.map[getName(this.map, name)];
|
1223
|
-
};
|
1224
|
-
|
1225
|
-
Headers.prototype.deleteAll = function deleteAll (){
|
1226
|
-
this.map = {};
|
1227
|
-
};
|
1228
|
-
|
1229
|
-
Headers.prototype.forEach = function forEach (callback, thisArg) {
|
1230
|
-
var this$1 = this;
|
1231
|
-
|
1232
|
-
each(this.map, function (list, name) {
|
1233
|
-
each(list, function (value) { return callback.call(thisArg, value, name, this$1); });
|
1234
|
-
});
|
1235
|
-
};
|
1236
|
-
|
1237
|
-
function getName(map, name) {
|
1238
|
-
return Object.keys(map).reduce(function (prev, curr) {
|
1239
|
-
return toLower(name) === toLower(curr) ? curr : prev;
|
1240
|
-
}, null);
|
1241
|
-
}
|
1242
|
-
|
1243
|
-
function normalizeName(name) {
|
1244
|
-
|
1245
|
-
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
|
1246
|
-
throw new TypeError('Invalid character in header field name');
|
1247
|
-
}
|
1248
|
-
|
1249
|
-
return trim(name);
|
1250
|
-
}
|
1251
|
-
|
1252
|
-
/**
|
1253
|
-
* HTTP Response.
|
1254
|
-
*/
|
1255
|
-
|
1256
|
-
var Response = function Response(body, ref) {
|
1257
|
-
var url = ref.url;
|
1258
|
-
var headers = ref.headers;
|
1259
|
-
var status = ref.status;
|
1260
|
-
var statusText = ref.statusText;
|
1261
|
-
|
1262
|
-
|
1263
|
-
this.url = url;
|
1264
|
-
this.ok = status >= 200 && status < 300;
|
1265
|
-
this.status = status || 0;
|
1266
|
-
this.statusText = statusText || '';
|
1267
|
-
this.headers = new Headers(headers);
|
1268
|
-
this.body = body;
|
1269
|
-
|
1270
|
-
if (isString(body)) {
|
1271
|
-
|
1272
|
-
this.bodyText = body;
|
1273
|
-
|
1274
|
-
} else if (isBlob(body)) {
|
1275
|
-
|
1276
|
-
this.bodyBlob = body;
|
1277
|
-
|
1278
|
-
if (isBlobText(body)) {
|
1279
|
-
this.bodyText = blobText(body);
|
1280
|
-
}
|
1281
|
-
}
|
1282
|
-
};
|
1283
|
-
|
1284
|
-
Response.prototype.blob = function blob () {
|
1285
|
-
return when(this.bodyBlob);
|
1286
|
-
};
|
1287
|
-
|
1288
|
-
Response.prototype.text = function text () {
|
1289
|
-
return when(this.bodyText);
|
1290
|
-
};
|
1291
|
-
|
1292
|
-
Response.prototype.json = function json () {
|
1293
|
-
return when(this.text(), function (text) { return JSON.parse(text); });
|
1294
|
-
};
|
1295
|
-
|
1296
|
-
function blobText(body) {
|
1297
|
-
return new PromiseObj(function (resolve) {
|
1298
|
-
|
1299
|
-
var reader = new FileReader();
|
1300
|
-
|
1301
|
-
reader.readAsText(body);
|
1302
|
-
reader.onload = function () {
|
1303
|
-
resolve(reader.result);
|
1304
|
-
};
|
1305
|
-
|
1306
|
-
});
|
1307
|
-
}
|
1308
|
-
|
1309
|
-
function isBlobText(body) {
|
1310
|
-
return body.type.indexOf('text') === 0 || body.type.indexOf('json') !== -1;
|
1311
|
-
}
|
1312
|
-
|
1313
|
-
/**
|
1314
|
-
* HTTP Request.
|
1315
|
-
*/
|
1316
|
-
|
1317
|
-
var Request = function Request(options$$1) {
|
1318
|
-
|
1319
|
-
this.body = null;
|
1320
|
-
this.params = {};
|
1321
|
-
|
1322
|
-
assign(this, options$$1, {
|
1323
|
-
method: toUpper(options$$1.method || 'GET')
|
1324
|
-
});
|
1325
|
-
|
1326
|
-
if (!(this.headers instanceof Headers)) {
|
1327
|
-
this.headers = new Headers(this.headers);
|
1328
|
-
}
|
1329
|
-
};
|
1330
|
-
|
1331
|
-
Request.prototype.getUrl = function getUrl (){
|
1332
|
-
return Url(this);
|
1333
|
-
};
|
1334
|
-
|
1335
|
-
Request.prototype.getBody = function getBody (){
|
1336
|
-
return this.body;
|
1337
|
-
};
|
1338
|
-
|
1339
|
-
Request.prototype.respondWith = function respondWith (body, options$$1) {
|
1340
|
-
return new Response(body, assign(options$$1 || {}, {url: this.getUrl()}));
|
1341
|
-
};
|
1342
|
-
|
1343
|
-
/**
|
1344
|
-
* Service for sending network requests.
|
1345
|
-
*/
|
1346
|
-
|
1347
|
-
var COMMON_HEADERS = {'Accept': 'application/json, text/plain, */*'};
|
1348
|
-
var JSON_CONTENT_TYPE = {'Content-Type': 'application/json;charset=utf-8'};
|
1349
|
-
|
1350
|
-
function Http(options$$1) {
|
1351
|
-
|
1352
|
-
var self = this || {}, client = Client(self.$vm);
|
1353
|
-
|
1354
|
-
defaults(options$$1 || {}, self.$options, Http.options);
|
1355
|
-
|
1356
|
-
Http.interceptors.forEach(function (handler) {
|
1357
|
-
client.use(handler);
|
1358
|
-
});
|
1359
|
-
|
1360
|
-
return client(new Request(options$$1)).then(function (response) {
|
1361
|
-
|
1362
|
-
return response.ok ? response : PromiseObj.reject(response);
|
1363
|
-
|
1364
|
-
}, function (response) {
|
1365
|
-
|
1366
|
-
if (response instanceof Error) {
|
1367
|
-
error(response);
|
1368
|
-
}
|
1369
|
-
|
1370
|
-
return PromiseObj.reject(response);
|
1371
|
-
});
|
1372
|
-
}
|
1373
|
-
|
1374
|
-
Http.options = {};
|
1375
|
-
|
1376
|
-
Http.headers = {
|
1377
|
-
put: JSON_CONTENT_TYPE,
|
1378
|
-
post: JSON_CONTENT_TYPE,
|
1379
|
-
patch: JSON_CONTENT_TYPE,
|
1380
|
-
delete: JSON_CONTENT_TYPE,
|
1381
|
-
common: COMMON_HEADERS,
|
1382
|
-
custom: {}
|
1383
|
-
};
|
1384
|
-
|
1385
|
-
Http.interceptors = [before, method, body, jsonp, header, cors];
|
1386
|
-
|
1387
|
-
['get', 'delete', 'head', 'jsonp'].forEach(function (method$$1) {
|
1388
|
-
|
1389
|
-
Http[method$$1] = function (url, options$$1) {
|
1390
|
-
return this(assign(options$$1 || {}, {url: url, method: method$$1}));
|
1391
|
-
};
|
1392
|
-
|
1393
|
-
});
|
1394
|
-
|
1395
|
-
['post', 'put', 'patch'].forEach(function (method$$1) {
|
1396
|
-
|
1397
|
-
Http[method$$1] = function (url, body$$1, options$$1) {
|
1398
|
-
return this(assign(options$$1 || {}, {url: url, method: method$$1, body: body$$1}));
|
1399
|
-
};
|
1400
|
-
|
1401
|
-
});
|
1402
|
-
|
1403
|
-
/**
|
1404
|
-
* Service for interacting with RESTful services.
|
1405
|
-
*/
|
1406
|
-
|
1407
|
-
function Resource(url, params, actions, options$$1) {
|
1408
|
-
|
1409
|
-
var self = this || {}, resource = {};
|
1410
|
-
|
1411
|
-
actions = assign({},
|
1412
|
-
Resource.actions,
|
1413
|
-
actions
|
1414
|
-
);
|
1415
|
-
|
1416
|
-
each(actions, function (action, name) {
|
1417
|
-
|
1418
|
-
action = merge({url: url, params: assign({}, params)}, options$$1, action);
|
1419
|
-
|
1420
|
-
resource[name] = function () {
|
1421
|
-
return (self.$http || Http)(opts(action, arguments));
|
1422
|
-
};
|
1423
|
-
});
|
1424
|
-
|
1425
|
-
return resource;
|
1426
|
-
}
|
1427
|
-
|
1428
|
-
function opts(action, args) {
|
1429
|
-
|
1430
|
-
var options$$1 = assign({}, action), params = {}, body;
|
1431
|
-
|
1432
|
-
switch (args.length) {
|
1433
|
-
|
1434
|
-
case 2:
|
1435
|
-
|
1436
|
-
params = args[0];
|
1437
|
-
body = args[1];
|
1438
|
-
|
1439
|
-
break;
|
1440
|
-
|
1441
|
-
case 1:
|
1442
|
-
|
1443
|
-
if (/^(POST|PUT|PATCH)$/i.test(options$$1.method)) {
|
1444
|
-
body = args[0];
|
1445
|
-
} else {
|
1446
|
-
params = args[0];
|
1447
|
-
}
|
1448
|
-
|
1449
|
-
break;
|
1450
|
-
|
1451
|
-
case 0:
|
1452
|
-
|
1453
|
-
break;
|
1454
|
-
|
1455
|
-
default:
|
1456
|
-
|
1457
|
-
throw 'Expected up to 2 arguments [params, body], got ' + args.length + ' arguments';
|
1458
|
-
}
|
1459
|
-
|
1460
|
-
options$$1.body = body;
|
1461
|
-
options$$1.params = assign({}, options$$1.params, params);
|
1462
|
-
|
1463
|
-
return options$$1;
|
1464
|
-
}
|
1465
|
-
|
1466
|
-
Resource.actions = {
|
1467
|
-
|
1468
|
-
get: {method: 'GET'},
|
1469
|
-
save: {method: 'POST'},
|
1470
|
-
query: {method: 'GET'},
|
1471
|
-
update: {method: 'PUT'},
|
1472
|
-
remove: {method: 'DELETE'},
|
1473
|
-
delete: {method: 'DELETE'}
|
1474
|
-
|
1475
|
-
};
|
1476
|
-
|
1477
|
-
/**
|
1478
|
-
* Install plugin.
|
1479
|
-
*/
|
1480
|
-
|
1481
|
-
function plugin(Vue) {
|
1482
|
-
|
1483
|
-
if (plugin.installed) {
|
1484
|
-
return;
|
1485
|
-
}
|
1486
|
-
|
1487
|
-
Util(Vue);
|
1488
|
-
|
1489
|
-
Vue.url = Url;
|
1490
|
-
Vue.http = Http;
|
1491
|
-
Vue.resource = Resource;
|
1492
|
-
Vue.Promise = PromiseObj;
|
1493
|
-
|
1494
|
-
Object.defineProperties(Vue.prototype, {
|
1495
|
-
|
1496
|
-
$url: {
|
1497
|
-
get: function get() {
|
1498
|
-
return options(Vue.url, this, this.$options.url);
|
1499
|
-
}
|
1500
|
-
},
|
1501
|
-
|
1502
|
-
$http: {
|
1503
|
-
get: function get() {
|
1504
|
-
return options(Vue.http, this, this.$options.http);
|
1505
|
-
}
|
1506
|
-
},
|
1507
|
-
|
1508
|
-
$resource: {
|
1509
|
-
get: function get() {
|
1510
|
-
return Vue.resource.bind(this);
|
1511
|
-
}
|
1512
|
-
},
|
1513
|
-
|
1514
|
-
$promise: {
|
1515
|
-
get: function get() {
|
1516
|
-
var this$1 = this;
|
1517
|
-
|
1518
|
-
return function (executor) { return new Vue.Promise(executor, this$1); };
|
1519
|
-
}
|
1520
|
-
}
|
1521
|
-
|
1522
|
-
});
|
1523
|
-
}
|
1524
|
-
|
1525
|
-
if (typeof window !== 'undefined' && window.Vue) {
|
1526
|
-
window.Vue.use(plugin);
|
1527
|
-
}
|
1528
|
-
|
1529
|
-
return plugin;
|
1530
|
-
|
1531
|
-
})));
|