@block-auth.io/angular 0.4.0 → 0.5.0

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 (153) hide show
  1. package/fesm2022/block-auth.io-angular.mjs +9976 -0
  2. package/fesm2022/block-auth.io-angular.mjs.map +1 -0
  3. package/index.d.ts +1155 -0
  4. package/package.json +16 -37
  5. package/.turbo/turbo-build.log +0 -37
  6. package/.turbo/turbo-lint.log +0 -4
  7. package/.turbo/turbo-test.log +0 -1400
  8. package/.turbo/turbo-typecheck.log +0 -19
  9. package/CHANGELOG.md +0 -273
  10. package/ng-package.json +0 -6
  11. package/scripts/css-to-ts.mjs +0 -14
  12. package/src/lib/__tests__/integration.test.ts +0 -45
  13. package/src/lib/block-auth.service.test.ts +0 -69
  14. package/src/lib/block-auth.service.ts +0 -81
  15. package/src/lib/components/btns/btn-base-provider.component.test.ts +0 -36
  16. package/src/lib/components/btns/btn-base-provider.component.ts +0 -61
  17. package/src/lib/components/btns/btn-block-auth.component.test.ts +0 -105
  18. package/src/lib/components/btns/btn-block-auth.component.ts +0 -117
  19. package/src/lib/components/btns/btn-gmail.component.test.ts +0 -16
  20. package/src/lib/components/btns/btn-gmail.component.ts +0 -41
  21. package/src/lib/components/btns/btn-google-base.component.test.ts +0 -16
  22. package/src/lib/components/btns/btn-google-base.component.ts +0 -73
  23. package/src/lib/components/btns/btn-metamask.component.test.ts +0 -20
  24. package/src/lib/components/btns/btn-metamask.component.ts +0 -98
  25. package/src/lib/components/btns/btn-microsoft.component.test.ts +0 -16
  26. package/src/lib/components/btns/btn-microsoft.component.ts +0 -77
  27. package/src/lib/components/btns/btn-phantom.component.test.ts +0 -20
  28. package/src/lib/components/btns/btn-phantom.component.ts +0 -93
  29. package/src/lib/components/btns/btn-signin.component.test.ts +0 -55
  30. package/src/lib/components/btns/btn-signin.component.ts +0 -108
  31. package/src/lib/components/btns/btn-wallet-connect.component.test.ts +0 -20
  32. package/src/lib/components/btns/btn-wallet-connect.component.ts +0 -109
  33. package/src/lib/components/btns/index.ts +0 -11
  34. package/src/lib/components/contents/content-signin.component.test.ts +0 -33
  35. package/src/lib/components/contents/content-signin.component.ts +0 -68
  36. package/src/lib/components/contents/content-signup.component.test.ts +0 -86
  37. package/src/lib/components/contents/content-signup.component.ts +0 -222
  38. package/src/lib/components/dds/change-account.component.test.ts +0 -66
  39. package/src/lib/components/dds/change-account.component.ts +0 -112
  40. package/src/lib/components/dds/dropdown-profile-btn.component.test.ts +0 -66
  41. package/src/lib/components/dds/dropdown-profile-btn.component.ts +0 -172
  42. package/src/lib/components/dds/dropdown-profile-item.component.test.ts +0 -75
  43. package/src/lib/components/dds/dropdown-profile-item.component.ts +0 -74
  44. package/src/lib/components/dds/dropdown-profile.component.test.ts +0 -110
  45. package/src/lib/components/dds/dropdown-profile.component.ts +0 -264
  46. package/src/lib/components/flow-block-auth.component.test.ts +0 -95
  47. package/src/lib/components/flow-block-auth.component.ts +0 -228
  48. package/src/lib/components/modals/modal-overlay.component.test.ts +0 -81
  49. package/src/lib/components/modals/modal-overlay.component.ts +0 -43
  50. package/src/lib/components/modals/modal-restoration-expired.component.test.ts +0 -71
  51. package/src/lib/components/modals/modal-restoration-expired.component.ts +0 -83
  52. package/src/lib/components/modals/modal-restore.component.test.ts +0 -74
  53. package/src/lib/components/modals/modal-restore.component.ts +0 -104
  54. package/src/lib/components/modals/modal-signin.component.test.ts +0 -66
  55. package/src/lib/components/modals/modal-signin.component.ts +0 -44
  56. package/src/lib/components/modals/modal-signup.component.test.ts +0 -56
  57. package/src/lib/components/modals/modal-signup.component.ts +0 -40
  58. package/src/lib/components/sections/footer-section.component.test.ts +0 -19
  59. package/src/lib/components/sections/footer-section.component.ts +0 -49
  60. package/src/lib/components/sections/internals/providers-buttons.component.test.ts +0 -27
  61. package/src/lib/components/sections/internals/providers-buttons.component.ts +0 -280
  62. package/src/lib/components/sections/internals/providers-filters.component.test.ts +0 -25
  63. package/src/lib/components/sections/internals/providers-filters.component.ts +0 -139
  64. package/src/lib/components/sections/internals/selected-button.component.test.ts +0 -36
  65. package/src/lib/components/sections/internals/selected-button.component.ts +0 -92
  66. package/src/lib/components/sections/login-section.component.test.ts +0 -49
  67. package/src/lib/components/sections/login-section.component.ts +0 -119
  68. package/src/lib/components/sections/providers-section.component.test.ts +0 -22
  69. package/src/lib/components/sections/providers-section.component.ts +0 -187
  70. package/src/lib/components/txns/internals/permissions-required-modal.component.test.ts +0 -36
  71. package/src/lib/components/txns/internals/permissions-required-modal.component.ts +0 -43
  72. package/src/lib/components/txns/internals/phone-input.component.test.ts +0 -119
  73. package/src/lib/components/txns/internals/phone-input.component.ts +0 -301
  74. package/src/lib/components/txns/internals/solicited-data-modal.component.test.ts +0 -700
  75. package/src/lib/components/txns/internals/solicited-data-modal.component.ts +0 -430
  76. package/src/lib/components/txns/internals/txn-error.component.test.ts +0 -127
  77. package/src/lib/components/txns/internals/txn-error.component.ts +0 -144
  78. package/src/lib/components/txns/internals/txn-type.component.test.ts +0 -52
  79. package/src/lib/components/txns/internals/txn-type.component.ts +0 -51
  80. package/src/lib/components/txns/internals/txn.component.test.ts +0 -593
  81. package/src/lib/components/txns/internals/txn.component.ts +0 -453
  82. package/src/lib/components/txns/txns-overview.component.test.ts +0 -421
  83. package/src/lib/components/txns/txns-overview.component.ts +0 -461
  84. package/src/lib/icons/ai-outline-disconnect.component.ts +0 -21
  85. package/src/lib/icons/bi-logo-gmail.component.ts +0 -21
  86. package/src/lib/icons/cg-profile.component.ts +0 -31
  87. package/src/lib/icons/check-icon.component.ts +0 -27
  88. package/src/lib/icons/ci-clock2.component.ts +0 -31
  89. package/src/lib/icons/fa-arrow-right.component.ts +0 -21
  90. package/src/lib/icons/fa-times.component.ts +0 -21
  91. package/src/lib/icons/fa-undo.component.ts +0 -21
  92. package/src/lib/icons/icons.test.ts +0 -25
  93. package/src/lib/icons/index.ts +0 -22
  94. package/src/lib/icons/io-ios-arrow-back.component.ts +0 -21
  95. package/src/lib/icons/io-ios-arrow-forward.component.ts +0 -21
  96. package/src/lib/icons/io-md-arrow-back.component.ts +0 -19
  97. package/src/lib/icons/io-md-arrow-forward.component.ts +0 -19
  98. package/src/lib/icons/pi-warning-fill.component.ts +0 -21
  99. package/src/lib/icons/tb-arrows-exchange2.component.ts +0 -30
  100. package/src/lib/icons/tb-copy-check-filled.component.ts +0 -21
  101. package/src/lib/icons/tb-copy.component.ts +0 -34
  102. package/src/lib/icons/ti-vendor-microsoft.component.ts +0 -21
  103. package/src/lib/inject-store.test.ts +0 -26
  104. package/src/lib/inject-store.ts +0 -16
  105. package/src/lib/primitives/arrow-icon.component.test.ts +0 -25
  106. package/src/lib/primitives/arrow-icon.component.ts +0 -45
  107. package/src/lib/primitives/btn-arrow-dir.component.test.ts +0 -22
  108. package/src/lib/primitives/btn-arrow-dir.component.ts +0 -65
  109. package/src/lib/primitives/btn-base.component.test.ts +0 -38
  110. package/src/lib/primitives/btn-base.component.ts +0 -140
  111. package/src/lib/primitives/divider-base.component.test.ts +0 -12
  112. package/src/lib/primitives/divider-base.component.ts +0 -74
  113. package/src/lib/primitives/dropdown-arrow.component.test.ts +0 -12
  114. package/src/lib/primitives/dropdown-arrow.component.ts +0 -46
  115. package/src/lib/primitives/dropdown-base.component.test.ts +0 -49
  116. package/src/lib/primitives/dropdown-base.component.ts +0 -329
  117. package/src/lib/primitives/helpers.ts +0 -151
  118. package/src/lib/primitives/horizontal-loader.component.test.ts +0 -20
  119. package/src/lib/primitives/horizontal-loader.component.ts +0 -46
  120. package/src/lib/primitives/icon-base.component.test.ts +0 -19
  121. package/src/lib/primitives/icon-base.component.ts +0 -58
  122. package/src/lib/primitives/img-loader.component.test.ts +0 -22
  123. package/src/lib/primitives/img-loader.component.ts +0 -121
  124. package/src/lib/primitives/index.ts +0 -29
  125. package/src/lib/primitives/input-base.component.test.ts +0 -20
  126. package/src/lib/primitives/input-base.component.ts +0 -210
  127. package/src/lib/primitives/lifetime-slider-base.component.test.ts +0 -88
  128. package/src/lib/primitives/lifetime-slider-base.component.ts +0 -75
  129. package/src/lib/primitives/oval-spinner.component.test.ts +0 -17
  130. package/src/lib/primitives/oval-spinner.component.ts +0 -136
  131. package/src/lib/primitives/pickers/dropdown-picker-animated-base.component.ts +0 -220
  132. package/src/lib/primitives/pickers/picker-button.component.ts +0 -74
  133. package/src/lib/primitives/pickers/time-picker-dropdown-selector.component.ts +0 -188
  134. package/src/lib/primitives/pickers/time-picker.component.ts +0 -124
  135. package/src/lib/primitives/pickers/time-unit-selector.component.ts +0 -82
  136. package/src/lib/primitives/progressbar.component.test.ts +0 -34
  137. package/src/lib/primitives/progressbar.component.ts +0 -36
  138. package/src/lib/primitives/providersStyles.ts +0 -218
  139. package/src/lib/primitives/slider-base.component.ts +0 -56
  140. package/src/lib/provide-block-auth.test.ts +0 -43
  141. package/src/lib/provide-block-auth.ts +0 -43
  142. package/src/lib/runtime/block-auth-runtime.directive.test.ts +0 -89
  143. package/src/lib/runtime/block-auth-runtime.directive.ts +0 -68
  144. package/src/lib/teleport-body.directive.test.ts +0 -29
  145. package/src/lib/teleport-body.directive.ts +0 -21
  146. package/src/lib/testing.ts +0 -15
  147. package/src/lib/transitions.css +0 -19
  148. package/src/public-api.ts +0 -86
  149. package/src/vitest.setup.ts +0 -8
  150. package/tailwind.config.cjs +0 -6
  151. package/tsconfig.json +0 -15
  152. package/tsconfig.lib.json +0 -9
  153. package/vite.config.mts +0 -44
