@enbox/browser 0.3.57 → 0.3.58

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 (40) hide show
  1. package/dist/browser.mjs +14 -14
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/dweb-connect-client.js +14 -15
  4. package/dist/esm/dweb-connect-client.js.map +1 -1
  5. package/dist/esm/dweb-connect-wallet.js +11 -13
  6. package/dist/esm/dweb-connect-wallet.js.map +1 -1
  7. package/dist/esm/handled-deferred.js +24 -0
  8. package/dist/esm/handled-deferred.js.map +1 -0
  9. package/dist/esm/index.js +7 -2
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/relay-connect-runner.js +55 -26
  12. package/dist/esm/relay-connect-runner.js.map +1 -1
  13. package/dist/esm/ui/connect-modal.js +111 -77
  14. package/dist/esm/ui/connect-modal.js.map +1 -1
  15. package/dist/esm/ui/qr.js +121 -64
  16. package/dist/esm/ui/qr.js.map +1 -1
  17. package/dist/esm/web-features.js +54 -41
  18. package/dist/esm/web-features.js.map +1 -1
  19. package/dist/types/dweb-connect-client.d.ts +4 -4
  20. package/dist/types/dweb-connect-client.d.ts.map +1 -1
  21. package/dist/types/dweb-connect-wallet.d.ts +3 -3
  22. package/dist/types/dweb-connect-wallet.d.ts.map +1 -1
  23. package/dist/types/handled-deferred.d.ts +22 -0
  24. package/dist/types/handled-deferred.d.ts.map +1 -0
  25. package/dist/types/index.d.ts +6 -3
  26. package/dist/types/index.d.ts.map +1 -1
  27. package/dist/types/relay-connect-runner.d.ts +1 -1
  28. package/dist/types/relay-connect-runner.d.ts.map +1 -1
  29. package/dist/types/ui/connect-modal.d.ts.map +1 -1
  30. package/dist/types/ui/qr.d.ts.map +1 -1
  31. package/dist/types/web-features.d.ts.map +1 -1
  32. package/package.json +11 -10
  33. package/src/dweb-connect-client.ts +15 -15
  34. package/src/dweb-connect-wallet.ts +14 -14
  35. package/src/handled-deferred.ts +38 -0
  36. package/src/index.ts +47 -0
  37. package/src/relay-connect-runner.ts +71 -30
  38. package/src/ui/connect-modal.ts +113 -72
  39. package/src/ui/qr.ts +145 -69
  40. package/src/web-features.ts +55 -43
@@ -426,6 +426,41 @@ function cancelNavigation(): void {
426
426
  activeNavigation = null;
427
427
  }
428
428
 
429
+ /**
430
+ * Opens the tab/loading-overlay target for a DRL anchor click, then resolves
431
+ * and navigates to the DRL's first working DWN endpoint. Extracted from the
432
+ * click handler so the handler itself stays a shallow guard-clause dispatch
433
+ * (Sonar S3776).
434
+ */
435
+ async function navigateToDrl(did: string, path: string, openAsTab: boolean): Promise<void> {
436
+ let tab: Window | null = null;
437
+ if (openAsTab) {
438
+ tab = window.open('', '_blank');
439
+ if (tab) {tab.document.write(tabContent);}
440
+ } else {
441
+ activeNavigation = path;
442
+ // this is to allow for cached DIDs to instantly load without any flash of loading UI
443
+ setTimeout(
444
+ () =>
445
+ document.documentElement.setAttribute('drl-link-loading', ''),
446
+ 50
447
+ );
448
+ }
449
+ const endpoints = await getDwnEndpoints(did);
450
+ if (!endpoints.length) {
451
+ throw new Error('no valid DWN endpoints found');
452
+ }
453
+ const url = `${endpoints[0].replace(
454
+ trailingSlashRegex,
455
+ ''
456
+ )}/${did}/${path}`;
457
+ if (openAsTab) {
458
+ if (tab && !tab.closed) {tab.location.href = url;}
459
+ } else if (activeNavigation === path) {
460
+ window.location.href = url;
461
+ }
462
+ }
463
+
429
464
  let activeNavigation: string | null = null;
430
465
  let linkFeaturesActive = false;
431
466
 
@@ -437,50 +472,27 @@ function addLinkFeatures(): void {
437
472
  if (!linkFeaturesActive) {
438
473
  clickHandler = async (event: MouseEvent): Promise<void> => {
439
474
  const anchor = (event.target as Element)?.closest('a');
440
- if (anchor) {
441
- const href = anchor.href;
442
- const parsed = parseDrlUrl(href);
443
- if (parsed) {
444
- const did = parsed[0];
445
- const path = parsed[1];
446
- const openAsTab = anchor.target === '_blank';
447
- event.preventDefault();
448
- try {
449
- let tab: Window | null = null;
450
- if (openAsTab) {
451
- tab = window.open('', '_blank');
452
- if (tab) {tab.document.write(tabContent);}
453
- } else {
454
- activeNavigation = path;
455
- // this is to allow for cached DIDs to instantly load without any flash of loading UI
456
- setTimeout(
457
- () =>
458
- document.documentElement.setAttribute('drl-link-loading', ''),
459
- 50
460
- );
461
- }
462
- const endpoints = await getDwnEndpoints(did);
463
- if (!endpoints.length) {
464
- throw new Error('no valid DWN endpoints found');
465
- }
466
- const url = `${endpoints[0].replace(
467
- trailingSlashRegex,
468
- ''
469
- )}/${did}/${path}`;
470
- if (openAsTab) {
471
- if (tab && !tab.closed) {tab.location.href = url;}
472
- } else if (activeNavigation === path) {
473
- window.location.href = url;
474
- }
475
- } catch {
476
- if (activeNavigation === path) {
477
- cancelNavigation();
478
- }
479
- throw new Error(
480
- `DID endpoint resolution failed for the DRL: ${href}`
481
- );
482
- }
475
+ if (!anchor) {
476
+ return;
477
+ }
478
+ const href = anchor.href;
479
+ const parsed = parseDrlUrl(href);
480
+ if (!parsed) {
481
+ return;
482
+ }
483
+ const did = parsed[0];
484
+ const path = parsed[1];
485
+ const openAsTab = anchor.target === '_blank';
486
+ event.preventDefault();
487
+ try {
488
+ await navigateToDrl(did, path, openAsTab);
489
+ } catch {
490
+ if (activeNavigation === path) {
491
+ cancelNavigation();
483
492
  }
493
+ throw new Error(
494
+ `DID endpoint resolution failed for the DRL: ${href}`
495
+ );
484
496
  }
485
497
  };
486
498