@one-paragon/angular-utilities 2.8.2 → 2.8.4
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.
- package/karma.conf.js +43 -0
- package/ng-package.json +7 -0
- package/package.json +15 -27
- package/src/action-state/action-state-spinner/action-state-spinner.component.css +16 -0
- package/src/action-state/action-state-spinner/action-state-spinner.component.html +7 -0
- package/src/action-state/action-state-spinner/action-state-spinner.component.spec.ts +25 -0
- package/src/action-state/action-state-spinner/action-state-spinner.component.ts +26 -0
- package/src/action-state/action-state-ui/action-state-ui.module.ts +13 -0
- package/src/action-state/index.ts +8 -0
- package/src/action-state/ngrx-ext/ngrx-ext.module.ts +14 -0
- package/src/action-state/ngrx.ts +69 -0
- package/src/http-request-state/RequestStateFactory.ts +56 -0
- package/src/http-request-state/RequestStateStore.ts +360 -0
- package/src/http-request-state/deprecated.ts +20 -0
- package/src/http-request-state/directives/HttpStateDirectiveBase.ts +29 -0
- package/src/http-request-state/directives/http-error-state-directive.ts +21 -0
- package/src/http-request-state/directives/http-inProgress-state-directive.ts +19 -0
- package/src/http-request-state/directives/http-notStarted-state-directive.ts +19 -0
- package/src/http-request-state/directives/http-success-state-directive.ts +29 -0
- package/src/http-request-state/directives/index.ts +5 -0
- package/src/http-request-state/directives/request-state-directive.spec.ts +73 -0
- package/src/http-request-state/directives/request-state-directive.ts +78 -0
- package/src/http-request-state/documentation/CREATE-REQUESTOR.md +667 -0
- package/src/http-request-state/documentation/README.md +191 -0
- package/src/http-request-state/documentation/REQUEST-STATE-STORE-CONFIG.md +648 -0
- package/src/http-request-state/documentation/REQUESTOR.md +616 -0
- package/src/http-request-state/helpers.ts +30 -0
- package/src/http-request-state/http-state-module.ts +23 -0
- package/src/http-request-state/index.ts +7 -0
- package/src/http-request-state/models/view-context.ts +18 -0
- package/src/http-request-state/observable.spec.ts +43 -0
- package/src/http-request-state/request-state.ts +66 -0
- package/src/http-request-state/rxjs/getRequestorBody.ts +10 -0
- package/src/http-request-state/rxjs/getRequestorState.ts +8 -0
- package/src/http-request-state/rxjs/index.ts +4 -0
- package/src/http-request-state/rxjs/tapError.ts +16 -0
- package/src/http-request-state/rxjs/tapSuccess.ts +16 -0
- package/src/http-request-state/strategies.spec.ts +42 -0
- package/src/http-request-state/types.ts +54 -0
- package/src/ngrx/actionable-selector.ts +189 -0
- package/src/ngrx/index.ts +1 -0
- package/src/public-api.ts +40 -0
- package/src/rxjs/defaultShareReplay.ts +8 -0
- package/src/rxjs/index.ts +5 -0
- package/src/rxjs/mapError.ts +8 -0
- package/src/rxjs/rxjs-operators.ts +130 -0
- package/src/rxjs/subjectifier.ts +17 -0
- package/src/rxjs/subscriber.directive.ts +57 -0
- package/src/specs/clickSubject.spec.ts +99 -0
- package/src/specs/dialog.spec.ts +101 -0
- package/src/specs/toggleGroupDirective.spec.ts +229 -0
- package/src/table-builder/classes/DefaultSettings.ts +11 -0
- package/src/table-builder/classes/MatTableObservableDataSource.ts +23 -0
- package/src/table-builder/classes/TableBuilderConfig.ts +49 -0
- package/src/table-builder/classes/TableBuilderDataSource.ts +64 -0
- package/src/table-builder/classes/TableState.ts +96 -0
- package/src/table-builder/classes/data-store.ts +10 -0
- package/src/table-builder/classes/display-col.ts +5 -0
- package/src/table-builder/classes/filter-info.ts +129 -0
- package/src/table-builder/classes/table-builder-general-settings.ts +233 -0
- package/src/table-builder/classes/table-builder.ts +105 -0
- package/src/table-builder/classes/table-store.helpers.ts +109 -0
- package/src/table-builder/classes/table-store.ts +540 -0
- package/src/table-builder/components/array-column.component.ts +34 -0
- package/src/table-builder/components/column-builder/column-builder.component.html +109 -0
- package/src/table-builder/components/column-builder/column-builder.component.scss +43 -0
- package/src/table-builder/components/column-builder/column-builder.component.spec.ts +49 -0
- package/src/table-builder/components/column-builder/column-builder.component.ts +130 -0
- package/src/table-builder/components/column-builder/column-helpers.ts +54 -0
- package/src/table-builder/components/column-header-menu/column-header-menu.component.html +128 -0
- package/src/table-builder/components/column-header-menu/column-header-menu.component.scss +97 -0
- package/src/table-builder/components/column-header-menu/column-header-menu.component.ts +113 -0
- package/src/table-builder/components/date-filter/date-filter.component.html +39 -0
- package/src/table-builder/components/date-filter/date-filter.component.ts +33 -0
- package/src/table-builder/components/date-time-filter/date-time-filter.component.html +25 -0
- package/src/table-builder/components/date-time-filter/date-time-filter.component.ts +33 -0
- package/src/table-builder/components/filter/filter.component.html +120 -0
- package/src/table-builder/components/filter/filter.component.scss +60 -0
- package/src/table-builder/components/filter/filter.component.spec.ts +86 -0
- package/src/table-builder/components/filter/filter.component.ts +73 -0
- package/src/table-builder/components/filter/in-list/in-list-filter.component.ts +171 -0
- package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.html +60 -0
- package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.scss +57 -0
- package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.ts +44 -0
- package/src/table-builder/components/generic-table/generic-table.component.html +140 -0
- package/src/table-builder/components/generic-table/generic-table.component.scss +45 -0
- package/src/table-builder/components/generic-table/generic-table.component.ts +531 -0
- package/src/table-builder/components/generic-table/paginator.component.ts +125 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.css +24 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.html +21 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.spec.ts +23 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.ts +26 -0
- package/src/table-builder/components/in-filter/in-filter.component.css +22 -0
- package/src/table-builder/components/in-filter/in-filter.component.html +38 -0
- package/src/table-builder/components/in-filter/in-filter.component.ts +66 -0
- package/src/table-builder/components/index.ts +9 -0
- package/src/table-builder/components/initialization-component/initialization.component.html +78 -0
- package/src/table-builder/components/initialization-component/initialization.component.ts +28 -0
- package/src/table-builder/components/link-column.component.ts +42 -0
- package/src/table-builder/components/number-filter/number-filter.component.css +10 -0
- package/src/table-builder/components/number-filter/number-filter.component.html +32 -0
- package/src/table-builder/components/number-filter/number-filter.component.spec.ts +30 -0
- package/src/table-builder/components/number-filter/number-filter.component.ts +34 -0
- package/src/table-builder/components/profiles-menu/profiles-menu.component.html +77 -0
- package/src/table-builder/components/profiles-menu/profiles-menu.component.scss +126 -0
- package/src/table-builder/components/profiles-menu/profiles-menu.component.spec.ts +23 -0
- package/src/table-builder/components/profiles-menu/profiles-menu.component.ts +64 -0
- package/src/table-builder/components/reset-menu/reset-menu.component.css +3 -0
- package/src/table-builder/components/reset-menu/reset-menu.component.html +10 -0
- package/src/table-builder/components/reset-menu/reset-menu.component.ts +87 -0
- package/src/table-builder/components/scroll-strategy.ts +139 -0
- package/src/table-builder/components/sort-menu/sort-menu.component-store.ts +57 -0
- package/src/table-builder/components/sort-menu/sort-menu.component.html +115 -0
- package/src/table-builder/components/sort-menu/sort-menu.component.scss +119 -0
- package/src/table-builder/components/sort-menu/sort-menu.component.ts +88 -0
- package/src/table-builder/components/table-container/table-container.component.html +94 -0
- package/src/table-builder/components/table-container/table-container.component.scss +60 -0
- package/src/table-builder/components/table-container/table-container.component.ts +467 -0
- package/src/table-builder/components/table-container/table-container.helpers/data-state.helpers.ts +113 -0
- package/src/table-builder/components/table-container/table-container.helpers/filter-state.helpers.ts +125 -0
- package/src/table-builder/components/table-container/table-container.helpers/groupBy.helpers.ts +172 -0
- package/src/table-builder/components/table-container/table-container.helpers/meta-data.helpers.ts +19 -0
- package/src/table-builder/components/table-container/table-container.helpers/sort-state.helpers.ts +47 -0
- package/src/table-builder/components/table-container/tableProps.ts +21 -0
- package/src/table-builder/components/table-container/virtual-scroll-container.ts +216 -0
- package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.html +42 -0
- package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.ts +47 -0
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.css +40 -0
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.html +11 -0
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.spec.ts +85 -0
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.ts +35 -0
- package/src/table-builder/components/table-container-filter/table-wrapper-filter-store.ts +13 -0
- package/src/table-builder/components/table-header-menu/table-header-menu.component.css +21 -0
- package/src/table-builder/components/table-header-menu/table-header-menu.component.html +48 -0
- package/src/table-builder/components/table-header-menu/table-header-menu.component.ts +36 -0
- package/src/table-builder/directives/custom-cell-directive.ts +63 -0
- package/src/table-builder/directives/custom-header-directive.ts +16 -0
- package/src/table-builder/directives/group-row-directive.ts +91 -0
- package/src/table-builder/directives/index.ts +8 -0
- package/src/table-builder/directives/multi-sort.directive.spec.ts +124 -0
- package/src/table-builder/directives/multi-sort.directive.ts +58 -0
- package/src/table-builder/directives/resize-column.directive.ts +107 -0
- package/src/table-builder/directives/table-wrapper.directive.ts +13 -0
- package/src/table-builder/directives/tb-filter.directive.ts +376 -0
- package/src/table-builder/documentation/table-builder/CUSTOM-CELL.md +568 -0
- package/src/table-builder/documentation/table-builder/CUSTOM-GROUP-ROW.md +356 -0
- package/src/table-builder/documentation/table-builder/METADATA-DOCUMENTATION.md +517 -0
- package/src/table-builder/documentation/table-builder/STYLER-STYLE.md +228 -0
- package/src/table-builder/documentation/table-builder/TABLE-BUILDER-CONFIG.md +325 -0
- package/src/table-builder/documentation/table-builder/TABLE-BUILDER-SETTINGS.md +515 -0
- package/src/table-builder/documentation/table-builder/TABLE-BUILDER.md +430 -0
- package/src/table-builder/documentation/table-builder/TABLE-CONTAINER.md +628 -0
- package/src/table-builder/enums/filterTypes.ts +39 -0
- package/src/table-builder/functions/boolean-filter-function.ts +12 -0
- package/src/table-builder/functions/date-filter-function.ts +85 -0
- package/src/table-builder/functions/download-data.ts +11 -0
- package/src/table-builder/functions/null-filter-function.ts +9 -0
- package/src/table-builder/functions/number-filter-function.ts +47 -0
- package/src/table-builder/functions/sort-data-function.ts +80 -0
- package/src/table-builder/functions/string-filter-function.ts +59 -0
- package/src/table-builder/interfaces/ColumnInfo.ts +9 -0
- package/src/table-builder/interfaces/dictionary.ts +3 -0
- package/src/table-builder/interfaces/meta-data.ts +279 -0
- package/src/table-builder/ngrx/tableBuilderStateStore.ts +203 -0
- package/src/table-builder/pipes/column-total.pipe.ts +16 -0
- package/src/table-builder/pipes/format-filter-type.pipe.ts +12 -0
- package/src/table-builder/pipes/format-filter-value.pipe.ts +71 -0
- package/src/table-builder/pipes/key-display.ts +13 -0
- package/src/table-builder/services/all-values-filter-creator.service.ts +92 -0
- package/src/table-builder/services/export-to-csv.service.ts +117 -0
- package/src/table-builder/services/link-creator.service.ts +98 -0
- package/src/table-builder/services/table-template-service.ts +47 -0
- package/src/table-builder/services/transform-creator.ts +90 -0
- package/src/table-builder/specs/table-custom-filters.spec.ts +262 -0
- package/src/table-builder/styles/collapser.styles.scss +16 -0
- package/src/table-builder/table-builder.module.ts +42 -0
- package/src/table-builder/types/group-types.ts +42 -0
- package/src/table-builder/types/index.ts +1 -0
- package/src/test.ts +17 -0
- package/src/utilities/array-helpers.ts +13 -0
- package/src/utilities/directives/auto-focus.directive.ts +20 -0
- package/src/utilities/directives/clickEmitterDirective.ts +15 -0
- package/src/utilities/directives/clickSubject.ts +19 -0
- package/src/utilities/directives/conditional-classes.directive.ts +36 -0
- package/src/utilities/directives/dialog-service.ts +19 -0
- package/src/utilities/directives/dialog.ts +174 -0
- package/src/utilities/directives/mat-toggle-group-directive.ts +60 -0
- package/src/utilities/directives/prevent-enter.directive.ts +12 -0
- package/src/utilities/directives/stop-propagation.directive.ts +19 -0
- package/src/utilities/directives/styler.ts +45 -0
- package/src/utilities/directives/trim-whitespace.directive.ts +20 -0
- package/src/utilities/index.ts +22 -0
- package/src/utilities/module.ts +53 -0
- package/src/utilities/pipes/function.pipe.ts +21 -0
- package/src/utilities/pipes/phone.pipe.ts +20 -0
- package/src/utilities/pipes/space-case.pipes.spec.ts +47 -0
- package/src/utilities/pipes/space-case.pipes.ts +29 -0
- package/tsconfig.lib.json +20 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/fesm2022/one-paragon-angular-utilities.mjs +0 -7328
- package/fesm2022/one-paragon-angular-utilities.mjs.map +0 -1
- package/types/one-paragon-angular-utilities.d.ts +0 -2197
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Directive, TemplateRef, Input, Component, Output, EventEmitter, ViewContainerRef, Injector, ChangeDetectionStrategy, inject, untracked, Signal, isSignal, input } from '@angular/core';
|
|
2
|
+
import { MatDialog, MatDialogRef, MatDialogConfig, MAT_DIALOG_DEFAULT_OPTIONS, DialogPosition } from '@angular/material/dialog';
|
|
3
|
+
import { Observable, Subject } from 'rxjs';
|
|
4
|
+
import { DialogService } from './dialog-service';
|
|
5
|
+
import { subscriber } from '../../rxjs';
|
|
6
|
+
import { toObservable } from '@angular/core/rxjs-interop';
|
|
7
|
+
|
|
8
|
+
interface DialogViewContext<T> {
|
|
9
|
+
$implicit: T,
|
|
10
|
+
opDialog: T,
|
|
11
|
+
close: () => void,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Component({
|
|
15
|
+
selector: 'dialog-wrapper',
|
|
16
|
+
template: ``,
|
|
17
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
18
|
+
})
|
|
19
|
+
export class DialogWrapper<T = any> {
|
|
20
|
+
private vcr = inject(ViewContainerRef);
|
|
21
|
+
|
|
22
|
+
viewEmbedded = false;
|
|
23
|
+
viewContext = {
|
|
24
|
+
close: () => {},
|
|
25
|
+
} as DialogViewContext<T>;
|
|
26
|
+
set template(tmpl: TemplateRef<DialogViewContext<T>>) {
|
|
27
|
+
if(this.viewEmbedded) {
|
|
28
|
+
this.vcr.clear();
|
|
29
|
+
}
|
|
30
|
+
this.viewEmbedded = true;
|
|
31
|
+
this.vcr.createEmbeddedView(tmpl, this.viewContext);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
set close(closeMethod: () => void ) {
|
|
35
|
+
this.viewContext.close = closeMethod;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
set data(value: T) {
|
|
39
|
+
this.viewContext.$implicit = value;
|
|
40
|
+
this.viewContext.opDialog = value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const defaultDialogConfig: MatDialogConfig = {
|
|
47
|
+
maxHeight: '95vh',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@Directive(
|
|
52
|
+
{ selector: '[opDialog]', }
|
|
53
|
+
) export class DialogDirective<T> {
|
|
54
|
+
private templateRef = inject<TemplateRef<DialogViewContext<T>>>(TemplateRef);
|
|
55
|
+
private dialog = inject(MatDialog);
|
|
56
|
+
private dialogConfig = inject(MAT_DIALOG_DEFAULT_OPTIONS, { optional: true }) || {};
|
|
57
|
+
private service = inject(DialogService);
|
|
58
|
+
|
|
59
|
+
@Output() opDialogClosed: EventEmitter<boolean> = new EventEmitter();
|
|
60
|
+
_dialogConfig: MatDialogConfig<T> = { ...this.dialogConfig, ...defaultDialogConfig };
|
|
61
|
+
@Input() opDialogAddDialogClass = true;
|
|
62
|
+
@Input() set opDialogConfig(config: MatDialogConfig<T>) {
|
|
63
|
+
|
|
64
|
+
this._dialogConfig = { ...this.dialogConfig, ...defaultDialogConfig, ...config };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get opDialogConfig() : MatDialogConfig<T> {
|
|
68
|
+
return this._dialogConfig;
|
|
69
|
+
}
|
|
70
|
+
injector = inject(Injector);
|
|
71
|
+
subscriber = subscriber(this.injector);
|
|
72
|
+
@Input('opDialog') set setControl(i: Observable<T> | Signal<T>){
|
|
73
|
+
let o: Observable<T>;
|
|
74
|
+
if(isSignal(i)){
|
|
75
|
+
o = toObservable<T>(i, { injector: this.injector })
|
|
76
|
+
} else {
|
|
77
|
+
o = i;
|
|
78
|
+
}
|
|
79
|
+
untracked(() => {
|
|
80
|
+
this.subscriber.on(o, this.setDataAndState);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Input('opDialogOrigin') nativeElement? : HTMLElement;
|
|
85
|
+
/**
|
|
86
|
+
* For use with origin element to keep dialog on screen.
|
|
87
|
+
* If true, will position based on width and height provided IF it was provide as a number.
|
|
88
|
+
* If no width provided or/and height, provide a default in number (of pixels) of the not provided values.
|
|
89
|
+
* If no width/height provided at all, will default to 600x400.
|
|
90
|
+
*/
|
|
91
|
+
$positionOnScreen = input<boolean | { height?: number, width?: number }>(false, { alias: 'opDialogPositionOnScreen' });
|
|
92
|
+
dialogRef?: MatDialogRef<any, boolean>;
|
|
93
|
+
componentWrapper?: DialogWrapper<T>;
|
|
94
|
+
|
|
95
|
+
_data = new Subject<Observable<T>>();
|
|
96
|
+
|
|
97
|
+
close() {
|
|
98
|
+
this.dialogRef?.close();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
initDialog() {
|
|
102
|
+
if(this.nativeElement){
|
|
103
|
+
const rect = this.nativeElement.getBoundingClientRect();
|
|
104
|
+
const position = { } as DialogPosition;
|
|
105
|
+
if(this.$positionOnScreen()) {
|
|
106
|
+
const viewportWidth = window.innerWidth;
|
|
107
|
+
const viewportHeight = window.innerHeight;
|
|
108
|
+
const p = this.$positionOnScreen();
|
|
109
|
+
const width = typeof p === 'object' && p.width ? p.width : typeof this.dialogConfig.width === 'number' ? this.dialogConfig.width : 600;
|
|
110
|
+
const height = typeof p === 'object' && p.height ? p.height : typeof this.dialogConfig.height === 'number' ? this.dialogConfig.height : 400;
|
|
111
|
+
|
|
112
|
+
// Check horizontal positioning
|
|
113
|
+
if(rect.left + width > viewportWidth) {
|
|
114
|
+
position.right = `${viewportWidth - rect.right}px`;
|
|
115
|
+
} else {
|
|
116
|
+
position.left = `${rect.left}px`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Check vertical positioning
|
|
120
|
+
if(rect.bottom + height > viewportHeight) {
|
|
121
|
+
position.bottom = `${viewportHeight - rect.top}px`;
|
|
122
|
+
} else {
|
|
123
|
+
position.top = `${rect.bottom - 20}px`;
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
position.top = `${rect.bottom}px`;
|
|
127
|
+
position.left = `${rect.left}px`;
|
|
128
|
+
}
|
|
129
|
+
this.opDialogConfig = { ...this.opDialogConfig, position };
|
|
130
|
+
}
|
|
131
|
+
if(this.opDialogAddDialogClass) {
|
|
132
|
+
this.opDialogConfig.panelClass = [...(Array.isArray(this.opDialogConfig.panelClass) ? this.opDialogConfig.panelClass : this.opDialogConfig.panelClass ? [this.opDialogConfig.panelClass] : []), 'opDialog'];
|
|
133
|
+
}
|
|
134
|
+
this.dialogRef = this.dialog.open(DialogWrapper, this.opDialogConfig);
|
|
135
|
+
this.componentWrapper = this.dialogRef.componentInstance;
|
|
136
|
+
this.componentWrapper!.close = () => this.dialogRef?.close();
|
|
137
|
+
this.componentWrapper!.data = this.opDialogConfig.data as T;
|
|
138
|
+
this.componentWrapper!.template = this.templateRef;
|
|
139
|
+
if(!this.opDialogConfig.disableClose) {
|
|
140
|
+
this.service.addDialogRef(this.dialogRef);
|
|
141
|
+
}
|
|
142
|
+
const sub = this.dialogRef.afterClosed().subscribe(() => {
|
|
143
|
+
this.opDialogClosed.emit(true);
|
|
144
|
+
this.service.removeDialogRef(this.dialogRef!);
|
|
145
|
+
this.dialogRef = undefined;
|
|
146
|
+
sub.unsubscribe();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
setDataAndState = (data: T) => {
|
|
150
|
+
if(data){
|
|
151
|
+
this.opDialogConfig.data = data;
|
|
152
|
+
this.setDialogState(true);
|
|
153
|
+
} else {
|
|
154
|
+
this.setDialogState(false);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setDialogState(open: boolean) {
|
|
159
|
+
if(open) {
|
|
160
|
+
if(!this.dialogRef) {
|
|
161
|
+
this.initDialog();
|
|
162
|
+
} else {
|
|
163
|
+
this.componentWrapper!.data = this.opDialogConfig.data as T;
|
|
164
|
+
}
|
|
165
|
+
} else if(!open && this.dialogRef) {
|
|
166
|
+
this.dialogRef.close();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static ngTemplateContextGuard<T>(dir: DialogDirective<T>, ctx: any): ctx is DialogViewContext<Exclude<T, false | 0 | '' | null | undefined>> {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ContentChildren, Directive, Input, Output, QueryList } from "@angular/core";
|
|
2
|
+
import { MatSlideToggle } from "@angular/material/slide-toggle";
|
|
3
|
+
import { merge, Observable, ReplaySubject, scan, startWith, switchMap } from "rxjs";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@Directive(
|
|
7
|
+
{ selector: '[opMatSlideToggleGroup]',
|
|
8
|
+
}
|
|
9
|
+
) export class MatSlideToggleGroupDirective {
|
|
10
|
+
@Input() allowMultiple = false;
|
|
11
|
+
|
|
12
|
+
_toggles!: QueryList<MatSlideToggle>;
|
|
13
|
+
@ContentChildren(MatSlideToggle) set toggles(val: QueryList<MatSlideToggle>) {
|
|
14
|
+
this._toggles = val;
|
|
15
|
+
this._ready.next(true);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private _ready = new ReplaySubject<boolean>(1);
|
|
19
|
+
|
|
20
|
+
@Output() get valueEmitter() : Observable<{[key:string]: boolean}> {
|
|
21
|
+
return this._ready.pipe( switchMap( _ => this.getObs()));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
getInitValue() {
|
|
26
|
+
const startValue = this._toggles.reduce( (prev, cur) => {
|
|
27
|
+
if(!cur.name) {
|
|
28
|
+
throw new Error('toggle must have the name attribute set');
|
|
29
|
+
}
|
|
30
|
+
prev[cur.name] = cur.checked
|
|
31
|
+
return prev;
|
|
32
|
+
}, {} as {[k:string]: boolean});
|
|
33
|
+
return startValue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getObs() {
|
|
37
|
+
var toggleChanges = merge(...this._toggles.map( toggle => toggle.change ));
|
|
38
|
+
|
|
39
|
+
const startValue = this.getInitValue();
|
|
40
|
+
|
|
41
|
+
return toggleChanges.pipe(
|
|
42
|
+
scan( (prev, cur) => {
|
|
43
|
+
const toggleName = cur.source.name!;
|
|
44
|
+
const newVal = { ...prev, [toggleName]: cur.checked };
|
|
45
|
+
if(cur.checked && !this.allowMultiple) {
|
|
46
|
+
Object.keys(prev)
|
|
47
|
+
.filter( key => key !== toggleName && prev[key])
|
|
48
|
+
.forEach( key => {
|
|
49
|
+
newVal[key] = false;
|
|
50
|
+
this._toggles.find( toggle => toggle.name === key)!.toggle();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return newVal;
|
|
54
|
+
}, startValue),
|
|
55
|
+
startWith(startValue),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Directive, HostListener } from "@angular/core";
|
|
2
|
+
|
|
3
|
+
@Directive({
|
|
4
|
+
selector: "[stop-propagation]",
|
|
5
|
+
})
|
|
6
|
+
export class StopPropagationDirective
|
|
7
|
+
{
|
|
8
|
+
@HostListener("click", ["$event"])
|
|
9
|
+
public onClick(event: any): void
|
|
10
|
+
{
|
|
11
|
+
event.stopPropagation();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@HostListener("mousedown", ["$event"])
|
|
15
|
+
public onMousedown(event: any): void
|
|
16
|
+
{
|
|
17
|
+
event.stopPropagation();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Directive, ElementRef, Renderer2, inject, input, effect, signal, untracked } from '@angular/core';
|
|
2
|
+
import { Dictionary } from '@ngrx/entity';
|
|
3
|
+
|
|
4
|
+
@Directive({ selector: '[styler]' })
|
|
5
|
+
export class StylerDirective {
|
|
6
|
+
private el = inject(ElementRef);
|
|
7
|
+
private renderer = inject(Renderer2);
|
|
8
|
+
|
|
9
|
+
$stylesApplied = signal<Dictionary<string>>({});
|
|
10
|
+
$element = input.required<any>({ alias: 'element' });
|
|
11
|
+
$styler = input.required<StylerStyle>({ alias: 'styler' });
|
|
12
|
+
#stylerEffect = effect(() => {
|
|
13
|
+
const styles = this.$styler();
|
|
14
|
+
const element = this.$element();
|
|
15
|
+
|
|
16
|
+
untracked(() => {
|
|
17
|
+
|
|
18
|
+
const toApply = Object.entries(styles ?? {}).reduce((acc, [key, val]) => {
|
|
19
|
+
if(!val) return acc;
|
|
20
|
+
if(typeof (val) === 'string'){
|
|
21
|
+
acc[key] = val;
|
|
22
|
+
this.el.nativeElement.style[key] = val;
|
|
23
|
+
} else if(!val?.condition || val?.condition === true || val?.condition(element)){
|
|
24
|
+
const value = typeof (val.value) === 'string' ? val.value : val?.value(element);
|
|
25
|
+
acc[key] = value;
|
|
26
|
+
this.el.nativeElement.style[key] = value;
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}, {} as Dictionary<string>);
|
|
30
|
+
|
|
31
|
+
Object.keys(this.$stylesApplied()).filter(key => !Object.keys(toApply).includes(key)).forEach(key => {
|
|
32
|
+
this.renderer.removeStyle(this.el.nativeElement, key);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
this.$stylesApplied.set(toApply);
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type StylerStyle<T = any> = Dictionary<
|
|
42
|
+
string | {
|
|
43
|
+
condition?: ((t: T) => boolean) | true,
|
|
44
|
+
value: ((t: T) => string) | string
|
|
45
|
+
}>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Directive, ElementRef, HostListener, inject } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Directive({
|
|
4
|
+
selector: 'input[trimWhitespace]',
|
|
5
|
+
})
|
|
6
|
+
export class TrimWhitespaceDirective {
|
|
7
|
+
private elem = inject(ElementRef);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@HostListener('blur') onBlur() {
|
|
11
|
+
const inputString = this.elem.nativeElement.value;
|
|
12
|
+
if(inputString) {
|
|
13
|
+
const newValue = inputString.trim().replace(/\t/g, '');
|
|
14
|
+
if(inputString !== newValue) {
|
|
15
|
+
this.elem.nativeElement.value = newValue;
|
|
16
|
+
this.elem.nativeElement.dispatchEvent(new Event('input', { bubbles: true }));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from './directives/prevent-enter.directive';
|
|
2
|
+
export * from './directives/stop-propagation.directive';
|
|
3
|
+
export * from './directives/auto-focus.directive';
|
|
4
|
+
export * from './directives/clickSubject';
|
|
5
|
+
export * from './directives/clickEmitterDirective';
|
|
6
|
+
export * from './directives/dialog';
|
|
7
|
+
export * from './directives/styler';
|
|
8
|
+
export * from './directives/mat-toggle-group-directive';
|
|
9
|
+
export * from './directives/trim-whitespace.directive';
|
|
10
|
+
|
|
11
|
+
export * from './pipes/function.pipe';
|
|
12
|
+
export * from './pipes/phone.pipe';
|
|
13
|
+
export * from './pipes/space-case.pipes';
|
|
14
|
+
|
|
15
|
+
export * from './directives/dialog-service';
|
|
16
|
+
|
|
17
|
+
export * from './directives/conditional-classes.directive'
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export * from './module';
|
|
21
|
+
|
|
22
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NgModule } from "@angular/core";
|
|
2
|
+
import { AutoFocusDirective } from "./directives/auto-focus.directive";
|
|
3
|
+
import { ClickEmitterDirective } from "./directives/clickEmitterDirective";
|
|
4
|
+
import { ClickSubjectDirective } from "./directives/clickSubject";
|
|
5
|
+
import { ConditionalClassesDirective } from "./directives/conditional-classes.directive";
|
|
6
|
+
import { DialogDirective } from "./directives/dialog";
|
|
7
|
+
import { DialogService } from "./directives/dialog-service";
|
|
8
|
+
import { MatSlideToggleGroupDirective } from "./directives/mat-toggle-group-directive";
|
|
9
|
+
import { PreventEnterDirective } from "./directives/prevent-enter.directive";
|
|
10
|
+
import { StopPropagationDirective } from "./directives/stop-propagation.directive";
|
|
11
|
+
import { TrimWhitespaceDirective } from "./directives/trim-whitespace.directive";
|
|
12
|
+
import { StylerDirective } from "./directives/styler";
|
|
13
|
+
import { FunctionPipe } from "./pipes/function.pipe";
|
|
14
|
+
import { PhoneNumberPipe } from "./pipes/phone.pipe";
|
|
15
|
+
import { SpaceCasePipe } from "./pipes/space-case.pipes";
|
|
16
|
+
|
|
17
|
+
@NgModule({
|
|
18
|
+
exports: [
|
|
19
|
+
StopPropagationDirective,
|
|
20
|
+
PreventEnterDirective,
|
|
21
|
+
SpaceCasePipe,
|
|
22
|
+
PhoneNumberPipe,
|
|
23
|
+
FunctionPipe,
|
|
24
|
+
TrimWhitespaceDirective,
|
|
25
|
+
StylerDirective,
|
|
26
|
+
AutoFocusDirective,
|
|
27
|
+
ClickSubjectDirective,
|
|
28
|
+
ClickEmitterDirective,
|
|
29
|
+
DialogDirective,
|
|
30
|
+
MatSlideToggleGroupDirective,
|
|
31
|
+
ConditionalClassesDirective,
|
|
32
|
+
],
|
|
33
|
+
imports: [
|
|
34
|
+
SpaceCasePipe,
|
|
35
|
+
PhoneNumberPipe,
|
|
36
|
+
FunctionPipe,
|
|
37
|
+
StopPropagationDirective,
|
|
38
|
+
StylerDirective,
|
|
39
|
+
PreventEnterDirective,
|
|
40
|
+
AutoFocusDirective,
|
|
41
|
+
TrimWhitespaceDirective,
|
|
42
|
+
ClickSubjectDirective,
|
|
43
|
+
ClickEmitterDirective,
|
|
44
|
+
DialogDirective,
|
|
45
|
+
MatSlideToggleGroupDirective,
|
|
46
|
+
ConditionalClassesDirective,
|
|
47
|
+
],
|
|
48
|
+
providers: [
|
|
49
|
+
DialogService
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
export class UtilitiesModule {
|
|
53
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
type Args<S extends object, O extends keyof S> = S[O] extends (...args: infer Params) => any ? Params : never;
|
|
4
|
+
type Return<S extends object, O extends keyof S> = S[O] extends (...args: any[]) => infer R ? R : never;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@Pipe({
|
|
8
|
+
name: 'func',
|
|
9
|
+
})
|
|
10
|
+
export class FunctionPipe implements PipeTransform {
|
|
11
|
+
transform<T, TParam extends any []>(func: (...args: TParam) => T, ...args: TParam): T;
|
|
12
|
+
transform<O extends object, S extends keyof O>(s: S, obj: O, ...args: Args<O, S>): Return<O, S>;
|
|
13
|
+
transform(func: any, ...args: any[]) {
|
|
14
|
+
if(typeof func === 'string') {
|
|
15
|
+
const [instance, ...tail] = args;
|
|
16
|
+
const method = (instance[func] as Function).bind(instance);
|
|
17
|
+
return method(...tail);
|
|
18
|
+
}
|
|
19
|
+
return func(...args);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Pipe({ name: 'phone' })
|
|
4
|
+
export class PhoneNumberPipe implements PipeTransform {
|
|
5
|
+
|
|
6
|
+
transform(phoneNum: string): any {
|
|
7
|
+
return phoneFormatter(phoneNum);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function phoneFormatter(phoneNum: string): string {
|
|
12
|
+
if(phoneNum) {
|
|
13
|
+
phoneNum = phoneNum.replace(/\D/g, '');
|
|
14
|
+
if(phoneNum[0] === '1') {
|
|
15
|
+
phoneNum = phoneNum.substring(1);
|
|
16
|
+
}
|
|
17
|
+
return '(' + phoneNum.slice(0, 3) + ') ' + phoneNum.slice(3, 6) + '-' + phoneNum.slice(6, 10) + ' ' + phoneNum.slice(10);
|
|
18
|
+
}
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SpaceCasePipe } from './space-case.pipes';
|
|
2
|
+
|
|
3
|
+
const pipe = new SpaceCasePipe();
|
|
4
|
+
|
|
5
|
+
describe('Space Case Pipe', () => {
|
|
6
|
+
|
|
7
|
+
it('one word camel case', () => {
|
|
8
|
+
const result = pipe.transform('promissory');
|
|
9
|
+
expect(result).toEqual('Promissory');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('one word pascal case', () => {
|
|
13
|
+
const result = pipe.transform('Promissory');
|
|
14
|
+
expect(result).toEqual('Promissory');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('two words camel case', () => {
|
|
18
|
+
const result = pipe.transform('promissoryNote');
|
|
19
|
+
expect(result).toEqual('Promissory Note');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('two words pascal case', () => {
|
|
23
|
+
const result = pipe.transform('PromissoryNote');
|
|
24
|
+
expect(result).toEqual('Promissory Note');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('bunch of capital letters in a row', () => {
|
|
28
|
+
const result = pipe.transform('IRALLCSingleMember');
|
|
29
|
+
expect(result).toEqual('IRALLC Single Member');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('underscores', () => {
|
|
33
|
+
const result = pipe.transform('Secured_promissory_Note_more');
|
|
34
|
+
expect(result).toEqual('Secured Promissory Note More');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('underscores', () => {
|
|
38
|
+
const result = pipe.transform('IRA_LLCSingleMember');
|
|
39
|
+
expect(result).toEqual('IRA LLC Single Member');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('blank', () => {
|
|
43
|
+
const result = pipe.transform('');
|
|
44
|
+
expect(result).toEqual('');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { inject, InjectionToken, Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Pipe({ name: 'spaceCase' })
|
|
4
|
+
export class SpaceCasePipe implements PipeTransform {
|
|
5
|
+
spaceCase = inject(SpaceCaseMapping, { optional: true }) || spaceCase;
|
|
6
|
+
transform = (value: string): string => {
|
|
7
|
+
return this.spaceCase(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Adds a space before uppercase letters that either
|
|
13
|
+
* 1. follows a lowercase letter or digit
|
|
14
|
+
* 2. or precedes a lowercase letter and follows an alpha-numeric character
|
|
15
|
+
*
|
|
16
|
+
* Uppercases the first digit
|
|
17
|
+
*
|
|
18
|
+
* Turns underscores into spaces
|
|
19
|
+
*/
|
|
20
|
+
export function spaceCase(value: string){
|
|
21
|
+
const phrase = value?.replace(regex1, '$1$3 $2$4')
|
|
22
|
+
// uppercase the first character of every word
|
|
23
|
+
return phrase?.replace(regex2, x => x.toUpperCase());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const regex1 = /([a-z0-9])([A-Z])|([a-zA-Z0-9])([A-Z])(?=[a-z])|_/g;
|
|
27
|
+
const regex2 = /(^| )(\w)/g;
|
|
28
|
+
|
|
29
|
+
export const SpaceCaseMapping = new InjectionToken<(arg: string) => string>('SpaceCaseMapping');
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/lib",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"inlineSources": true,
|
|
9
|
+
"types": [],
|
|
10
|
+
"lib": [
|
|
11
|
+
"dom",
|
|
12
|
+
"ES2023",
|
|
13
|
+
"ES2024.Object"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"exclude": [
|
|
17
|
+
"src/test.ts",
|
|
18
|
+
"**/*.spec.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
+
{
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"outDir": "../../out-tsc/spec",
|
|
6
|
+
"types": [
|
|
7
|
+
"jasmine"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src/test.ts"
|
|
12
|
+
],
|
|
13
|
+
"include": [
|
|
14
|
+
"**/*.spec.ts",
|
|
15
|
+
"**/*.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|