@enigmatry/entry-components 15.0.0-preview.3 → 15.0.0-preview.5

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 (30) hide show
  1. package/common/README.md +56 -1
  2. package/common/common.module.d.ts +6 -2
  3. package/common/directives/auto-disable-button.directive.d.ts +26 -0
  4. package/common/directives/index.d.ts +2 -1
  5. package/common/event-plugins/abstract.plugin.d.ts +40 -0
  6. package/common/event-plugins/debounce.plugin.d.ts +15 -0
  7. package/common/event-plugins/index.d.ts +2 -0
  8. package/common/event-plugins/throttle.plugin.d.ts +15 -0
  9. package/common/public-api.d.ts +2 -1
  10. package/esm2020/common/common.module.mjs +28 -5
  11. package/esm2020/common/directives/auto-disable-button.directive.mjs +75 -0
  12. package/esm2020/common/directives/index.mjs +3 -2
  13. package/esm2020/common/event-plugins/abstract.plugin.mjs +35 -0
  14. package/esm2020/common/event-plugins/debounce.plugin.mjs +34 -0
  15. package/esm2020/common/event-plugins/index.mjs +3 -0
  16. package/esm2020/common/event-plugins/throttle.plugin.mjs +34 -0
  17. package/esm2020/common/public-api.mjs +3 -2
  18. package/esm2020/modules/entry-components.module.mjs +6 -2
  19. package/esm2020/public-api.mjs +2 -1
  20. package/fesm2015/enigmatry-entry-components-common.mjs +192 -7
  21. package/fesm2015/enigmatry-entry-components-common.mjs.map +1 -1
  22. package/fesm2015/enigmatry-entry-components.mjs +6 -1
  23. package/fesm2015/enigmatry-entry-components.mjs.map +1 -1
  24. package/fesm2020/enigmatry-entry-components-common.mjs +192 -7
  25. package/fesm2020/enigmatry-entry-components-common.mjs.map +1 -1
  26. package/fesm2020/enigmatry-entry-components.mjs +6 -1
  27. package/fesm2020/enigmatry-entry-components.mjs.map +1 -1
  28. package/modules/entry-components.module.d.ts +8 -7
  29. package/package.json +3 -2
  30. package/public-api.d.ts +1 -0
@@ -1,13 +1,85 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, Self, NgModule, InjectionToken } from '@angular/core';
2
+ import { Directive, Input, Self, Injectable, NgModule, InjectionToken } from '@angular/core';
3
3
  import { CommonModule } from '@angular/common';
4
- import { Subject, fromEvent } from 'rxjs';
4
+ import { Subject, fromEvent, timer } from 'rxjs';
5
5
  import { takeUntil } from 'rxjs/operators';
6
+ import { coerceNumberProperty } from '@angular/cdk/coercion';
6
7
  import * as i1 from '@angular/forms';
8
+ import { debounce, throttle } from 'lodash-es';
9
+ import { EVENT_MANAGER_PLUGINS } from '@angular/platform-browser';
7
10
 
8
11
  const NG_VALID_CLASS = '.ng-valid';
9
12
  const NG_INVALID_CLASS = '.ng-invalid';
10
13
 
