@optionfactory/ful 1.0.2 → 1.0.3
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/dist/ful.iife.js +74 -9
- package/dist/ful.iife.js.map +1 -1
- package/dist/ful.iife.min.js +1 -1
- package/dist/ful.iife.min.js.map +1 -1
- package/dist/ful.min.mjs +1 -1
- package/dist/ful.min.mjs.map +1 -1
- package/dist/ful.mjs +74 -10
- package/dist/ful.mjs.map +1 -1
- package/package.json +1 -1
package/dist/ful.mjs
CHANGED
|
@@ -949,6 +949,65 @@ class AuthorizationCodeFlowInterceptor {
|
|
|
949
949
|
}
|
|
950
950
|
}
|
|
951
951
|
|
|
952
|
+
class AsyncEvents {
|
|
953
|
+
static async fireAsync(el, evt) {
|
|
954
|
+
el.dispatchEvent(evt);
|
|
955
|
+
return await evt.async?.promise;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
*
|
|
959
|
+
* @param {*} el
|
|
960
|
+
* @param {*} type
|
|
961
|
+
* @param {*} fn returning the result
|
|
962
|
+
* @param {*} options
|
|
963
|
+
* @returns
|
|
964
|
+
*/
|
|
965
|
+
static asyncOn(el, type, fn, options) {
|
|
966
|
+
const listener = async (event) => {
|
|
967
|
+
let resolve, reject;
|
|
968
|
+
const promise = new Promise((res, rej) => {
|
|
969
|
+
resolve = res;
|
|
970
|
+
reject = rej;
|
|
971
|
+
});
|
|
972
|
+
event.async = { promise };
|
|
973
|
+
try {
|
|
974
|
+
//@ts-ignore
|
|
975
|
+
resolve(await fn(event));
|
|
976
|
+
} catch (e) {
|
|
977
|
+
//@ts-ignore
|
|
978
|
+
reject(e);
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
el.addEventListener(type, listener, options);
|
|
982
|
+
return listener;
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
*
|
|
986
|
+
* @param {*} el
|
|
987
|
+
* @param {*} type
|
|
988
|
+
* @param {*} listener the listener returned by asyncOn
|
|
989
|
+
* @param {*} options
|
|
990
|
+
*/
|
|
991
|
+
static asyncOff(el, type, listener, options) {
|
|
992
|
+
el.removeEventListener(type, listener, options);
|
|
993
|
+
}
|
|
994
|
+
static mixInto(...classes) {
|
|
995
|
+
for (const k of classes) {
|
|
996
|
+
Object.assign(k.prototype, {
|
|
997
|
+
async fireAsync(evt) {
|
|
998
|
+
return await AsyncEvents.fireAsync(this, evt);
|
|
999
|
+
},
|
|
1000
|
+
asyncOn(type, fn, options) {
|
|
1001
|
+
return AsyncEvents.asyncOn(this, type, fn, options);
|
|
1002
|
+
},
|
|
1003
|
+
asyncOff(type, listener, options) {
|
|
1004
|
+
return AsyncEvents.asyncOff(this, type, listener, options);
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
952
1011
|
const timing = {
|
|
953
1012
|
sleep(ms) {
|
|
954
1013
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -1243,8 +1302,8 @@ class LocalFormLoader {
|
|
|
1243
1302
|
async prepare(values, form) {
|
|
1244
1303
|
return await this.#requestMapper(values, form);
|
|
1245
1304
|
}
|
|
1246
|
-
async submit(values, form) {
|
|
1247
|
-
return
|
|
1305
|
+
async submit(values, form, response) {
|
|
1306
|
+
return response;
|
|
1248
1307
|
}
|
|
1249
1308
|
async transform(response, form) {
|
|
1250
1309
|
return await this.#responseMapper(response, form);
|
|
@@ -1286,13 +1345,17 @@ class Form extends ParsedElement {
|
|
|
1286
1345
|
try {
|
|
1287
1346
|
const loader = Loaders.fromAttributes(this, 'loaders:form');
|
|
1288
1347
|
const values = this.values;
|
|
1289
|
-
|
|
1290
|
-
const se = new CustomEvent('submit', { bubbles: true, cancelable: true, detail: { values, request } });
|
|
1291
|
-
if (!this.dispatchEvent(se)) {
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1348
|
+
let request = await loader.prepare(values, this);
|
|
1294
1349
|
try {
|
|
1295
|
-
const
|
|
1350
|
+
const se = new CustomEvent('submit', { bubbles: true, cancelable: true, detail: { values, request } });
|
|
1351
|
+
if (!this.dispatchEvent(se)) {
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
const sre = new CustomEvent('submit:requested', { bubbles: true, cancelable: false, detail: { values: se.detail.values, request: se.detail.request} });
|
|
1355
|
+
let response = await AsyncEvents.fireAsync(this, sre);
|
|
1356
|
+
request = sre.detail.request;
|
|
1357
|
+
|
|
1358
|
+
response = await loader.submit(request, this, response);
|
|
1296
1359
|
const mapped = await loader.transform(response, this);
|
|
1297
1360
|
this.dispatchEvent(new CustomEvent('submit:success', { bubbles: true, cancelable: false, detail: { values, request, response: mapped } }));
|
|
1298
1361
|
} catch (e) {
|
|
@@ -1300,12 +1363,13 @@ class Form extends ParsedElement {
|
|
|
1300
1363
|
if (e instanceof Failure) {
|
|
1301
1364
|
this.errors = e.problems;
|
|
1302
1365
|
}
|
|
1303
|
-
|
|
1366
|
+
console.warn("failed to submit form", this, "reason:", e);
|
|
1304
1367
|
}
|
|
1305
1368
|
} finally {
|
|
1306
1369
|
this.spinner(false);
|
|
1307
1370
|
}
|
|
1308
1371
|
}
|
|
1372
|
+
|
|
1309
1373
|
spinner(spin) {
|
|
1310
1374
|
this.querySelectorAll('ful-spinner').forEach(el => {
|
|
1311
1375
|
const hel = /** @type HTMLElement */ (el);
|
|
@@ -2578,5 +2642,5 @@ class Plugin {
|
|
|
2578
2642
|
}
|
|
2579
2643
|
}
|
|
2580
2644
|
|
|
2581
|
-
export { AuthorizationCodeFlow, AuthorizationCodeFlowInterceptor, AuthorizationCodeFlowSession, Base64, Bindings, Checkbox, Dropdown, Failure, Form, FormLoader, Hex, HttpClient, HttpClientError, Input, InstantFilter, Loaders, LocalDateFilter, LocalStorage, MediaType, Pagination, Plugin, RadioGroup, Select, SelectLoader, SessionStorage, SortButton, Spinner, Table, TableSchemaParser, TextFilter, VersionedStorage, timing };
|
|
2645
|
+
export { AsyncEvents, AuthorizationCodeFlow, AuthorizationCodeFlowInterceptor, AuthorizationCodeFlowSession, Base64, Bindings, Checkbox, Dropdown, Failure, Form, FormLoader, Hex, HttpClient, HttpClientError, Input, InstantFilter, Loaders, LocalDateFilter, LocalStorage, MediaType, Pagination, Plugin, RadioGroup, Select, SelectLoader, SessionStorage, SortButton, Spinner, Table, TableSchemaParser, TextFilter, VersionedStorage, timing };
|
|
2582
2646
|
//# sourceMappingURL=ful.mjs.map
|