@verisoft/ui-primeng 20.0.0 → 20.1.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 (219) hide show
  1. package/.eslintrc.json +43 -0
  2. package/assets/.gitkeep +0 -0
  3. package/jest.config.ts +22 -0
  4. package/ng-package.json +14 -0
  5. package/package.json +6 -18
  6. package/project.json +36 -0
  7. package/src/index.ts +34 -0
  8. package/src/lib/components/breadcrumb/breadcrumb.component.html +11 -0
  9. package/src/lib/components/breadcrumb/breadcrumb.component.scss +18 -0
  10. package/src/lib/components/breadcrumb/breadcrumb.component.spec.ts +21 -0
  11. package/src/lib/components/breadcrumb/breadcrumb.component.stories.ts +36 -0
  12. package/src/lib/components/breadcrumb/breadcrumb.component.ts +27 -0
  13. package/src/lib/components/breadcrumb/breadcrumb.pipe.ts +13 -0
  14. package/src/lib/components/breadcrumb/index.ts +1 -0
  15. package/src/lib/components/button/button-severity.pipe.ts +20 -0
  16. package/src/lib/components/button/button.component.html +20 -0
  17. package/src/lib/components/button/button.component.scss +0 -0
  18. package/src/lib/components/button/button.component.spec.ts +21 -0
  19. package/src/lib/components/button/button.component.ts +49 -0
  20. package/src/lib/components/button/index.ts +1 -0
  21. package/src/lib/components/calendar/calendar.component.html +53 -0
  22. package/src/lib/components/calendar/calendar.component.scss +0 -0
  23. package/src/lib/components/calendar/calendar.component.spec.ts +21 -0
  24. package/src/lib/components/calendar/calendar.component.ts +70 -0
  25. package/src/lib/components/calendar/index.ts +1 -0
  26. package/src/lib/components/checkbox/checkbox.component.html +20 -0
  27. package/src/lib/components/checkbox/checkbox.component.scss +15 -0
  28. package/src/lib/components/checkbox/checkbox.component.spec.ts +21 -0
  29. package/src/lib/components/checkbox/checkbox.component.stories.ts +72 -0
  30. package/src/lib/components/checkbox/checkbox.component.ts +46 -0
  31. package/src/lib/components/checkbox/index.ts +1 -0
  32. package/src/lib/components/confirm-dialog/confirm-dialog.component.html +51 -0
  33. package/src/lib/components/confirm-dialog/confirm-dialog.component.scss +3 -0
  34. package/src/lib/components/confirm-dialog/confirm-dialog.component.spec.ts +21 -0
  35. package/src/lib/components/confirm-dialog/confirm-dialog.component.stories.ts +74 -0
  36. package/src/lib/components/confirm-dialog/confirm-dialog.component.ts +73 -0
  37. package/src/lib/components/confirm-dialog/index.ts +1 -0
  38. package/src/lib/components/dropdown/dropdown.component.html +93 -0
  39. package/src/lib/components/dropdown/dropdown.component.scss +16 -0
  40. package/src/lib/components/dropdown/dropdown.component.spec.ts +21 -0
  41. package/src/lib/components/dropdown/dropdown.component.ts +139 -0
  42. package/src/lib/components/dropdown/index.ts +1 -0
  43. package/src/lib/components/dropdown-button/dropdown-button.component.html +1 -0
  44. package/src/lib/components/dropdown-button/dropdown-button.component.ts +20 -0
  45. package/src/lib/components/dropdown-button/index.ts +1 -0
  46. package/src/lib/components/errors/error.component.html +7 -0
  47. package/src/lib/components/errors/error.component.scss +3 -0
  48. package/src/lib/components/errors/error.component.ts +34 -0
  49. package/src/lib/components/errors/index.ts +1 -0
  50. package/src/lib/components/feature-list/directives/feature-list-column.directive.ts +32 -0
  51. package/src/lib/components/feature-list/directives/feature-list-filter-field.directive.ts +8 -0
  52. package/src/lib/components/feature-list/feature-list-filter.pipe.ts +21 -0
  53. package/src/lib/components/feature-list/feature-list-page.component.ts +32 -0
  54. package/src/lib/components/feature-list/feature-list-page.model.ts +42 -0
  55. package/src/lib/components/feature-list/feature-list.component.html +59 -0
  56. package/src/lib/components/feature-list/feature-list.component.scss +10 -0
  57. package/src/lib/components/feature-list/feature-list.component.ts +341 -0
  58. package/src/lib/components/feature-list/index.ts +5 -0
  59. package/src/lib/components/filter/directives/filter-field.directive.ts +34 -0
  60. package/src/lib/components/filter/filter.component.html +68 -0
  61. package/src/lib/components/filter/filter.component.scss +0 -0
  62. package/src/lib/components/filter/filter.component.spec.ts +21 -0
  63. package/src/lib/components/filter/filter.component.stories.ts +23 -0
  64. package/src/lib/components/filter/filter.component.ts +281 -0
  65. package/src/lib/components/filter/filter.model.ts +18 -0
  66. package/src/lib/components/filter/index.ts +2 -0
  67. package/src/lib/components/form-field/form-field.component.html +42 -0
  68. package/src/lib/components/form-field/form-field.component.scss +0 -0
  69. package/src/lib/components/form-field/form-field.component.spec.ts +21 -0
  70. package/src/lib/components/form-field/form-field.component.stories.ts +69 -0
  71. package/src/lib/components/form-field/form-field.component.ts +37 -0
  72. package/src/lib/components/form-field/index.ts +1 -0
  73. package/src/lib/components/header/header.component.html +84 -0
  74. package/src/lib/components/header/header.component.scss +0 -0
  75. package/src/lib/components/header/header.component.spec.ts +21 -0
  76. package/src/lib/components/header/header.component.stories.ts +24 -0
  77. package/src/lib/components/header/header.component.ts +65 -0
  78. package/src/lib/components/header/index.ts +2 -0
  79. package/src/lib/components/header/services/header-provider.service.ts +15 -0
  80. package/src/lib/components/icon/icon.component.html +2 -0
  81. package/src/lib/components/icon/icon.component.scss +51 -0
  82. package/src/lib/components/icon/icon.component.ts +86 -0
  83. package/src/lib/components/icon/index.ts +2 -0
  84. package/src/lib/components/input-group/index.ts +1 -0
  85. package/src/lib/components/input-group/input-group.component.html +34 -0
  86. package/src/lib/components/input-group/input-group.component.spec.ts +21 -0
  87. package/src/lib/components/input-group/input-group.component.ts +58 -0
  88. package/src/lib/components/loader/index.ts +1 -0
  89. package/src/lib/components/loader/loader.component.html +5 -0
  90. package/src/lib/components/loader/loader.component.scss +0 -0
  91. package/src/lib/components/loader/loader.component.spec.ts +21 -0
  92. package/src/lib/components/loader/loader.component.ts +16 -0
  93. package/src/lib/components/multiselect/index.ts +1 -0
  94. package/src/lib/components/multiselect/multiselect.component.html +67 -0
  95. package/src/lib/components/multiselect/multiselect.component.scss +0 -0
  96. package/src/lib/components/multiselect/multiselect.component.spec.ts +21 -0
  97. package/src/lib/components/multiselect/multiselect.component.ts +120 -0
  98. package/src/lib/components/number-input/index.ts +1 -0
  99. package/src/lib/components/number-input/number-input.component.html +22 -0
  100. package/src/lib/components/number-input/number-input.component.spec.ts +21 -0
  101. package/src/lib/components/number-input/number-input.component.ts +55 -0
  102. package/src/lib/components/page-header/index.ts +1 -0
  103. package/src/lib/components/page-header/page-header.component.html +35 -0
  104. package/src/lib/components/page-header/page-header.component.scss +0 -0
  105. package/src/lib/components/page-header/page-header.component.spec.ts +21 -0
  106. package/src/lib/components/page-header/page-header.component.ts +31 -0
  107. package/src/lib/components/password/index.ts +1 -0
  108. package/src/lib/components/password/password.component.html +24 -0
  109. package/src/lib/components/password/password.component.scss +0 -0
  110. package/src/lib/components/password/password.component.spec.ts +21 -0
  111. package/src/lib/components/password/password.component.ts +56 -0
  112. package/src/lib/components/radiobutton/index.ts +1 -0
  113. package/src/lib/components/radiobutton/radiobutton.component.html +34 -0
  114. package/src/lib/components/radiobutton/radiobutton.component.scss +6 -0
  115. package/src/lib/components/radiobutton/radiobutton.component.spec.ts +21 -0
  116. package/src/lib/components/radiobutton/radiobutton.component.stories.ts +71 -0
  117. package/src/lib/components/radiobutton/radiobutton.component.ts +61 -0
  118. package/src/lib/components/section/index.ts +1 -0
  119. package/src/lib/components/section/section.component.html +25 -0
  120. package/src/lib/components/section/section.component.scss +0 -0
  121. package/src/lib/components/section/section.component.spec.ts +21 -0
  122. package/src/lib/components/section/section.component.ts +31 -0
  123. package/src/lib/components/shared-components/.eslintrc.json +42 -0
  124. package/src/lib/components/shared-components/action-button-group/action-button-group.component.html +25 -0
  125. package/src/lib/components/shared-components/action-button-group/action-button-group.component.scss +0 -0
  126. package/src/lib/components/shared-components/action-button-group/action-button-group.component.spec.ts +21 -0
  127. package/src/lib/components/shared-components/action-button-group/action-button-group.component.ts +111 -0
  128. package/src/lib/components/shared-components/action-button-group/components/action-button/action-button.component.html +10 -0
  129. package/src/lib/components/shared-components/action-button-group/components/action-button/action-button.component.scss +0 -0
  130. package/src/lib/components/shared-components/action-button-group/components/action-button/action-button.component.spec.ts +21 -0
  131. package/src/lib/components/shared-components/action-button-group/components/action-button/action-button.component.ts +69 -0
  132. package/src/lib/components/shared-components/action-button-group/index.ts +2 -0
  133. package/src/lib/components/shared-components/dynamic-component/dynamic-component-factory.service.ts +142 -0
  134. package/src/lib/components/shared-components/dynamic-component/dynamic-component.component.ts +56 -0
  135. package/src/lib/components/shared-components/dynamic-component/index.ts +2 -0
  136. package/src/lib/components/shared-components/generic-field/generic-field.component.html +98 -0
  137. package/src/lib/components/shared-components/generic-field/generic-field.component.spec.ts +21 -0
  138. package/src/lib/components/shared-components/generic-field/generic-field.component.ts +90 -0
  139. package/src/lib/components/shared-components/generic-field/index.ts +1 -0
  140. package/src/lib/components/shared-components/generic-form/generic-form.component.html +46 -0
  141. package/src/lib/components/shared-components/generic-form/generic-form.component.spec.ts +21 -0
  142. package/src/lib/components/shared-components/generic-form/generic-form.component.ts +56 -0
  143. package/src/lib/components/shared-components/generic-form/generic-form.model.spec.ts +82 -0
  144. package/src/lib/components/shared-components/generic-form/generic-form.model.ts +68 -0
  145. package/src/lib/components/shared-components/generic-form/index.ts +2 -0
  146. package/src/lib/components/shared-components/index.ts +4 -0
  147. package/src/lib/components/side-menu/index.ts +2 -0
  148. package/src/lib/components/side-menu/side-menu.component.html +53 -0
  149. package/src/lib/components/side-menu/side-menu.component.scss +0 -0
  150. package/src/lib/components/side-menu/side-menu.component.spec.ts +21 -0
  151. package/src/lib/components/side-menu/side-menu.component.ts +96 -0
  152. package/src/lib/components/side-menu/side-menu.module.ts +66 -0
  153. package/src/lib/components/slider/index.ts +1 -0
  154. package/src/lib/components/slider/slider.component.html +19 -0
  155. package/src/lib/components/slider/slider.component.spec.ts +21 -0
  156. package/src/lib/components/slider/slider.component.ts +56 -0
  157. package/src/lib/components/snackbar/index.ts +2 -0
  158. package/src/lib/components/snackbar/services/snackbar.service.ts +45 -0
  159. package/src/lib/components/snackbar/snackbar.component.html +3 -0
  160. package/src/lib/components/snackbar/snackbar.component.scss +0 -0
  161. package/src/lib/components/snackbar/snackbar.component.spec.ts +21 -0
  162. package/src/lib/components/snackbar/snackbar.component.stories.ts +70 -0
  163. package/src/lib/components/snackbar/snackbar.component.ts +25 -0
  164. package/src/lib/components/stepper/index.ts +1 -0
  165. package/src/lib/components/stepper/stepper.component.html +35 -0
  166. package/src/lib/components/stepper/stepper.component.spec.ts +21 -0
  167. package/src/lib/components/stepper/stepper.component.ts +39 -0
  168. package/src/lib/components/switch/index.ts +1 -0
  169. package/src/lib/components/switch/switch.component.html +18 -0
  170. package/src/lib/components/switch/switch.component.scss +0 -0
  171. package/src/lib/components/switch/switch.component.spec.ts +21 -0
  172. package/src/lib/components/switch/switch.component.stories.ts +65 -0
  173. package/src/lib/components/switch/switch.component.ts +52 -0
  174. package/src/lib/components/tab-view/index.ts +2 -0
  175. package/src/lib/components/tab-view/tab-view-item.component.ts +22 -0
  176. package/src/lib/components/tab-view/tab-view.component.html +41 -0
  177. package/src/lib/components/tab-view/tab-view.component.ts +55 -0
  178. package/src/lib/components/table/index.ts +1 -0
  179. package/src/lib/components/table/table-filter.pipe.ts +59 -0
  180. package/src/lib/components/table/table.component.html +127 -0
  181. package/src/lib/components/table/table.component.scss +11 -0
  182. package/src/lib/components/table/table.component.spec.ts +21 -0
  183. package/src/lib/components/table/table.component.stories.ts +55 -0
  184. package/src/lib/components/table/table.component.ts +288 -0
  185. package/src/lib/components/table/table.models.ts +26 -0
  186. package/src/lib/components/tag/index.ts +2 -0
  187. package/src/lib/components/tag/tag.component.html +12 -0
  188. package/src/lib/components/tag/tag.component.scss +33 -0
  189. package/src/lib/components/tag/tag.component.ts +83 -0
  190. package/src/lib/components/textarea/index.ts +1 -0
  191. package/src/lib/components/textarea/textarea.component.html +40 -0
  192. package/src/lib/components/textarea/textarea.component.scss +5 -0
  193. package/src/lib/components/textarea/textarea.component.spec.ts +21 -0
  194. package/src/lib/components/textarea/textarea.component.stories.ts +98 -0
  195. package/src/lib/components/textarea/textarea.component.ts +62 -0
  196. package/src/lib/components/textfield/index.ts +1 -0
  197. package/src/lib/components/textfield/textfield.component.html +82 -0
  198. package/src/lib/components/textfield/textfield.component.scss +23 -0
  199. package/src/lib/components/textfield/textfield.component.spec.ts +21 -0
  200. package/src/lib/components/textfield/textfield.component.stories.ts +85 -0
  201. package/src/lib/components/textfield/textfield.component.ts +68 -0
  202. package/src/lib/components/tooltip/index.ts +1 -0
  203. package/src/lib/components/tooltip/tooltip.component.html +3 -0
  204. package/src/lib/components/tooltip/tooltip.component.ts +17 -0
  205. package/src/lib/icons.ts +36 -0
  206. package/src/lib/interceptors/http-error-message.interceptor.ts +35 -0
  207. package/src/lib/pages/not-found-page/not-found-page.component.html +26 -0
  208. package/src/lib/pages/not-found-page/not-found-page.component.scss +0 -0
  209. package/src/lib/pages/not-found-page/not-found-page.component.spec.ts +21 -0
  210. package/src/lib/pages/not-found-page/not-found-page.component.ts +16 -0
  211. package/src/tab-view.ts +1 -0
  212. package/src/test-setup.ts +8 -0
  213. package/tsconfig.json +29 -0
  214. package/tsconfig.lib.json +18 -0
  215. package/tsconfig.lib.prod.json +9 -0
  216. package/tsconfig.spec.json +16 -0
  217. package/fesm2022/verisoft-ui-primeng.mjs +0 -2866
  218. package/fesm2022/verisoft-ui-primeng.mjs.map +0 -1
  219. package/index.d.ts +0 -729