14
+ /**
15
+ * Auto disable button after click or submit with entry-auto-disable directive.
16
+ * Directive is applied to 'button[entry-auto-disable]:not([disabled])'
17
+ * Default auto disable interval is 2000ms (2sec)
18
+ *
19
+ * Usage
20
+ * <button mat-button entry-submit-button entry-auto-disable type="submit">Submit</button>
21
+ * or with auto disabled interval in milliseconds
22
+ * <button mat-button entry-submit-button entry-auto-disable="5000" type="submit">Submit</button>
23
+ */
24
+ class AutoDisableButtonDirective {
25
+ constructor(elementRef) {
26
+ this.elementRef = elementRef;
27
+ this._destroy$ = new Subject();
28
+ this._disableIntervalInMs = 2000;
29
+ }
30
+ get disableIntervalInMs() {
31
+ return this._disableIntervalInMs;
32
+ }
33
+ set disableIntervalInMs(value) {
34
+ this._disableIntervalInMs = coerceNumberProperty(value, 2000);
35
+ }
36
+ ngOnInit() {
37
+ const button = this.elementRef.nativeElement;
38
+ const isTypeSubmit = button.getAttribute('type') === 'submit';
39
+ const form = button.closest('form');
40
+ if (isTypeSubmit && form) {
41
+ // listen to form submit event
42
+ fromEvent(form, 'submit')
43
+ .pipe(takeUntil(this._destroy$))
44
+ .subscribe(_ => {
45
+ if (form.matches(NG_VALID_CLASS)) {
46
+ this.disableButton(this._disableIntervalInMs);
47
+ }
48
+ });
49
+ }
50
+ else {
51
+ // otherwise listen to click event
52
+ fromEvent(button, 'click')
53
+ .pipe(takeUntil(this._destroy$))
54
+ .subscribe(_ => this.disableButton(this._disableIntervalInMs));
55
+ }
56
+ }
57
+ ngOnDestroy() {
58
+ this._destroy$.next();
59
+ this._destroy$.complete();
60
+ }
61
+ disableButton(disablePeriodInMs) {
62
+ const button = this.elementRef.nativeElement;
63
+ button.disabled = true;
64
+ timer(disablePeriodInMs)
65
+ .pipe(takeUntil(this._destroy$))
66
+ .subscribe(() => button.disabled = false);
67
+ }
68
+ }
69
+ AutoDisableButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AutoDisableButtonDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
70
+ AutoDisableButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: AutoDisableButtonDirective, isStandalone: true, selector: "button[entry-auto-disable]:not([disabled])", inputs: { disableIntervalInMs: ["entry-auto-disable", "disableIntervalInMs"] }, ngImport: i0 });
71
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AutoDisableButtonDirective, decorators: [{
72
+ type: Directive,
73
+ args: [{
74
+ standalone: true,
75
+ // eslint-disable-next-line @angular-eslint/directive-selector
76
+ selector: 'button[entry-auto-disable]:not([disabled])'
77
+ }]
78
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { disableIntervalInMs: [{
79
+ type: Input,
80
+ args: ['entry-auto-disable']
81
+ }] } });
82
+
11
83
  /**
12
84
  * Scroll to first invalid control when form is submitted.
13
85
  * Directive is applied to 'form[formGroup],form[ngForm]' (reactive or template driven forms)
@@ -55,13 +127,126 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
55
127
  }] }, { type: i0.ElementRef }];
56
128
  } });
57
129
 
130
+ /**
131
+ * abstract class EventManagerPlugin will be exposed in the public api
132
+ * https://github.com/angular/angular/pull/49969
133
+ *
134
+ * Until then creating it from reference
135
+ * https://github.com/angular/angular/blob/main/packages/platform-browser/src/dom/events/event_manager.ts#L93
136
+ *
137
+ * How to create custom event modifiers
138
+ * https://github.com/Tinkoff/ng-event-plugins,
139
+ * https://github.com/angular/angular/blob/main/packages/platform-browser/src/dom/events/key_events.ts
140
+ * https://netbasal.com/lifting-the-veil-insights-into-angulars-eventmanagerplugin-ed9d14cbb31a
141
+ */
142
+ class EventManagerPlugin {
143
+ }
144
+ /**
145
+ * Entry event plugin base class
146
+ */
147
+ class EntryEventManagerPlugin extends EventManagerPlugin {
148
+ /** return `true` for every event name that has specified modifier */
149
+ supports(eventName) {
150
+ return eventName.includes(this.modifier);
151
+ }
152
+ /** unwrap params e.g. (click.debounce.500) => ['debounce', 500] */
153
+ unwrapParams(eventName) {
154
+ return eventName
155
+ .substring(eventName.indexOf(this.modifier))
156
+ .split('.')
157
+ .filter(x => !!x);
158
+ }
159
+ /** get event name e.g. (click.debounce.500) => click */
160
+ unwrapEventName(eventName) {
161
+ return eventName.substring(0, eventName.indexOf(this.modifier));
162
+ }
163
+ }
164
+
165
+ /* eslint-disable @typescript-eslint/ban-types */
166
+ /**
167
+ * Provides event plugin for debouncing events.
168
+ *
169
+ * How to use:
170
+ * <button (click.debounce)="doSomething($event)">
171
+ * <input (keyup.debounce.500)="doSomething($event)">
172
+ */
173
+ class DebounceEventPlugin extends EntryEventManagerPlugin {
174
+ constructor() {
175
+ super(...arguments);
176
+ this.modifier = '.debounce';
177
+ }
178
+ addEventListener(element, eventName, originalHandler) {
179
+ // e.g. (click.debounce.500)
180
+ const [_modifier, milliseconds = 500, option = 'leading'] = this.unwrapParams(eventName);
181
+ // run original handler inside ngZone in which the event occurred
182
+ const innerHandler = (event) => this.manager.getZone().runGuarded(() => originalHandler(event));
183
+ // create debounced handler
184
+ const debouncedHandler = debounce(innerHandler, milliseconds, { leading: option === 'leading', trailing: option === 'trailing' });
185
+ // register event with debounced handler
186
+ return this.manager.addEventListener(element, this.unwrapEventName(eventName), debouncedHandler);
187
+ }
188
+ }
189
+ DebounceEventPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DebounceEventPlugin, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
190
+ DebounceEventPlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DebounceEventPlugin });
191
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DebounceEventPlugin, decorators: [{
192
+ type: Injectable
193
+ }] });
194
+
195
+ /* eslint-disable @typescript-eslint/ban-types */
196
+ /**
197
+ * Provides event plugin for throttling events.
198
+ *
199
+ * How to use:
200
+ * <button (click.throttle)="doSomething($event)">
201
+ * <input (keyup.throttle.500)="doSomething($event)">
202
+ */
203
+ class ThrottleEventPlugin extends EntryEventManagerPlugin {
204
+ constructor() {
205
+ super(...arguments);
206
+ this.modifier = '.throttle';
207
+ }
208
+ addEventListener(element, eventName, originalHandler) {
209
+ // e.g. (keyup.throttle.500)
210
+ const [_modifier, milliseconds = 500] = this.unwrapParams(eventName);
211
+ // run original handler inside ngZone in which the event occurred
212
+ const innerHandler = (event) => this.manager.getZone().runGuarded(() => originalHandler(event));
213
+ // create throttled handler
214
+ const throttledHandler = throttle(innerHandler, milliseconds);
215
+ // register event with throttled handler
216
+ return this.manager.addEventListener(element, this.unwrapEventName(eventName), throttledHandler);
217
+ }
218
+ }
219
+ ThrottleEventPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ThrottleEventPlugin, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
220
+ ThrottleEventPlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ThrottleEventPlugin });
221
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ThrottleEventPlugin, decorators: [{
222
+ type: Injectable
223
+ }] });
224
+
58
225
  const DIRECTIVES = [
59
- ScrollToInvalidControlDirective
226
+ AutoDisableButtonDirective,
227
+ ScrollToInvalidControlDirective,
60
228
  ];
229
+ const EVENT_PLUGINS = [
230
+ DebounceEventPlugin,
231
+ ThrottleEventPlugin
232
+ ];
233
+ const NG_EVENT_PLUGINS = EVENT_PLUGINS.map(useClass => ({
234
+ provide: EVENT_MANAGER_PLUGINS,
235
+ multi: true,
236
+ useClass
237
+ }));
61
238
  class EntryCommonModule {
239
+ static forRoot() {
240
+ return {
241
+ ngModule: EntryCommonModule,
242
+ providers: NG_EVENT_PLUGINS
243
+ };
244
+ }
62
245
  }
63
246
  EntryCommonModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
64
- EntryCommonModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, imports: [CommonModule, ScrollToInvalidControlDirective], exports: [ScrollToInvalidControlDirective] });
247
+ EntryCommonModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, imports: [CommonModule, AutoDisableButtonDirective,
248
+ ScrollToInvalidControlDirective], exports: [AutoDisableButtonDirective,
249
+ ScrollToInvalidControlDirective] });
65
250
  EntryCommonModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, imports: [CommonModule] });
66
251
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, decorators: [{
67
252
  type: NgModule,
@@ -69,10 +254,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
69
254
  declarations: [],
70
255
  imports: [
71
256
  CommonModule,
72
- ...DIRECTIVES
257
+ DIRECTIVES
73
258
  ],
74
259
  exports: [
75
- ...DIRECTIVES
260
+ DIRECTIVES
76
261
  ]
77
262
  }]
78
263
  }] });
