@agorapulse/ui-components 22.9.7 → 22.9.9-beta.1

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/agorapulse-ui-components-22.9.9-beta.1.tgz +0 -0
  2. package/fesm2022/agorapulse-ui-components-button.mjs +2 -0
  3. package/fesm2022/agorapulse-ui-components-button.mjs.map +1 -1
  4. package/fesm2022/agorapulse-ui-components-confirm-modal.mjs +19 -21
  5. package/fesm2022/agorapulse-ui-components-confirm-modal.mjs.map +1 -1
  6. package/fesm2022/agorapulse-ui-components-datepicker.mjs +14 -33
  7. package/fesm2022/agorapulse-ui-components-datepicker.mjs.map +1 -1
  8. package/fesm2022/agorapulse-ui-components-directives.mjs +3 -17
  9. package/fesm2022/agorapulse-ui-components-directives.mjs.map +1 -1
  10. package/fesm2022/agorapulse-ui-components-filter-dropdown.mjs +1 -1
  11. package/fesm2022/agorapulse-ui-components-filter-dropdown.mjs.map +1 -1
  12. package/fesm2022/agorapulse-ui-components-i18n.mjs +7 -0
  13. package/fesm2022/agorapulse-ui-components-i18n.mjs.map +1 -1
  14. package/fesm2022/agorapulse-ui-components-icon-button.mjs +4 -2
  15. package/fesm2022/agorapulse-ui-components-icon-button.mjs.map +1 -1
  16. package/fesm2022/agorapulse-ui-components-snackbars-thread.mjs +99 -93
  17. package/fesm2022/agorapulse-ui-components-snackbars-thread.mjs.map +1 -1
  18. package/fesm2022/agorapulse-ui-components-social-button.mjs +4 -2
  19. package/fesm2022/agorapulse-ui-components-social-button.mjs.map +1 -1
  20. package/fesm2022/agorapulse-ui-components-split-button.mjs +8 -2
  21. package/fesm2022/agorapulse-ui-components-split-button.mjs.map +1 -1
  22. package/fesm2022/agorapulse-ui-components-testing.mjs +157 -0
  23. package/fesm2022/agorapulse-ui-components-testing.mjs.map +1 -0
  24. package/fesm2022/agorapulse-ui-components-toggle.mjs +15 -19
  25. package/fesm2022/agorapulse-ui-components-toggle.mjs.map +1 -1
  26. package/fesm2022/agorapulse-ui-components.mjs +1 -1
  27. package/fesm2022/agorapulse-ui-components.mjs.map +1 -1
  28. package/package.json +5 -1
  29. package/types/agorapulse-ui-components-confirm-modal.d.ts +16 -11
  30. package/types/agorapulse-ui-components-datepicker.d.ts +2 -7
  31. package/types/agorapulse-ui-components-directives.d.ts +1 -7
  32. package/types/agorapulse-ui-components-i18n.d.ts +7 -0
  33. package/types/agorapulse-ui-components-snackbars-thread.d.ts +92 -27
  34. package/types/agorapulse-ui-components-testing.d.ts +97 -0
  35. package/types/agorapulse-ui-components-toggle.d.ts +4 -5
  36. package/types/agorapulse-ui-components.d.ts +1 -1
  37. package/agorapulse-ui-components-22.9.7.tgz +0 -0
@@ -1,8 +1,7 @@
1
+ import * as i0 from '@angular/core';
2
+ import { TranslationRequest, I18nOf } from '@agorapulse/ui-components/i18n';
1
3
  import { SymbolRegistry } from '@agorapulse/ui-symbol';
2
- import { Router } from '@angular/router';
3
- import { SafeHtml, DomSanitizer } from '@angular/platform-browser';
4
4
  import { BehaviorSubject } from 'rxjs';
5
- import * as i0 from '@angular/core';
6
5
 
7
6
  /**
8
7
  * Info - 0
@@ -10,8 +9,8 @@ import * as i0 from '@angular/core';
10
9
  * Warning - 2
11
10
  * Error - 3
12
11
  */
