vsn 0.1.117 → 0.1.119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/service.html +2 -1
- package/demo/vsn.js +2 -2
- package/demo/xhr-test.html +8 -2
- package/dist/AST/XHRNode.js +4 -1
- package/dist/AST/XHRNode.js.map +1 -1
- package/dist/Scope/ScopeDataAbstract.d.ts +2 -0
- package/dist/Scope/ScopeDataAbstract.js +4 -0
- package/dist/Scope/ScopeDataAbstract.js.map +1 -1
- package/dist/Scope/properties/Property.d.ts +1 -0
- package/dist/Scope/properties/Property.js +22 -1
- package/dist/Scope/properties/Property.js.map +1 -1
- package/dist/Tag.d.ts +1 -0
- package/dist/attributes/Exec.d.ts +1 -0
- package/dist/attributes/Exec.js +21 -3
- package/dist/attributes/Exec.js.map +1 -1
- package/dist/attributes/XHRAttribute.js +18 -1
- package/dist/attributes/XHRAttribute.js.map +1 -1
- package/dist/contrib/XHR.d.ts +21 -0
- package/dist/contrib/XHR.js +78 -0
- package/dist/contrib/XHR.js.map +1 -0
- package/dist/contrib/_imports.d.ts +1 -0
- package/dist/contrib/_imports.js +6 -0
- package/dist/contrib/_imports.js.map +1 -0
- package/dist/demo/ServiceDemo.d.ts +1 -1
- package/dist/demo/ServiceDemo.js +42 -1
- package/dist/demo/ServiceDemo.js.map +1 -1
- package/dist/demo.min.js +3 -0
- package/dist/demo.min.js.LICENSE.txt +9 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vsn.min.js +3 -0
- package/dist/vsn.min.js.LICENSE.txt +9 -0
- package/package.json +1 -1
- package/src/AST/XHRNode.ts +4 -1
- package/src/Scope/ScopeDataAbstract.ts +8 -0
- package/src/Scope/properties/Property.ts +23 -0
- package/src/Tag.ts +25 -6
- package/src/attributes/Exec.ts +9 -1
- package/src/attributes/XHRAttribute.ts +19 -0
- package/src/contrib/XHR.ts +46 -0
- package/src/contrib/_imports.ts +1 -0
- package/src/demo/ServiceDemo.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
|
4
|
+
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
5
|
+
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
6
|
+
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
7
|
+
* Code distributed by Google as part of the polymer project is also
|
|
8
|
+
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
9
|
+
*/
|
package/package.json
CHANGED
package/src/AST/XHRNode.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface IScopeData {
|
|
|
8
8
|
export class ScopeDataAbstract extends EventDispatcher {
|
|
9
9
|
[key: string]: any;
|
|
10
10
|
__properties__: string[];
|
|
11
|
+
__methods__: string[];
|
|
11
12
|
protected _lastData: any;
|
|
12
13
|
|
|
13
14
|
constructor() {
|
|
@@ -16,6 +17,13 @@ export class ScopeDataAbstract extends EventDispatcher {
|
|
|
16
17
|
// Objects may have __properties__ from prototype
|
|
17
18
|
if(!this['__properties__'])
|
|
18
19
|
this.__properties__ = [];
|
|
20
|
+
|
|
21
|
+
if(!this['__methods__'])
|
|
22
|
+
this.__methods__ = [];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
createMethod(name: string, method: (...args: any[]) => any) {
|
|
26
|
+
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
createProperty(name: string, propertyType: any = Property, config?: IPropertyConfig): any {
|
|
@@ -24,6 +24,29 @@ export function property(propertyType = Property, config: {} | null = {}) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export function method(config: {} | null = {}) {
|
|
28
|
+
return function(target: any, key: string) {
|
|
29
|
+
if(target.__methods__ == undefined) {
|
|
30
|
+
target.__methods__ = [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Abstract/extended classes share __properties__
|
|
34
|
+
if(target.__methods__.indexOf(key) == -1)
|
|
35
|
+
target.__methods__.push(key);
|
|
36
|
+
|
|
37
|
+
const getter = function() {
|
|
38
|
+
return config;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
Object.defineProperty(target, '__'+key+'__', {
|
|
42
|
+
get: getter,
|
|
43
|
+
set: v => {},
|
|
44
|
+
enumerable:false,
|
|
45
|
+
configurable: true
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
27
50
|
export type TValidator = (value: any) => string[];
|
|
28
51
|
|
|
29
52
|
export interface IPropertyConfig {
|
package/src/Tag.ts
CHANGED
|
@@ -39,7 +39,24 @@ export class Tag extends DOMObject {
|
|
|
39
39
|
'@html',
|
|
40
40
|
'@class',
|
|
41
41
|
'@value',
|
|
42
|
-
'@disabled'
|
|
42
|
+
'@disabled',
|
|
43
|
+
'@hidden',
|
|
44
|
+
'@selected',
|
|
45
|
+
'@readonly',
|
|
46
|
+
'@multiple',
|
|
47
|
+
'@required',
|
|
48
|
+
'@autofocus',
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
public static readonly flagAttributes: string[] = [
|
|
52
|
+
'@disabled',
|
|
53
|
+
'@hidden',
|
|
54
|
+
'@checked',
|
|
55
|
+
'@selected',
|
|
56
|
+
'@readonly',
|
|
57
|
+
'@multiple',
|
|
58
|
+
'@required',
|
|
59
|
+
'@autofocus',
|
|
43
60
|
];
|
|
44
61
|
|
|
45
62
|
protected inputTags: string[] = [
|
|
@@ -396,11 +413,12 @@ export class Tag extends DOMObject {
|
|
|
396
413
|
const classes: string[] = value instanceof Array ? value : [value];
|
|
397
414
|
if (classes.length)
|
|
398
415
|
this.element.classList.add(...classes);
|
|
399
|
-
} else if (key
|
|
416
|
+
} else if (Tag.flagAttributes.indexOf(key) > -1) {
|
|
417
|
+
const attrKey = key.replace('@', '');
|
|
400
418
|
if (!!value) {
|
|
401
|
-
this.element.setAttribute(
|
|
419
|
+
this.element.setAttribute(attrKey, '');
|
|
402
420
|
} else {
|
|
403
|
-
this.element.removeAttribute(
|
|
421
|
+
this.element.removeAttribute(attrKey);
|
|
404
422
|
}
|
|
405
423
|
}
|
|
406
424
|
} else {
|
|
@@ -418,8 +436,9 @@ export class Tag extends DOMObject {
|
|
|
418
436
|
return this.value;
|
|
419
437
|
else if (key === '@class') {
|
|
420
438
|
return Array.from(this.element.classList);
|
|
421
|
-
} else if (key
|
|
422
|
-
|
|
439
|
+
} else if (Tag.flagAttributes.indexOf(key) > -1) {
|
|
440
|
+
const attrKey = key.replace('@', '');
|
|
441
|
+
return this.element.hasAttribute(attrKey);
|
|
423
442
|
}
|
|
424
443
|
}
|
|
425
444
|
return this.element.getAttribute(key);
|
package/src/attributes/Exec.ts
CHANGED
|
@@ -18,7 +18,15 @@ export class Exec extends Attribute {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
public async extract() {
|
|
21
|
-
|
|
21
|
+
if (this.hasModifier('defer')) {
|
|
22
|
+
this.tag.dom.once('built', () => this.execute());
|
|
23
|
+
} else {
|
|
24
|
+
await this.execute();
|
|
25
|
+
}
|
|
22
26
|
await super.extract();
|
|
23
27
|
}
|
|
28
|
+
|
|
29
|
+
public async execute() {
|
|
30
|
+
await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
|
|
31
|
+
}
|
|
24
32
|
}
|
|
@@ -2,6 +2,7 @@ import {Registry} from "../Registry";
|
|
|
2
2
|
import {Attribute} from "../Attribute";
|
|
3
3
|
import {Tree} from "../AST";
|
|
4
4
|
import {VisionHelper} from "../helpers/VisionHelper";
|
|
5
|
+
import {XHR} from "../contrib/XHR";
|
|
5
6
|
|
|
6
7
|
@Registry.attribute('vsn-xhr')
|
|
7
8
|
export class XHRAttribute extends Attribute {
|
|
@@ -61,12 +62,30 @@ export class XHRAttribute extends Attribute {
|
|
|
61
62
|
} else if (this.isAnchor) {
|
|
62
63
|
url = this.tag.element.getAttribute('href');
|
|
63
64
|
method = this.getAttributeBinding('GET');
|
|
65
|
+
method = method.toUpperCase();
|
|
66
|
+
if (['POST', 'PUT'].indexOf(method) > -1) {
|
|
67
|
+
formData = new FormData();
|
|
68
|
+
}
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
this.request.addEventListener('loadend', this.handleXHREvent.bind(this));
|
|
67
72
|
this.request.addEventListener('error', this.handleXHREvent.bind(this));
|
|
68
73
|
this.request.open(method, url);
|
|
69
74
|
this.request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
75
|
+
const siteHeaders = XHR.instance.getHeaders();
|
|
76
|
+
for (const key in siteHeaders) {
|
|
77
|
+
this.request.setRequestHeader(key, siteHeaders[key]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (formData instanceof FormData) {
|
|
81
|
+
const siteFormData = XHR.instance.getFormData();
|
|
82
|
+
if (siteFormData) {
|
|
83
|
+
for (const key in siteFormData) {
|
|
84
|
+
formData.append(key, siteFormData[key]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
70
89
|
this.request.send(formData);
|
|
71
90
|
}
|
|
72
91
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {Registry} from "../Registry";
|
|
2
|
+
import {Service} from "../Service";
|
|
3
|
+
import {property} from "../Scope/properties/Property";
|
|
4
|
+
|
|
5
|
+
@Registry.service('XHR')
|
|
6
|
+
export class XHR extends Service {
|
|
7
|
+
@property()
|
|
8
|
+
public readonly siteHeaders: { [key: string]: {[key: string]: string}} = {};
|
|
9
|
+
|
|
10
|
+
@property()
|
|
11
|
+
public readonly siteFormData: { [key: string]: {[key: string]: string}} = {};
|
|
12
|
+
|
|
13
|
+
public addHeader(key: string, value: string, site: string = null) {
|
|
14
|
+
if (site === null)
|
|
15
|
+
site = window.location.hostname;
|
|
16
|
+
|
|
17
|
+
if (!this.siteHeaders[site]) {
|
|
18
|
+
this.siteHeaders[site] = {};
|
|
19
|
+
}
|
|
20
|
+
this.siteHeaders[site][key] = value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public addFormData(key: string, value: string, site: string = null) {
|
|
24
|
+
if (site === null)
|
|
25
|
+
site = window.location.hostname;
|
|
26
|
+
|
|
27
|
+
if (!this.siteFormData[site]) {
|
|
28
|
+
this.siteFormData[site] = {};
|
|
29
|
+
}
|
|
30
|
+
this.siteFormData[site][key] = value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public getHeaders(site: string = null) {
|
|
34
|
+
if (site === null)
|
|
35
|
+
site = window.location.hostname;
|
|
36
|
+
|
|
37
|
+
return this.siteHeaders[site];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public getFormData(site: string = null) {
|
|
41
|
+
if (site === null)
|
|
42
|
+
site = window.location.hostname;
|
|
43
|
+
|
|
44
|
+
return this.siteFormData[site];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {XHR} from "./XHR";
|
package/src/demo/ServiceDemo.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.119';
|
|
2
2
|
|