@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.
Files changed (37) hide show
  1. package/dist/App.d.ts +1 -1
  2. package/dist/App.d.ts.map +1 -1
  3. package/dist/App.js +3 -3
  4. package/dist/App.js.map +1 -1
  5. package/dist/core/AtomLoader.d.ts.map +1 -1
  6. package/dist/core/AtomLoader.js +42 -16
  7. package/dist/core/AtomLoader.js.map +1 -1
  8. package/dist/services/BusyIndicatorService.d.ts +1 -2
  9. package/dist/services/BusyIndicatorService.d.ts.map +1 -1
  10. package/dist/services/BusyIndicatorService.js +1 -1
  11. package/dist/services/BusyIndicatorService.js.map +1 -1
  12. package/dist/services/FetchBuilder.d.ts.map +1 -1
  13. package/dist/services/FetchBuilder.js +21 -12
  14. package/dist/services/FetchBuilder.js.map +1 -1
  15. package/dist/services/http/RestService.d.ts.map +1 -1
  16. package/dist/services/http/RestService.js +34 -26
  17. package/dist/services/http/RestService.js.map +1 -1
  18. package/dist/tsconfig.tsbuildinfo +1 -1
  19. package/dist/web/services/PopupService.d.ts.map +1 -1
  20. package/dist/web/services/PopupService.js +26 -7
  21. package/dist/web/services/PopupService.js.map +1 -1
  22. package/dist/web/services/PopupWindow.js +7 -5
  23. package/dist/web/services/PopupWindow.js.map +1 -1
  24. package/dist/web/services/WebBusyIndicatorService.d.ts +1 -2
  25. package/dist/web/services/WebBusyIndicatorService.d.ts.map +1 -1
  26. package/dist/web/services/WebBusyIndicatorService.js +5 -1
  27. package/dist/web/services/WebBusyIndicatorService.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/App.ts +4 -4
  30. package/src/core/AtomLoader.ts +139 -151
  31. package/src/services/BusyIndicatorService.ts +2 -2
  32. package/src/services/FetchBuilder.ts +44 -49
  33. package/src/services/http/RestService.ts +119 -125
  34. package/src/web/services/PopupService.tsx +18 -6
  35. package/src/web/services/PopupWindow.tsx +6 -6
  36. package/src/web/services/WebBusyIndicatorService.ts +6 -2
  37. 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