@@ -94,5 +279,5 @@ function provideConfig(token, factory) {
94
279
  * Generated bundle index. Do not edit.
95
280
  */
96
281
 
97
- export { EntryCommonModule, ScrollToInvalidControlDirective, createInjectionToken, provideConfig };
282
+ export { AutoDisableButtonDirective, DebounceEventPlugin, EntryCommonModule, NG_EVENT_PLUGINS, ScrollToInvalidControlDirective, ThrottleEventPlugin, createInjectionToken, provideConfig };
98
283
  //# sourceMappingURL=enigmatry-entry-components-common.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"enigmatry-entry-components-common.mjs","sources":["../../../../libs/entry-components/common/constants.ts","../../../../libs/entry-components/common/directives/scroll-to-invalid-control.directive.ts","../../../../libs/entry-components/common/common.module.ts","../../../../libs/entry-components/common/utils/provide-config.ts","../../../../libs/entry-components/common/enigmatry-entry-components-common.ts"],"sourcesContent":["export const NG_VALID_CLASS = '.ng-valid';\r\nexport const NG_INVALID_CLASS = '.ng-invalid';\r\n","import { Directive, ElementRef, OnDestroy, OnInit, Self } from '@angular/core';\r\nimport { ControlContainer } from '@angular/forms';\r\nimport { Subject, fromEvent } from 'rxjs';\r\nimport { takeUntil } from 'rxjs/operators';\r\nimport { NG_INVALID_CLASS } from '../constants';\r\n\r\n/**\r\n * Scroll to first invalid control when form is submitted.\r\n * Directive is applied to 'form[formGroup],form[ngForm]' (reactive or template driven forms)\r\n */\r\n@Directive({\r\n standalone: true,\r\n selector: 'form[formGroup],form[ngForm]'\r\n})\r\nexport class ScrollToInvalidControlDirective implements OnInit, OnDestroy {\r\n\r\n private destroy$ = new Subject<void>();\r\n\r\n constructor(\r\n @Self() private form: ControlContainer,\r\n private elementRef: ElementRef<HTMLFormElement>) { }\r\n\r\n ngOnInit(): void {\r\n fromEvent(this.elementRef.nativeElement, 'submit')\r\n .pipe(takeUntil(this.destroy$))\r\n .subscribe(_ => {\r\n if (this.form.invalid) {\r\n this.scrollToInvalidControl();\r\n }\r\n });\r\n }\r\n\r\n ngOnDestroy(): void {\r\n this.destroy$.next();\r\n this.destroy$.complete();\r\n }\r\n\r\n private scrollToInvalidControl() {\r\n const firstInvalidControl: HTMLElement =\r\n this.elementRef.nativeElement.querySelector(NG_INVALID_CLASS);\r\n\r\n if (firstInvalidControl) {\r\n firstInvalidControl.scrollIntoView({\r\n behavior: 'smooth',\r\n block: 'center' // vertical alignment\r\n });\r\n }\r\n }\r\n}\r\n","import { NgModule } from '@angular/core';\r\nimport { CommonModule } from '@angular/common';\r\n\r\n/** Directives */\r\n\r\nimport { ScrollToInvalidControlDirective } from './directives/scroll-to-invalid-control.directive';\r\n\r\nconst DIRECTIVES = [\r\n ScrollToInvalidControlDirective\r\n];\r\n\r\n@NgModule({\r\n declarations: [\r\n ],\r\n imports: [\r\n CommonModule,\r\n ...DIRECTIVES\r\n ],\r\n exports: [\r\n ...DIRECTIVES\r\n ]\r\n})\r\nexport class EntryCommonModule {\r\n}\r\n","import { InjectionToken, Provider } from '@angular/core';\r\n\r\nexport function createInjectionToken<T>(defaultValue: T): InjectionToken<T> {\r\n return new InjectionToken<T>(defaultValue.constructor.name,\r\n {\r\n providedIn: 'root',\r\n factory: () => defaultValue\r\n }\r\n );\r\n}\r\n\r\nexport function provideConfig<T>(token: InjectionToken<T>, factory: () => T): Provider {\r\n return {\r\n provide: token,\r\n useFactory: factory\r\n };\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAAO,MAAM,cAAc,GAAG,WAAW,CAAC;AACnC,MAAM,gBAAgB,GAAG,aAAa;;ACK7C;;;AAGG;MAKU,+BAA+B,CAAA;IAI1C,WACkB,CAAA,IAAsB,EAC9B,UAAuC,EAAA;AAD/B,QAAA,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAkB;AAC9B,QAAA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,SAAA,aAAa,CAAI,KAAwB,EAAE,OAAgB,EAAA;IACzE,OAAO;AACL,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,UAAU,EAAE,OAAO;KACpB,CAAC;AACJ;;AChBA;;AAEG;;;;"}
1
+ {"version":3,"file":"enigmatry-entry-components-common.mjs","sources":["../../../../libs/entry-components/common/constants.ts","../../../../libs/entry-components/common/directives/auto-disable-button.directive.ts","../../../../libs/entry-components/common/directives/scroll-to-invalid-control.directive.ts","../../../../libs/entry-components/common/event-plugins/abstract.plugin.ts","../../../../libs/entry-components/common/event-plugins/debounce.plugin.ts","../../../../libs/entry-components/common/event-plugins/throttle.plugin.ts","../../../../libs/entry-components/common/common.module.ts","../../../../libs/entry-components/common/utils/provide-config.ts","../../../../libs/entry-components/common/enigmatry-entry-components-common.ts"],"sourcesContent":["export const NG_VALID_CLASS = '.ng-valid';\r\nexport const NG_INVALID_CLASS = '.ng-invalid';\r\n","import { Directive, ElementRef, Input, OnDestroy, OnInit } from '@angular/core';\nimport { Subject, fromEvent, timer } from 'rxjs';\nimport { takeUntil } from 'rxjs/operators';\nimport { NG_VALID_CLASS } from '../constants';\nimport { NumberInput, coerceNumberProperty } from '@angular/cdk/coercion';\n\n/**\n * Auto disable button after click or submit with entry-auto-disable directive.\n * Directive is applied to 'button[entry-auto-disable]:not([disabled])'\n * Default auto disable interval is 2000ms (2sec)\n *\n * Usage\n * <button mat-button entry-submit-button entry-auto-disable type=\"submit\">Submit</button>\n * or with auto disabled interval in milliseconds\n * <button mat-button entry-submit-button entry-auto-disable=\"5000\" type=\"submit\">Submit</button>\n */\n@Directive({\n standalone: true,\n // eslint-disable-next-line @angular-eslint/directive-selector\n selector: 'button[entry-auto-disable]:not([disabled])'\n})\nexport class AutoDisableButtonDirective implements OnInit, OnDestroy {\n\n private _destroy$ = new Subject<void>();\n private _disableIntervalInMs = 2000;\n\n constructor(private elementRef: ElementRef<HTMLButtonElement>) { }\n\n @Input('entry-auto-disable')\n get disableIntervalInMs() {\n return this._disableIntervalInMs;\n }\n set disableIntervalInMs(value: NumberInput) {\n this._disableIntervalInMs = coerceNumberProperty(value, 2000);\n }\n\n ngOnInit(): void {\n const button = this.elementRef.nativeElement;\n const isTypeSubmit = button.getAttribute('type') === 'submit';\n const form: HTMLFormElement = button.closest('form');\n\n if (isTypeSubmit && form) {\n // listen to form submit event\n fromEvent(form, 'submit')\n .pipe(takeUntil(this._destroy$))\n .subscribe(_ => {\n if (form.matches(NG_VALID_CLASS)) {\n this.disableButton(this._disableIntervalInMs);\n }\n });\n } else {\n // otherwise listen to click event\n fromEvent(button, 'click')\n .pipe(takeUntil(this._destroy$))\n .subscribe(_ => this.disableButton(this._disableIntervalInMs));\n }\n }\n\n ngOnDestroy(): void {\n this._destroy$.next();\n this._destroy$.complete();\n }\n\n private disableButton(disablePeriodInMs: number): void {\n const button = this.elementRef.nativeElement;\n\n button.disabled = true;\n\n timer(disablePeriodInMs)\n .pipe(takeUntil(this._destroy$))\n .subscribe(() => button.disabled = false);\n }\n}\n","import { Directive, ElementRef, OnDestroy, OnInit, Self } from '@angular/core';\r\nimport { ControlContainer } from '@angular/forms';\r\nimport { Subject, fromEvent } from 'rxjs';\r\nimport { takeUntil } from 'rxjs/operators';\r\nimport { NG_INVALID_CLASS } from '../constants';\r\n\r\n/**\r\n * Scroll to first invalid control when form is submitted.\r\n * Directive is applied to 'form[formGroup],form[ngForm]' (reactive or template driven forms)\r\n */\r\n@Directive({\r\n standalone: true,\r\n selector: 'form[formGroup],form[ngForm]'\r\n})\r\nexport class ScrollToInvalidControlDirective implements OnInit, OnDestroy {\r\n\r\n private destroy$ = new Subject<void>();\r\n\r\n constructor(\r\n @Self() private form: ControlContainer,\r\n private elementRef: ElementRef<HTMLFormElement>) { }\r\n\r\n ngOnInit(): void {\r\n fromEvent(this.elementRef.nativeElement, 'submit')\r\n .pipe(takeUntil(this.destroy$))\r\n .subscribe(_ => {\r\n if (this.form.invalid) {\r\n this.scrollToInvalidControl();\r\n }\r\n });\r\n }\r\n\r\n ngOnDestroy(): void {\r\n this.destroy$.next();\r\n this.destroy$.complete();\r\n }\r\n\r\n private scrollToInvalidControl() {\r\n const firstInvalidControl: HTMLElement =\r\n this.elementRef.nativeElement.querySelector(NG_INVALID_CLASS);\r\n\r\n if (firstInvalidControl) {\r\n firstInvalidControl.scrollIntoView({\r\n behavior: 'smooth',\r\n block: 'center' // vertical alignment\r\n });\r\n }\r\n }\r\n}\r\n","import { EventManager } from '@angular/platform-browser';\r\n\r\n/**\r\n * abstract class EventManagerPlugin will be exposed in the public api\r\n * https://github.com/angular/angular/pull/49969\r\n *\r\n * Until then creating it from reference\r\n * https://github.com/angular/angular/blob/main/packages/platform-browser/src/dom/events/event_manager.ts#L93\r\n *\r\n * How to create custom event modifiers\r\n * https://github.com/Tinkoff/ng-event-plugins,\r\n * https://github.com/angular/angular/blob/main/packages/platform-browser/src/dom/events/key_events.ts\r\n * https://netbasal.com/lifting-the-veil-insights-into-angulars-eventmanagerplugin-ed9d14cbb31a\r\n */\r\nexport abstract class EventManagerPlugin {\r\n\r\n // Using non-null assertion because it's set by EventManager's constructor\r\n manager!: EventManager;\r\n\r\n /** Should return `true` for every event name that should be supported by this plugin */\r\n abstract supports(eventName: string): boolean;\r\n\r\n /**\r\n * Registers a handler for a specific element and event.\r\n *\r\n * @param element The HTML element to receive event notifications.\r\n * @param eventName The name of the event to listen for.\r\n * @param handler A function to call when the notification occurs. Receives the\r\n * event object as an argument.\r\n * @returns A callback function that can be used to remove the handler.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/ban-types\r\n abstract addEventListener(element: HTMLElement, eventName: string, handler: Function): Function;\r\n}\r\n\r\n/**\r\n * Entry event plugin base class\r\n */\r\nexport abstract class EntryEventManagerPlugin extends EventManagerPlugin {\r\n abstract modifier: string;\r\n\r\n /** return `true` for every event name that has specified modifier */\r\n supports(eventName: string): boolean {\r\n return eventName.includes(this.modifier);\r\n }\r\n\r\n /** unwrap params e.g. (click.debounce.500) => ['debounce', 500] */\r\n unwrapParams(eventName: string): string[] {\r\n return eventName\r\n .substring(eventName.indexOf(this.modifier))\r\n .split('.')\r\n .filter(x => !!x);\r\n }\r\n\r\n /** get event name e.g. (click.debounce.500) => click */\r\n unwrapEventName(eventName: string): string {\r\n return eventName.substring(0, eventName.indexOf(this.modifier));\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/ban-types */\r\nimport { Injectable } from '@angular/core';\r\nimport { EntryEventManagerPlugin } from './abstract.plugin';\r\nimport { debounce } from 'lodash-es';\r\n\r\n/**\r\n * Provides event plugin for debouncing events.\r\n *\r\n * How to use:\r\n * <button (click.debounce)=\"doSomething($event)\">\r\n * <input (keyup.debounce.500)=\"doSomething($event)\">\r\n */\r\n@Injectable()\r\nexport class DebounceEventPlugin extends EntryEventManagerPlugin {\r\n\r\n modifier = '.debounce';\r\n\r\n addEventListener(element: HTMLElement, eventName: string, originalHandler: Function): Function {\r\n // e.g. (click.debounce.500)\r\n const [_modifier, milliseconds = 500, option = 'leading'] = this.unwrapParams(eventName);\r\n\r\n // run original handler inside ngZone in which the event occurred\r\n const innerHandler = (event: any) => this.manager.getZone().runGuarded(() => originalHandler(event));\r\n\r\n // create debounced handler\r\n const debouncedHandler = debounce(innerHandler, milliseconds,\r\n { leading: option === 'leading', trailing: option === 'trailing' });\r\n\r\n // register event with debounced handler\r\n return this.manager.addEventListener(element, this.unwrapEventName(eventName), debouncedHandler);\r\n }\r\n}\r\n","/* eslint-disable @typescript-eslint/ban-types */\r\nimport { Injectable } from '@angular/core';\r\nimport { EntryEventManagerPlugin } from './abstract.plugin';\r\nimport { throttle } from 'lodash-es';\r\n\r\n/**\r\n * Provides event plugin for throttling events.\r\n *\r\n * How to use:\r\n * <button (click.throttle)=\"doSomething($event)\">\r\n * <input (keyup.throttle.500)=\"doSomething($event)\">\r\n */\r\n@Injectable()\r\nexport class ThrottleEventPlugin extends EntryEventManagerPlugin {\r\n\r\n modifier = '.throttle';\r\n\r\n addEventListener(element: HTMLElement, eventName: string, originalHandler: Function): Function {\r\n // e.g. (keyup.throttle.500)\r\n const [_modifier, milliseconds = 500] = this.unwrapParams(eventName);\r\n\r\n // run original handler inside ngZone in which the event occurred\r\n const innerHandler = (event: any) => this.manager.getZone().runGuarded(() => originalHandler(event));\r\n\r\n // create throttled handler\r\n const throttledHandler = throttle(innerHandler, milliseconds);\r\n\r\n // register event with throttled handler\r\n return this.manager.addEventListener(element, this.unwrapEventName(eventName), throttledHandler);\r\n }\r\n}\r\n","import { ModuleWithProviders, NgModule, Provider } from '@angular/core';\nimport { CommonModule } from '@angular/common';\r\n\r\n/** Directives */\r\n\r\nimport { AutoDisableButtonDirective } from './directives/auto-disable-button.directive';\r\nimport { ScrollToInvalidControlDirective } from './directives/scroll-to-invalid-control.directive';\r\n\r\nconst DIRECTIVES = [\r\n AutoDisableButtonDirective,\r\n ScrollToInvalidControlDirective,\r\n];\r\n\r\n/** Event plugins */\n\nimport { DebounceEventPlugin } from './event-plugins/debounce.plugin';\nimport { ThrottleEventPlugin } from './event-plugins/throttle.plugin';\nimport { EVENT_MANAGER_PLUGINS } from '@angular/platform-browser';\n\nconst EVENT_PLUGINS = [\n DebounceEventPlugin,\n ThrottleEventPlugin\n];\n\nexport const NG_EVENT_PLUGINS: Provider[] = EVENT_PLUGINS.map(useClass => ({\n provide: EVENT_MANAGER_PLUGINS,\n multi: true,\n useClass\n}));\n\n\n@NgModule({\r\n declarations: [\r\n ],\r\n imports: [\r\n CommonModule,\r\n DIRECTIVES\r\n ],\r\n exports: [\r\n DIRECTIVES\r\n ]\r\n})\r\nexport class EntryCommonModule {\r\n static forRoot(): ModuleWithProviders<EntryCommonModule> {\n return {\n ngModule: EntryCommonModule,\n providers: NG_EVENT_PLUGINS\n };\n }\n}\r\n","import { InjectionToken, Provider } from '@angular/core';\r\n\r\nexport function createInjectionToken<T>(defaultValue: T): InjectionToken<T> {\r\n return new InjectionToken<T>(defaultValue.constructor.name,\r\n {\r\n providedIn: 'root',\r\n factory: () => defaultValue\r\n }\r\n );\r\n}\r\n\r\nexport function provideConfig<T>(token: InjectionToken<T>, factory: () => T): Provider {\r\n return {\r\n provide: token,\r\n useFactory: factory\r\n };\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;AAAO,MAAM,cAAc,GAAG,WAAW,CAAC;AACnC,MAAM,gBAAgB,GAAG,aAAa;;ACK7C;;;;;;;;;AASG;MAMU,0BAA0B,CAAA;AAKrC,IAAA,WAAA,CAAoB,UAAyC,EAAA;AAAzC,QAAA,IAAU,CAAA,UAAA,GAAV,UAAU,CAA+B;AAHrD,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,OAAO,EAAQ,CAAC;AAChC,QAAA,IAAoB,CAAA,oBAAA,GAAG,IAAI,CAAC;KAE8B;AAElE,IAAA,IACI,mBAAmB,GAAA;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;KAClC;IACD,IAAI,mBAAmB,CAAC,KAAkB,EAAA;QACxC,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;KAC/D;IAED,QAAQ,GAAA;AACN,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC;QAC7C,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,QAAQ,CAAC;QAC9D,MAAM,IAAI,GAAoB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAErD,IAAI,YAAY,IAAI,IAAI,EAAE;;AAExB,YAAA,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC;AACtB,iBAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBAC/B,SAAS,CAAC,CAAC,IAAG;AACb,gBAAA,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;AAChC,oBAAA,IAAI,CAAC,aAAa,C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AAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,iBAAiB,YAP1B,YAAY,CAAA,EAAA,CAAA,CAAA;2FAOH,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAX7B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EACb;AACD,oBAAA,OAAO,EAAE;wBACP,YAAY;wBACZ,UAAU;AACX,qBAAA;AACD,oBAAA,OAAO,EAAE;wBACP,UAAU;AACX,qBAAA;iBACF,CAAA;;;ACvCK,SAAU,oBAAoB,CAAI,YAAe,EAAA;IACrD,OAAO,IAAI,cAAc,CAAI,YAAY,CAAC,WAAW,CAAC,IAAI,EACxD;AACE,QAAA,UAAU,EAAE,MAAM;AAClB,QAAA,OAAO,EAAE,MAAM,YAAY;AAC5B,KAAA,CACF,CAAC;AACJ,CAAC;AAEe,SAAA,aAAa,CAAI,KAAwB,EAAE,OAAgB,EAAA;IACzE,OAAO;AACL,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,UAAU,EAAE,OAAO;KACpB,CAAC;AACJ;;AChBA;;AAEG;;;;"}
@@ -1,5 +1,7 @@
1
1
  import { EntryButtonModule } from '@enigmatry/entry-components/button';
2
2
  export * from '@enigmatry/entry-components/button';
3
+ import { NG_EVENT_PLUGINS, EntryCommonModule } from '@enigmatry/entry-components/common';
4
+ export * from '@enigmatry/entry-components/common';
3
5
  import { EntryDialogModule } from '@enigmatry/entry-components/dialog';
4
6
  export * from '@enigmatry/entry-components/dialog';
5
7
  import { EntryFileInputModule } from '@enigmatry/entry-components/file-input';
@@ -27,7 +29,7 @@ class EntryComponentsModule {
27
29
  const permissionServiceProvider = options.permissionService
28
30
  ? [{ provide: EntryPermissionService, useClass: options.permissionService }]
29
31
  : [];
30
- const providers = [...permissionServiceProvider];
32
+ const providers = [...permissionServiceProvider, ...NG_EVENT_PLUGINS];
31
33
  return {
32
34
  ngModule: EntryComponentsModule,
33
35
  providers
@@ -36,6 +38,7 @@ class EntryComponentsModule {
36
38
  }
37
39
  EntryComponentsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: EntryComponentsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
38
40
  EntryComponentsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: EntryComponentsModule, exports: [EntryButtonModule,
41
+ EntryCommonModule,
39
42
  EntryDialogModule,
40
43
  EntryFileInputModule,
41
44
  EntryValidationModule,
@@ -43,6 +46,7 @@ EntryComponentsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", v
43
46
  EntrySearchFilterModule,
44
47
  EntryTableModule] });
45
48
  EntryComponentsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: EntryComponentsModule, imports: [EntryButtonModule,
49
+ EntryCommonModule,
46
50
  EntryDialogModule,
47
51
  EntryFileInputModule,
48
52
  EntryValidationModule,
@@ -55,6 +59,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
55
59
  declarations: [],
56
60
  exports: [
57
61
  EntryButtonModule,
62
+ EntryCommonModule,
58
63
  EntryDialogModule,
59
64
  EntryFileInputModule,
60
65
  EntryValidationModule,
@@ -1 +1 @@
1
- {"version":3,"file":"enigmatry-entry-components.mjs","sources":["../../../../libs/entry-components/modules/entry-components.module.ts","../../../../libs/entry-components/public-api.ts","../../../../libs/entry-components/enigmatry-entry-components.ts"],"sourcesContent":["import { ModuleWithProviders, NgModule, Provider, Type } from '@angular/core';\r\nimport { EntryButtonModule } from '@enigmatry/entry-components/button';\r\nimport { EntryDialogModule } from '@enigmatry/entry-components/dialog';\r\nimport { EntryPermissionModule, EntryPermissionService } from '@enigmatry/entry-components/permissions';\r\nimport { EntrySearchFilterModule } from '@enigmatry/entry-components/search-filter';\r\nimport { EntryValidationModule } from '@enigmatry/entry-components/validation';\r\nimport { EntryFileInputModule } from '@enigmatry/entry-components/file-input';\r\nimport { EntryTableModule } from '@enigmatry/entry-components/table';\r\n\r\ninterface EntryComponentsModuleOptions {\r\n permissionService?: Type<any>;\r\n}\r\n\r\n/**\r\n * Exports all entry components.\r\n *\r\n * Usage\r\n * import EntryComponentsModule in shared.module.ts to have access to all components, directives, pipes.\r\n * import EntryComponentsModule.forRoot() in app.module.ts to register root module providers.\r\n */\r\n@NgModule({\r\n declarations: [],\r\n exports: [\r\n EntryButtonModule,\r\n EntryDialogModule,\r\n EntryFileInputModule,\r\n EntryValidationModule,\r\n EntryPermissionModule,\r\n EntrySearchFilterModule,\r\n EntryTableModule\r\n ]\r\n})\r\nexport class EntryComponentsModule {\r\n static forRoot(options: EntryComponentsModuleOptions = {}): ModuleWithProviders<EntryComponentsModule> {\r\n\r\n const permissionServiceProvider: Provider[] = options.permissionService\r\n ? [{ provide: EntryPermissionService, useClass: options.permissionService }]\r\n : [];\r\n\r\n const providers: Provider[] = [...permissionServiceProvider];\r\n return {\r\n ngModule: EntryComponentsModule,\r\n providers\r\n };\r\n }\r\n}\r\n","\n/*\n * Public API Surface of entry-components\n */\nexport * from '@enigmatry/entry-components/button';\nexport * from '@enigmatry/entry-components/dialog';\nexport * from '@enigmatry/entry-components/file-input';\nexport * from '@enigmatry/entry-components/permissions';\nexport * from '@enigmatry/entry-components/search-filter';\nexport * from '@enigmatry/entry-components/validation';\nexport * from '@enigmatry/entry-components/table';\n\nexport { EntryComponentsModule } from './modules/entry-components.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAaA;;;;;;AAMG;MAaU,qBAAqB,CAAA;AAChC,IAAA,OAAO,OAAO,CAAC,OAAA,GAAwC,EAAE,EAAA;AAEvD,QAAA,MAAM,yBAAyB,GAAe,OAAO,CAAC,iBAAiB;AACrE,cAAE,CAAC,EAAE,OA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-entry-components.mjs","sources":["../../../../libs/entry-components/modules/entry-components.module.ts","../../../../libs/entry-components/public-api.ts","../../../../libs/entry-components/enigmatry-entry-components.ts"],"sourcesContent":["import { ModuleWithProviders, NgModule, Provider, Type } from '@angular/core';\r\nimport { EntryButtonModule } from '@enigmatry/entry-components/button';\r\nimport { EntryDialogModule } from '@enigmatry/entry-components/dialog';\r\nimport { EntryPermissionModule, EntryPermissionService } from '@enigmatry/entry-components/permissions';\r\nimport { EntrySearchFilterModule } from '@enigmatry/entry-components/search-filter';\r\nimport { EntryValidationModule } from '@enigmatry/entry-components/validation';\r\nimport { EntryFileInputModule } from '@enigmatry/entry-components/file-input';\r\nimport { EntryTableModule } from '@enigmatry/entry-components/table';\r\nimport { EntryCommonModule, NG_EVENT_PLUGINS } from '@enigmatry/entry-components/common';\r\n\r\ninterface EntryComponentsModuleOptions {\r\n permissionService?: Type<any>;\r\n}\r\n\r\n/**\r\n * Exports all entry components.\r\n *\r\n * Usage\r\n * import EntryComponentsModule in shared.module.ts to have access to all components, directives, pipes.\r\n * import EntryComponentsModule.forRoot() in app.module.ts to register root module providers.\r\n */\r\n@NgModule({\r\n declarations: [],\r\n exports: [\r\n EntryButtonModule,\r\n EntryCommonModule,\r\n EntryDialogModule,\r\n EntryFileInputModule,\r\n EntryValidationModule,\r\n EntryPermissionModule,\r\n EntrySearchFilterModule,\r\n EntryTableModule\r\n ]\r\n})\r\nexport class EntryComponentsModule {\r\n static forRoot(options: EntryComponentsModuleOptions = {}): ModuleWithProviders<EntryComponentsModule> {\r\n\r\n const permissionServiceProvider: Provider[] = options.permissionService\r\n ? [{ provide: EntryPermissionService, useClass: options.permissionService }]\r\n : [];\r\n\r\n const providers: Provider[] = [...permissionServiceProvider, ...NG_EVENT_PLUGINS];\r\n return {\r\n ngModule: EntryComponentsModule,\r\n providers\r\n };\r\n }\r\n}\r\n","\n/*\n * Public API Surface of entry-components\n */\nexport * from '@enigmatry/entry-components/button';\nexport * from '@enigmatry/entry-components/common';\nexport * from '@enigmatry/entry-components/dialog';\nexport * from '@enigmatry/entry-components/file-input';\nexport * from '@enigmatry/entry-components/permissions';\nexport * from '@enigmatry/entry-components/search-filter';\nexport * from '@enigmatry/entry-components/validation';\nexport * from '@enigmatry/entry-components/table';\n\nexport { EntryComponentsModule } from './modules/entry-components.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAcA;;;;;;AAMG;MAcU,qBAAqB,CAAA;AAChC,IAAA,OAAO,OAAO,CAAC,OAAA,GAAwC,EAAE,EAAA;AAEvD,QAAA,MAAM,yBAAyB,GAAe,OAAO,CAAC,iBAAiB;AACrE,cAAE,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC;cAC1E,EAAE,CAAC;QAEP,MAAM,SAAS,GAAe,CAAC,GAAG,yBAAyB,EAAE,GAAG,gBAAgB,CAAC,CAAC;QAClF,OAAO;AACL,YAAA,QAAQ,EAAE,qBAAqB;YAC/B,SAAS;SACV,CAAC;KACH;;kHAZU,qBAAqB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;AAArB,qBAAA,CAAA,IAAA,GAAA,EAAA,CAAA,mBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,qBAAqB,YAV9B,iBAAiB;QACjB,iBAAiB;QACjB,iBAAiB;QACjB,oBAAoB;QACpB,qBAAqB;QACrB,qBAAqB;QACrB,uBAAuB;QACvB,gBAAgB,CAAA,EAAA,CAAA,CAAA;AAGP,qBAAA,CAAA,IAAA,GAAA,EAAA,CAAA,mBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,qBAAqB,YAV9B,iBAAiB;QACjB,iBAAiB;QACjB,iBAAiB;QACjB,oBAAoB;QACpB,qBAAqB;QACrB,qBAAqB;QACrB,uBAAuB;QACvB,gBAAgB,CAAA,EAAA,CAAA,CAAA;2FAGP,qBAAqB,EAAA,UAAA,EAAA,CAAA;kBAbjC,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,OAAO,EAAE;wBACP,iBAAiB;wBACjB,iBAAiB;wBACjB,iBAAiB;wBACjB,oBAAoB;wBACpB,qBAAqB;wBACrB,qBAAqB;wBACrB,uBAAuB;wBACvB,gBAAgB;AACjB,qBAAA;iBACF,CAAA;;;AChCD;;AAEG;;ACHH;;AAEG;;;;"}
@@ -1,13 +1,85 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, Self, NgModule, InjectionToken } from '@angular/core';
2
+ import { Directive, Input, Self, Injectable, NgModule, InjectionToken } from '@angular/core';
3
3
  import { CommonModule } from '@angular/common';
4
- import { Subject, fromEvent } from 'rxjs';
4
+ import { Subject, fromEvent, timer } from 'rxjs';
5
5
  import { takeUntil } from 'rxjs/operators';
6
+ import { coerceNumberProperty } from '@angular/cdk/coercion';
6
7
  import * as i1 from '@angular/forms';
8
+ import { debounce, throttle } from 'lodash-es';
9
+ import { EVENT_MANAGER_PLUGINS } from '@angular/platform-browser';
7
10
 
8
11
  const NG_VALID_CLASS = '.ng-valid';
9
12
  const NG_INVALID_CLASS = '.ng-invalid';
10
13
 
14
+ /**
15
+ * Auto disable button after click or submit with entry-auto-disable directive.
16
+ * Directive is applied to 'button[entry-auto-disable]:not([disabled])'
17
+ * Default auto disable interval is 2000ms (2sec)
18
+ *
19
+ * Usage
20
+ * <button mat-button entry-submit-button entry-auto-disable type="submit">Submit</button>
21
+ * or with auto disabled interval in milliseconds
22
+ * <button mat-button entry-submit-button entry-auto-disable="5000" type="submit">Submit</button>
23
+ */
24
+ class AutoDisableButtonDirective {
25
+ constructor(elementRef) {
26
+ this.elementRef = elementRef;
27
+ this._destroy$ = new Subject();
28
+ this._disableIntervalInMs = 2000;
29
+ }
30
+ get disableIntervalInMs() {
31
+ return this._disableIntervalInMs;
32
+ }
33
+ set disableIntervalInMs(value) {
34
+ this._disableIntervalInMs = coerceNumberProperty(value, 2000);
35
+ }
36
+ ngOnInit() {
37
+ const button = this.elementRef.nativeElement;
38
+ const isTypeSubmit = button.getAttribute('type') === 'submit';
39
+ const form = button.closest('form');
40
+ if (isTypeSubmit && form) {
41
+ // listen to form submit event
42
+ fromEvent(form, 'submit')
43
+ .pipe(takeUntil(this._destroy$))
44
+ .subscribe(_ => {
45
+ if (form.matches(NG_VALID_CLASS)) {
46
+ this.disableButton(this._disableIntervalInMs);
47
+ }
48
+ });
49
+ }
50
+ else {
51
+ // otherwise listen to click event
52
+ fromEvent(button, 'click')
53
+ .pipe(takeUntil(this._destroy$))
54
+ .subscribe(_ => this.disableButton(this._disableIntervalInMs));
55
+ }
56
+ }
57
+ ngOnDestroy() {
58
+ this._destroy$.next();
59
+ this._destroy$.complete();
60
+ }
61
+ disableButton(disablePeriodInMs) {
62
+ const button = this.elementRef.nativeElement;
63
+ button.disabled = true;
64
+ timer(disablePeriodInMs)
65
+ .pipe(takeUntil(this._destroy$))
66
+ .subscribe(() => button.disabled = false);
67
+ }
68
+ }
69
+ AutoDisableButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AutoDisableButtonDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
70
+ AutoDisableButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: AutoDisableButtonDirective, isStandalone: true, selector: "button[entry-auto-disable]:not([disabled])", inputs: { disableIntervalInMs: ["entry-auto-disable", "disableIntervalInMs"] }, ngImport: i0 });
71
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: AutoDisableButtonDirective, decorators: [{
72
+ type: Directive,
73
+ args: [{
74
+ standalone: true,
75
+ // eslint-disable-next-line @angular-eslint/directive-selector
76
+ selector: 'button[entry-auto-disable]:not([disabled])'
77
+ }]
78
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { disableIntervalInMs: [{
79
+ type: Input,
80
+ args: ['entry-auto-disable']
81
+ }] } });
82
+
11
83
  /**
12
84
  * Scroll to first invalid control when form is submitted.
13
85
  * Directive is applied to 'form[formGroup],form[ngForm]' (reactive or template driven forms)
@@ -53,13 +125,126 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
53
125
  type: Self
54
126
  }] }, { type: i0.ElementRef }]; } });
55
127
 
128
+ /**
129
+ * abstract class EventManagerPlugin will be exposed in the public api
130
+ * https://github.com/angular/angular/pull/49969
131
+ *
132
+ * Until then creating it from reference
133
+ * https://github.com/angular/angular/blob/main/packages/platform-browser/src/dom/events/event_manager.ts#L93
134
+ *
135
+ * How to create custom event modifiers
136
+ * https://github.com/Tinkoff/ng-event-plugins,
137
+ * https://github.com/angular/angular/blob/main/packages/platform-browser/src/dom/events/key_events.ts
138
+ * https://netbasal.com/lifting-the-veil-insights-into-angulars-eventmanagerplugin-ed9d14cbb31a
139
+ */
140
+ class EventManagerPlugin {
141
+ }
142
+ /**
143
+ * Entry event plugin base class
144
+ */
145
+ class EntryEventManagerPlugin extends EventManagerPlugin {
146
+ /** return `true` for every event name that has specified modifier */
147
+ supports(eventName) {
148
+ return eventName.includes(this.modifier);
149
+ }
150
+ /** unwrap params e.g. (click.debounce.500) => ['debounce', 500] */
151
+ unwrapParams(eventName) {
152
+ return eventName
153
+ .substring(eventName.indexOf(this.modifier))
154
+ .split('.')
155
+ .filter(x => !!x);
156
+ }
157
+ /** get event name e.g. (click.debounce.500) => click */
158
+ unwrapEventName(eventName) {
159
+ return eventName.substring(0, eventName.indexOf(this.modifier));
160
+ }
161
+ }
162
+
163
+ /* eslint-disable @typescript-eslint/ban-types */
164
+ /**
165
+ * Provides event plugin for debouncing events.
166
+ *
167
+ * How to use:
168
+ * <button (click.debounce)="doSomething($event)">
169
+ * <input (keyup.debounce.500)="doSomething($event)">
170
+ */
171
+ class DebounceEventPlugin extends EntryEventManagerPlugin {
172
+ constructor() {
173
+ super(...arguments);
174
+ this.modifier = '.debounce';
175
+ }
176
+ addEventListener(element, eventName, originalHandler) {
177
+ // e.g. (click.debounce.500)
178
+ const [_modifier, milliseconds = 500, option = 'leading'] = this.unwrapParams(eventName);
179
+ // run original handler inside ngZone in which the event occurred
180
+ const innerHandler = (event) => this.manager.getZone().runGuarded(() => originalHandler(event));
181
+ // create debounced handler
182
+ const debouncedHandler = debounce(innerHandler, milliseconds, { leading: option === 'leading', trailing: option === 'trailing' });
183
+ // register event with debounced handler
184
+ return this.manager.addEventListener(element, this.unwrapEventName(eventName), debouncedHandler);
185
+ }
186
+ }
187
+ DebounceEventPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DebounceEventPlugin, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
188
+ DebounceEventPlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DebounceEventPlugin });
189
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: DebounceEventPlugin, decorators: [{
190
+ type: Injectable
191
+ }] });
192
+
193
+ /* eslint-disable @typescript-eslint/ban-types */
194
+ /**
195
+ * Provides event plugin for throttling events.
196
+ *
197
+ * How to use:
198
+ * <button (click.throttle)="doSomething($event)">
199
+ * <input (keyup.throttle.500)="doSomething($event)">
200
+ */
201
+ class ThrottleEventPlugin extends EntryEventManagerPlugin {
202
+ constructor() {
203
+ super(...arguments);
204
+ this.modifier = '.throttle';
205
+ }
206
+ addEventListener(element, eventName, originalHandler) {
207
+ // e.g. (keyup.throttle.500)
208
+ const [_modifier, milliseconds = 500] = this.unwrapParams(eventName);
209
+ // run original handler inside ngZone in which the event occurred
210
+ const innerHandler = (event) => this.manager.getZone().runGuarded(() => originalHandler(event));
211
+ // create throttled handler
212
+ const throttledHandler = throttle(innerHandler, milliseconds);
213
+ // register event with throttled handler
214
+ return this.manager.addEventListener(element, this.unwrapEventName(eventName), throttledHandler);
215
+ }
216
+ }
217
+ ThrottleEventPlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ThrottleEventPlugin, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
218
+ ThrottleEventPlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ThrottleEventPlugin });
219
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ThrottleEventPlugin, decorators: [{
220
+ type: Injectable
221
+ }] });
222
+
56
223
  const DIRECTIVES = [
57
- ScrollToInvalidControlDirective
224
+ AutoDisableButtonDirective,
225
+ ScrollToInvalidControlDirective,
58
226
  ];