@@ -0,0 +1,111 @@
1
+ import {
2
+ AfterContentInit,
3
+ ChangeDetectionStrategy,
4
+ ChangeDetectorRef,
5
+ Component,
6
+ ContentChildren,
7
+ Input,
8
+ QueryList,
9
+ } from '@angular/core';
10
+ import {
11
+ ACTION_BUTTON_GROUP_COMPONENT_TOKEN,
12
+ ActionButton,
13
+ ActionButtonGroupCore,
14
+ IconPositionType,
15
+ MenuItem,
16
+ queryListChanged,
17
+ ScreenSizeService,
18
+ UnsubscribeComponent,
19
+ } from '@verisoft/ui-core';
20
+ import {
21
+ combineLatestWith,
22
+ takeUntil,
23
+ } from 'rxjs';
24
+ import { Icons } from '../../../icons';
25
+ import { DropdownButtonComponent } from '../../dropdown-button';
26
+ import { ActionButtonComponent } from './components/action-button/action-button.component';
27
+
28
+ @Component({
29
+ selector: 'v-action-button-group',
30
+ imports: [ActionButtonComponent, DropdownButtonComponent],
31
+ templateUrl: './action-button-group.component.html',
32
+ styleUrl: './action-button-group.component.scss',
33
+ changeDetection: ChangeDetectionStrategy.OnPush,
34
+ providers: [
35
+ {
36
+ provide: ACTION_BUTTON_GROUP_COMPONENT_TOKEN,
37
+ useExisting: ActionButtonGroupComponent,
38
+ },
39
+ ]
40
+ })
41
+ export class ActionButtonGroupComponent
42
+ extends UnsubscribeComponent
43
+ implements AfterContentInit, ActionButtonGroupCore {
44
+ @ContentChildren(ActionButtonComponent)
45
+ actions!: QueryList<ActionButtonComponent>;
46
+
47
+ @Input() maxItems = 3;
48
+
49
+ @Input() maxItemsMobile = 0;
50
+
51
+ @Input() items: ActionButton[] = [];
52
+
53
+ @Input() menuIconPos: IconPositionType = 'right';
54
+
55
+ @Input() menuIcon = Icons.action;
56
+
57
+ @Input() label?: string;
58
+
59
+ @Input() icon?: string;
60
+
61
+ icons = Icons;
62
+ allItems: ActionButton[] = [];
63
+ visibleActions: ActionButton[] = [];
64
+ menuItems: MenuItem[] = [];
65
+
66
+ constructor(
67
+ private readonly changeDetectorRef: ChangeDetectorRef,
68
+ readonly screenSizeService: ScreenSizeService
69
+ ) {
70
+ super();
71
+ }
72
+
73
+ ngAfterContentInit(): void {
74
+ this.subscribeItemChange();
75
+ }
76
+
77
+ fireClick(item: ActionButton, event: MouseEvent) {
78
+ event.stopPropagation();
79
+ item.click.emit();
80
+ }
81
+
82
+ private subscribeItemChange(): void {
83
+ const screenResize$ = this.screenSizeService.isMobileBlock;
84
+
85
+ const actions$ = queryListChanged(this.actions);
86
+
87
+ screenResize$
88
+ .pipe(takeUntil(this.destroyed$), combineLatestWith(actions$))
89
+ .subscribe(([isMobile, actions]) => {
90
+ this.computeItems(actions, isMobile);
91
+ });
92
+ }
93
+
94
+ private computeItems(actions: ActionButton[], isMobile: boolean) {
95
+ const allItems = [...(this.items ?? []), ...actions];
96
+ const maxItems = isMobile ? this.maxItemsMobile : this.maxItems;
97
+ this.visibleActions = allItems.slice(0, maxItems);
98
+ this.menuItems = allItems.slice(maxItems).map(this.convertToMenuItem);
99
+ this.changeDetectorRef.detectChanges();
100
+ }
101
+
102
+ private convertToMenuItem(item: ActionButton): MenuItem {
103
+ return {
104
+ label: item.label,
105
+ icon: item.icon,
106
+ command: () => {
107
+ item.click.emit();
108
+ },
109
+ };
110
+ }
111
+ }
@@ -0,0 +1,10 @@
1
+ <v-button
2
+ [label]="label"
3
+ [disabled]="disabled"
4
+ [icon]="icon"
5
+ [outlined]="outlined"
6
+ tooltipPosition="bottom"
7
+ [size]="size"
8
+ [severity]="severity"
9
+ (click)="handleClick($event)"
10
+ />
@@ -0,0 +1,21 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { ActionButtonComponent } from './action-button.component';
3
+
4
+ describe('ActionButtonComponent', () => {
5
+ let component: ActionButtonComponent;
6
+ let fixture: ComponentFixture<ActionButtonComponent>;
7
+
8
+ beforeEach(async () => {
9
+ await TestBed.configureTestingModule({
10
+ imports: [ActionButtonComponent],
11
+ }).compileComponents();
12
+
13
+ fixture = TestBed.createComponent(ActionButtonComponent);
14
+ component = fixture.componentInstance;
15
+ fixture.detectChanges();
16
+ });
17
+
18
+ it('should create', () => {
19
+ expect(component).toBeTruthy();
20
+ });
21
+ });
@@ -0,0 +1,69 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ Component,
4
+ EventEmitter,
5
+ inject,
6
+ Input,
7
+ OnChanges,
8
+ Output,
9
+ SimpleChanges,
10
+ } from '@angular/core';
11
+ import {
12
+ ACTION_BUTTON_GROUP_COMPONENT_TOKEN,
13
+ ActionButton,
14
+ ActionButtonGroupCore,
15
+ ControlSeverityType,
16
+ FieldSizeType,
17
+ } from '@verisoft/ui-core';
18
+ import { Observable, Subject } from 'rxjs';
19
+ import { Icons } from '../../../../../icons';
20
+ import { ButtonComponent } from '../../../../button';
21
+
22
+ @Component({
23
+ selector: 'v-action-button',
24
+ imports: [ButtonComponent],
25
+ templateUrl: './action-button.component.html',
26
+ styleUrl: './action-button.component.scss',
27
+ changeDetection: ChangeDetectionStrategy.OnPush
28
+ })
29
+ export class ActionButtonComponent implements ActionButton, OnChanges {
30
+ @Input() disabled = false;
31
+ @Input() toolTip?: string;
32
+ @Input() id?: string;
33
+ @Input() icon?: string;
34
+ @Input() outlined = false;
35
+ @Input() raised = false;
36
+ @Input() severity?: ControlSeverityType;
37
+ @Input() label?: string;
38
+ @Input() size?: FieldSizeType;
39
+ // eslint-disable-next-line @angular-eslint/no-output-native
40
+ @Output() click = new EventEmitter<MouseEvent>();
41
+
42
+ icons = Icons
43
+
44
+ private propertyChangeSubject = new Subject();
45
+
46
+ propertyChanged: Observable<unknown> =
47
+ this.propertyChangeSubject.asObservable();
48
+
49
+ buttonGroup: ActionButtonGroupCore | null = inject<ActionButtonGroupCore>(
50
+ ACTION_BUTTON_GROUP_COMPONENT_TOKEN,
51
+ {
52
+ optional: true,
53
+ }
54
+ );
55
+
56
+ ngOnChanges(changes: SimpleChanges): void {
57
+ const isValueChange = Object.keys(changes).some(
58
+ (x) => !changes[x].firstChange
59
+ );
60
+ if (isValueChange) {
61
+ this.propertyChangeSubject.next(null);
62
+ }
63
+ }
64
+
65
+ handleClick(event: MouseEvent) {
66
+ event.stopPropagation();
67
+ this.click.emit(event);
68
+ }
69
+ }
@@ -0,0 +1,2 @@
1
+ export * from './action-button-group.component';
2
+ export * from './components/action-button/action-button.component';
@@ -0,0 +1,142 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import {
3
+ Injectable,
4
+ ViewContainerRef,
5
+ Type,
6
+ ComponentFactoryResolver,
7
+ Injector,
8
+ ComponentRef,
9
+ ComponentFactory,
10
+ OnChanges,
11
+ SimpleChanges,
12
+ SimpleChange,
13
+ EventEmitter,
14
+ OnDestroy,
15
+ } from '@angular/core';
16
+ import { ExtendedComponent } from '@verisoft/ui-core';
17
+ import { Subscription } from 'rxjs';
18
+
19
+ @Injectable({
20
+ providedIn: 'root',
21
+ })
22
+ export class DynamicComponentFactoryService implements OnDestroy {
23
+ constructor(private componentFactoryResolver: ComponentFactoryResolver) { }
24
+
25
+ ngOnDestroy(): void {
26
+ this.unsubscribeComponentEvents(this);
27
+ }
28
+
29
+ async createDynamicComponent<TComponent>(
30
+ componentType: Type<TComponent>,
31
+ viewContainerRef: ViewContainerRef,
32
+ inputs: ExtendedComponent<TComponent>,
33
+ injector: Injector | undefined = undefined
34
+ ) {
35
+ const componentFactory =
36
+ this.componentFactoryResolver.resolveComponentFactory(componentType);
37
+ viewContainerRef.clear();
38
+ const component = viewContainerRef.createComponent(
39
+ componentFactory,
40
+ undefined,
41
+ injector
42
+ );
43
+ this.setComponentDataInt(componentFactory, component, inputs);
44
+ this.fireComponentEvents(component.instance, inputs);
45
+ return component;
46
+ }
47
+
48
+ setComponentData<TComponent>(
49
+ component: ComponentRef<TComponent>,
50
+ inputs: Partial<TComponent>
51
+ ) {
52
+ const factory = this.componentFactoryResolver.resolveComponentFactory(
53
+ component.componentType
54
+ );
55
+
56
+ this.setComponentDataInt(factory, component, inputs);
57
+ }
58
+
59
+ private unsubscribeComponentEvents<TComponent>(instance: TComponent) {
60
+ const subscriptionStoreKey = '__outputSubscriptions__';
61
+ const subscriptions = (instance as any)[subscriptionStoreKey] as Map<string, Subscription>;
62
+
63
+ if (subscriptions) {
64
+ subscriptions.forEach((sub) => sub.unsubscribe());
65
+ subscriptions.clear();
66
+ }
67
+ }
68
+
69
+ private fireComponentEvents<TComponent>(
70
+ instance: TComponent,
71
+ inputs: ExtendedComponent<TComponent>
72
+ ) {
73
+ if (!instance || typeof instance !== 'object') return;
74
+
75
+ this.fireInputComponentEvents(instance, inputs);
76
+ this.fireOutputComponentEvents(instance, inputs);
77
+ }
78
+
79
+ private setComponentDataInt<TComponent>(
80
+ factory: ComponentFactory<TComponent>,
81
+ component: ComponentRef<TComponent>,
82
+ inputs: Partial<TComponent>
83
+ ) {
84
+ if (inputs) {
85
+ const propertyNames = factory.inputs.map((x) => x.propName);
86
+ const inputsHash = new Set(propertyNames);
87
+ Object.keys(inputs)
88
+ .filter((x) => inputsHash.has(x))
89
+ .forEach((x) => {
90
+ (<{ [key: string]: unknown }>component.instance)[x] = (<
91
+ { [key: string]: unknown }
92
+ >inputs)[x];
93
+ });
94
+ }
95
+ }
96
+
97
+ private fireInputComponentEvents<TComponent>(
98
+ instance: TComponent,
99
+ inputs: ExtendedComponent<TComponent>
100
+ ) {
101
+ const onChangeComponent = instance as unknown as OnChanges;
102
+ if (onChangeComponent.ngOnChanges && inputs) {
103
+ const changeEventArgs = Object.keys(inputs).reduce((changes: SimpleChanges, key: string) => {
104
+ const inputValue = (inputs as { [key: string]: unknown })[key];
105
+ changes[key] = new SimpleChange(undefined, inputValue, true);
106
+ return changes;
107
+ }, {} as SimpleChanges);
108
+
109
+ onChangeComponent.ngOnChanges(changeEventArgs);
110
+ }
111
+ }
112
+
113
+ private fireOutputComponentEvents<TComponent>(
114
+ instance: TComponent & object,
115
+ inputs: ExtendedComponent<TComponent>
116
+ ) {
117
+ const outputs = Object.keys(inputs).filter((key) => {
118
+ const emitter = (instance as Record<string, any>)[key];
119
+ return emitter instanceof EventEmitter;
120
+ });
121
+
122
+ const subscriptionStoreKey = '__outputSubscriptions__';
123
+ if (!(subscriptionStoreKey in instance)) {
124
+ (instance as any)[subscriptionStoreKey] = new Map<string, Subscription>();
125
+ }
126
+ const subscriptions = (instance as any)[subscriptionStoreKey] as Map<string, Subscription>;
127
+
128
+ for (const outputKey of outputs) {
129
+ const eventEmitter = (instance as Record<string, any>)[outputKey] as EventEmitter<any>;
130
+ const callback = inputs[outputKey] as (value: any) => void;
131
+
132
+ if (eventEmitter && typeof callback === 'function') {
133
+ if (subscriptions.has(outputKey)) {
134
+ subscriptions.get(outputKey)!.unsubscribe();
135
+ }
136
+
137
+ const subscription = eventEmitter.subscribe((value: any) => callback(value));
138
+ subscriptions.set(outputKey, subscription);
139
+ }
140
+ }
141
+ }
142
+ }
@@ -0,0 +1,56 @@
1
+ import {
2
+ AfterViewInit,
3
+ ChangeDetectionStrategy,
4
+ ChangeDetectorRef,
5
+ Component,
6
+ inject,
7
+ Injector,
8
+ Input,
9
+ OnChanges,
10
+ Type,
11
+ ViewChild,
12
+ ViewContainerRef,
13
+ } from '@angular/core';
14
+ import { ExtendedComponent } from '@verisoft/ui-core';
15
+ import { DynamicComponentFactoryService } from './dynamic-component-factory.service';
16
+
17
+ @Component({
18
+ selector: 'v-dynamic-component',
19
+ standalone: true,
20
+ changeDetection: ChangeDetectionStrategy.OnPush,
21
+ template: `<ng-container #dynamicContainer></ng-container>`,
22
+ })
23
+ export class DynamicComponent<TComponent> implements AfterViewInit, OnChanges {
24
+ @Input() componentType!: Type<TComponent>;
25
+
26
+ @Input() data!: ExtendedComponent<TComponent>;
27
+
28
+ @ViewChild('dynamicContainer', { read: ViewContainerRef, static: true })
29
+ container!: ViewContainerRef;
30
+
31
+ private factoryServices = inject(DynamicComponentFactoryService);
32
+
33
+ private changeDetectorRef = inject(ChangeDetectorRef);
34
+
35
+ private injector = inject(Injector);
36
+
37
+ ngOnChanges(): void {
38
+ this.createComponent();
39
+ }
40
+
41
+ ngAfterViewInit(): void {
42
+ this.createComponent();
43
+ this.changeDetectorRef.detectChanges();
44
+ }
45
+
46
+ private createComponent() {
47
+ if (this.container) {
48
+ this.factoryServices.createDynamicComponent(
49
+ this.componentType,
50
+ this.container,
51
+ this.data,
52
+ this.injector
53
+ );
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,2 @@
1
+ export * from './dynamic-component-factory.service';
2
+ export * from './dynamic-component.component';
@@ -0,0 +1,98 @@
1
+ @if (!type || type === fieldTypes.text) {
2
+ <v-textfield
3
+ [label]="label"
4
+ [floatLabel]="floatLabel === true"
5
+ [size]="size"
6
+ [formControl]="formControl"
7
+ />
8
+ } @else if (type === fieldTypes.dropdown && !datasource) {
9
+ <v-dropdown
10
+ [label]="!floatLabel ? label : ''"
11
+ [floatLabel]="floatLabel ? label : ''"
12
+ [testId]="testId"
13
+ [options]="options"
14
+ [optionLabel]="optionLabel"
15
+ [optionValue]="optionValue ?? optionLabel"
16
+ [loading]="loading"
17
+ [forceMinWidth]="true"
18
+ [formControl]="formControl"
19
+ [showFilter]="showFilter ?? false"
20
+ [localSearch]="localSearch ?? false"
21
+ (changeEvent)="changed.emit($event)"
22
+ (clearEvent)="cleared.emit($event)"
23
+ (lazyLoadEvent)="lazyLoad.emit($any($event))"
24
+ (showEvent)="showed.emit($event)"
25
+ />
26
+ } @else if (type === fieldTypes.dropdown && datasource) {
27
+ <v-dropdown
28
+ useDatasource
29
+ [forceMinWidth]="true"
30
+ [datasource]="datasource"
31
+ [optionLabel]="optionLabel"
32
+ [optionValue]="optionValue ?? optionLabel"
33
+ [label]="!floatLabel ? label : ''"
34
+ [floatLabel]="floatLabel ? label : ''"
35
+ [testId]="testId"
36
+ [loading]="loading"
37
+ [formControl]="formControl"
38
+ [showFilter]="showFilter ?? false"
39
+ [filterField]="filterField ?? 'fulltext'"
40
+ [localSearch]="localSearch ?? false"
41
+ (changeEvent)="changed.emit($event)"
42
+ (clearEvent)="cleared.emit($event)"
43
+ (lazyLoadEvent)="lazyLoad.emit($any($event))"
44
+ (showEvent)="showed.emit($event)"
45
+ />
46
+ } @else if (type === fieldTypes.multiselect && !datasource) {
47
+ <v-multiselect
48
+ [label]="!floatLabel ? label : ''"
49
+ [floatLabel]="floatLabel ? label : ''"
50
+ [testId]="testId"
51
+ [options]="options"
52
+ [optionLabel]="optionLabel"
53
+ [optionValue]="optionValue ?? optionLabel"
54
+ [loading]="loading"
55
+ [formControl]="formControl"
56
+ (changeEvent)="changed.emit($event)"
57
+ (clearEvent)="cleared.emit($event)"
58
+ (lazyLoadEvent)="lazyLoad.emit($any($event))"
59
+ (showEvent)="showed.emit($event)"
60
+ />
61
+ } @else if (type === fieldTypes.multiselect && datasource) {
62
+ <v-multiselect
63
+ useDatasource
64
+ [datasource]="datasource"
65
+ [optionLabel]="optionLabel"
66
+ [optionValue]="optionValue ?? optionLabel"
67
+ [label]="!floatLabel ? label : ''"
68
+ [floatLabel]="floatLabel ? label : ''"
69
+ [testId]="testId"
70
+ [loading]="loading"
71
+ [formControl]="formControl"
72
+ (changeEvent)="changed.emit($event)"
73
+ (clearEvent)="cleared.emit($event)"
74
+ (lazyLoadEvent)="lazyLoad.emit($any($event))"
75
+ (showEvent)="showed.emit($event)"
76
+ />
77
+ } @else if (type === fieldTypes.checkbox) {
78
+ <v-checkbox
79
+ [label]="label"
80
+ [testId]="testId"
81
+ [formControl]="formControl"
82
+ [indeterminate]="true"
83
+ />
84
+ } @else if (type === fieldTypes.simplecheckbox) {
85
+ <v-checkbox
86
+ [label]="label"
87
+ [testId]="testId"
88
+ [formControl]="formControl"
89
+ />
90
+ } @else if (type === fieldTypes.calendar) {
91
+ <v-calendar
92
+ [label]="!floatLabel ? label : ''"
93
+ [floatLabel]="floatLabel ? label : ''"
94
+ [testId]="testId"
95
+ [formControl]="formControl"
96
+ [icon]="icons.calendar"
97
+ />
98
+ }
@@ -0,0 +1,21 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { GenericFieldComponent } from './generic-field.component';
3
+
4
+ describe('GenericFieldComponent', () => {
5
+ let component: GenericFieldComponent<string>;
6
+ let fixture: ComponentFixture<GenericFieldComponent<string>>;
7
+
8
+ beforeEach(async () => {
9
+ await TestBed.configureTestingModule({
10
+ imports: [GenericFieldComponent],
11
+ }).compileComponents();
12
+
13
+ fixture = TestBed.createComponent(GenericFieldComponent<string>);
14
+ component = fixture.componentInstance;
15
+ fixture.detectChanges();
16
+ });
17
+
18
+ it('should create', () => {
19
+ expect(component).toBeTruthy();
20
+ });
21
+ });
@@ -0,0 +1,90 @@
1
+
2
+ import {
3
+ ChangeDetectionStrategy,
4
+ Component,
5
+ EventEmitter,
6
+ Input,
7
+ Output,
8
+ } from '@angular/core';
9
+ import { ReactiveFormsModule } from '@angular/forms';
10
+ import {
11
+ DatasourceType,
12
+ FilterEvent,
13
+ LazyLoadEvent,
14
+ } from '@verisoft/core';
15
+ import {
16
+ BaseFormInputComponent,
17
+ DatasourceDirective,
18
+ FieldSize,
19
+ FieldSizeType,
20
+ GENERIC_FIELD_COMPONENT_TOKEN,
21
+ GenericFieldCore,
22
+ GenericFieldType,
23
+ GenericFieldTypeType,
24
+ } from '@verisoft/ui-core';
25
+ import { Icons } from '../../../icons';
26
+ import { CalendarComponent } from '../../calendar';
27
+ import { CheckboxComponent } from '../../checkbox';
28
+ import { DropdownComponent } from '../../dropdown';
29
+ import { MultiselectComponent } from '../../multiselect';
30
+ import { TextfieldComponent } from '../../textfield';
31
+
32
+ @Component({
33
+ selector: 'v-generic-field',
34
+ imports: [
35
+ DropdownComponent,
36
+ CalendarComponent,
37
+ MultiselectComponent,
38
+ TextfieldComponent,
39
+ ReactiveFormsModule,
40
+ CheckboxComponent,
41
+ DatasourceDirective
42
+ ],
43
+ providers: [
44
+ {
45
+ provide: GENERIC_FIELD_COMPONENT_TOKEN,
46
+ useExisting: GenericFieldComponent,
47
+ },
48
+ ],
49
+ templateUrl: './generic-field.component.html',
50
+ changeDetection: ChangeDetectionStrategy.OnPush
51
+ })
52
+ export class GenericFieldComponent<T>
53
+ extends BaseFormInputComponent
54
+ implements GenericFieldCore<T>
55
+ {
56
+ @Input() type?: GenericFieldTypeType = GenericFieldType.text;
57
+
58
+ @Input() floatLabel?: boolean;
59
+
60
+ @Input() optionLabel: string | undefined;
61
+
62
+ @Input() optionValue: string | undefined;
63
+
64
+ @Input() options: T[] | undefined;
65
+
66
+ @Input() size?: FieldSizeType = FieldSize.medium;
67
+
68
+ @Input() loading = false;
69
+
70
+ @Input() lazy = false;
71
+
72
+ @Input() filter = true;
73
+
74
+ @Input() datasource?: DatasourceType<T>
75
+
76
+ @Input() filterField?: string;
77
+
78
+ @Input() showFilter?: boolean;
79
+
80
+ @Input() localSearch?: boolean;
81
+
82
+ @Output() changed = new EventEmitter<any>();
83
+ @Output() showed = new EventEmitter<any>();
84
+ @Output() cleared = new EventEmitter<any>();
85
+ @Output() lazyLoad = new EventEmitter<LazyLoadEvent>();
86
+ @Output() filtered = new EventEmitter<FilterEvent>();
87
+
88
+ fieldTypes = GenericFieldType;
89
+ icons = Icons;
90
+ }
@@ -0,0 +1 @@
1
+ export * from './generic-field.component';
@@ -0,0 +1,46 @@
1
+ @if (formGroupComputed) {
2
+ <div
3
+ class="v-generic-form"
4
+ [ngClass]="showAsRow ? 'd-flex flex-row' : 'row'"
5
+ [formGroup]="formGroupComputed"
6
+ >
7
+ @for(field of fields; track field) { @if (columnClass) {
8
+ <div class="v-generic-form__column {{ columnClass }}">
9
+ <v-generic-field
10
+ [type]="field.type"
11
+ [label]="field.label ?? 'NOT SET' | translate"
12
+ [floatLabel]="field.floatLabel"
13
+ [testId]="field.testId"
14
+ [options]="field.options"
15
+ [optionLabel]="field.optionLabel"
16
+ [optionValue]="field.optionValue ?? field.optionLabel"
17
+ [options]="field.options"
18
+ [size]="field.size"
19
+ [formControlName]="field.name"
20
+ [datasource]="field.datasource"
21
+ [showFilter]="field.showFilter"
22
+ [filterField]="field.filterField"
23
+ [localSearch]="field.localSearch"
24
+ ></v-generic-field>
25
+ </div>
26
+ } @else {
27
+ <v-generic-field
28
+ class="me-4"
29
+ [type]="field.type"
30
+ [label]="field.label ?? 'NOT SET' | translate"
31
+ [floatLabel]="field.floatLabel"
32
+ [testId]="field.testId"
33
+ [options]="field.options"
34
+ [optionLabel]="field.optionLabel"
35
+ [optionValue]="field.optionValue ?? field.optionLabel"
36
+ [options]="field.options"
37
+ [size]="field.size"
38
+ [formControlName]="field.name"
39
+ [datasource]="field.datasource"
40
+ [showFilter]="field.showFilter"
41
+ [filterField]="field.filterField"
42
+ [localSearch]="field.localSearch"
43
+ ></v-generic-field>
44
+ } }
45
+ </div>
46
+ }