13
- type externalSnackbarTypeAllowed = 'info' | 'success' | 'warning' | 'error';
14
- type internalSnackbarTypeAllowed = 0 | 1 | 2 | 3;
12
+ type externalSnackbarTypeAllowed = 'info' | 'success' | 'error';
13
+ type internalSnackbarTypeAllowed = 0 | 1 | 3;
15
14
  /**
16
15
  * We use enum to avoid problem with isolatedModules when export const enum
17
16
  * https://ncjamieson.com/dont-export-const-enums/
@@ -19,32 +18,51 @@ type internalSnackbarTypeAllowed = 0 | 1 | 2 | 3;
19
18
  declare enum SnackbarTypeValues {
20
19
  INFO = "info",
21
20
  SUCCESS = "success",
22
- WARNING = "warning",
23
21
  ERROR = "error"
24
22
  }
23
+ /**
24
+ * A snackbar to show.
25
+ *
26
+ * @example
27
+ * const snackbar: SnackbarsThreadBase = { i18n: { message: 'post.saved', action: 'common.undo' }, snackbarType: 1, callback: undo };
28
+ */
25
29
  interface SnackbarsThreadBase {
26
- actionName?: string;
27
- navigateInternalUrl?: string;
30
+ /** `message` is rendered as sanitized HTML, whatever its form; `action` is the text of the link, rendered as text. */
31
+ i18n: I18nOf<'message', 'action'>;
32
+ /** 0 info, 1 success, 3 error. */
28
33
  snackbarType: internalSnackbarTypeAllowed;
29
- snackbarText: string | SafeHtml;
34
+ /** URL the action navigates to. */
35
+ navigateInternalUrl?: string;
36
+ /** Opens `navigateInternalUrl` in a new tab instead of navigating. */
30
37
  openUrlInNewTab?: boolean;
38
+ /** Called by the action instead of navigating; the snackbar is removed first. */
31
39
  callback?: () => void;
32
40
  }
41
+ /**
42
+ * What a snackbar shown by tone can carry besides its message.
43
+ *
44
+ * @example
45
+ * snackbars.success('rule.created', { action: 'rule.open', navigateInternalUrl: `/rules/${id}` });
46
+ */
47
+ interface SnackbarOptions {
48
+ /** Text of the link; shown only with `callback` or `navigateInternalUrl`, rendered as text. */
49
+ action?: TranslationRequest;
50
+ /** Runs when the link is clicked. */
51
+ callback?: () => void;
52
+ /** App route the link opens. */
53
+ navigateInternalUrl?: string;
54
+ /** Opens `navigateInternalUrl` in a new tab. */
55
+ openUrlInNewTab?: boolean;
56
+ /** Milliseconds before the snackbar closes; 0 keeps it open. Defaults to 5000. */
57
+ timeout?: number;
58
+ }
33
59
  interface SnackbarsThreadComplete extends SnackbarsThreadBase {
34
60
  id: string;
35
61
  }
36
- declare abstract class CodeStatus {
37
- snackbarText: string;
38
- snackbarType: internalSnackbarTypeAllowed;
39
- protected constructor(snackbarText: string, snackbarType: internalSnackbarTypeAllowed);
40
- }
41
- declare function generateCodeStatus(text: string, type: externalSnackbarTypeAllowed): CodeStatus;
42
62
 
