vsn 0.1.112 → 0.1.113

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.
@@ -0,0 +1 @@
1
+ foo
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>VSN Post Replace Test</title>
6
+ </head>
7
+ <body>
8
+
9
+ <div id="test"></div>
10
+
11
+ <form method="post" action="./xhr-response.html" vsn-xhr="#submit.@value = response">
12
+ <input type="hidden" name="csrf_token" value="1234567890" />
13
+ <input type="submit" value="Submit" id="submit" />
14
+ </form>
15
+
16
+ <a href="./xhr-response.html" vsn-xhr="#link.@text = response" id="link">Link</a>
17
+
18
+ <script type="text/javascript" src="vsn.js"></script>
19
+ </body>
20
+ </html>
@@ -0,0 +1,12 @@
1
+ import { Attribute } from "../Attribute";
2
+ import { Tree } from "../AST";
3
+ export declare class XHRAttribute extends Attribute {
4
+ static readonly canDefer: boolean;
5
+ protected tree: Tree;
6
+ get code(): any;
7
+ compile(): Promise<void>;
8
+ connect(): Promise<void>;
9
+ get isForm(): boolean;
10
+ get isAnchor(): boolean;
11
+ handleEvent(e: any): Promise<void>;
12
+ }
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
24
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
+ return new (P || (P = Promise))(function (resolve, reject) {
26
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+ var __generator = (this && this.__generator) || function (thisArg, body) {
33
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
34
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
35
+ function verb(n) { return function (v) { return step([n, v]); }; }
36
+ function step(op) {
37
+ if (f) throw new TypeError("Generator is already executing.");
38
+ while (_) try {
39
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
40
+ if (y = 0, t) op = [op[0] & 2, t.value];
41
+ switch (op[0]) {
42
+ case 0: case 1: t = op; break;
43
+ case 4: _.label++; return { value: op[1], done: false };
44
+ case 5: _.label++; y = op[1]; op = [0]; continue;
45
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
46
+ default:
47
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
48
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
49
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
50
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
51
+ if (t[2]) _.ops.pop();
52
+ _.trys.pop(); continue;
53
+ }
54
+ op = body.call(thisArg, _);
55
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
56
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
57
+ }
58
+ };
59
+ Object.defineProperty(exports, "__esModule", { value: true });
60
+ exports.XHRAttribute = void 0;
61
+ var Registry_1 = require("../Registry");
62
+ var Attribute_1 = require("../Attribute");
63
+ var AST_1 = require("../AST");
64
+ var XHRAttribute = /** @class */ (function (_super) {
65
+ __extends(XHRAttribute, _super);
66
+ function XHRAttribute() {
67
+ return _super !== null && _super.apply(this, arguments) || this;
68
+ }
69
+ Object.defineProperty(XHRAttribute.prototype, "code", {
70
+ get: function () {
71
+ return this.getAttributeValue();
72
+ },
73
+ enumerable: false,
74
+ configurable: true
75
+ });
76
+ XHRAttribute.prototype.compile = function () {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ return __generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0:
81
+ this.tree = new AST_1.Tree(this.code);
82
+ return [4 /*yield*/, this.tree.prepare(this.tag.scope, this.tag.dom, this.tag)];
83
+ case 1:
84
+ _a.sent();
85
+ return [4 /*yield*/, _super.prototype.compile.call(this)];
86
+ case 2:
87
+ _a.sent();
88
+ return [2 /*return*/];
89
+ }
90
+ });
91
+ });
92
+ };
93
+ XHRAttribute.prototype.connect = function () {
94
+ return __awaiter(this, void 0, void 0, function () {
95
+ return __generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0:
98
+ if (this.isForm) {
99
+ this.tag.addEventHandler('submit', this.getAttributeModifiers(), this.handleEvent, this);
100
+ }
101
+ else if (this.isAnchor) {
102
+ this.tag.addEventHandler('click', this.getAttributeModifiers(), this.handleEvent, this);
103
+ }
104
+ return [4 /*yield*/, _super.prototype.connect.call(this)];
105
+ case 1:
106
+ _a.sent();
107
+ return [2 /*return*/];
108
+ }
109
+ });
110
+ });
111
+ };
112
+ Object.defineProperty(XHRAttribute.prototype, "isForm", {
113
+ get: function () {
114
+ return this.tag.element.tagName === 'FORM';
115
+ },
116
+ enumerable: false,
117
+ configurable: true
118
+ });
119
+ Object.defineProperty(XHRAttribute.prototype, "isAnchor", {
120
+ get: function () {
121
+ return this.tag.element.tagName === 'A';
122
+ },
123
+ enumerable: false,
124
+ configurable: true
125
+ });
126
+ XHRAttribute.prototype.handleEvent = function (e) {
127
+ return __awaiter(this, void 0, void 0, function () {
128
+ var request, method, url, data;
129
+ var _this = this;
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ e.preventDefault();
134
+ request = new XMLHttpRequest();
135
+ request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
136
+ if (this.isForm) {
137
+ url = this.tag.element.getAttribute('action');
138
+ method = this.getAttributeBinding(this.tag.element.getAttribute('method'));
139
+ data = new FormData(this.tag.element);
140
+ }
141
+ else if (this.isAnchor) {
142
+ url = this.tag.element.getAttribute('href');
143
+ method = this.getAttributeBinding('GET');
144
+ }
145
+ request.onload = function () { return __awaiter(_this, void 0, void 0, function () {
146
+ return __generator(this, function (_a) {
147
+ switch (_a.label) {
148
+ case 0:
149
+ this.tag.scope.set('status', request.status);
150
+ if (!(request.status >= 200 && request.status < 300)) return [3 /*break*/, 2];
151
+ this.tag.scope.set('response', request.response);
152
+ return [4 /*yield*/, this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag)];
153
+ case 1:
154
+ _a.sent();
155
+ return [3 /*break*/, 3];
156
+ case 2:
157
+ console.error(request.statusText);
158
+ _a.label = 3;
159
+ case 3: return [2 /*return*/];
160
+ }
161
+ });
162
+ }); };
163
+ request.open(method, url);
164
+ request.send(data);
165
+ return [4 /*yield*/, this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag)];
166
+ case 1:
167
+ _a.sent();
168
+ return [2 /*return*/];
169
+ }
170
+ });
171
+ });
172
+ };
173
+ XHRAttribute.canDefer = false;
174
+ XHRAttribute = __decorate([
175
+ Registry_1.Registry.attribute('vsn-xhr')
176
+ ], XHRAttribute);
177
+ return XHRAttribute;
178
+ }(Attribute_1.Attribute));
179
+ exports.XHRAttribute = XHRAttribute;
180
+ //# sourceMappingURL=XHRAttribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"XHRAttribute.js","sourceRoot":"","sources":["../../src/attributes/XHRAttribute.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAqC;AACrC,0CAAuC;AACvC,8BAA4B;AAG5B;IAAkC,gCAAS;IAA3C;;IA6DA,CAAC;IAzDG,sBAAW,8BAAI;aAAf;YACI,OAAO,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACpC,CAAC;;;OAAA;IAEY,8BAAO,GAApB;;;;;wBACI,IAAI,CAAC,IAAI,GAAG,IAAI,UAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;wBAChC,qBAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAA;;wBAA/D,SAA+D,CAAC;wBAChE,qBAAM,iBAAM,OAAO,WAAE,EAAA;;wBAArB,SAAqB,CAAC;;;;;KACzB;IAEY,8BAAO,GAApB;;;;;wBACI,IAAI,IAAI,CAAC,MAAM,EAAE;4BACb,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,QAAQ,EAAE,IAAI,C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IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;yBAC5C;wBAED,OAAO,CAAC,MAAM,GAAG;;;;wCACb,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;6CACzC,CAAA,OAAO,CAAC,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA,EAA7C,wBAA6C;wCAC7C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;wCACjD,qBAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAA;;wCAAhE,SAAgE,CAAC;;;wCAEjE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;;;;;6BAEzC,CAAA;wBACD,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;wBAC1B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;wBAEnB,qBAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAA;;wBAAhE,SAAgE,CAAC;;;;;KACpE;IA3DsB,qBAAQ,GAAY,KAAK,CAAC;IADxC,YAAY;QADxB,mBAAQ,CAAC,SAAS,CAAC,SAAS,CAAC;OACjB,YAAY,CA6DxB;IAAD,mBAAC;CAAA,AA7DD,CAAkC,qBAAS,GA6D1C;AA7DY,oCAAY"}
@@ -27,3 +27,4 @@ export { StandardAttribute } from "./StandardAttribute";
27
27
  export { StyleAttribute } from "./StyleAttribute";
