@web-atoms/core 2.4.75 → 2.5.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/App.d.ts +1 -1
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +3 -3
- package/dist/App.js.map +1 -1
- package/dist/core/AtomLoader.d.ts.map +1 -1
- package/dist/core/AtomLoader.js +42 -16
- package/dist/core/AtomLoader.js.map +1 -1
- package/dist/services/BusyIndicatorService.d.ts +1 -2
- package/dist/services/BusyIndicatorService.d.ts.map +1 -1
- package/dist/services/BusyIndicatorService.js +1 -1
- package/dist/services/BusyIndicatorService.js.map +1 -1
- package/dist/services/FetchBuilder.d.ts.map +1 -1
- package/dist/services/FetchBuilder.js +21 -12
- package/dist/services/FetchBuilder.js.map +1 -1
- package/dist/services/http/RestService.d.ts.map +1 -1
- package/dist/services/http/RestService.js +34 -26
- package/dist/services/http/RestService.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/web/services/PopupService.d.ts.map +1 -1
- package/dist/web/services/PopupService.js +26 -7
- package/dist/web/services/PopupService.js.map +1 -1
- package/dist/web/services/PopupWindow.js +7 -5
- package/dist/web/services/PopupWindow.js.map +1 -1
- package/dist/web/services/WebBusyIndicatorService.d.ts +1 -2
- package/dist/web/services/WebBusyIndicatorService.d.ts.map +1 -1
- package/dist/web/services/WebBusyIndicatorService.js +5 -1
- package/dist/web/services/WebBusyIndicatorService.js.map +1 -1
- package/package.json +2 -2
- package/src/App.ts +4 -4
- package/src/core/AtomLoader.ts +139 -151
- package/src/services/BusyIndicatorService.ts +2 -2
- package/src/services/FetchBuilder.ts +44 -49
- package/src/services/http/RestService.ts +119 -125
- package/src/web/services/PopupService.tsx +18 -6
- package/src/web/services/PopupWindow.tsx +6 -6
- package/src/web/services/WebBusyIndicatorService.ts +6 -2
- package/tsconfig.json +2 -1
|
@@ -247,65 +247,60 @@ export default class FetchBuilder {
|
|
|
247
247
|
postProcessor: (r: Response, next?: (data) => any) => T | Promise<T>): Promise<{ result: T, headers: any, status: number }> {
|
|
248
248
|
|
|
249
249
|
let { log, logError, hideBusyIndicator } = this.request;
|
|
250
|
-
|
|
250
|
+
using _d = !hideBusyIndicator ? App.current.createBusyIndicator() : null;
|
|
251
251
|
try {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (headers.hasOwnProperty(key)) {
|
|
264
|
-
log?.(`${key}: ${headers[key]}`);
|
|
265
|
-
}
|
|
252
|
+
|
|
253
|
+
const { headers, fetchProxy, jsonPostProcessor } = this.request;
|
|
254
|
+
const r = await (fetchProxy ?? fetch)(this.request.url, this.request);
|
|
255
|
+
if (ensureSuccess) {
|
|
256
|
+
if (r.status > 300) {
|
|
257
|
+
log = logError;
|
|
258
|
+
log?.(`fetch: ${this.request.method ?? "GET"} ${this.request.url}`);
|
|
259
|
+
if (log && headers) {
|
|
260
|
+
for (const key in headers) {
|
|
261
|
+
if (headers.hasOwnProperty(key)) {
|
|
262
|
+
log?.(`${key}: ${headers[key]}`);
|
|
266
263
|
}
|
|
267
264
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
logError = null;
|
|
280
|
-
throw new JsonError(message, json);
|
|
281
|
-
}
|
|
282
|
-
const text = await r.text();
|
|
283
|
-
log?.(text);
|
|
265
|
+
}
|
|
266
|
+
log?.(`${r.status} ${r.statusText || "Http Error"}`);
|
|
267
|
+
const type = r.headers.get("content-type");
|
|
268
|
+
if (/\/json/i.test(type)) {
|
|
269
|
+
const json: any = await r.json();
|
|
270
|
+
log?.(json);
|
|
271
|
+
const message = json.title
|
|
272
|
+
?? json.detail
|
|
273
|
+
?? json.message
|
|
274
|
+
?? json.exceptionMessage
|
|
275
|
+
?? "Json Server Error";
|
|
284
276
|
log = null;
|
|
285
277
|
logError = null;
|
|
286
|
-
throw new
|
|
278
|
+
throw new JsonError(message, json);
|
|
287
279
|
}
|
|
280
|
+
const text = await r.text();
|
|
281
|
+
log?.(text);
|
|
282
|
+
log = null;
|
|
283
|
+
logError = null;
|
|
284
|
+
throw new Error(`Fetch failed with error ${r.status} for ${this.request.url}\n${text}`);
|
|
288
285
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
286
|
+
}
|
|
287
|
+
log?.(`${this.request.method ?? "GET"} ${this.request.url}`);
|
|
288
|
+
if (log && headers) {
|
|
289
|
+
for (const key in headers) {
|
|
290
|
+
if (headers.hasOwnProperty(key)) {
|
|
291
|
+
log?.(`${key}: ${headers[key]}`);
|
|
295
292
|
}
|
|
296
293
|
}
|
|
297
|
-
const result = await postProcessor(r, jsonPostProcessor);
|
|
298
|
-
if (log) {
|
|
299
|
-
log(`${r.status} ${r.statusText || "OK"}`)
|
|
300
|
-
log(result);
|
|
301
|
-
}
|
|
302
|
-
return { result, headers: r.headers, status: r.status };
|
|
303
|
-
} catch (error) {
|
|
304
|
-
log?.(error);
|
|
305
|
-
throw error;
|
|
306
294
|
}
|
|
307
|
-
|
|
308
|
-
|
|
295
|
+
const result = await postProcessor(r, jsonPostProcessor);
|
|
296
|
+
if (log) {
|
|
297
|
+
log(`${r.status} ${r.statusText || "OK"}`)
|
|
298
|
+
log(result);
|
|
299
|
+
}
|
|
300
|
+
return { result, headers: r.headers, status: r.status };
|
|
301
|
+
} catch (error) {
|
|
302
|
+
log?.(error);
|
|
303
|
+
throw error;
|
|
309
304
|
}
|
|
310
305
|
}
|
|
311
306
|
|
|
@@ -456,157 +456,151 @@ export class BaseService {
|
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
-
|
|
459
|
+
using _busyIndicator = this.showProgress ? ( this.app.createBusyIndicator({
|
|
460
460
|
title: url,
|
|
461
461
|
description: `${method} ${url}`
|
|
462
462
|
}) ) : null;
|
|
463
463
|
|
|
464
|
-
try {
|
|
465
464
|
|
|
466
|
-
|
|
465
|
+
url = UMD.resolvePath(url);
|
|
467
466
|
|
|
468
|
-
|
|
469
|
-
|
|
467
|
+
let options: AjaxOptions = new AjaxOptions();
|
|
468
|
+
options.method = method;
|
|
470
469
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
470
|
+
if (methodOptions) {
|
|
471
|
+
options.headers = methodOptions.headers;
|
|
472
|
+
options.dataType = methodOptions.accept;
|
|
473
|
+
}
|
|
475
474
|
|
|
476
|
-
|
|
475
|
+
const methodHeaders = (options.headers = options.headers || {});
|
|
477
476
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
477
|
+
const headers = this.headers
|
|
478
|
+
? ({ ... this.headers, ... methodHeaders })
|
|
479
|
+
: methodHeaders;
|
|
481
480
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
481
|
+
// this is necessary to support IsAjaxRequest in ASP.NET MVC
|
|
482
|
+
if (!headers["X-Requested-With"]) {
|
|
483
|
+
headers["X-Requested-With"] = "XMLHttpRequest";
|
|
484
|
+
}
|
|
486
485
|
|
|
487
|
-
|
|
486
|
+
options.dataType = options.dataType || "application/json";
|
|
488
487
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
488
|
+
const jsonOptions = {
|
|
489
|
+
... this.jsonOptions,
|
|
490
|
+
... (methodOptions ? methodOptions.jsonOptions : {})
|
|
491
|
+
};
|
|
493
492
|
|
|
494
|
-
|
|
493
|
+
if (bag) {
|
|
495
494
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
495
|
+
for (let i: number = 0; i < bag.length; i++) {
|
|
496
|
+
const p: ServiceParameter = bag[i];
|
|
497
|
+
const vi = values[i];
|
|
498
|
+
const v: any = vi === undefined ? p.defaultValue : vi;
|
|
499
|
+
if (v instanceof CancelToken) {
|
|
500
|
+
options.cancel = v;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
switch (p.type) {
|
|
504
|
+
case "path":
|
|
505
|
+
if (v === undefined) {
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
const vs: string = v + "";
|
|
509
|
+
const replacer = `{${p.key}}`;
|
|
510
|
+
url = url.split(replacer).join(vs);
|
|
511
|
+
break;
|
|
512
|
+
case "query":
|
|
513
|
+
if (v === undefined) {
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
if (url.indexOf("?") === -1) {
|
|
517
|
+
url += "?";
|
|
518
|
+
}
|
|
519
|
+
if (! /(\&|\?)$/.test(url)) {
|
|
520
|
+
url += "&";
|
|
521
|
+
}
|
|
522
|
+
url += `${encodeURIComponent(p.key)}=${encodeURIComponent(v)}`;
|
|
523
|
+
break;
|
|
524
|
+
case "queries":
|
|
525
|
+
if (url.indexOf("?") === -1) {
|
|
526
|
+
url += "?";
|
|
527
|
+
}
|
|
528
|
+
if (! /(\&|\?)$/.test(url)) {
|
|
529
|
+
url += "&";
|
|
530
|
+
}
|
|
531
|
+
for (const key in v) {
|
|
532
|
+
if (v.hasOwnProperty(key)) {
|
|
533
|
+
const element = v[key];
|
|
534
|
+
if (element !== undefined) {
|
|
535
|
+
url += `${encodeURIComponent(key)}=${encodeURIComponent(element)}&`;
|
|
538
536
|
}
|
|
539
537
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
options.url = url;
|
|
568
|
-
|
|
569
|
-
const xhr = await this.ajax(url, options);
|
|
570
|
-
|
|
571
|
-
if (/json/i.test(xhr.responseType)) {
|
|
572
|
-
const text = xhr.responseText;
|
|
573
|
-
const response = this.jsonService.parse(text, jsonOptions );
|
|
574
|
-
|
|
575
|
-
if (xhr.status >= 400) {
|
|
576
|
-
throw new JsonError(
|
|
577
|
-
typeof response === "string"
|
|
578
|
-
? response
|
|
579
|
-
: ( response.title
|
|
580
|
-
?? response.detail
|
|
581
|
-
?? response.message
|
|
582
|
-
?? response.exceptionMessage
|
|
583
|
-
?? text
|
|
584
|
-
?? "Json Server Error"), response);
|
|
585
|
-
}
|
|
586
|
-
if (methodOptions && methodOptions.returnHeaders) {
|
|
587
|
-
return {
|
|
588
|
-
headers: this.parseHeaders(xhr.responseHeaders),
|
|
589
|
-
value: response
|
|
590
|
-
};
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
case "body":
|
|
541
|
+
options.data = v;
|
|
542
|
+
options = this.encodeData(options);
|
|
543
|
+
break;
|
|
544
|
+
case "bodyformmodel":
|
|
545
|
+
options.data = v;
|
|
546
|
+
break;
|
|
547
|
+
case "rawbody":
|
|
548
|
+
options.data = v;
|
|
549
|
+
break;
|
|
550
|
+
case "xmlbody":
|
|
551
|
+
options.contentType = "text/xml";
|
|
552
|
+
options.data = v;
|
|
553
|
+
break;
|
|
554
|
+
case "cancel":
|
|
555
|
+
options.cancel = v as CancelToken;
|
|
556
|
+
break;
|
|
557
|
+
case "header":
|
|
558
|
+
if (v === undefined) {
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
headers[p.key] = v;
|
|
562
|
+
break;
|
|
591
563
|
}
|
|
592
|
-
return response;
|
|
593
564
|
}
|
|
565
|
+
}
|
|
566
|
+
options.url = url;
|
|
567
|
+
|
|
568
|
+
const xhr = await this.ajax(url, options);
|
|
569
|
+
|
|
570
|
+
if (/json/i.test(xhr.responseType)) {
|
|
571
|
+
const text = xhr.responseText;
|
|
572
|
+
const response = this.jsonService.parse(text, jsonOptions );
|
|
573
|
+
|
|
594
574
|
if (xhr.status >= 400) {
|
|
595
|
-
throw new
|
|
575
|
+
throw new JsonError(
|
|
576
|
+
typeof response === "string"
|
|
577
|
+
? response
|
|
578
|
+
: ( response.title
|
|
579
|
+
?? response.detail
|
|
580
|
+
?? response.message
|
|
581
|
+
?? response.exceptionMessage
|
|
582
|
+
?? text
|
|
583
|
+
?? "Json Server Error"), response);
|
|
596
584
|
}
|
|
597
|
-
|
|
598
585
|
if (methodOptions && methodOptions.returnHeaders) {
|
|
599
586
|
return {
|
|
600
587
|
headers: this.parseHeaders(xhr.responseHeaders),
|
|
601
|
-
value:
|
|
588
|
+
value: response
|
|
602
589
|
};
|
|
603
590
|
}
|
|
604
|
-
return
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
591
|
+
return response;
|
|
592
|
+
}
|
|
593
|
+
if (xhr.status >= 400) {
|
|
594
|
+
throw new Error(xhr.responseText || "Server Error");
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (methodOptions && methodOptions.returnHeaders) {
|
|
598
|
+
return {
|
|
599
|
+
headers: this.parseHeaders(xhr.responseHeaders),
|
|
600
|
+
value: xhr.responseText
|
|
601
|
+
};
|
|
609
602
|
}
|
|
603
|
+
return xhr.responseText;
|
|
610
604
|
|
|
611
605
|
}
|
|
612
606
|
|
|
@@ -561,12 +561,24 @@ export default class PopupService {
|
|
|
561
561
|
vm[key] = e;
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
|
-
(control as any).init
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
564
|
+
const init = (control as any).init;
|
|
565
|
+
if (init) {
|
|
566
|
+
const c = (control as any).init();
|
|
567
|
+
if (c?.then) {
|
|
568
|
+
c.then(() =>
|
|
569
|
+
control.element.dispatchEvent(new CustomEvent("popupReady", { bubbles: true })),
|
|
570
|
+
(error) => {
|
|
571
|
+
control.element.dispatchEvent(new CustomEvent("popupReady", { bubbles: true }));
|
|
572
|
+
if(!CancelToken.isCancelled(error)) {
|
|
573
|
+
console.error(error);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
} else {
|
|
577
|
+
control.element.dispatchEvent(new CustomEvent("popupReady", { bubbles: true }));
|
|
578
|
+
}
|
|
579
|
+
} else {
|
|
580
|
+
control.element.dispatchEvent(new CustomEvent("popupReady", { bubbles: true }));
|
|
581
|
+
}
|
|
570
582
|
}
|
|
571
583
|
cancelToken?.registerForCancel(cancel);
|
|
572
584
|
isModal = modal;
|
|
@@ -229,19 +229,19 @@ export default class PopupWindow extends AtomControl {
|
|
|
229
229
|
|
|
230
230
|
// init will be called if parameters are set...
|
|
231
231
|
// this.runAfterInit(() => this.app.runAsync(() => this.init?.()));
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
const p = this.element;
|
|
233
|
+
this.bindEvent(this.element, "popupReady", (e) => {
|
|
234
|
+
if (e.defaultPrevented) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
234
237
|
p.setAttribute("data-ready", "true");
|
|
235
|
-
}, 10, this.element);
|
|
236
|
-
|
|
237
|
-
setTimeout((p: HTMLElement) => {
|
|
238
238
|
const parent = (p.offsetParent ?? document.body) as HTMLElement;
|
|
239
239
|
const left = `${(parent.offsetWidth - p.offsetWidth) / 2}px`;
|
|
240
240
|
const top = `${(parent.offsetHeight - p.offsetHeight) / 2}px`;
|
|
241
241
|
p.style.left = left;
|
|
242
242
|
p.style.top = top;
|
|
243
243
|
p.removeAttribute("not-ready");
|
|
244
|
-
}
|
|
244
|
+
});
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
protected render(node: XNode, e?: any, creator?: any): void {
|
|
@@ -21,7 +21,7 @@ export class WebBusyIndicatorService extends BusyIndicatorService {
|
|
|
21
21
|
|
|
22
22
|
private indicators: number = 0;
|
|
23
23
|
|
|
24
|
-
public createIndicator():
|
|
24
|
+
public createIndicator(): Disposable {
|
|
25
25
|
|
|
26
26
|
const host = document.createElement("div");
|
|
27
27
|
const popup = new AtomControl(this.app, host);
|
|
@@ -70,6 +70,10 @@ export class WebBusyIndicatorService extends BusyIndicatorService {
|
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
return
|
|
73
|
+
return {
|
|
74
|
+
[Symbol.dispose]() {
|
|
75
|
+
popup.dispose();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
74
78
|
}
|
|
75
79
|
}
|