@webqit/webflo 0.9.0-0 → 0.9.2
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/package.json +2 -2
- package/src/runtime-pi/client/Runtime.js +8 -4
- package/src/runtime-pi/client/RuntimeClient.js +2 -5
- package/src/runtime-pi/server/Runtime.js +2 -2
- package/src/runtime-pi/server/RuntimeClient.js +3 -2
- package/src/runtime-pi/server/whatwag.js +9 -12
- package/src/runtime-pi/xHttpMessage.js +2 -2
- package/src/runtime-pi/xRequest.js +2 -2
- package/src/runtime-pi/xResponse.js +4 -3
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"vanila-javascript"
|
|
13
13
|
],
|
|
14
14
|
"homepage": "https://webqit.io/tooling/webflo",
|
|
15
|
-
"version": "0.9.
|
|
15
|
+
"version": "0.9.2",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@octokit/webhooks": "^7.15.1",
|
|
39
39
|
"@webqit/backpack": "^0.0.37",
|
|
40
|
-
"@webqit/oohtml-ssr": "^1.0.
|
|
40
|
+
"@webqit/oohtml-ssr": "^1.0.3",
|
|
41
41
|
"@webqit/util": "^0.8.9",
|
|
42
42
|
"client-sessions": "^0.8.0",
|
|
43
43
|
"form-data-encoder": "^1.6.0",
|
|
@@ -22,8 +22,8 @@ const FormData = xFormData(whatwag.FormData);
|
|
|
22
22
|
const ReadableStream = whatwag.ReadableStream;
|
|
23
23
|
const RequestHeaders = xRequestHeaders(whatwag.Headers);
|
|
24
24
|
const ResponseHeaders = xResponseHeaders(whatwag.Headers);
|
|
25
|
-
const Request = xRequest(whatwag.Request, RequestHeaders, FormData);
|
|
26
|
-
const Response = xResponse(whatwag.Response, ResponseHeaders, FormData);
|
|
25
|
+
const Request = xRequest(whatwag.Request, RequestHeaders, FormData, whatwag.Blob);
|
|
26
|
+
const Response = xResponse(whatwag.Response, ResponseHeaders, FormData, whatwag.Blob);
|
|
27
27
|
const fetch = xfetch(whatwag.fetch);
|
|
28
28
|
const HttpEvent = xHttpEvent(Request, Response, URL);
|
|
29
29
|
|
|
@@ -101,7 +101,7 @@ export default class Runtime {
|
|
|
101
101
|
if (!anchor.target && !anchor.download && (!anchor.origin || anchor.origin === this.location.origin)) {
|
|
102
102
|
if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) return;
|
|
103
103
|
// Publish everything, including hash
|
|
104
|
-
this.go(Url.copy(anchor), { src: anchor, srcType: 'link', });
|
|
104
|
+
this.go(Url.copy(anchor), {}, { src: anchor, srcType: 'link', });
|
|
105
105
|
// URLs with # will cause a natural navigation
|
|
106
106
|
// even if pointing to a different page, a natural navigation will still happen
|
|
107
107
|
// because with the Observer.set() above, window.document.location.href would have become
|
|
@@ -144,7 +144,11 @@ export default class Runtime {
|
|
|
144
144
|
actionEl.search = wwwFormSerialize(query);
|
|
145
145
|
formData = null;
|
|
146
146
|
}
|
|
147
|
-
this.go(Url.copy(actionEl), {
|
|
147
|
+
this.go(Url.copy(actionEl), {
|
|
148
|
+
method: submitParams.method,
|
|
149
|
+
body: formData,
|
|
150
|
+
headers: { contentType: submitParams.enctype },
|
|
151
|
+
}, { ...submitParams, src: form, srcType: 'form', });
|
|
148
152
|
// URLs with # will cause a natural navigation
|
|
149
153
|
// even if pointing to a different page, a natural navigation will still happen
|
|
150
154
|
// because with the Observer.set() above, window.document.location.href would have become
|
|
@@ -83,7 +83,7 @@ export default class RuntimeClient {
|
|
|
83
83
|
window.document.setState({ page: data }, { update: 'merge' });
|
|
84
84
|
window.document.body.setAttribute('template', 'page/' + httpEvent.url.pathname.split('/').filter(a => a).map(a => a + '+-').join('/'));
|
|
85
85
|
await new Promise(res => (window.document.templatesReadyState === 'complete' && res(), window.document.addEventListener('templatesreadystatechange', res)));
|
|
86
|
-
return
|
|
86
|
+
return window;
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -97,16 +97,13 @@ export default class RuntimeClient {
|
|
|
97
97
|
async scrollIntoView(httpEvent) {
|
|
98
98
|
if (!(httpEvent.detail.src instanceof Element)) return;
|
|
99
99
|
await new Promise(res => setTimeout(res, 10));
|
|
100
|
-
let viewportTop;
|
|
100
|
+
let viewportTop, urlTarget;
|
|
101
101
|
if (httpEvent.url.hash && (urlTarget = document.querySelector(httpEvent.url.hash))) {
|
|
102
102
|
urlTarget.scrollIntoView();
|
|
103
103
|
} else if (viewportTop = Array.from(document.querySelectorAll('[data-viewport-top]')).pop()) {
|
|
104
104
|
viewportTop.focus();
|
|
105
105
|
} else {
|
|
106
|
-
document.documentElement.classList.add('scroll-reset');
|
|
107
106
|
document.body.scrollIntoView();
|
|
108
|
-
await new Promise(res => setTimeout(res, 600));
|
|
109
|
-
document.documentElement.classList.remove('scroll-reset');
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
109
|
|
|
@@ -28,8 +28,8 @@ const FormData = xFormData(whatwag.FormData);
|
|
|
28
28
|
const ReadableStream = whatwag.ReadableStream;
|
|
29
29
|
const RequestHeaders = xRequestHeaders(whatwag.Headers);
|
|
30
30
|
const ResponseHeaders = xResponseHeaders(whatwag.Headers);
|
|
31
|
-
const Request = xRequest(whatwag.Request, RequestHeaders, FormData);
|
|
32
|
-
const Response = xResponse(whatwag.Response, ResponseHeaders, FormData);
|
|
31
|
+
const Request = xRequest(whatwag.Request, RequestHeaders, FormData, whatwag.Blob);
|
|
32
|
+
const Response = xResponse(whatwag.Response, ResponseHeaders, FormData, whatwag.Blob);
|
|
33
33
|
const fetch = xfetch(whatwag.fetch);
|
|
34
34
|
const HttpEvent = xHttpEvent(Request, Response, URL);
|
|
35
35
|
|
|
@@ -70,7 +70,7 @@ export default class RuntimeClient {
|
|
|
70
70
|
// Renderer
|
|
71
71
|
async render(httpEvent, router, response) {
|
|
72
72
|
let data = await response.json();
|
|
73
|
-
|
|
73
|
+
let rendering = await router.route('render', httpEvent, data, async (httpEvent, data) => {
|
|
74
74
|
var renderFile, pathnameSplit = httpEvent.url.pathname.split('/');
|
|
75
75
|
while ((renderFile = Path.join(this.cx.CWD, this.cx.layout.PUBLIC_DIR, './' + pathnameSplit.join('/'), 'index.html'))
|
|
76
76
|
&& (this.renderFileCache[renderFile] === false/* false on previous runs */ || !Fs.existsSync(renderFile))) {
|
|
@@ -95,8 +95,9 @@ export default class RuntimeClient {
|
|
|
95
95
|
window.document.setState({ page: data, url: httpEvent.url }, { update: 'merge' });
|
|
96
96
|
window.document.body.setAttribute('template', 'page/' + httpEvent.url.pathname.split('/').filter(a => a).map(a => a + '+-').join('/'));
|
|
97
97
|
await new Promise(res => setTimeout(res, 10));
|
|
98
|
-
return window
|
|
98
|
+
return window;
|
|
99
99
|
});
|
|
100
|
+
return rendering + '';
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
}
|
|
@@ -8,29 +8,26 @@ import fetch, { Request, Response, Headers } from 'node-fetch';
|
|
|
8
8
|
import { FormDataEncoder } from 'form-data-encoder';
|
|
9
9
|
import { Readable } from "stream";
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Patch MessageStream with formData()
|
|
13
|
-
*/
|
|
14
|
-
const _streamFormDataPatch = MessageStream => class extends MessageStream {
|
|
15
|
-
// formData() polyfill
|
|
16
|
-
async formData() { return null; }
|
|
17
|
-
};
|
|
18
|
-
|
|
19
11
|
/**
|
|
20
12
|
* The NavigationEvent class
|
|
21
13
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
if (!Request.prototype.formData) {
|
|
15
|
+
Request.prototype.formData = async function() { return null }
|
|
16
|
+
}
|
|
17
|
+
if (!Response.prototype.formData) {
|
|
18
|
+
Response.prototype.formData = async function() { return null }
|
|
19
|
+
}
|
|
24
20
|
FormData.encode = formData => {
|
|
25
21
|
const encoder = new FormDataEncoder(formData);
|
|
26
22
|
return [ Readable.from(encoder.encode()), encoder.headers ];
|
|
27
23
|
};
|
|
24
|
+
|
|
28
25
|
export {
|
|
29
26
|
URL,
|
|
30
27
|
fetch,
|
|
31
28
|
Headers,
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
Request,
|
|
30
|
+
Response,
|
|
34
31
|
FormData,
|
|
35
32
|
Readable as ReadableStream,
|
|
36
33
|
File,
|
|
@@ -123,7 +123,7 @@ const xHttpMessage = (whatwagHttpMessage, Headers, FormData) => {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
export default xHttpMessage;
|
|
126
|
-
export function encodeBody(body, FormData) {
|
|
126
|
+
export function encodeBody(body, FormData, Blob) {
|
|
127
127
|
const detailsObj = { body, input: body };
|
|
128
128
|
const encodeFormData = (detailsObj, formData) => {
|
|
129
129
|
if (!FormData.encode) return;
|
|
@@ -170,7 +170,7 @@ export function encodeBody(body, FormData) {
|
|
|
170
170
|
detailsObj.body = JSON.stringify(body);
|
|
171
171
|
detailsObj.headers = {
|
|
172
172
|
contentType: 'application/json',
|
|
173
|
-
contentLength: Buffer.byteLength(detailsObj.body, 'utf8')
|
|
173
|
+
contentLength: (new Blob([ detailsObj.body ])).size, // Buffer.byteLength(detailsObj.body, 'utf8') isn't cross-environment
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
detailsObj.resolved = body;
|
|
@@ -7,7 +7,7 @@ import xHttpMessage, { encodeBody } from './xHttpMessage.js';
|
|
|
7
7
|
/**
|
|
8
8
|
* The xRequest Mixin
|
|
9
9
|
*/
|
|
10
|
-
const xRequest = (whatwagRequest, Headers, FormData) => class extends xHttpMessage(whatwagRequest, Headers, FormData) {
|
|
10
|
+
const xRequest = (whatwagRequest, Headers, FormData, Blob) => class extends xHttpMessage(whatwagRequest, Headers, FormData) {
|
|
11
11
|
|
|
12
12
|
constructor(input, init = {}) {
|
|
13
13
|
init = { ...init };
|
|
@@ -30,7 +30,7 @@ const xRequest = (whatwagRequest, Headers, FormData) => class extends xHttpMessa
|
|
|
30
30
|
}
|
|
31
31
|
// Init can contain "already-parsed request content"
|
|
32
32
|
if (('body' in init)) {
|
|
33
|
-
bodyAttrs = encodeBody(init.body, FormData);
|
|
33
|
+
bodyAttrs = encodeBody(init.body, FormData, Blob);
|
|
34
34
|
init.body = bodyAttrs.body;
|
|
35
35
|
}
|
|
36
36
|
let isNavigateMode;
|
|
@@ -7,13 +7,13 @@ import xHttpMessage, { encodeBody } from './xHttpMessage.js';
|
|
|
7
7
|
/**
|
|
8
8
|
* The xResponse Mixin
|
|
9
9
|
*/
|
|
10
|
-
const xResponse = (whatwagResponse, Headers, FormData) => class extends xHttpMessage(whatwagResponse, Headers, FormData) {
|
|
10
|
+
const xResponse = (whatwagResponse, Headers, FormData, Blob) => class extends xHttpMessage(whatwagResponse, Headers, FormData) {
|
|
11
11
|
|
|
12
12
|
// construct
|
|
13
13
|
constructor(body = null, init = {}) {
|
|
14
14
|
let bodyAttrs = {}, isResponseInput;
|
|
15
15
|
if (arguments.length) {
|
|
16
|
-
if (
|
|
16
|
+
if (body instanceof whatwagResponse) {
|
|
17
17
|
isResponseInput = body;
|
|
18
18
|
// Inherit init
|
|
19
19
|
init = { status: body.status, statusText: body.statusText, headers: body.headers, ...init };
|
|
@@ -22,13 +22,14 @@ const xResponse = (whatwagResponse, Headers, FormData) => class extends xHttpMes
|
|
|
22
22
|
bodyAttrs = body.bodyAttrs || {};
|
|
23
23
|
body = body.body;
|
|
24
24
|
} else {
|
|
25
|
-
bodyAttrs = encodeBody(body, FormData);
|
|
25
|
+
bodyAttrs = encodeBody(body, FormData, Blob);
|
|
26
26
|
body = bodyAttrs.body;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
super(body, init, bodyAttrs);
|
|
30
30
|
if (isResponseInput) {
|
|
31
31
|
// Through the backdoor
|
|
32
|
+
this.attrs.url = isResponseInput.url;
|
|
32
33
|
this.attrs.ok = isResponseInput.ok;
|
|
33
34
|
this.attrs.status = isResponseInput.status; // In case it was earlier deleted
|
|
34
35
|
this.attrs.type = isResponseInput.type;
|