@one-paragon/angular-utilities 2.2.4 → 2.2.6
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 +44 -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 +25 -0
- package/src/action-state/action-state-ui/action-state-ui.module.ts +13 -0
- package/{action-state/index.d.ts → src/action-state/index.ts} +8 -4
- 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 +284 -0
- package/{http-request-state/deprecated.d.ts → src/http-request-state/deprecated.ts} +20 -20
- 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/{http-request-state/directives/index.d.ts → src/http-request-state/directives/index.ts} +5 -5
- 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/helpers.ts +30 -0
- package/src/http-request-state/http-state-module.ts +23 -0
- package/{http-request-state/index.d.ts → src/http-request-state/index.ts} +7 -7
- 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/{http-request-state/rxjs/index.d.ts → src/http-request-state/rxjs/index.ts} +4 -4
- 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 +160 -0
- package/src/ngrx/index.ts +1 -0
- package/{public-api.d.ts → src/public-api.ts} +35 -16
- package/src/rxjs/defaultShareReplay.ts +8 -0
- package/{rxjs/index.d.ts → src/rxjs/index.ts} +5 -5
- 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 +95 -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 +50 -0
- package/src/table-builder/classes/TableBuilderDataSource.ts +64 -0
- package/src/table-builder/classes/TableState.ts +125 -0
- package/src/table-builder/classes/data-store.ts +10 -0
- package/{table-builder/classes/display-col.d.ts → src/table-builder/classes/display-col.ts} +5 -5
- package/src/table-builder/classes/filter-info.ts +125 -0
- package/src/table-builder/classes/table-builder-general-settings.ts +205 -0
- package/src/table-builder/classes/table-builder.ts +105 -0
- package/src/table-builder/classes/table-store.helpers.ts +104 -0
- package/src/table-builder/classes/table-store.ts +440 -0
- package/src/table-builder/components/array-column.component.ts +34 -0
- package/src/table-builder/components/column-builder/column-builder.component.html +87 -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 +129 -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 +110 -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 +94 -0
- package/src/table-builder/components/date-filter/date-filter.component.html +25 -0
- package/src/table-builder/components/date-filter/date-filter.component.ts +22 -0
- package/src/table-builder/components/date-time-filter/date-time-filter.component.html +11 -0
- package/src/table-builder/components/date-time-filter/date-time-filter.component.ts +20 -0
- package/src/table-builder/components/filter/filter.component.html +109 -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 +64 -0
- package/src/table-builder/components/filter/in-list/in-list-filter.component.ts +102 -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 +97 -0
- package/src/table-builder/components/generic-table/generic-table.component.scss +38 -0
- package/src/table-builder/components/generic-table/generic-table.component.ts +403 -0
- package/src/table-builder/components/generic-table/paginator.component.ts +112 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.css +17 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.html +14 -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 +25 -0
- package/src/table-builder/components/in-filter/in-filter.component.css +3 -0
- package/src/table-builder/components/in-filter/in-filter.component.html +23 -0
- package/src/table-builder/components/in-filter/in-filter.component.ts +65 -0
- package/{table-builder/components/index.d.ts → src/table-builder/components/index.ts} +9 -9
- package/src/table-builder/components/initialization-component/initialization.component.html +78 -0
- package/src/table-builder/components/initialization-component/initialization.component.ts +27 -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 +25 -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 +25 -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 +63 -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 +81 -0
- package/src/table-builder/components/table-container/table-container.component.ts +403 -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 +122 -0
- package/src/table-builder/components/table-container/table-container.helpers/meta-data.helpers.ts +16 -0
- package/src/table-builder/components/table-container/table-container.helpers/sort-state.helpers.ts +47 -0
- package/src/table-builder/components/table-container/table-container.scss +47 -0
- package/src/table-builder/components/table-container/tableProps.ts +18 -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 +35 -0
- package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.ts +44 -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 +36 -0
- package/src/table-builder/components/table-container-filter/table-wrapper-filter-store.ts +23 -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 +50 -0
- package/src/table-builder/components/table-header-menu/table-header-menu.component.ts +35 -0
- package/src/table-builder/directives/custom-cell-directive.ts +57 -0
- package/{table-builder/directives/index.d.ts → src/table-builder/directives/index.ts} +6 -5
- package/src/table-builder/directives/multi-sort.directive.spec.ts +124 -0
- package/src/table-builder/directives/multi-sort.directive.ts +50 -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/enums/filterTypes.ts +40 -0
- package/src/table-builder/functions/boolean-filter-function.ts +12 -0
- package/src/table-builder/functions/date-filter-function.ts +78 -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 +41 -0
- package/src/table-builder/functions/sort-data-function.ts +80 -0
- package/src/table-builder/functions/string-filter-function.ts +53 -0
- package/{table-builder/interfaces/ColumnInfo.d.ts → src/table-builder/interfaces/ColumnInfo.ts} +7 -6
- package/{table-builder/interfaces/dictionary.d.ts → src/table-builder/interfaces/dictionary.ts} +3 -3
- package/src/table-builder/interfaces/report-def.ts +254 -0
- package/src/table-builder/ngrx/tableBuilderStateStore.ts +197 -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 +67 -0
- package/src/table-builder/pipes/key-display.ts +13 -0
- package/src/table-builder/services/export-to-csv.service.ts +113 -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 +96 -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 +38 -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 +144 -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 +44 -0
- package/src/utilities/directives/trim-whitespace.directive.ts +20 -0
- package/{utilities/index.d.ts → src/utilities/index.ts} +22 -15
- 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 +26 -0
- package/tsconfig.lib.json +20 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/action-state/action-state-spinner/action-state-spinner.component.d.ts +0 -12
- package/action-state/action-state-ui/action-state-ui.module.d.ts +0 -7
- package/action-state/ngrx-ext/ngrx-ext.module.d.ts +0 -8
- package/action-state/ngrx.d.ts +0 -31
- package/fesm2022/one-paragon-angular-utilities.mjs +0 -6531
- package/fesm2022/one-paragon-angular-utilities.mjs.map +0 -1
- package/http-request-state/RequestStateFactory.d.ts +0 -17
- package/http-request-state/RequestStateStore.d.ts +0 -101
- package/http-request-state/directives/HttpStateDirectiveBase.d.ts +0 -14
- package/http-request-state/directives/http-error-state-directive.d.ts +0 -10
- package/http-request-state/directives/http-inProgress-state-directive.d.ts +0 -10
- package/http-request-state/directives/http-notStarted-state-directive.d.ts +0 -10
- package/http-request-state/directives/http-success-state-directive.d.ts +0 -17
- package/http-request-state/directives/request-state-directive.d.ts +0 -34
- package/http-request-state/helpers.d.ts +0 -9
- package/http-request-state/http-state-module.d.ts +0 -11
- package/http-request-state/request-state.d.ts +0 -12
- package/http-request-state/rxjs/getRequestorBody.d.ts +0 -3
- package/http-request-state/rxjs/getRequestorState.d.ts +0 -3
- package/http-request-state/rxjs/tapError.d.ts +0 -3
- package/http-request-state/rxjs/tapSuccess.d.ts +0 -3
- package/http-request-state/types.d.ts +0 -41
- package/index.d.ts +0 -5
- package/ngrx/actionable-selector.d.ts +0 -32
- package/ngrx/index.d.ts +0 -1
- package/rxjs/defaultShareReplay.d.ts +0 -2
- package/rxjs/mapError.d.ts +0 -2
- package/rxjs/rxjs-operators.d.ts +0 -13
- package/rxjs/subjectifier.d.ts +0 -10
- package/rxjs/subscriber.directive.d.ts +0 -14
- package/table-builder/classes/DefaultSettings.d.ts +0 -9
- package/table-builder/classes/MatTableObservableDataSource.d.ts +0 -9
- package/table-builder/classes/TableBuilderConfig.d.ts +0 -23
- package/table-builder/classes/TableBuilderDataSource.d.ts +0 -18
- package/table-builder/classes/TableState.d.ts +0 -81
- package/table-builder/classes/data-store.d.ts +0 -8
- package/table-builder/classes/filter-info.d.ts +0 -39
- package/table-builder/classes/table-builder-general-settings.d.ts +0 -119
- package/table-builder/classes/table-builder.d.ts +0 -22
- package/table-builder/classes/table-store.d.ts +0 -146
- package/table-builder/classes/table-store.helpers.d.ts +0 -31
- package/table-builder/components/array-column.component.d.ts +0 -15
- package/table-builder/components/column-builder/column-builder.component.d.ts +0 -41
- package/table-builder/components/column-builder/column-helpers.d.ts +0 -38
- package/table-builder/components/column-header-menu/column-header-menu.component.d.ts +0 -50
- package/table-builder/components/date-filter/date-filter.component.d.ts +0 -37
- package/table-builder/components/date-time-filter/date-time-filter.component.d.ts +0 -37
- package/table-builder/components/filter/filter.component.d.ts +0 -48
- package/table-builder/components/filter/in-list/in-list-filter.component.d.ts +0 -22
- package/table-builder/components/gen-col-displayer/gen-col-displayer.component.d.ts +0 -17
- package/table-builder/components/generic-table/generic-table.component.d.ts +0 -85
- package/table-builder/components/generic-table/paginator.component.d.ts +0 -26
- package/table-builder/components/group-by-list/group-by-list.component.d.ts +0 -11
- package/table-builder/components/in-filter/in-filter.component.d.ts +0 -20
- package/table-builder/components/initialization-component/initialization.component.d.ts +0 -15
- package/table-builder/components/link-column.component.d.ts +0 -23
- package/table-builder/components/number-filter/number-filter.component.d.ts +0 -39
- package/table-builder/components/profiles-menu/profiles-menu.component.d.ts +0 -33
- package/table-builder/components/reset-menu/reset-menu.component.d.ts +0 -25
- package/table-builder/components/scroll-strategy.d.ts +0 -45
- package/table-builder/components/sort-menu/sort-menu.component-store.d.ts +0 -24
- package/table-builder/components/sort-menu/sort-menu.component.d.ts +0 -19
- package/table-builder/components/table-container/table-container.component.d.ts +0 -104
- package/table-builder/components/table-container/table-container.helpers/data-state.helpers.d.ts +0 -7
- package/table-builder/components/table-container/table-container.helpers/filter-state.helpers.d.ts +0 -19
- package/table-builder/components/table-container/table-container.helpers/groupBy.helpers.d.ts +0 -19
- package/table-builder/components/table-container/table-container.helpers/meta-data.helpers.d.ts +0 -2
- package/table-builder/components/table-container/table-container.helpers/sort-state.helpers.d.ts +0 -12
- package/table-builder/components/table-container/tableProps.d.ts +0 -10
- package/table-builder/components/table-container/virtual-scroll-container.d.ts +0 -40
- package/table-builder/components/table-container-filter/filter-list/filter-list.component.d.ts +0 -15
- package/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.d.ts +0 -12
- package/table-builder/components/table-container-filter/table-wrapper-filter-store.d.ts +0 -14
- package/table-builder/components/table-header-menu/table-header-menu.component.d.ts +0 -15
- package/table-builder/directives/custom-cell-directive.d.ts +0 -34
- package/table-builder/directives/multi-sort.directive.d.ts +0 -10
- package/table-builder/directives/resize-column.directive.d.ts +0 -43
- package/table-builder/directives/table-wrapper.directive.d.ts +0 -8
- package/table-builder/directives/tb-filter.directive.d.ts +0 -116
- package/table-builder/enums/filterTypes.d.ts +0 -36
- package/table-builder/functions/boolean-filter-function.d.ts +0 -3
- package/table-builder/functions/date-filter-function.d.ts +0 -4
- package/table-builder/functions/download-data.d.ts +0 -1
- package/table-builder/functions/null-filter-function.d.ts +0 -2
- package/table-builder/functions/number-filter-function.d.ts +0 -4
- package/table-builder/functions/sort-data-function.d.ts +0 -6
- package/table-builder/functions/string-filter-function.d.ts +0 -5
- package/table-builder/interfaces/report-def.d.ts +0 -223
- package/table-builder/ngrx/tableBuilderStateStore.d.ts +0 -69
- package/table-builder/pipes/column-total.pipe.d.ts +0 -8
- package/table-builder/pipes/format-filter-type.pipe.d.ts +0 -8
- package/table-builder/pipes/format-filter-value.pipe.d.ts +0 -11
- package/table-builder/pipes/key-display.d.ts +0 -9
- package/table-builder/services/export-to-csv.service.d.ts +0 -14
- package/table-builder/services/link-creator.service.d.ts +0 -16
- package/table-builder/services/table-template-service.d.ts +0 -14
- package/table-builder/services/transform-creator.d.ts +0 -9
- package/table-builder/table-builder.module.d.ts +0 -14
- package/utilities/array-helpers.d.ts +0 -1
- package/utilities/directives/auto-focus.directive.d.ts +0 -9
- package/utilities/directives/clickEmitterDirective.d.ts +0 -7
- package/utilities/directives/clickSubject.d.ts +0 -9
- package/utilities/directives/conditional-classes.directive.d.ts +0 -12
- package/utilities/directives/dialog-service.d.ts +0 -10
- package/utilities/directives/dialog.d.ts +0 -45
- package/utilities/directives/mat-toggle-group-directive.d.ts +0 -21
- package/utilities/directives/prevent-enter.directive.d.ts +0 -6
- package/utilities/directives/stop-propagation.directive.d.ts +0 -7
- package/utilities/directives/styler.d.ts +0 -16
- package/utilities/directives/trim-whitespace.directive.d.ts +0 -7
- package/utilities/module.d.ts +0 -19
- package/utilities/pipes/function.pipe.d.ts +0 -11
- package/utilities/pipes/phone.pipe.d.ts +0 -8
- package/utilities/pipes/space-case.pipes.d.ts +0 -17
package/src/test.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
+
|
|
3
|
+
import 'zone.js';
|
|
4
|
+
import 'zone.js/testing';
|
|
5
|
+
import { getTestBed } from '@angular/core/testing';
|
|
6
|
+
import {
|
|
7
|
+
BrowserDynamicTestingModule,
|
|
8
|
+
platformBrowserDynamicTesting
|
|
9
|
+
} from '@angular/platform-browser-dynamic/testing';
|
|
10
|
+
|
|
11
|
+
// First, initialize the Angular testing environment.
|
|
12
|
+
getTestBed().initTestEnvironment(
|
|
13
|
+
BrowserDynamicTestingModule,
|
|
14
|
+
platformBrowserDynamicTesting(), {
|
|
15
|
+
teardown: { destroyAfterEach: false }
|
|
16
|
+
}
|
|
17
|
+
);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const replaceInArrayWithClone = <T = any>(arr: T[], findMeth: (t: T) => boolean, actionOnClone: (t: T) => any = ((t: T) => {})): T[] => {
|
|
2
|
+
const index = arr.findIndex(findMeth);
|
|
3
|
+
const clonedArray = [...arr];
|
|
4
|
+
const t = clonedArray[index];
|
|
5
|
+
clonedArray[index] =
|
|
6
|
+
t != null && typeof t === 'object' ?
|
|
7
|
+
Array.isArray(t) ?
|
|
8
|
+
[...t] as any
|
|
9
|
+
: { ...t }
|
|
10
|
+
: t;
|
|
11
|
+
actionOnClone(clonedArray[index]);
|
|
12
|
+
return clonedArray;
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Directive, ElementRef, AfterViewInit, Input, inject } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Directive({
|
|
4
|
+
selector: '[autoFocus]',
|
|
5
|
+
})
|
|
6
|
+
export class AutoFocusDirective implements AfterViewInit {
|
|
7
|
+
private elementRef = inject(ElementRef);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@Input() autoFocus = true;
|
|
11
|
+
|
|
12
|
+
ngAfterViewInit() {
|
|
13
|
+
if(this.autoFocus){
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
this.elementRef.nativeElement.focus();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Directive } from '@angular/core';
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@Directive({
|
|
6
|
+
selector: '[clickEmitter]',
|
|
7
|
+
exportAs: 'clickEmitter',
|
|
8
|
+
host: {
|
|
9
|
+
'(click)': 'next(true)'
|
|
10
|
+
},
|
|
11
|
+
}) export class ClickEmitterDirective extends Subject<boolean> {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Directive, Input } from '@angular/core';
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
@Directive({
|
|
5
|
+
selector: '[clickSubject]',
|
|
6
|
+
exportAs: 'clickSubject',
|
|
7
|
+
host: {
|
|
8
|
+
'(click)': 'next(this._val)'
|
|
9
|
+
},
|
|
10
|
+
}) export class ClickSubjectDirective<T = boolean> extends Subject<T> {
|
|
11
|
+
constructor( ) {
|
|
12
|
+
super();
|
|
13
|
+
}
|
|
14
|
+
_val!: T;
|
|
15
|
+
|
|
16
|
+
@Input('clickSubject') set clickSubject( val: T) {
|
|
17
|
+
this._val = val;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Directive, ElementRef, Renderer2, effect, inject, input, untracked } from '@angular/core';
|
|
2
|
+
import { Dictionary, Predicate } from '@ngrx/entity';
|
|
3
|
+
|
|
4
|
+
@Directive({
|
|
5
|
+
selector: '[conditionalClasses]',
|
|
6
|
+
})
|
|
7
|
+
export class ConditionalClassesDirective {
|
|
8
|
+
private el = inject(ElementRef);
|
|
9
|
+
private renderer = inject(Renderer2);
|
|
10
|
+
|
|
11
|
+
$element = input.required<any>({ alias: 'element' });
|
|
12
|
+
$classes = input<Dictionary<Predicate<any> | true>>(undefined, { alias: 'conditionalClasses' });
|
|
13
|
+
|
|
14
|
+
classesApplied: string[] = [];
|
|
15
|
+
|
|
16
|
+
#onClasses = effect(() => {
|
|
17
|
+
const classes = this.$classes();
|
|
18
|
+
untracked(() => {
|
|
19
|
+
const element = this.$element();
|
|
20
|
+
let toApply: string [] = [];
|
|
21
|
+
if(classes) {
|
|
22
|
+
toApply = Object.keys(classes)
|
|
23
|
+
.filter( key => (classes![key] === true) || classes![key]!(element) );
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var classesNotYetApplied = toApply.filter( c => !this.classesApplied.includes(c) );
|
|
27
|
+
var classesToRemove = this.classesApplied.filter( c => !toApply.includes(c));
|
|
28
|
+
|
|
29
|
+
classesToRemove.forEach( c => this.renderer.removeClass( this.el.nativeElement, c ) );
|
|
30
|
+
|
|
31
|
+
classesNotYetApplied.forEach( c => this.renderer.addClass( this.el.nativeElement, c ) );
|
|
32
|
+
|
|
33
|
+
this.classesApplied = toApply;
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { MatDialogRef } from '@angular/material/dialog';
|
|
3
|
+
|
|
4
|
+
@Injectable({ providedIn: 'root' })
|
|
5
|
+
export class DialogService {
|
|
6
|
+
allOpenOpDialogs: MatDialogRef<any>[] = [];
|
|
7
|
+
|
|
8
|
+
addDialogRef(ref: MatDialogRef<any>) {
|
|
9
|
+
this.allOpenOpDialogs.push(ref);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
removeDialogRef(ref: MatDialogRef<any>) {
|
|
13
|
+
this.allOpenOpDialogs = this.allOpenOpDialogs.filter(rf => ref.id !== rf.id);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
closeAllOpDialogs() {
|
|
17
|
+
this.allOpenOpDialogs.forEach(ref => ref.close());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Directive, TemplateRef, Input, Component, Output, EventEmitter, ViewContainerRef, Injector, ChangeDetectionStrategy, inject, untracked, Signal, isSignal } from '@angular/core';
|
|
2
|
+
import { MatDialog, MatDialogRef, MatDialogConfig, MAT_DIALOG_DEFAULT_OPTIONS } 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
|
+
import { DialogConfig } from '@angular/cdk/dialog';
|
|
8
|
+
|
|
9
|
+
interface DialogViewContext<T> {
|
|
10
|
+
$implicit: T,
|
|
11
|
+
opDialog: T,
|
|
12
|
+
close: () => void,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Component({
|
|
16
|
+
selector: 'dialog-wrapper',
|
|
17
|
+
template: ``,
|
|
18
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
19
|
+
})
|
|
20
|
+
export class DialogWrapper<T = any> {
|
|
21
|
+
private vcr = inject(ViewContainerRef);
|
|
22
|
+
|
|
23
|
+
viewEmbedded = false;
|
|
24
|
+
viewContext = {
|
|
25
|
+
close: () => {},
|
|
26
|
+
} as DialogViewContext<T>;
|
|
27
|
+
set template(tmpl: TemplateRef<DialogViewContext<T>>) {
|
|
28
|
+
if(this.viewEmbedded) {
|
|
29
|
+
this.vcr.clear();
|
|
30
|
+
}
|
|
31
|
+
this.viewEmbedded = true;
|
|
32
|
+
this.vcr.createEmbeddedView(tmpl, this.viewContext);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set close(closeMethod: () => void ) {
|
|
36
|
+
this.viewContext.close = closeMethod;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
set data(value: T) {
|
|
40
|
+
this.viewContext.$implicit = value;
|
|
41
|
+
this.viewContext.opDialog = value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const defaultDialogConfig: MatDialogConfig = {
|
|
48
|
+
maxHeight: '95vh',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@Directive(
|
|
53
|
+
{ selector: '[opDialog]', }
|
|
54
|
+
) export class DialogDirective<T> {
|
|
55
|
+
private templateRef = inject<TemplateRef<DialogViewContext<T>>>(TemplateRef);
|
|
56
|
+
private dialog = inject(MatDialog);
|
|
57
|
+
private dialogConfig = inject(MAT_DIALOG_DEFAULT_OPTIONS, { optional: true }) || {};
|
|
58
|
+
private service = inject(DialogService);
|
|
59
|
+
|
|
60
|
+
@Output() opDialogClosed: EventEmitter<boolean> = new EventEmitter();
|
|
61
|
+
_dialogConfig: MatDialogConfig<T> = { ...this.dialogConfig, ...defaultDialogConfig };
|
|
62
|
+
@Input() opDialogAddDialogClass = true;
|
|
63
|
+
@Input() set opDialogConfig(config: MatDialogConfig<T>) {
|
|
64
|
+
|
|
65
|
+
this._dialogConfig = { ...this.dialogConfig, ...defaultDialogConfig, ...config };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get opDialogConfig() : MatDialogConfig<T> {
|
|
69
|
+
return this._dialogConfig;
|
|
70
|
+
}
|
|
71
|
+
injector = inject(Injector);
|
|
72
|
+
subscriber = subscriber(this.injector);
|
|
73
|
+
@Input('opDialog') set setControl(i: Observable<T> | Signal<T>){
|
|
74
|
+
let o: Observable<T>;
|
|
75
|
+
if(isSignal(i)){
|
|
76
|
+
o = toObservable<T>(i, { injector: this.injector })
|
|
77
|
+
} else {
|
|
78
|
+
o = i;
|
|
79
|
+
}
|
|
80
|
+
untracked(() => {
|
|
81
|
+
this.subscriber.on(o, this.setDataAndState);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@Input('opDialogOrigin') nativeElement? : HTMLElement;
|
|
86
|
+
dialogRef?: MatDialogRef<any, boolean>;
|
|
87
|
+
componentWrapper?: DialogWrapper<T>;
|
|
88
|
+
|
|
89
|
+
_data = new Subject<Observable<T>>();
|
|
90
|
+
|
|
91
|
+
close() {
|
|
92
|
+
this.dialogRef?.close();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
initDialog() {
|
|
96
|
+
if(this.nativeElement){
|
|
97
|
+
const rect = this.nativeElement.getBoundingClientRect();
|
|
98
|
+
const position = { left: `${rect.left}px`, top: `${rect.bottom - 50}px` };
|
|
99
|
+
this.opDialogConfig = { ...this.opDialogConfig, position };
|
|
100
|
+
}
|
|
101
|
+
if(this.opDialogAddDialogClass) {
|
|
102
|
+
this.opDialogConfig.panelClass = [...(Array.isArray(this.opDialogConfig.panelClass) ? this.opDialogConfig.panelClass : this.opDialogConfig.panelClass ? [this.opDialogConfig.panelClass] : []), 'opDialog'];
|
|
103
|
+
}
|
|
104
|
+
this.dialogRef = this.dialog.open(DialogWrapper, this.opDialogConfig);
|
|
105
|
+
this.componentWrapper = this.dialogRef.componentInstance;
|
|
106
|
+
this.componentWrapper!.close = () => this.dialogRef?.close();
|
|
107
|
+
this.componentWrapper!.data = this.opDialogConfig.data as T;
|
|
108
|
+
this.componentWrapper!.template = this.templateRef;
|
|
109
|
+
if(!this.opDialogConfig.disableClose) {
|
|
110
|
+
this.service.addDialogRef(this.dialogRef);
|
|
111
|
+
}
|
|
112
|
+
const sub = this.dialogRef.afterClosed().subscribe(() => {
|
|
113
|
+
this.opDialogClosed.emit(true);
|
|
114
|
+
this.service.removeDialogRef(this.dialogRef!);
|
|
115
|
+
this.dialogRef = undefined;
|
|
116
|
+
sub.unsubscribe();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
setDataAndState = (data: T) => {
|
|
120
|
+
if(data){
|
|
121
|
+
this.opDialogConfig.data = data;
|
|
122
|
+
this.setDialogState(true);
|
|
123
|
+
} else {
|
|
124
|
+
this.setDialogState(false);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
setDialogState(open: boolean) {
|
|
129
|
+
if(open) {
|
|
130
|
+
if(!this.dialogRef) {
|
|
131
|
+
this.initDialog();
|
|
132
|
+
} else {
|
|
133
|
+
this.componentWrapper!.data = this.opDialogConfig.data as T;
|
|
134
|
+
}
|
|
135
|
+
} else if(!open && this.dialogRef) {
|
|
136
|
+
this.dialogRef.close();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static ngTemplateContextGuard<T>(dir: DialogDirective<T>, ctx: any): ctx is DialogViewContext<Exclude<T, false | 0 | '' | null | undefined>> {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
}
|
|
@@ -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,44 @@
|
|
|
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
|
+
untracked(() => {
|
|
15
|
+
const element = this.$element();
|
|
16
|
+
|
|
17
|
+
const toApply = Object.entries(styles ?? {}).reduce((acc, [key, val]) => {
|
|
18
|
+
if(!val) return acc;
|
|
19
|
+
if(typeof (val) === 'string'){
|
|
20
|
+
acc[key] = val;
|
|
21
|
+
this.el.nativeElement.style[key] = val;
|
|
22
|
+
} else if(!val?.condition || val?.condition === true || val?.condition(element)){
|
|
23
|
+
const value = typeof (val.value) === 'string' ? val.value : val?.value(element);
|
|
24
|
+
acc[key] = value;
|
|
25
|
+
this.el.nativeElement.style[key] = value;
|
|
26
|
+
}
|
|
27
|
+
return acc;
|
|
28
|
+
}, {} as Dictionary<string>);
|
|
29
|
+
|
|
30
|
+
Object.keys(this.$stylesApplied()).filter(key => !Object.keys(toApply).includes(key)).forEach(key => {
|
|
31
|
+
this.renderer.removeStyle(this.el.nativeElement, key);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
this.$stylesApplied.set(toApply);
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type StylerStyle<T = any> = Dictionary<
|
|
41
|
+
string | {
|
|
42
|
+
condition?: ((t: T) => boolean) | true,
|
|
43
|
+
value: ((t: T) => string) | string
|
|
44
|
+
}>
|
|
@@ -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
|
+
}
|
|
@@ -1,15 +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/
|
|
12
|
-
export * from './pipes/
|
|
13
|
-
export * from './
|
|
14
|
-
|
|
15
|
-
export * from './
|
|
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,26 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
@Pipe({ name: 'spaceCase' })
|
|
4
|
+
export class SpaceCasePipe implements PipeTransform {
|
|
5
|
+
transform(value: string): string {
|
|
6
|
+
return spaceCase(value);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Adds a space before uppercase letters that either
|
|
12
|
+
* 1. follows a lowercase letter or digit
|
|
13
|
+
* 2. or precedes a lowercase letter and follows an alpha-numeric character
|
|
14
|
+
*
|
|
15
|
+
* Uppercases the first digit
|
|
16
|
+
*
|
|
17
|
+
* Turns underscores into spaces
|
|
18
|
+
*/
|
|
19
|
+
export function spaceCase(value: string){
|
|
20
|
+
const phrase = value?.replace(regex1, '$1$3 $2$4')
|
|
21
|
+
// uppercase the first character of every word
|
|
22
|
+
return phrase?.replace(regex2, x => x.toUpperCase());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const regex1 = /([a-z0-9])([A-Z])|([a-zA-Z0-9])([A-Z])(?=[a-z])|_/g;
|
|
26
|
+
const regex2 = /(^| )(\w)/g;
|