- let d:IDisposable;
250
+ using _d = !hideBusyIndicator ? App.current.createBusyIndicator() : null;
251
251
  try {
252
- d = !hideBusyIndicator ? App.current.createBusyIndicator() : null;
253
- try {
254
-
255
- const { headers, fetchProxy, jsonPostProcessor } = this.request;
256
- const r = await (fetchProxy ?? fetch)(this.request.url, this.request);
257
- if (ensureSuccess) {
258
- if (r.status > 300) {
259
- log = logError;
260
- log?.(`fetch: ${this.request.method ?? "GET"} ${this.request.url}`);
261
- if (log && headers) {
262
- for (const key in headers) {
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
- log?.(`${r.status} ${r.statusText || "Http Error"}`);
269
- const type = r.headers.get("content-type");
270
- if (/\/json/i.test(type)) {
271
- const json: any = await r.json();
272
- log?.(json);
273
- const message = json.title
274
- ?? json.detail
275
- ?? json.message
276
- ?? json.exceptionMessage
277
- ?? "Json Server Error";
278
- log = null;
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 Error(`Fetch failed with error ${r.status} for ${this.request.url}\n${text}`);
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
- log?.(`${this.request.method ?? "GET"} ${this.request.url}`);
290
- if (log && headers) {
291
- for (const key in headers) {
292
- if (headers.hasOwnProperty(key)) {
293
- log?.(`${key}: ${headers[key]}`);
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
- } finally {
308
- d?.dispose();
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
- const busyIndicator = this.showProgress ? ( this.app.createBusyIndicator({
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
- url = UMD.resolvePath(url);
465
+ url = UMD.resolvePath(url);
467
466
 
468
- let options: AjaxOptions = new AjaxOptions();
469
- options.method = method;
467
+ let options: AjaxOptions = new AjaxOptions();
468
+ options.method = method;
470
469
 
471
- if (methodOptions) {
472
- options.headers = methodOptions.headers;
473
- options.dataType = methodOptions.accept;
474
- }
470
+ if (methodOptions) {
471
+ options.headers = methodOptions.headers;
472
+ options.dataType = methodOptions.accept;
473
+ }
475
474
 
476
- const methodHeaders = (options.headers = options.headers || {});
475
+ const methodHeaders = (options.headers = options.headers || {});
477
476
 
478
- const headers = this.headers
479
- ? ({ ... this.headers, ... methodHeaders })
480
- : methodHeaders;
477
+ const headers = this.headers
478
+ ? ({ ... this.headers, ... methodHeaders })
479
+ : methodHeaders;
481
480
 
482
- // this is necessary to support IsAjaxRequest in ASP.NET MVC
483
- if (!headers["X-Requested-With"]) {
484
- headers["X-Requested-With"] = "XMLHttpRequest";
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
- options.dataType = options.dataType || "application/json";
486
+ options.dataType = options.dataType || "application/json";
488
487
 
489
- const jsonOptions = {
490
- ... this.jsonOptions,
491
- ... (methodOptions ? methodOptions.jsonOptions : {})
492
- };
488
+ const jsonOptions = {
489
+ ... this.jsonOptions,
490
+ ... (methodOptions ? methodOptions.jsonOptions : {})
491
+ };
493
492
 
494
- if (bag) {
493
+ if (bag) {
495
494
 
496
- for (let i: number = 0; i < bag.length; i++) {
497
- const p: ServiceParameter = bag[i];
498
- const vi = values[i];
499
- const v: any = vi === undefined ? p.defaultValue : vi;
500
- if (v instanceof CancelToken) {
501
- options.cancel = v;
502
- continue;
503
- }
504
- switch (p.type) {
505
- case "path":
506
- if (v === undefined) {
507
- continue;
508
- }
509
- const vs: string = v + "";
510
- const replacer = `{${p.key}}`;
511
- url = url.split(replacer).join(vs);
512
- break;
513
- case "query":
514
- if (v === undefined) {
515
- continue;
516
- }
517
- if (url.indexOf("?") === -1) {
518
- url += "?";
519
- }
520
- if (! /(\&|\?)$/.test(url)) {
521
- url += "&";
522
- }
523
- url += `${encodeURIComponent(p.key)}=${encodeURIComponent(v)}`;
524
- break;
525
- case "queries":
526
- if (url.indexOf("?") === -1) {
527
- url += "?";
528
- }
529
- if (! /(\&|\?)$/.test(url)) {
530
- url += "&";
531
- }
532
- for (const key in v) {
533
- if (v.hasOwnProperty(key)) {
534
- const element = v[key];
535
- if (element !== undefined) {
536
- url += `${encodeURIComponent(key)}=${encodeURIComponent(element)}&`;
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
- break;
541
- case "body":
542
- options.data = v;
543
- options = this.encodeData(options);
544
- break;
545
- case "bodyformmodel":
546
- options.data = v;
547
- break;
548
- case "rawbody":
549
- options.data = v;
550
- break;
551
- case "xmlbody":
552
- options.contentType = "text/xml";
553
- options.data = v;
554
- break;
555
- case "cancel":
556
- options.cancel = v as CancelToken;
557
- break;
558
- case "header":
559
- if (v === undefined) {
560
- continue;
561
- }
562
- headers[p.key] = v;
563
- break;
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 Error(xhr.responseText || "Server Error");
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: xhr.responseText
588
+ value: response
602
589
  };
603
590
  }
604
- return xhr.responseText;
605
- } finally {
606
- if (busyIndicator) {
607
- busyIndicator.dispose();
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
- ?.catch((error) => {
566
- if (!CancelToken.isCancelled(error)) {
567
- console.error(error);
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
- setTimeout((p: HTMLElement) => {
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
- }, 1000, this.element);
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(): IDisposable {
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 popup;
73
+ return {
74
+ [Symbol.dispose]() {
75
+ popup.dispose();
76
+ }
77
+ }
74
78
  }
75
79
  }
package/tsconfig.json CHANGED
@@ -16,7 +16,8 @@
16
16
  "jsxFactory": "XNode.create",
17
17
  "lib": [
18
18
  "es6",
19
- "dom"
19
+ "dom",
20
+ "ESNext.Disposable"
20
21
  ]
21
22
  },
22
23
  "include": [