28
28
  export { TemplateAttribute } from "./TemplateAttribute";
29
29
  export { TypeAttribute } from "./TypeAttribute";
30
+ export { XHRAttribute } from "./XHRAttribute";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeAttribute = exports.TemplateAttribute = exports.StyleAttribute = exports.StandardAttribute = exports.SetAttribute = exports.ServiceAttribute = exports.ScriptAttribute = exports.ScopeChange = exports.ScopeAttribute = exports.RootAttribute = exports.Referenced = exports.On = exports.Name = exports.ModelAttribute = exports.ListItemModel = exports.ListItem = exports.List = exports.LazyAttribute = exports.KeyUp = exports.KeyDown = exports.JSONAttribute = exports.If = exports.Format = exports.Exec = exports.DisableIf = exports.ControllerAttribute = exports.ComponentAttribute = exports.Bind = exports.AddClassIf = void 0;
3
+ exports.XHRAttribute = exports.TypeAttribute = exports.TemplateAttribute = exports.StyleAttribute = exports.StandardAttribute = exports.SetAttribute = exports.ServiceAttribute = exports.ScriptAttribute = exports.ScopeChange = exports.ScopeAttribute = exports.RootAttribute = exports.Referenced = exports.On = exports.Name = exports.ModelAttribute = exports.ListItemModel = exports.ListItem = exports.List = exports.LazyAttribute = exports.KeyUp = exports.KeyDown = exports.JSONAttribute = exports.If = exports.Format = exports.Exec = exports.DisableIf = exports.ControllerAttribute = exports.ComponentAttribute = exports.Bind = exports.AddClassIf = void 0;
4
4
  var AddClassIf_1 = require("./AddClassIf");