43
63
  declare class SnackbarsThreadService {
44
- private domSanitizer;
45
64
  private _list;
46
65
  snackbarList: BehaviorSubject<SnackbarsThreadComplete[]>;
47
- constructor(domSanitizer: DomSanitizer);
48
66
  private _emit;
49
67
  add(elem: SnackbarsThreadBase, timeout?: number): void;
50
68
  addWithId(elem: SnackbarsThreadBase, id: string, timeout?: number): void;
@@ -52,31 +70,78 @@ declare class SnackbarsThreadService {
52
70
  * Adds the snackbar and return its ID so it can be closed further
53
71
  */
54
72
  addSnackbar(elem: SnackbarsThreadBase, timeout?: number): string;
73
+ /**
74
+ * Shows a success snackbar and returns its id; `message` is rendered as sanitized HTML.
75
+ * `options` adds a link (`action` with `callback` or `navigateInternalUrl`) and sets the `timeout`.
76
+ *
77
+ * @example
78
+ * snackbars.success('post.saved');
79
+ * snackbars.success('rule.created', { action: 'rule.open', navigateInternalUrl: `/rules/${id}` });
80
+ */
81
+ success(message: TranslationRequest, options?: SnackbarOptions): string;
82
+ /**
83
+ * Shows an error snackbar; same contract as {@link success}.
84
+ *
85
+ * @example
86
+ * snackbars.error({ key: 'post.failed', params: { count: 2 } });
87
+ */
88
+ error(message: TranslationRequest, options?: SnackbarOptions): string;
89
+ /**
90
+ * Shows an info snackbar, styled as a success; same contract as {@link success}.
91
+ *
92
+ * @example
93
+ * snackbars.info('post.scheduled');
94
+ */
95
+ info(message: TranslationRequest, options?: SnackbarOptions): string;
96
+ /**
97
+ * Shows a snackbar whose type is data rather than a literal; same contract as {@link success}.
98
+ * `info` is styled as a success.
99
+ *
100
+ * @example
101
+ * snackbars.show('post.saved', status.type);
102
+ */
103
+ show(message: TranslationRequest, type: externalSnackbarTypeAllowed, options?: SnackbarOptions): string;
55
104
  remove(id: string | undefined): void;
56
105
  private generateId;
57
106
  static ɵfac: i0.ɵɵFactoryDeclaration<SnackbarsThreadService, never>;
58
107
  static ɵprov: i0.ɵɵInjectableDeclaration<SnackbarsThreadService>;
59
108
  }
60
109
 
110
+ /**
111
+ * Shows the snackbars added through {@link SnackbarsThreadService}; their texts are resolved while shown, so they follow language changes.
112
+ */
61
113
  declare class SnackbarsThreadComponent {
62
- snackbarsThreadService: SnackbarsThreadService;
63
- symbolRegistry: SymbolRegistry;
64
- private readonly router;
65
114
  SnackbarTypesMap: {
66
- 0: string;
67
- 1: string;
68
- 2: string;
69
- 3: string;
115
+ readonly 0: "info";
116
+ readonly 1: "success";
117
+ readonly 3: "error";
70
118
  };
71
119
  SnackbarIconsMap: {
72
120
  [k: number]: string;
73
121
  };
74
- constructor(snackbarsThreadService: SnackbarsThreadService, symbolRegistry: SymbolRegistry, router: Router);
122
+ readonly snackbarsThreadService: SnackbarsThreadService;
123
+ readonly symbolRegistry: SymbolRegistry;
124
+ private readonly router;
125
+ private readonly resolveTexts;
126
+ private readonly snackbars;
127
+ protected readonly rows: i0.Signal<{
128
+ snackbar: SnackbarsThreadComplete;
129
+ texts: {
130
+ readonly message: string | undefined;
131
+ readonly action: string | undefined;
132
+ };
133
+ }[]>;
134
+ protected readonly iconLabels: i0.Signal<{
135
+ readonly info: string;
136
+ readonly success: string;
137
+ readonly error: string;
138
+ }>;
139
+ constructor();
75
140
  remove(id: string): void;
76
141
  onActionClick(snackbar: SnackbarsThreadBase, id: string): void;
77
142
  static ɵfac: i0.ɵɵFactoryDeclaration<SnackbarsThreadComponent, never>;
78
143
  static ɵcmp: i0.ɵɵComponentDeclaration<SnackbarsThreadComponent, "ap-snackbars-thread", never, {}, {}, never, never, true, never>;
79
144
  }
80
145
 
81
- export { CodeStatus, SnackbarTypeValues, SnackbarsThreadComponent, SnackbarsThreadService, generateCodeStatus };
82
- export type { SnackbarsThreadBase, externalSnackbarTypeAllowed };
146
+ export { SnackbarTypeValues, SnackbarsThreadComponent, SnackbarsThreadService };
147
+ export type { SnackbarOptions, SnackbarsThreadBase, externalSnackbarTypeAllowed };
@@ -0,0 +1,97 @@
1
+ import { ComponentType } from '@angular/cdk/portal';
2
+ import * as i0 from '@angular/core';
3
+ import { TemplateRef, Provider } from '@angular/core';
4
+ import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
5
+ import { TranslationRequest } from '@agorapulse/ui-components/i18n';
6
+ import { SnackbarsThreadService, externalSnackbarTypeAllowed, SnackbarOptions, SnackbarsThreadBase } from '@agorapulse/ui-components/snackbars-thread';
7
+
8
+ /** A text as a spec compares it: a key with its optional params, or raw text. A bare key string becomes `{ key }`. */
9
+ type ShownText = {
10
+ key: string;
11
+ params?: Record<string, unknown>;
12
+ } | {
13
+ raw: string;
14
+ };
15
+
16
+ /** One confirm modal the code under test opened. */
17
+ interface AskedConfirmation {
18
+ title: ShownText;
19
+ message: ShownText;
20
+ confirm?: ShownText;
21
+ cancel?: ShownText;
22
+ }
23
+ /**
24
+ * A {@link MatDialog} for specs that answers every `ConfirmModalComponent.open` with {@link answer} instead of rendering
25
+ * it, and records the texts of each modal in {@link asked}. Any other component goes to the real dialog. It needs no
26
+ * test runner, so it works under Jest and Vitest alike.
27
+ *
28
+ * @example
29
+ * TestBed.configureTestingModule({ providers: [provideFakeConfirmModal({ answer: false })] });
30
+ * const confirmModal = TestBed.inject(FakeConfirmModal);
31
+ * // ...act...
32
+ * expect(confirmModal.asked).toEqual([{ title: { key: 'post.delete.title' }, message: { key: 'post.delete.message' } }]);
33
+ */
34
+ declare class FakeConfirmModal extends MatDialog {
35
+ /** Every confirm modal opened, oldest first. */
36
+ readonly asked: AskedConfirmation[];
37
+ /** What the next modals answer: `true` confirms, `false` cancels, `undefined` closes without a choice. */
38
+ answer: boolean | undefined;
39
+ open<T, D = unknown, R = unknown>(component: ComponentType<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
40
+ open<T, D = unknown, R = unknown>(template: TemplateRef<T>, config?: MatDialogConfig<D>): MatDialogRef<T, R>;
41
+ /** Forgets every modal opened so far. */
42
+ clear(): void;
43
+ static ɵfac: i0.ɵɵFactoryDeclaration<FakeConfirmModal, never>;
44
+ static ɵprov: i0.ɵɵInjectableDeclaration<FakeConfirmModal>;
45
+ }
46
+ /**
47
+ * Provides {@link FakeConfirmModal} in place of {@link MatDialog}; inject the fake to set the answer and read what was asked.
48
+ *
49
+ * @example
50
+ * providers: [provideFakeConfirmModal({ answer: true })]
51
+ */
52
+ declare function provideFakeConfirmModal(options?: {
53
+ answer?: boolean | undefined;
54
+ }): Provider[];
55
+
56
+ /** One snackbar the code under test showed. */
57
+ interface ShownSnackbar {
58
+ type: externalSnackbarTypeAllowed;
59
+ message: ShownText;
60
+ action?: ShownText;
61
+ navigateInternalUrl?: string;
62
+ openUrlInNewTab?: boolean;
63
+ callback?: () => void;
64
+ /** Present only when it differs from the service's default of 5000 ms; 0 keeps the snackbar open. */
65
+ timeout?: number;
66
+ }
67
+ /**
68
+ * A {@link SnackbarsThreadService} for specs: it records every snackbar in {@link shown}, with its tone and its texts,
69
+ * and never starts a timer. It needs no test runner, so it works under Jest and Vitest alike.
70
+ *
71
+ * @example
72
+ * TestBed.configureTestingModule({ providers: [provideFakeSnackbars()] });
73
+ * const snackbars = TestBed.inject(FakeSnackbarsThreadService);
74
+ * // ...act...
75
+ * expect(snackbars.shown).toEqual([{ type: 'error', message: { key: 'post.failed' } }]);
76
+ */
77
+ declare class FakeSnackbarsThreadService extends SnackbarsThreadService {
78
+ /** Every snackbar shown, oldest first; removing one does not drop it from here. */
79
+ readonly shown: ShownSnackbar[];
80
+ private pendingType;
81
+ show(message: TranslationRequest, type: externalSnackbarTypeAllowed, options?: SnackbarOptions): string;
82
+ addWithId(elem: SnackbarsThreadBase, id: string, timeout?: number): void;
83
+ /** Forgets every snackbar shown so far, e.g. the ones a spec's setup raised. */
84
+ clear(): void;
85
+ static ɵfac: i0.ɵɵFactoryDeclaration<FakeSnackbarsThreadService, never>;
86
+ static ɵprov: i0.ɵɵInjectableDeclaration<FakeSnackbarsThreadService>;
87
+ }
88
+ /**
89
+ * Provides {@link FakeSnackbarsThreadService} in place of {@link SnackbarsThreadService}; inject the fake to read what was shown.
90
+ *
91
+ * @example
92
+ * providers: [provideFakeSnackbars()]
93
+ */
94
+ declare function provideFakeSnackbars(): Provider[];
95
+
96
+ export { FakeConfirmModal, FakeSnackbarsThreadService, provideFakeConfirmModal, provideFakeSnackbars };
97
+ export type { AskedConfirmation, ShownSnackbar, ShownText };
@@ -1,5 +1,6 @@
1
1
  import * as _angular_core from '@angular/core';
2
2
  import { AfterContentInit, OnChanges, OnInit, ElementRef, EventEmitter } from '@angular/core';
3
+ import { I18nOf } from '@agorapulse/ui-components/i18n';
3
4
  import { ControlValueAccessor, FormControl } from '@angular/forms';
4
5
 
5
6
  declare const AP_CHECKBOX_CONTROL_VALUE_ACCESSOR: {
@@ -21,10 +22,8 @@ declare class ToggleComponent implements ControlValueAccessor, AfterContentInit,
21
22
  checked: boolean;
22
23
  required: boolean;
23
24
  confirm: boolean;
24
- confirmMessage: string;
25
- confirmOk: string;
26
- confirmCancel: string;
27
- confirmTitle: string;
25
+ /** Texts of the confirmation shown when `confirm` is set; the title and message default to the DS texts, the buttons to the confirm modal's. */
26
+ readonly i18n: _angular_core.InputSignal<I18nOf<never, "cancel" | "confirm" | "confirmTitle" | "confirmMessage">>;
28
27
  set name(name: string);
29
28
  get name(): string;
30
29
  readonly change: EventEmitter<boolean>;
@@ -47,7 +46,7 @@ declare class ToggleComponent implements ControlValueAccessor, AfterContentInit,
47
46
  };
48
47
  _preventBubblingFromLabel(event: MouseEvent): void;
49
48
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<ToggleComponent, never>;
50
- static ɵcmp: _angular_core.ɵɵComponentDeclaration<ToggleComponent, "ap-toggle", never, { "ariaLabel": { "alias": "aria-label"; "required": false; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; }; "ariaDescribedby": { "alias": "aria-describedby"; "required": false; }; "labelPosition": { "alias": "labelPosition"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "checked": { "alias": "checked"; "required": false; }; "required": { "alias": "required"; "required": false; }; "confirm": { "alias": "confirm"; "required": false; }; "confirmMessage": { "alias": "confirmMessage"; "required": false; }; "confirmOk": { "alias": "confirmOk"; "required": false; }; "confirmCancel": { "alias": "confirmCancel"; "required": false; }; "confirmTitle": { "alias": "confirmTitle"; "required": false; }; "name": { "alias": "name"; "required": true; }; }, { "change": "change"; }, never, ["*"], true, never>;
49
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<ToggleComponent, "ap-toggle", never, { "ariaLabel": { "alias": "aria-label"; "required": false; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; }; "ariaDescribedby": { "alias": "aria-describedby"; "required": false; }; "labelPosition": { "alias": "labelPosition"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "checked": { "alias": "checked"; "required": false; }; "required": { "alias": "required"; "required": false; }; "confirm": { "alias": "confirm"; "required": false; }; "i18n": { "alias": "i18n"; "required": false; "isSignal": true; }; "name": { "alias": "name"; "required": true; }; }, { "change": "change"; }, never, ["*"], true, never>;
51
50
  static ngAcceptInputType_disabled: unknown;
52
51
  static ngAcceptInputType_required: unknown;
53
52
  }
@@ -36,7 +36,7 @@ export { PaginatorButtonComponent, PaginatorComponent } from '@agorapulse/ui-com
36
36
  import * as i17 from '@agorapulse/ui-components/slide-toggle';
37
37
  export { SlideToggleComponent } from '@agorapulse/ui-components/slide-toggle';
38
38
  import * as i18 from '@agorapulse/ui-components/snackbars-thread';
39
- export { CodeStatus, SnackbarTypeValues, SnackbarsThreadBase, SnackbarsThreadComponent, SnackbarsThreadService, externalSnackbarTypeAllowed, generateCodeStatus } from '@agorapulse/ui-components/snackbars-thread';
39
+ export { SnackbarOptions, SnackbarTypeValues, SnackbarsThreadBase, SnackbarsThreadComponent, SnackbarsThreadService, externalSnackbarTypeAllowed } from '@agorapulse/ui-components/snackbars-thread';
40
40
  import * as i19 from '@agorapulse/ui-components/tooltip';
41
41
  export { CustomTooltipAvatarItem, CustomTooltipPresentationItem, CustomTooltipType, TooltipDirective, TooltipExternalTriggerDirective } from '@agorapulse/ui-components/tooltip';
42
42
  import * as i20 from '@agorapulse/ui-components/add-comment';
Binary file