@pageboard/html 0.14.4 → 0.14.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pageboard/html",
3
- "version": "0.14.4",
3
+ "version": "0.14.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "repository": {
package/ui/form.js CHANGED
@@ -338,32 +338,32 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
338
338
  }
339
339
  async postMethod(e, state) {
340
340
  const form = this;
341
- if (e.type != "submit" && form.elements.find(item => item.type == "submit")) return;
342
-
343
- form.classList.add('loading');
344
-
345
- await Promise.all(
346
- Array.from(form.elements)
347
- .filter(node => Boolean(node.presubmit) && !node.disabled)
348
- .map(input => input.presubmit(state))
349
- );
350
-
351
- const request = form.read(true);
352
- form.disable();
353
-
354
- const res = await state.fetch(form.method, Page.format({
355
- pathname: form.getAttribute('action'),
356
- query: state.query
357
- }), request).catch(err => err);
341
+ if (e.type != "submit" && form.elements.find(item => item.type == "submit")) {
342
+ return;
343
+ }
358
344
 
359
345
  const scope = state.scope.copy();
346
+ scope.$request = form.read(true);
347
+ try {
348
+ const prelist = Array.from(form.elements)
349
+ .filter(node => Boolean(node.presubmit) && !node.disabled);
350
+ form.disable();
351
+ for (const node of prelist) {
352
+ await node.presubmit(state);
353
+ }
354
+ form.classList.add('loading');
355
+ scope.$response = await state.fetch(form.method, Page.format({
356
+ pathname: form.getAttribute('action'),
357
+ query: state.query
358
+ }), scope.$request);
359
+ } catch (err) {
360
+ scope.$response = err;
361
+ }
362
+ const res = scope.$response;
360
363
  if (res?.grants) state.scope.$grants = res.grants;
361
- scope.$request = request;
362
-
363
- scope.$response = res;
364
364
  scope.$status = res.status;
365
- form.enable();
366
365
 
366
+ form.enable();
367
367
  form.classList.remove('loading');
368
368
 
369
369
  // messages shown inside form, no navigation
package/ui/input-file.js CHANGED
@@ -99,10 +99,20 @@ class HTMLElementInputFile extends Page.create(HTMLInputElement) {
99
99
 
100
100
  xhr.addEventListener('load', () => {
101
101
  track(100);
102
+ let obj;
102
103
  try {
103
- pass(JSON.parse(xhr.responseText));
104
- } catch (ex) {
105
- fail(ex);
104
+ obj = JSON.parse(xhr.responseText);
105
+ } catch {
106
+ obj = { type: 'error', data: { message: xhr.responseText } };
107
+ }
108
+ if (obj.type == "error") {
109
+ obj.statusText = obj.data?.message ?? '';
110
+ }
111
+ obj.status = xhr.status;
112
+ if (xhr.status < 200 || xhr.status >= 400) {
113
+ fail(obj);
114
+ } else {
115
+ pass(obj);
106
116
  }
107
117
  });
108
118
 
@@ -110,7 +120,7 @@ class HTMLElementInputFile extends Page.create(HTMLInputElement) {
110
120
  if (xhr.status == 0) return fail("Connection error");
111
121
  const msg = xhr.statusText || "Connection error";
112
122
  const err = new Error(msg);
113
- err.statusCode = xhr.status;
123
+ err.status = xhr.status;
114
124
  fail(err);
115
125
  });
116
126
  try {