227
+ const EVENT_PLUGINS = [
228
+ DebounceEventPlugin,
229
+ ThrottleEventPlugin
230
+ ];
231
+ const NG_EVENT_PLUGINS = EVENT_PLUGINS.map(useClass => ({
232
+ provide: EVENT_MANAGER_PLUGINS,
233
+ multi: true,
234
+ useClass
235
+ }));
59
236
  class EntryCommonModule {
237
+ static forRoot() {
238
+ return {
239
+ ngModule: EntryCommonModule,
240
+ providers: NG_EVENT_PLUGINS
241
+ };
242
+ }
60
243
  }
61
244
  EntryCommonModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
62
- EntryCommonModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, imports: [CommonModule, ScrollToInvalidControlDirective], exports: [ScrollToInvalidControlDirective] });
245
+ EntryCommonModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, imports: [CommonModule, AutoDisableButtonDirective,
246
+ ScrollToInvalidControlDirective], exports: [AutoDisableButtonDirective,
247
+ ScrollToInvalidControlDirective] });
63
248
  EntryCommonModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, imports: [CommonModule] });
64
249
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: EntryCommonModule, decorators: [{
65
250
  type: NgModule,
@@ -67,10 +252,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
67
252
  declarations: [],
68
253
  imports: [
69
254
  CommonModule,
70
- ...DIRECTIVES
255
+ DIRECTIVES
71
256
  ],
72
257
  exports: [
73
- ...DIRECTIVES
258
+ DIRECTIVES
74
259
  ]
75
260
  }]
76
261
  }] });
@@ -92,5 +277,5 @@ function provideConfig(token, factory) {
92
277
  * Generated bundle index. Do not edit.
93
278
  */
94
279
 
95
- export { EntryCommonModule, ScrollToInvalidControlDirective, createInjectionToken, provideConfig };
280
+ export { AutoDisableButtonDirective, DebounceEventPlugin, EntryCommonModule, NG_EVENT_PLUGINS, ScrollToInvalidControlDirective, ThrottleEventPlugin, createInjectionToken, provideConfig };
96
281
  //# sourceMappingURL=enigmatry-entry-components-common.mjs.map