@pageboard/html 0.14.4 → 0.14.6
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 +1 -1
- package/ui/fieldset-list.js +3 -0
- package/ui/form.js +30 -25
- package/ui/input-file.js +14 -4
package/package.json
CHANGED
package/ui/fieldset-list.js
CHANGED
|
@@ -37,8 +37,10 @@ class HTMLElementFieldsetList extends Page.Element {
|
|
|
37
37
|
fill(values, scope) {
|
|
38
38
|
if (scope.$write || this.prefix == null) return;
|
|
39
39
|
// unflatten array-values
|
|
40
|
+
const vars = [];
|
|
40
41
|
for (const [key, val] of Object.entries(values)) {
|
|
41
42
|
if (!this.#prefixed(key)) continue;
|
|
43
|
+
vars.push(key);
|
|
42
44
|
if (Array.isArray(val)) {
|
|
43
45
|
for (let i = 0; i < val.length; i++) {
|
|
44
46
|
values[key + '.' + i] = val[i];
|
|
@@ -49,6 +51,7 @@ class HTMLElementFieldsetList extends Page.Element {
|
|
|
49
51
|
const list = this.#listFromValues({ ...values });
|
|
50
52
|
if (this.#initialSize == null) this.#initialSize = list.length;
|
|
51
53
|
this.#resize(list.length, scope);
|
|
54
|
+
return vars;
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
reset() {
|
package/ui/form.js
CHANGED
|
@@ -31,6 +31,7 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
|
|
|
31
31
|
if (action == "toggle") {
|
|
32
32
|
action = val ? "enable" : "disable";
|
|
33
33
|
}
|
|
34
|
+
const isQuery = ctx.expr.path[0] == "$query" && ctx.expr.path.length == 1;
|
|
34
35
|
|
|
35
36
|
state.finish(() => {
|
|
36
37
|
if (action == "enable") {
|
|
@@ -41,7 +42,10 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
|
|
|
41
42
|
if (val == null) {
|
|
42
43
|
form.reset?.();
|
|
43
44
|
} else if (typeof val == "object") {
|
|
44
|
-
form.fill?.(this.linearizeValues(val), state.scope);
|
|
45
|
+
const vars = form.fill?.(this.linearizeValues(val), state.scope) ?? [];
|
|
46
|
+
if (isQuery) {
|
|
47
|
+
for (const name of vars) state.vars[name] = true;
|
|
48
|
+
}
|
|
45
49
|
form.save?.();
|
|
46
50
|
}
|
|
47
51
|
}
|
|
@@ -222,14 +226,15 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
|
|
|
222
226
|
}
|
|
223
227
|
fill(query, scope) {
|
|
224
228
|
// fieldset-list are not custom inputs yet
|
|
229
|
+
const vars = [];
|
|
225
230
|
for (const node of this.querySelectorAll("element-fieldset-list")) {
|
|
226
|
-
node.fill
|
|
231
|
+
if (node.fill) vars.push(...node.fill(query, scope));
|
|
227
232
|
}
|
|
228
|
-
|
|
233
|
+
|
|
229
234
|
for (const elem of this.elements) {
|
|
230
235
|
const name = elem.name;
|
|
231
236
|
if (!name) continue;
|
|
232
|
-
if (name in query
|
|
237
|
+
if (name in query) vars.push(name);
|
|
233
238
|
const val = query[name];
|
|
234
239
|
if (val === undefined) {
|
|
235
240
|
elem.reset?.();
|
|
@@ -338,32 +343,32 @@ class HTMLElementForm extends Page.create(HTMLFormElement) {
|
|
|
338
343
|
}
|
|
339
344
|
async postMethod(e, state) {
|
|
340
345
|
const form = this;
|
|
341
|
-
if (e.type != "submit" && form.elements.find(item => item.type == "submit"))
|
|
342
|
-
|
|
343
|
-
|
|
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);
|
|
346
|
+
if (e.type != "submit" && form.elements.find(item => item.type == "submit")) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
358
349
|
|
|
359
350
|
const scope = state.scope.copy();
|
|
351
|
+
scope.$request = form.read(true);
|
|
352
|
+
try {
|
|
353
|
+
const prelist = Array.from(form.elements)
|
|
354
|
+
.filter(node => Boolean(node.presubmit) && !node.disabled);
|
|
355
|
+
form.disable();
|
|
356
|
+
for (const node of prelist) {
|
|
357
|
+
await node.presubmit(state);
|
|
358
|
+
}
|
|
359
|
+
form.classList.add('loading');
|
|
360
|
+
scope.$response = await state.fetch(form.method, Page.format({
|
|
361
|
+
pathname: form.getAttribute('action'),
|
|
362
|
+
query: state.query
|
|
363
|
+
}), scope.$request);
|
|
364
|
+
} catch (err) {
|
|
365
|
+
scope.$response = err;
|
|
366
|
+
}
|
|
367
|
+
const res = scope.$response;
|
|
360
368
|
if (res?.grants) state.scope.$grants = res.grants;
|
|
361
|
-
scope.$request = request;
|
|
362
|
-
|
|
363
|
-
scope.$response = res;
|
|
364
369
|
scope.$status = res.status;
|
|
365
|
-
form.enable();
|
|
366
370
|
|
|
371
|
+
form.enable();
|
|
367
372
|
form.classList.remove('loading');
|
|
368
373
|
|
|
369
374
|
// 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
|
-
|
|
104
|
-
} catch
|
|
105
|
-
|
|
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.
|
|
123
|
+
err.status = xhr.status;
|
|
114
124
|
fail(err);
|
|
115
125
|
});
|
|
116
126
|
try {
|