@@ -1,75 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { Component } from '@angular/core';
3
- import { render, screen, fireEvent } from '@testing-library/angular';
4
- import { DropdownProfileItemComponent } from './dropdown-profile-item.component';
5
-
6
- // Port de packages/react/src/components/dds/DropdownProfileItem.test.tsx (mapa:
7
- // packages/vue/.../DropdownProfileItem.test.ts). Puramente presentacional.
8
- describe('DropdownProfileItem', () => {
9
- it('renderiza el texto y emite clicked al pulsar', async () => {
10
- const onClick = vi.fn();
11
- @Component({
12
- standalone: true,
13
- imports: [DropdownProfileItemComponent],
14
- template: `<ba-dropdown-profile-item text="Disconnect" (clicked)="f()" />`,
15
- })
16
- class Host {
17
- f = onClick;
18
- }
19
- await render(Host);
20
- await fireEvent.click(screen.getByText('Disconnect'));
21
- expect(onClick).toHaveBeenCalled();
22
- });
23
-
24
- it('no emite clicked cuando disabled=true', async () => {
25
- const onClick = vi.fn();
26
- @Component({
27
- standalone: true,
28
- imports: [DropdownProfileItemComponent],
29
- template: `<ba-dropdown-profile-item text="Disconnect" [disabled]="true" (clicked)="f()" />`,
30
- })
31
- class Host {
32
- f = onClick;
33
- }
34
- await render(Host);
35
- await fireEvent.click(screen.getByText('Disconnect'));
36
- expect(onClick).not.toHaveBeenCalled();
37
- });
38
-
39
- it('renderiza el contenido proyectado de los slots firstIcon/secondIcon', async () => {
40
- @Component({
41
- standalone: true,
42
- imports: [DropdownProfileItemComponent],
43
- template: `<ba-dropdown-profile-item text="Item">
44
- <span slot="firstIcon" data-testid="first-icon"></span>
45
- <span slot="secondIcon" data-testid="second-icon"></span>
46
- </ba-dropdown-profile-item>`,
47
- })
48
- class Host {}
49
- await render(Host);
50
- expect(screen.getByTestId('first-icon')).toBeDefined();
51
- expect(screen.getByTestId('second-icon')).toBeDefined();
52
- });
53
-
54
- it('aplica el estilo de borde superior cuando isTopBorder=true', async () => {
55
- const { container } = await render(DropdownProfileItemComponent, {
56
- inputs: { text: 'Item', isTopBorder: true },
57
- });
58
- expect(container.querySelector('li')?.className).toContain('bas-border-t');
59
- });
60
-
61
- // Regresión: el host es display:contents para que el <li> (bas-w-full) sea hijo
62
- // directo del flex de la <ul> y los items queden alineados a la izquierda (no
63
- // centrados por el `bas-items-center` de la ul encogiendo el host).
64
- it('el host es transparente al layout (display: contents)', async () => {
65
- @Component({
66
- standalone: true,
67
- imports: [DropdownProfileItemComponent],
68
- template: `<ba-dropdown-profile-item text="Item" />`,
69
- })
70
- class Host {}
71
- const { container } = await render(Host);
72
- const host = container.querySelector('ba-dropdown-profile-item') as HTMLElement;
73
- expect(host.style.display).toBe('contents');
74
- });
75
- });
@@ -1,74 +0,0 @@
1
- import { ChangeDetectionStrategy, Component, Type, input, output } from '@angular/core';
2
- import { NgComponentOutlet } from '@angular/common';
3
-
4
- // `firstIcon`/`secondIcon` (ReactNode) -> proyección de contenido con
5
- // `[slot=firstIcon]`/`[slot=secondIcon]` (misma convención `[slot=icon]` ya
6
- // usada por `ba-btn-base-provider`). `onClick` -> output `clicked`.
7
- //
8
- // Además, para el caso de la lista de items adicionales de `DropdownProfile`
9
- // (iconos dinámicos por-item que no se pueden proyectar estáticamente dentro de
10
- // un `@for`), se acepta un `firstIcon` opcional como *tipo de componente*
11
- // (`Type<unknown>`) renderizado vía `NgComponentOutlet` — equivalente Angular
12
- // idiomático del `VNode | (() => VNode)` del port Vue.
13
- //
14
- // La animación framer-motion (`motion.li` + `liItemVariants`) se elimina: el
15
- // panel completo se anima a nivel de `DropdownProfile` (mismo patrón que
16
- // `DropdownBase`). `onAnimationComplete` también se elimina aquí; la señal
17
- // equivalente ("panel abierto") la gestiona `DropdownProfile`.
18
- @Component({
19
- selector: 'ba-dropdown-profile-item',
20
- standalone: true,
21
- // El host debe ser transparente al layout para que el <li> (bas-w-full) sea
22
- // hijo directo del flex de la <ul> (como en React, donde <motion.li> se
23
- // renderiza directamente). Sin esto el host `<ba-dropdown-profile-item>` es un
24
- // flex-item que, con `bas-items-center` en la ul, se encoge a su contenido y
25
- // queda CENTRADO en vez de llenar el ancho y alinear el texto a la izquierda.
26
- host: { style: 'display: contents' },
27
- changeDetection: ChangeDetectionStrategy.OnPush,
28
- imports: [NgComponentOutlet],
29
- template: `
30
- <li
31
- [id]="id()"
32
- [class]="
33
- 'bas-box-border bas-max-h-[36px] bas-min-h-[36px] bas-w-full ' +
34
- (isTopBorder()
35
- ? 'bas-border-t bas-border-[var(--bal-primary-90)] bas-border-solid bas-border-x-0 bas-border-b-0 bas-box-border hover:bas-border-[var(--bal-primary-100)] bal-ba-transition-2'
36
- : '')
37
- "
38
- >
39
- <div
40
- [class]="
41
- 'bal-ba-transition-2 bas-box-border bas-flex bas-w-full bas-flex-row bas-items-center bas-justify-between bas-gap-2 bas-px-2 bas-py-1 bas-text-[var(--bal-primary-700)] hover:bas-bg-[var(--bal-primary-10)] hover:bas-text-[var(--bal-primary-900)] ' +
42
- classNames() + ' ' +
43
- (isTopBorder() ? 'bas-h-[35px]' : 'bas-h-9') + ' ' +
44
- (disabled() ? 'bas-cursor-not-allowed bas-opacity-50' : 'bas-cursor-pointer')
45
- "
46
- (click)="onItemClicked()"
47
- >
48
- <div class="bas-flex bas-h-full bas-w-fit bas-flex-row bas-items-center bas-gap-3">
49
- @if (firstIcon()) {
50
- <ng-container [ngComponentOutlet]="firstIcon()" [ngComponentOutletInputs]="{ class: 'bas-h-5 bas-w-5' }" />
51
- }
52
- <ng-content select="[slot=firstIcon]" />
53
- <p class="bas-m-0 bas-text-base">{{ text() }}</p>
54
- </div>
55
- <ng-content select="[slot=secondIcon]" />
56
- </div>
57
- </li>
58
- `,
59
- })
60
- export class DropdownProfileItemComponent {
61
- id = input('dd-item-container');
62
- text = input('');
63
- isTopBorder = input(false);
64
- classNames = input('');
65
- disabled = input(false);
66
- /** Icono dinámico opcional (tipo de componente) para items en bucle. */
67
- firstIcon = input<Type<unknown> | null>(null);
68
-
69
- clicked = output<void>();
70
-
71
- onItemClicked(): void {
72
- if (!this.disabled()) this.clicked.emit();
73
- }
74
- }
@@ -1,110 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { Component } from '@angular/core';
3
- import { render, screen, fireEvent, waitFor } from '@testing-library/angular';
4
- import { map } from 'nanostores';
5
- import { DropdownProfileComponent } from './dropdown-profile.component';
6
- import { provideBlockAuthClientForTest } from '../../testing';
7
-
8
- vi.mock('@wagmi/core', () => ({
9
- createConfig: vi.fn(() => ({ connectors: [] })),
10
- connect: vi.fn(), disconnect: vi.fn(), getAccount: vi.fn(() => ({})),
11
- signMessage: vi.fn(), watchAccount: vi.fn(() => () => undefined), http: vi.fn(),
12
- }));
13
- vi.mock('@wagmi/connectors', () => ({
14
- injected: vi.fn(() => ({ id: 'injected' })), walletConnect: vi.fn(() => ({ id: 'walletConnect' })),
15
- }));
16
-
17
- // Port de packages/react/src/components/dds/DropdownProfile.test.tsx (mapa:
18
- // packages/vue/.../DropdownProfile.test.ts). Client falso con `logout` spy y
19
- // stores nanostores; serviceName 'blockauth' para textos en inglés.
20
- describe('DropdownProfile', () => {
21
- // isSigned: true — el item list (My profile/Change account/Disconnect)
22
- // solo se muestra autenticado (ver dropdown-profile.component.ts).
23
- function makeClient(logout = vi.fn(async () => {}), uiOverrides: Record<string, unknown> = {}) {
24
- return {
25
- logout,
26
- web3: { signup: vi.fn() },
27
- oauth: { signupGoogle: vi.fn(), signupMicrosoft: vi.fn() },
28
- connectBlockAuth: vi.fn(),
29
- state: { $ui: map({ serviceName: 'blockauth', isSigned: true, ...uiOverrides }), $ws: map({}) },
30
- } as any;
31
- }
32
-
33
- it('"Disconnect" llama a client.logout() ANTES del prop onLogout (orden critico)', async () => {
34
- const callOrder: string[] = [];
35
- const client = makeClient(vi.fn(async () => {
36
- callOrder.push('logout');
37
- }));
38
- const onLogout = vi.fn(async () => {
39
- callOrder.push('onLogout');
40
- });
41
- @Component({
42
- standalone: true,
43
- imports: [DropdownProfileComponent],
44
- template: `<ba-dropdown-profile [onLogout]="ol" />`,
45
- })
46
- class Host {
47
- ol = onLogout;
48
- }
49
- await render(Host, { providers: [provideBlockAuthClientForTest(client)] });
50
-
51
- await fireEvent.click(screen.getByTestId('dropdown-profile-btn'));
52
- await fireEvent.click(screen.getByText('Disconnect'));
53
-
54
- await waitFor(() => expect(onLogout).toHaveBeenCalled());
55
- expect(client.logout).toHaveBeenCalled();
56
- expect(callOrder).toEqual(['logout', 'onLogout']);
57
- });
58
-
59
- it('abre y cierra el panel al pulsar el boton de perfil', async () => {
60
- await render(DropdownProfileComponent, {
61
- providers: [provideBlockAuthClientForTest(makeClient())],
62
- });
63
- // Panel cerrado inicialmente: "Disconnect" no está en el DOM.
64
- expect(screen.queryByText('Disconnect')).toBeNull();
65
- await fireEvent.click(screen.getByTestId('dropdown-profile-btn'));
66
- expect(screen.getByText('Disconnect')).toBeTruthy();
67
- });
68
-
69
- it('click-outside cierra el panel; click en el propio boton de perfil no cuenta como fuera', async () => {
70
- await render(DropdownProfileComponent, {
71
- providers: [provideBlockAuthClientForTest(makeClient())],
72
- });
73
- await fireEvent.click(screen.getByTestId('dropdown-profile-btn'));
74
- expect(screen.getByText('Disconnect')).toBeTruthy();
75
-
76
- const outside = document.createElement('div');
77
- document.body.appendChild(outside);
78
- await fireEvent.click(outside);
79
- await waitFor(() => expect(screen.queryByText('Disconnect')).toBeNull());
80
- document.body.removeChild(outside);
81
- });
82
-
83
- it('renderiza el item por defecto "My profile" cuando no se pasan additionalDropdownItems', async () => {
84
- await render(DropdownProfileComponent, {
85
- providers: [provideBlockAuthClientForTest(makeClient())],
86
- });
87
- await fireEvent.click(screen.getByTestId('dropdown-profile-btn'));
88
- expect(screen.getByText('My profile')).toBeTruthy();
89
- });
90
-
91
- // Regresión: el contenedor raíz debe encogerse a su contenido (bas-w-fit) para
92
- // que el panel (bas-w-full) tome el ancho del botón y no se estire al ancho del
93
- // contenedor de la app. Igual que React/Vue.
94
- it('el contenedor raíz usa bas-w-fit (panel compacto, no a ancho completo)', async () => {
95
- await render(DropdownProfileComponent, {
96
- providers: [provideBlockAuthClientForTest(makeClient())],
97
- });
98
- expect(screen.getByTestId('dropdown-profile').className).toContain('bas-w-fit');
99
- });
100
-
101
- it('sin firmar (conectado pero no autenticado) solo permite copiar el DID', async () => {
102
- await render(DropdownProfileComponent, {
103
- providers: [provideBlockAuthClientForTest(makeClient(vi.fn(), { isSigned: false }))],
104
- });
105
- await fireEvent.click(screen.getByTestId('dropdown-profile-btn'));
106
- expect(screen.queryByText('My profile')).toBeNull();
107
- expect(screen.queryByText('Change account')).toBeNull();
108
- expect(screen.queryByText('Disconnect')).toBeNull();
109
- });
110
- });
@@ -1,264 +0,0 @@
1
- import {
2
- ChangeDetectionStrategy,
3
- Component,
4
- DestroyRef,
5
- ElementRef,
6
- HostListener,
7
- Type,
8
- computed,
9
- inject,
10
- input,
11
- signal,
12
- viewChild,
13
- } from '@angular/core';
14
- import { $locale } from '@block-auth.io/core';
15
- import { injectBlockAuthClient } from '../../provide-block-auth';
16
- import { injectStore } from '../../inject-store';
17
- import { CgProfileComponent, AiOutlineDisconnectComponent } from '../../icons';
18
- import { ChangeAccountComponent } from './change-account.component';
19
- import { DropdownProfileItemComponent } from './dropdown-profile-item.component';
20
- import { DropdownProfileBtnComponent } from './dropdown-profile-btn.component';
21
-
22
- // Decisiones de diseño:
23
- // - `onLogout`/`onNavigate` son INPUTS DE FUNCIÓN (no outputs): `onLogout` se
24
- // hace `await` DESPUÉS de `client.logout()` (orden crítico, un output no se
25
- // puede "esperar"); `onNavigate` es un hook de host con rama alternativa
26
- // (`window.location.href`) cuando es null. El resto de callbacks son outputs
27
- // (`clicked`/`changeAccountClicked`).
28
- // - Refs `profileBtnEl`/`dropdownPanelEl` (viewChild) sobre `<div>`s propios de
29
- // este componente para el click-outside.
30
- // - La animación de apertura es `@if` + clase `ba-pop`. Al abrir, un
31
- // `setTimeout(200)` marca `isAnimationCompleted` (habilita `overflow-y-auto`).
32
- // - `additionalDropdownItems[].firstIcon` es un tipo de componente
33
- // (`Type<unknown>`) renderizado por `dropdown-profile-item` vía NgComponentOutlet.
34
- // - "Disconnect": `client.logout()` PRIMERO y `onLogout()` DESPUÉS (verificado
35
- // en el test).
36
- export interface DropdownProfileAdditionalItem {
37
- onClick: () => void;
38
- /** String plano o mapa de locale (`{ es, en }`). */
39
- text: string | Record<string, string>;
40
- firstIcon?: Type<unknown> | null;
41
- disabled?: boolean;
42
- }
43
-
44
- @Component({
45
- selector: 'ba-dropdown-profile',
46
- standalone: true,
47
- changeDetection: ChangeDetectionStrategy.OnPush,
48
- imports: [DropdownProfileBtnComponent, DropdownProfileItemComponent, ChangeAccountComponent],
49
- template: `
50
- <div
51
- data-testid="dropdown-profile"
52
- class="bas-flex bas-w-fit bas-flex-col bas-items-center bas-justify-start"
53
- [style.height.px]="getHeight(dropdownBtnSize())"
54
- >
55
- <div #profileBtnEl>
56
- <ba-dropdown-profile-btn
57
- [serviceName]="serviceName()"
58
- [dropdownBtnBgClassNames]="dropdownBtnBgClassNames()"
59
- [dropdownBtnSize]="dropdownBtnSize()"
60
- [dropdownBtnBorderClassNames]="dropdownBtnBorderClassNames()"
61
- [dropdownBtnTextColorClassNames]="dropdownBtnTextColorClassNames()"
62
- [height]="getHeight(dropdownBtnSize())"
63
- [isProfileOpen]="isProfileOpen()"
64
- (clicked)="onProfileClicked()"
65
- />
66
- </div>
67
- @if (isProfileOpen()) {
68
- <div
69
- #dropdownPanelEl
70
- class="ba-pop bal-ba-transition-2 bal-ba-shadow-base bal-ba-hover-shadow-md bas-z-50 bas-mt-2 bas-box-border bas-w-full bas-overflow-hidden bas-rounded-md bas-border bas-border-solid bas-border-[var(--bal-primary-100)] bas-bg-white hover:bas-border-[var(--bal-primary-300)]"
71
- [style.minHeight.px]="dropdownHeight() ?? totalDropdownItems() * 36 + 2"
72
- >
73
- <ul
74
- [class]="
75
- 'bas-flex bas-h-full bas-w-full bas-box-border bas-flex-col bas-items-center bas-justify-start bas-text-base bas-text-[var(--bal-primary-700)] bal-ba-transition-2 hover:bas-text-[var(--bal-primary-900)] bal-ba-scroll-base bas-p-0 bas-m-0 ' +
76
- (isAnimationCompleted() && isProfileOpen() ? 'bas-overflow-y-auto' : '')
77
- "
78
- [style.maxHeight.px]="dropdownHeight() ?? totalDropdownItems() * 36"
79
- >
80
- <!-- ADDITIONAL ITEMS -->
81
- @for (item of itemsToShow(); track $index; let index = $index) {
82
- <ba-dropdown-profile-item
83
- [id]="'ba-ddi-additional-item-' + index"
84
- [text]="localized(item.text, '')"
85
- [firstIcon]="item.firstIcon ?? null"
86
- [isTopBorder]="index !== 0"
87
- [disabled]="item.disabled ?? false"
88
- (clicked)="item.onClick()"
89
- />
90
- }
91
- <!-- CHANGE ACCOUNT + DISCONNECT — hidden until the login transaction is signed -->
92
- @if (isSigned()) {
93
- <ba-change-account
94
- [serviceName]="serviceName()"
95
- [text]="localized(btnsTexts().changeAccount, 'Change account')"
96
- [disabled]="disabled()"
97
- [isTopBorder]="isWeb3Service() || itemsToShow().length > 0"
98
- (changeAccountClicked)="onChangeAccountClicked()"
99
- />
100
- <ba-dropdown-profile-item
101
- id="ba-dd8-disconnect-0"
102
- [text]="localized(btnsTexts().disconnect, 'Disconnect')"
103
- [firstIcon]="disconnectIcon"
104
- [isTopBorder]="true"
105
- (clicked)="onDisconnectClicked()"
106
- />
107
- }
108
- </ul>
109
- </div>
110
- }
111
- </div>
112
- `,
113
- styles: [
114
- `
115
- .ba-pop {
116
- animation: ba-pop-in 0.15s ease;
117
- transform-origin: top right;
118
- }
119
- @keyframes ba-pop-in {
120
- from { opacity: 0; transform: scale(0.95); }
121
- to { opacity: 1; transform: scale(1); }
122
- }
123
- `,
124
- ],
125
- })
126
- export class DropdownProfileComponent {
127
- onLogout = input<() => void | Promise<void>>(async () => {});
128
- /** Host-app navigation for "My profile" when already on the identity origin. */
129
- onNavigate = input<((path: string) => void) | null>(null);
130
- isInsideModal = input(false);
131
- /** Modal container that scopes the click-outside listener when `isInsideModal`. */
132
- container = input<HTMLElement | null>(null);
133
- /** Disables the "Change account" row (default: disabled — not functional yet). */
134
- disabled = input(true);
135
- dropdownBtnSize = input<'xs' | 'small' | 'base' | 'large'>('base');
136
- dropdownBtnBgClassNames = input('bas-bg-transparent');
137
- dropdownBtnTextColorClassNames = input(
138
- 'bas-text-[var(--bal-primary-700)] group-hover:bas-text-[var(--bal-primary-900)]',
139
- );
140
- dropdownBtnBorderClassNames = input<string | undefined>(undefined);
141
- dropdownHeight = input<number | null>(null);
142
- additionalDropdownItems = input<DropdownProfileAdditionalItem[] | null>(null);
143
-
144
- private readonly profileBtnEl = viewChild<ElementRef<HTMLDivElement>>('profileBtnEl');
145
- private readonly dropdownPanelEl = viewChild<ElementRef<HTMLDivElement>>('dropdownPanelEl');
146
-
147
- private readonly client = injectBlockAuthClient();
148
- private readonly ui = injectStore(this.client.state.$ui);
149
- private readonly locale = injectStore($locale);
150
-
151
- protected readonly disconnectIcon = AiOutlineDisconnectComponent;
152
- protected readonly isProfileOpen = signal(false);
153
- protected readonly isAnimationCompleted = signal(false);
154
- private animTimeout: ReturnType<typeof setTimeout> | undefined;
155
-
156
- protected readonly serviceName = computed(() => this.ui().serviceName ?? 'blockauth');
157
- protected readonly isSigned = computed(() => this.ui().isSigned);
158
-
159
- private readonly uiConfigContent = computed(
160
- () =>
161
- this.ui().uiConfig as
162
- | { config?: { content?: { btns?: Record<string, Record<string, string>> } } }
163
- | null,
164
- );
165
- private readonly isUiConfig = computed(
166
- () => this.uiConfigContent() != null && Object.keys(this.uiConfigContent()!).length > 0,
167
- );
168
- protected readonly btnsTexts = computed(
169
- () =>
170
- (this.isUiConfig() && this.uiConfigContent()?.config?.content?.btns) || {
171
- disconnect: { es: 'Desconectar', en: 'Disconnect' },
172
- changeAccount: { es: 'Cambiar cuenta', en: 'Change account' },
173
- },
174
- );
175
-
176
- private readonly defaultAdditionalDropdownItems = computed<DropdownProfileAdditionalItem[]>(() => [
177
- {
178
- onClick: () => {
179
- const url = 'https://identity.block-auth.io';
180
- const identityOrigin = 'https://identity.block-auth.io';
181
- if (typeof window === 'undefined') return;
182
- if (window.location.origin === identityOrigin) {
183
- const navigate = this.onNavigate();
184
- if (navigate) navigate('/user/profile');
185
- else window.location.href = url;
186
- } else {
187
- window.open(url, '_blank');
188
- }
189
- },
190
- text: { es: 'Mi perfil', en: 'My profile' },
191
- firstIcon: CgProfileComponent,
192
- disabled: false,
193
- },
194
- ]);
195
-
196
- // Not fully authenticated yet (connected but transaction unsigned): only the
197
- // "Copy DID" row in `DropdownProfileBtnComponent` is a valid action, so the
198
- // item list (My profile / Change account / Disconnect) stays empty.
199
- protected readonly itemsToShow = computed(() =>
200
- this.isSigned() ? this.additionalDropdownItems() ?? this.defaultAdditionalDropdownItems() : [],
201
- );
202
- private readonly web2Services = ['google', 'microsoft'];
203
- protected readonly isWeb3Service = computed(() => !this.web2Services.includes(this.serviceName()));
204
- protected readonly totalDropdownItems = computed(() => (this.isSigned() ? 2 + this.itemsToShow().length : 0));
205
-
206
- private readonly heightBySize: Record<string, number> = { xs: 46, small: 52, base: 58, large: 64 };
207
-
208
- constructor() {
209
- inject(DestroyRef).onDestroy(() => {
210
- if (this.animTimeout) clearTimeout(this.animTimeout);
211
- });
212
- }
213
-
214
- getHeight(size: string): number {
215
- return this.heightBySize[size];
216
- }
217
-
218
- localized(text: string | Record<string, string> | undefined, fallback: string): string {
219
- if (!text) return fallback;
220
- if (typeof text === 'string') return text;
221
- return text[this.locale()] ?? text['en'] ?? fallback;
222
- }
223
-
224
- onProfileClicked(): void {
225
- if (!this.isSigned()) return;
226
- this.isAnimationCompleted.set(false);
227
- const next = !this.isProfileOpen();
228
- this.isProfileOpen.set(next);
229
- if (this.animTimeout) clearTimeout(this.animTimeout);
230
- if (next) this.animTimeout = setTimeout(() => this.isAnimationCompleted.set(true), 200);
231
- }
232
-
233
- async onDisconnectClicked(): Promise<void> {
234
- this.isAnimationCompleted.set(false);
235
- this.isProfileOpen.set(false);
236
- // Clear BlockAuth state first, then let the host app tear down — otherwise
237
- // onLogout could read stale storage. Order is critical (verified in test).
238
- await this.client.logout();
239
- await this.onLogout()();
240
- }
241
-
242
- onChangeAccountClicked(): void {
243
- if (this.disabled()) return;
244
- this.isAnimationCompleted.set(false);
245
- this.isProfileOpen.set(false);
246
- }
247
-
248
- // Click-outside. Con @HostListener el listener vive siempre en document; para
249
- // respetar la
250
- // semántica "escuchar sobre `container` cuando `isInsideModal && container`"
251
- // se ignora todo click fuera de ese contenedor. Un click sobre el propio
252
- // botón de perfil nunca cuenta como "fuera". "Fuera" se calcula vs el panel.
253
- @HostListener('document:click', ['$event'])
254
- onDocumentClick(e: MouseEvent): void {
255
- if (!this.isProfileOpen()) return;
256
- const target = e.target as Node;
257
- const container = this.container();
258
- if (this.isInsideModal() && container && !container.contains(target)) return;
259
- const btnEl = this.profileBtnEl()?.nativeElement;
260
- if (btnEl && btnEl.contains(target)) return;
261
- const panel = this.dropdownPanelEl()?.nativeElement;
262
- if (panel && !panel.contains(target)) this.isProfileOpen.set(false);
263
- }
264
- }
@@ -1,95 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { Component } from '@angular/core';
3
- import { render, screen, fireEvent, waitFor } from '@testing-library/angular';
4
- import { map, atom } from 'nanostores';
5
-
6
- vi.mock('@wagmi/core', () => ({
7
- createConfig: vi.fn(() => ({ connectors: [] })),
8
- connect: vi.fn(), disconnect: vi.fn(), getAccount: vi.fn(() => ({})),
9
- signMessage: vi.fn(), watchAccount: vi.fn(() => () => undefined), http: vi.fn(),
10
- }));
11
- vi.mock('@wagmi/connectors', () => ({
12
- injected: vi.fn(() => ({ id: 'injected' })), walletConnect: vi.fn(() => ({ id: 'walletConnect' })),
13
- }));
14
-
15
- import { FlowBlockAuthComponent } from './flow-block-auth.component';
16
- import { provideBlockAuthClientForTest } from '../testing';
17
-
18
- // Port de packages/react/src/components/FlowBlockAuth.test.tsx. El `initializeSdk`
19
- // se pone en `false` donde no se quiere arrancar el runtime real (el arranque
20
- // del runtime lo cubre block-auth-runtime.directive.test.ts). Client falso con
21
- // stores nanostores y spies de acción.
22
- function makeClient(ui: Record<string, unknown> = {}) {
23
- return {
24
- requestSignin: vi.fn(),
25
- openModal: vi.fn(),
26
- closeModal: vi.fn(),
27
- cancelTxns: vi.fn(),
28
- logout: vi.fn(async () => {}),
29
- web3: { signup: vi.fn() },
30
- oauth: { signupGoogle: vi.fn(), signupMicrosoft: vi.fn() },
31
- state: {
32
- $ws: map<Record<string, unknown>>({ ready: false }),
33
- $ui: map<Record<string, unknown>>({ ...ui }),
34
- $wallet: map({}),
35
- $openModals: atom<string[]>([]),
36
- },
37
- } as any;
38
- }
39
-
40
- describe('FlowBlockAuth', () => {
41
- it('renderiza el contenedor del orquestador sin romperse', async () => {
42
- @Component({
43
- standalone: true,
44
- imports: [FlowBlockAuthComponent],
45
- template: `<ba-flow-block-auth [initializeSdk]="false" />`,
46
- })
47
- class Host {}
48
- await render(Host, { providers: [provideBlockAuthClientForTest(makeClient())] });
49
- expect(screen.getByTestId('flow-blockauth')).toBeTruthy();
50
- });
51
-
52
- it('no se rompe cuando initializeSdk esta desactivado', async () => {
53
- @Component({
54
- standalone: true,
55
- imports: [FlowBlockAuthComponent],
56
- template: `<ba-flow-block-auth [initializeSdk]="false" />`,
57
- })
58
- class Host {}
59
- await render(Host, { providers: [provideBlockAuthClientForTest(makeClient())] });
60
- expect(screen.getByTestId('flow-blockauth')).toBeTruthy();
61
- });
62
-
63
- it('en estado log-in, click en el boton de estado llama a client.requestSignin', async () => {
64
- const client = makeClient({
65
- isSdkSignedIn: true,
66
- isServiceConnected: true,
67
- isSigned: false,
68
- isSignedFirstCheck: true,
69
- isOnDeletion: false,
70
- serviceName: 'blockauth',
71
- uiConfig: { config: { content: { btns: { logIn: { en: 'Log in', es: 'Iniciar sesion' } } } } },
72
- });
73
- client.state.$ws.setKey('ready', true);
74
-
75
- @Component({
76
- standalone: true,
77
- imports: [FlowBlockAuthComponent],
78
- template: `<ba-flow-block-auth [initializeSdk]="false" [showDropdownWhenConnected]="false" />`,
79
- })
80
- class Host {}
81
- const { container } = await render(Host, {
82
- providers: [provideBlockAuthClientForTest(client)],
83
- });
84
-
85
- const btn = container.querySelector('#btn-flow-blockauth') as HTMLButtonElement;
86
- expect(btn).toBeTruthy();
87
- expect(btn.disabled).toBe(false);
88
- expect(btn.className).toContain('bal-ba-glass-status-btn');
89
- expect(btn.className).toContain('bal-ba-glass-tone-ready');
90
- await fireEvent.click(btn);
91
-
92
- await waitFor(() => expect(client.requestSignin).toHaveBeenCalled());
93
- expect(client.openModal).toHaveBeenCalledWith('signin');
94
- });
95
- });