5
5
  Object.defineProperty(exports, "AddClassIf", { enumerable: true, get: function () { return AddClassIf_1.AddClassIf; } });
6
6
  var Bind_1 = require("./Bind");
@@ -59,4 +59,6 @@ var TemplateAttribute_1 = require("./TemplateAttribute");
59
59
  Object.defineProperty(exports, "TemplateAttribute", { enumerable: true, get: function () { return TemplateAttribute_1.TemplateAttribute; } });
60
60
  var TypeAttribute_1 = require("./TypeAttribute");
61
61
  Object.defineProperty(exports, "TypeAttribute", { enumerable: true, get: function () { return TypeAttribute_1.TypeAttribute; } });
62
+ var XHRAttribute_1 = require("./XHRAttribute");
63
+ Object.defineProperty(exports, "XHRAttribute", { enumerable: true, get: function () { return XHRAttribute_1.XHRAttribute; } });
62
64
  //# sourceMappingURL=_imports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_imports.js","sourceRoot":"","sources":["../../src/attributes/_imports.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAAhC,wGAAA,UAAU,OAAA;AAClB,+BAA4B;AAApB,4FAAA,IAAI,OAAA;AACZ,2DAAwD;AAAhD,wHAAA,kBAAkB,OAAA;AAC1B,6DAA0D;AAAlD,0HAAA,mBAAmB,OAAA;AAC3B,yCAAsC;AAA9B,sGAAA,SAAS,OAAA;AACjB,+BAA4B;AAApB,4FAAA,IAAI,OAAA;AACZ,mCAAgC;AAAxB,gGAAA,MAAM,OAAA;AACd,2BAAwB;AAAhB,wFAAA,EAAE,OAAA;AACV,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,qCAAkC;AAA1B,kGAAA,OAAO,OAAA;AACf,iCAA8B;AAAtB,8FAAA,KAAK,OAAA;AACb,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,+BAA4B;AAApB,4FAAA,IAAI,OAAA;AACZ,uCAAoC;AAA5B,oGAAA,QAAQ,OAAA;AAChB,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,mDAAgD;AAAxC,gHAAA,cAAc,OAAA;AACtB,+BAA4B;AAApB,4FAAA,IAAI,OAAA;AACZ,2BAAwB;AAAhB,wFAAA,EAAE,OAAA;AACV,2CAAwC;AAAhC,wGAAA,UAAU,OAAA;AAClB,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,mDAAgD;AAAxC,gHAAA,cAAc,OAAA;AACtB,6CAA0C;AAAlC,0GAAA,WAAW,OAAA;AACnB,qDAAkD;AAA1C,kHAAA,eAAe,OAAA;AACvB,uDAAoD;AAA5C,oHAAA,gBAAgB,OAAA;AACxB,+CAA4C;AAApC,4GAAA,YAAY,OAAA;AACpB,yDAAsD;AAA9C,sHAAA,iBA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A;AACpB,yDAAsD;AAA9C,sHAAA,iBAAiB,OAAA;AACzB,mDAAgD;AAAxC,gHAAA,cAAc,OAAA;AACtB,yDAAsD;AAA9C,sHAAA,iBAAiB,OAAA;AACzB,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,+CAA4C;AAApC,4GAAA,YAAY,OAAA"}
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.112";
1
+ export declare const VERSION = "0.1.113";
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.1.112';
4
+ exports.VERSION = '0.1.113';
5
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.112",
3
+ "version": "0.1.113",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
@@ -0,0 +1,67 @@
1
+ import {Registry} from "../Registry";
2
+ import {Attribute} from "../Attribute";
3
+ import {Tree} from "../AST";
4
+
5
+ @Registry.attribute('vsn-xhr')
6
+ export class XHRAttribute extends Attribute {
7
+ public static readonly canDefer: boolean = false;
8
+ protected tree: Tree;
9
+
10
+ public get code() {
11
+ return this.getAttributeValue();
12
+ }
13
+
14
+ public async compile() {
15
+ this.tree = new Tree(this.code);
16
+ await this.tree.prepare(this.tag.scope, this.tag.dom, this.tag);
17
+ await super.compile();
18
+ }
19
+
20
+ public async connect() {
21
+ if (this.isForm) {
22
+ this.tag.addEventHandler('submit', this.getAttributeModifiers(), this.handleEvent, this);
23
+ } else if (this.isAnchor) {
24
+ this.tag.addEventHandler('click', this.getAttributeModifiers(), this.handleEvent, this);
25
+ }
26
+ await super.connect();
27
+ }
28
+
29
+ public get isForm() {
30
+ return this.tag.element.tagName === 'FORM';
31
+ }
32
+
33
+ public get isAnchor() {
34
+ return this.tag.element.tagName === 'A';
35
+ }
36
+
37
+ public async handleEvent(e) {
38
+ e.preventDefault();
39
+ const request = new XMLHttpRequest();
40
+ request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
41
+ let method;
42
+ let url;
43
+ let data;
44
+ if (this.isForm) {
45
+ url = this.tag.element.getAttribute('action');
46
+ method = this.getAttributeBinding(this.tag.element.getAttribute('method'));
47
+ data = new FormData(this.tag.element as HTMLFormElement);
48
+ } else if (this.isAnchor) {
49
+ url = this.tag.element.getAttribute('href');
50
+ method = this.getAttributeBinding('GET');
51
+ }
52
+
53
+ request.onload = async () => {
54
+ this.tag.scope.set('status', request.status);
55
+ if (request.status >= 200 && request.status < 300) {
56
+ this.tag.scope.set('response', request.response);
57
+ await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
58
+ } else {
59
+ console.error(request.statusText);
60
+ }
61
+ }
62
+ request.open(method, url);
63
+ request.send(data);
64
+
65
+ await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
66
+ }
67
+ }
@@ -27,3 +27,4 @@ export {StandardAttribute} from "./StandardAttribute";
27
27
  export {StyleAttribute} from "./StyleAttribute";
28
28
  export {TemplateAttribute} from "./TemplateAttribute";
29
29
  export {TypeAttribute} from "./TypeAttribute";
30
+ export {XHRAttribute} from "./XHRAttribute";
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.112';
1
+ export const VERSION = '0.1.113';
2
2