ngx-promise-buttons 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -27,17 +27,13 @@ Install it via npm:
27
27
  npm install ngx-promise-buttons -S
28
28
  ```
29
29
 
30
- And add it as a dependency to your main module
30
+ Add it to your app using bootstrapApplication:
31
31
  ```typescript
32
- import {NgxPromiseButtonModule} from 'ngx-promise-buttons';
33
-
34
- @NgModule({
35
- imports: [
36
- NgxPromiseButtonModule.forRoot(),
32
+ bootstrapApplication(AppComponent, {
33
+ providers: [
34
+ provideNgxPromiseButtons({ handleCurrentBtnOnly: true }),
37
35
  ],
38
- })
39
- export class MainAppModule {
40
- }
36
+ });
41
37
  ```
42
38
  Using the buttons is easy. Just pass a promise to the directive:
43
39
  ```html
@@ -68,28 +64,14 @@ There are selectors you can use to style. There is the `.is-loading` class on th
68
64
 
69
65
 
70
66
  ## Configuration
71
- Configuration is done via the forRoot method of the promise button module:
67
+ You can pass a config object to provideNgxPromiseButtons:
72
68
  ```typescript
73
- import {NgxPromiseButtonModule} from 'ngx-promise-buttons';
74
-
75
- @NgModule({
76
- imports: [
77
- NgxPromiseButtonModule
78
- .forRoot({
79
- // your custom config goes here
80
- spinnerTpl: '<span class="btn-spinner"></span>',
81
- // disable buttons when promise is pending
82
- disableBtn: true,
83
- // the class used to indicate a pending promise
84
- btnLoadingClass: 'is-loading',
85
- // only disable and show is-loading class for clicked button,
86
- // even when they share the same promise
87
- handleCurrentBtnOnly: false,
88
- }),
89
- ],
90
- })
91
- export class MainAppModule {
92
- }
69
+ provideNgxPromiseButtons({
70
+ spinnerTpl: '<span class="btn-spinner"></span>',
71
+ disableBtn: true,
72
+ btnLoadingClass: 'is-loading',
73
+ handleCurrentBtnOnly: false,
74
+ });
93
75
  ```
94
76
 
95
77
  ## Using observables
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, HostListener, Input, Inject, Directive, NgModule } from '@angular/core';
2
+ import { InjectionToken, makeEnvironmentProviders, HostListener, Input, Optional, Inject, Directive } from '@angular/core';
3
3
  import { Observable, Subscription } from 'rxjs';
4
4
 
5
5
  const DEFAULT_CFG = {
@@ -10,7 +10,15 @@ const DEFAULT_CFG = {
10
10
  minDuration: null,
11
11
  };
12
12
 
13
- const userCfg = new InjectionToken('cfg');
13
+ const USER_CFG = new InjectionToken('Promise Button Config');
14
+ const DEFAULT_CONFIG = {
15
+ // default values
16
+ };
17
+ function provideNgxPromiseButtons(config = DEFAULT_CONFIG) {
18
+ return makeEnvironmentProviders([
19
+ { provide: USER_CFG, useValue: { ...DEFAULT_CONFIG, ...config } }
20
+ ]);
21
+ }
14
22
 
15
23
  class PromiseBtnDirective {
16
24
  // this is added to fix the overriding of the disabled state by the loading indicator button.
@@ -204,18 +212,19 @@ class PromiseBtnDirective {
204
212
  this.initLoadingState(this.btnEl);
205
213
  }, 0);
206
214
  }
207
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: PromiseBtnDirective, deps: [{ token: i0.ElementRef }, { token: userCfg }], target: i0.ɵɵFactoryTarget.Directive }); }
208
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: PromiseBtnDirective, isStandalone: false, selector: "[promiseBtn]", inputs: { isDisabledFromTheOutsideSetter: ["disabled", "isDisabledFromTheOutsideSetter"], promiseBtn: "promiseBtn" }, host: { listeners: { "click": "handleCurrentBtnOnly()" } }, ngImport: i0 }); }
215
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: PromiseBtnDirective, deps: [{ token: i0.ElementRef }, { token: USER_CFG, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); }
216
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: PromiseBtnDirective, isStandalone: true, selector: "[promiseBtn]", inputs: { isDisabledFromTheOutsideSetter: ["disabled", "isDisabledFromTheOutsideSetter"], promiseBtn: "promiseBtn" }, host: { listeners: { "click": "handleCurrentBtnOnly()" } }, ngImport: i0 }); }
209
217
  }
210
218
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: PromiseBtnDirective, decorators: [{
211
219
  type: Directive,
212
220
  args: [{
213
221
  selector: '[promiseBtn]',
214
- standalone: false
215
222
  }]
216
223
  }], ctorParameters: () => [{ type: i0.ElementRef }, { type: undefined, decorators: [{
224
+ type: Optional
225
+ }, {
217
226
  type: Inject,
218
- args: [userCfg]
227
+ args: [USER_CFG]
219
228
  }] }], propDecorators: { isDisabledFromTheOutsideSetter: [{
220
229
  type: Input,
221
230
  args: ['disabled']
@@ -226,36 +235,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImpor
226
235
  args: ['click']
227
236
  }] } });
228
237
 
229
- class NgxPromiseButtonModule {
230
- // add forRoot to make it configurable
231
- static forRoot(config) {
232
- // NOTE: this is never allowed to contain any conditional logic
233
- return {
234
- ngModule: NgxPromiseButtonModule,
235
- providers: [{ provide: userCfg, useValue: config }]
236
- };
237
- }
238
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NgxPromiseButtonModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
239
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.6", ngImport: i0, type: NgxPromiseButtonModule, declarations: [PromiseBtnDirective], exports: [PromiseBtnDirective] }); }
240
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NgxPromiseButtonModule }); }
241
- }
242
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NgxPromiseButtonModule, decorators: [{
243
- type: NgModule,
244
- args: [{
245
- declarations: [
246
- PromiseBtnDirective,
247
- ],
248
- imports: [],
249
- exports: [
250
- PromiseBtnDirective,
251
- ],
252
- providers: []
253
- }]
254
- }] });
255
-
256
238
  /**
257
239
  * Generated bundle index. Do not edit.
258
240
  */
259
241
 
260
- export { NgxPromiseButtonModule, PromiseBtnDirective };
242
+ export { DEFAULT_CONFIG, PromiseBtnDirective, USER_CFG, provideNgxPromiseButtons };
261
243
  //# sourceMappingURL=ngx-promise-buttons.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ngx-promise-buttons.mjs","sources":["../../../projects/ngx-promise-buttons/src/default-promise-btn-config.ts","../../../projects/ngx-promise-buttons/src/user-cfg.ts","../../../projects/ngx-promise-buttons/src/promise-btn.directive.ts","../../../projects/ngx-promise-buttons/src/ngx-promise-buttons.module.ts","../../../projects/ngx-promise-buttons/src/ngx-promise-buttons.ts"],"sourcesContent":["import {PromiseBtnConfig} from './promise-btn-config';\r\n\r\nexport const DEFAULT_CFG: PromiseBtnConfig = {\r\n spinnerTpl: '<span class=\"btn-spinner\"></span>',\r\n disableBtn: true,\r\n btnLoadingClass: 'is-loading',\r\n handleCurrentBtnOnly: false,\r\n minDuration: null,\r\n};\r\n\r\n","import {InjectionToken} from '@angular/core';\r\n\r\nexport const userCfg = new InjectionToken('cfg');\r\n","import {AfterContentInit, Directive, ElementRef, HostListener, Inject, Input, OnDestroy} from '@angular/core';\r\nimport {Observable, Subscription} from 'rxjs';\r\nimport {DEFAULT_CFG} from './default-promise-btn-config';\r\nimport {PromiseBtnConfig} from './promise-btn-config';\r\nimport {userCfg} from './user-cfg';\r\n\r\n@Directive({\r\n selector: '[promiseBtn]',\r\n standalone: false\r\n})\r\n\r\nexport class PromiseBtnDirective implements OnDestroy, AfterContentInit {\r\n cfg: PromiseBtnConfig;\r\n // the timeout used for min duration display\r\n minDurationTimeout: number;\r\n // boolean to determine minDurationTimeout state\r\n isMinDurationTimeoutDone: boolean;\r\n // boolean to determine if promise was resolved\r\n isPromiseDone: boolean;\r\n // the promise button button element\r\n btnEl: HTMLElement;\r\n // the promise itself or a function expression\r\n // NOTE: we need the type any here as we might deal with custom promises like bluebird\r\n promise: any;\r\n\r\n // this is added to fix the overriding of the disabled state by the loading indicator button.\r\n @Input('disabled')\r\n set isDisabledFromTheOutsideSetter(v: boolean) {\r\n this.isDisabledFromTheOutside = v;\r\n if (v) {\r\n // disabled means always disabled\r\n this.btnEl.setAttribute('disabled', 'disabled');\r\n } else if (this.isPromiseDone || this.isPromiseDone === undefined) {\r\n this.btnEl.removeAttribute('disabled');\r\n }\r\n // else the button is loading, so do not change the disabled loading state.\r\n }\r\n\r\n isDisabledFromTheOutside: boolean;\r\n\r\n private _fakePromiseResolve: (value: void) => void;\r\n\r\n constructor(el: ElementRef,\r\n @Inject(userCfg) cfg: PromiseBtnConfig) {\r\n // provide configuration\r\n this.cfg = Object.assign({}, DEFAULT_CFG, cfg);\r\n\r\n // save element\r\n this.btnEl = el.nativeElement;\r\n }\r\n\r\n @Input()\r\n set promiseBtn(passedValue: any) {\r\n const isObservable: boolean = passedValue instanceof Observable;\r\n const isSubscription: boolean = passedValue instanceof Subscription;\r\n const isBoolean: boolean = typeof passedValue === 'boolean';\r\n const isPromise: boolean = passedValue instanceof Promise || (\r\n passedValue !== null &&\r\n typeof passedValue === 'object' &&\r\n typeof passedValue.then === 'function' &&\r\n typeof passedValue.catch === 'function'\r\n );\r\n\r\n if (isObservable) {\r\n throw new TypeError('promiseBtn must be an instance of Subscription, instance of Observable given');\r\n } else if (isSubscription) {\r\n const sub: Subscription = passedValue;\r\n if (!sub.closed) {\r\n this.promise = new Promise((resolve) => {\r\n sub.add(resolve);\r\n });\r\n }\r\n } else if (isPromise) {\r\n this.promise = passedValue;\r\n } else if (isBoolean) {\r\n this.promise = this.createPromiseFromBoolean(passedValue);\r\n }\r\n\r\n this.checkAndInitPromiseHandler(this.btnEl);\r\n }\r\n\r\n ngAfterContentInit() {\r\n this.prepareBtnEl(this.btnEl);\r\n // trigger changes once to handle initial promises\r\n this.checkAndInitPromiseHandler(this.btnEl);\r\n }\r\n\r\n ngOnDestroy() {\r\n // cleanup\r\n if (this.minDurationTimeout) {\r\n clearTimeout(this.minDurationTimeout);\r\n }\r\n }\r\n\r\n createPromiseFromBoolean(val: boolean): Promise<any> {\r\n if (val) {\r\n return new Promise((resolve) => {\r\n this._fakePromiseResolve = resolve;\r\n });\r\n } else {\r\n if (this._fakePromiseResolve) {\r\n this._fakePromiseResolve();\r\n }\r\n return this.promise;\r\n }\r\n }\r\n\r\n /**\r\n * Initializes all html and event handlers\r\n */\r\n prepareBtnEl(btnEl: HTMLElement) {\r\n // handle promises passed via promiseBtn attribute\r\n this.appendSpinnerTpl(btnEl);\r\n }\r\n\r\n /**\r\n * Checks if all required parameters are there and inits the promise handler\r\n */\r\n checkAndInitPromiseHandler(btnEl: HTMLElement) {\r\n // check if element and promise is set\r\n if (btnEl && this.promise) {\r\n this.initPromiseHandler(btnEl);\r\n }\r\n }\r\n\r\n /**\r\n * Helper FN to add class\r\n */\r\n addLoadingClass(el: any) {\r\n if (typeof this.cfg.btnLoadingClass === 'string') {\r\n el.classList.add(this.cfg.btnLoadingClass);\r\n }\r\n }\r\n\r\n /**\r\n * Helper FN to remove classes\r\n */\r\n removeLoadingClass(el: any) {\r\n if (typeof this.cfg.btnLoadingClass === 'string') {\r\n el.classList.remove(this.cfg.btnLoadingClass);\r\n }\r\n }\r\n\r\n /**\r\n * Handles everything to be triggered when the button is set\r\n * to loading state.\r\n */\r\n initLoadingState(btnEl: HTMLElement) {\r\n this.addLoadingClass(btnEl);\r\n this.disableBtn(btnEl);\r\n }\r\n\r\n /**\r\n * Handles everything to be triggered when loading is finished\r\n */\r\n cancelLoadingStateIfPromiseAndMinDurationDone(btnEl: HTMLElement) {\r\n if ((!this.cfg.minDuration || this.isMinDurationTimeoutDone) && this.isPromiseDone) {\r\n this.removeLoadingClass(btnEl);\r\n this.enableBtn(btnEl);\r\n }\r\n }\r\n\r\n disableBtn(btnEl: HTMLElement) {\r\n if (this.cfg.disableBtn) {\r\n btnEl.setAttribute('disabled', 'disabled');\r\n }\r\n }\r\n\r\n enableBtn(btnEl: HTMLElement) {\r\n if (this.cfg.disableBtn) {\r\n if (this.isDisabledFromTheOutside) {\r\n btnEl.setAttribute('disabled', 'disabled');\r\n } else {\r\n btnEl.removeAttribute('disabled');\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Initializes a watcher for the promise. Also takes\r\n * this.cfg.minDuration into account if given.\r\n */\r\n\r\n initPromiseHandler(btnEl: HTMLElement) {\r\n const promise = this.promise;\r\n\r\n // watch promise to resolve or fail\r\n this.isMinDurationTimeoutDone = false;\r\n this.isPromiseDone = false;\r\n\r\n // create timeout if option is set\r\n if (this.cfg.minDuration) {\r\n this.minDurationTimeout = window.setTimeout(() => {\r\n this.isMinDurationTimeoutDone = true;\r\n this.cancelLoadingStateIfPromiseAndMinDurationDone(btnEl);\r\n }, this.cfg.minDuration);\r\n }\r\n\r\n const resolveLoadingState = () => {\r\n this.isPromiseDone = true;\r\n this.cancelLoadingStateIfPromiseAndMinDurationDone(btnEl);\r\n };\r\n\r\n if (!this.cfg.handleCurrentBtnOnly) {\r\n this.initLoadingState(btnEl);\r\n }\r\n // native Promise doesn't have finally\r\n if (promise.finally) {\r\n promise.finally(resolveLoadingState);\r\n } else {\r\n promise\r\n .then(resolveLoadingState)\r\n .catch(resolveLoadingState);\r\n }\r\n\r\n }\r\n\r\n\r\n /**\r\n * $compile and append the spinner template to the button.\r\n */\r\n appendSpinnerTpl(btnEl: HTMLElement) {\r\n // TODO add some kind of compilation later on\r\n btnEl.insertAdjacentHTML('beforeend', this.cfg.spinnerTpl as string);\r\n }\r\n\r\n /**\r\n * Limit loading state to show only for the currently clicked button.\r\n * Executed only if this.cfg.handleCurrentBtnOnly is set\r\n */\r\n @HostListener('click')\r\n handleCurrentBtnOnly() {\r\n if (!this.cfg.handleCurrentBtnOnly) {\r\n return true; // return true for testing\r\n }\r\n\r\n // Click triggers @Input update\r\n // We need to use timeout to wait for @Input to update\r\n window.setTimeout(() => {\r\n // return if something else than a promise is passed\r\n if (!this.promise) {\r\n return;\r\n }\r\n\r\n this.initLoadingState(this.btnEl);\r\n }, 0);\r\n }\r\n}\r\n","import {ModuleWithProviders, NgModule} from '@angular/core';\r\nimport {PromiseBtnDirective} from './promise-btn.directive';\r\nimport {PromiseBtnConfig} from './promise-btn-config';\r\nimport {userCfg} from './user-cfg';\r\n\r\n@NgModule({\r\n declarations: [\r\n PromiseBtnDirective,\r\n ],\r\n imports: [],\r\n exports: [\r\n PromiseBtnDirective,\r\n ],\r\n providers: []\r\n})\r\nexport class NgxPromiseButtonModule {\r\n // add forRoot to make it configurable\r\n static forRoot(config?: PromiseBtnConfig): ModuleWithProviders<NgxPromiseButtonModule> {\r\n // NOTE: this is never allowed to contain any conditional logic\r\n return {\r\n ngModule: NgxPromiseButtonModule,\r\n providers: [{provide: userCfg, useValue: config}]\r\n };\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAEO,MAAM,WAAW,GAAqB;AAC3C,IAAA,UAAU,EAAE,mCAAmC;AAC/C,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,eAAe,EAAE,YAAY;AAC7B,IAAA,oBAAoB,EAAE,KAAK;AAC3B,IAAA,WAAW,EAAE,IAAI;CAClB;;ACNM,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,KAAK,CAAC;;MCSnC,mBAAmB,CAAA;;IAe9B,IACI,8BAA8B,CAAC,CAAU,EAAA;AAC3C,QAAA,IAAI,CAAC,wBAAwB,GAAG,CAAC;QACjC,IAAI,CAAC,EAAE;;YAEL,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC;QACjD;aAAO,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE;AACjE,Y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,EAAE;wBACZ,mBAAmB;AACpB,qBAAA;AACD,oBAAA,OAAO,EAAE,EAAE;AACX,oBAAA,OAAO,EAAE;wBACP,mBAAmB;AACpB,qBAAA;AACD,oBAAA,SAAS,EAAE;AACZ,iBAAA;;;ACdD;;AAEG;;;;"}
1
+ {"version":3,"file":"ngx-promise-buttons.mjs","sources":["../../../projects/ngx-promise-buttons/src/default-promise-btn-config.ts","../../../projects/ngx-promise-buttons/src/provider.ts","../../../projects/ngx-promise-buttons/src/promise-btn.directive.ts","../../../projects/ngx-promise-buttons/src/ngx-promise-buttons.ts"],"sourcesContent":["import {PromiseBtnConfig} from './promise-btn-config';\r\n\r\nexport const DEFAULT_CFG: PromiseBtnConfig = {\r\n spinnerTpl: '<span class=\"btn-spinner\"></span>',\r\n disableBtn: true,\r\n btnLoadingClass: 'is-loading',\r\n handleCurrentBtnOnly: false,\r\n minDuration: null,\r\n};\r\n\r\n","import { InjectionToken, EnvironmentProviders, makeEnvironmentProviders, Optional, SkipSelf, inject } from '@angular/core';\r\nimport { PromiseBtnConfig } from './promise-btn-config';\r\n\r\nexport const USER_CFG = new InjectionToken<PromiseBtnConfig>('Promise Button Config');\r\n\r\nexport const DEFAULT_CONFIG: PromiseBtnConfig = {\r\n // default values\r\n};\r\n\r\nexport function provideNgxPromiseButtons(config: PromiseBtnConfig = DEFAULT_CONFIG): EnvironmentProviders {\r\n return makeEnvironmentProviders([\r\n { provide: USER_CFG, useValue: { ...DEFAULT_CONFIG, ...config } }\r\n ]);\r\n}\r\n","import {AfterContentInit, Directive, ElementRef, HostListener, Inject, Input, OnDestroy, Optional} from '@angular/core';\r\nimport {Observable, Subscription} from 'rxjs';\r\nimport {DEFAULT_CFG} from './default-promise-btn-config';\r\nimport {PromiseBtnConfig} from './promise-btn-config';\r\nimport {USER_CFG} from \"./provider\";\r\n\r\n@Directive({\r\n selector: '[promiseBtn]',\r\n})\r\n\r\nexport class PromiseBtnDirective implements OnDestroy, AfterContentInit {\r\n cfg: PromiseBtnConfig;\r\n // the timeout used for min duration display\r\n minDurationTimeout: number;\r\n // boolean to determine minDurationTimeout state\r\n isMinDurationTimeoutDone: boolean;\r\n // boolean to determine if promise was resolved\r\n isPromiseDone: boolean;\r\n // the promise button button element\r\n btnEl: HTMLElement;\r\n // the promise itself or a function expression\r\n // NOTE: we need the type any here as we might deal with custom promises like bluebird\r\n promise: any;\r\n\r\n // this is added to fix the overriding of the disabled state by the loading indicator button.\r\n @Input('disabled')\r\n set isDisabledFromTheOutsideSetter(v: boolean) {\r\n this.isDisabledFromTheOutside = v;\r\n if (v) {\r\n // disabled means always disabled\r\n this.btnEl.setAttribute('disabled', 'disabled');\r\n } else if (this.isPromiseDone || this.isPromiseDone === undefined) {\r\n this.btnEl.removeAttribute('disabled');\r\n }\r\n // else the button is loading, so do not change the disabled loading state.\r\n }\r\n\r\n isDisabledFromTheOutside: boolean;\r\n\r\n private _fakePromiseResolve: (value: void) => void;\r\n\r\n constructor(el: ElementRef,\r\n @Optional() @Inject(USER_CFG) cfg?: PromiseBtnConfig) {\r\n // provide configuration\r\n this.cfg = Object.assign({}, DEFAULT_CFG, cfg);\r\n\r\n // save element\r\n this.btnEl = el.nativeElement;\r\n }\r\n\r\n @Input()\r\n set promiseBtn(passedValue: any) {\r\n const isObservable: boolean = passedValue instanceof Observable;\r\n const isSubscription: boolean = passedValue instanceof Subscription;\r\n const isBoolean: boolean = typeof passedValue === 'boolean';\r\n const isPromise: boolean = passedValue instanceof Promise || (\r\n passedValue !== null &&\r\n typeof passedValue === 'object' &&\r\n typeof passedValue.then === 'function' &&\r\n typeof passedValue.catch === 'function'\r\n );\r\n\r\n if (isObservable) {\r\n throw new TypeError('promiseBtn must be an instance of Subscription, instance of Observable given');\r\n } else if (isSubscription) {\r\n const sub: Subscription = passedValue;\r\n if (!sub.closed) {\r\n this.promise = new Promise((resolve) => {\r\n sub.add(resolve);\r\n });\r\n }\r\n } else if (isPromise) {\r\n this.promise = passedValue;\r\n } else if (isBoolean) {\r\n this.promise = this.createPromiseFromBoolean(passedValue);\r\n }\r\n\r\n this.checkAndInitPromiseHandler(this.btnEl);\r\n }\r\n\r\n ngAfterContentInit() {\r\n this.prepareBtnEl(this.btnEl);\r\n // trigger changes once to handle initial promises\r\n this.checkAndInitPromiseHandler(this.btnEl);\r\n }\r\n\r\n ngOnDestroy() {\r\n // cleanup\r\n if (this.minDurationTimeout) {\r\n clearTimeout(this.minDurationTimeout);\r\n }\r\n }\r\n\r\n createPromiseFromBoolean(val: boolean): Promise<any> {\r\n if (val) {\r\n return new Promise((resolve) => {\r\n this._fakePromiseResolve = resolve;\r\n });\r\n } else {\r\n if (this._fakePromiseResolve) {\r\n this._fakePromiseResolve();\r\n }\r\n return this.promise;\r\n }\r\n }\r\n\r\n /**\r\n * Initializes all html and event handlers\r\n */\r\n prepareBtnEl(btnEl: HTMLElement) {\r\n // handle promises passed via promiseBtn attribute\r\n this.appendSpinnerTpl(btnEl);\r\n }\r\n\r\n /**\r\n * Checks if all required parameters are there and inits the promise handler\r\n */\r\n checkAndInitPromiseHandler(btnEl: HTMLElement) {\r\n // check if element and promise is set\r\n if (btnEl && this.promise) {\r\n this.initPromiseHandler(btnEl);\r\n }\r\n }\r\n\r\n /**\r\n * Helper FN to add class\r\n */\r\n addLoadingClass(el: any) {\r\n if (typeof this.cfg.btnLoadingClass === 'string') {\r\n el.classList.add(this.cfg.btnLoadingClass);\r\n }\r\n }\r\n\r\n /**\r\n * Helper FN to remove classes\r\n */\r\n removeLoadingClass(el: any) {\r\n if (typeof this.cfg.btnLoadingClass === 'string') {\r\n el.classList.remove(this.cfg.btnLoadingClass);\r\n }\r\n }\r\n\r\n /**\r\n * Handles everything to be triggered when the button is set\r\n * to loading state.\r\n */\r\n initLoadingState(btnEl: HTMLElement) {\r\n this.addLoadingClass(btnEl);\r\n this.disableBtn(btnEl);\r\n }\r\n\r\n /**\r\n * Handles everything to be triggered when loading is finished\r\n */\r\n cancelLoadingStateIfPromiseAndMinDurationDone(btnEl: HTMLElement) {\r\n if ((!this.cfg.minDuration || this.isMinDurationTimeoutDone) && this.isPromiseDone) {\r\n this.removeLoadingClass(btnEl);\r\n this.enableBtn(btnEl);\r\n }\r\n }\r\n\r\n disableBtn(btnEl: HTMLElement) {\r\n if (this.cfg.disableBtn) {\r\n btnEl.setAttribute('disabled', 'disabled');\r\n }\r\n }\r\n\r\n enableBtn(btnEl: HTMLElement) {\r\n if (this.cfg.disableBtn) {\r\n if (this.isDisabledFromTheOutside) {\r\n btnEl.setAttribute('disabled', 'disabled');\r\n } else {\r\n btnEl.removeAttribute('disabled');\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Initializes a watcher for the promise. Also takes\r\n * this.cfg.minDuration into account if given.\r\n */\r\n\r\n initPromiseHandler(btnEl: HTMLElement) {\r\n const promise = this.promise;\r\n\r\n // watch promise to resolve or fail\r\n this.isMinDurationTimeoutDone = false;\r\n this.isPromiseDone = false;\r\n\r\n // create timeout if option is set\r\n if (this.cfg.minDuration) {\r\n this.minDurationTimeout = window.setTimeout(() => {\r\n this.isMinDurationTimeoutDone = true;\r\n this.cancelLoadingStateIfPromiseAndMinDurationDone(btnEl);\r\n }, this.cfg.minDuration);\r\n }\r\n\r\n const resolveLoadingState = () => {\r\n this.isPromiseDone = true;\r\n this.cancelLoadingStateIfPromiseAndMinDurationDone(btnEl);\r\n };\r\n\r\n if (!this.cfg.handleCurrentBtnOnly) {\r\n this.initLoadingState(btnEl);\r\n }\r\n // native Promise doesn't have finally\r\n if (promise.finally) {\r\n promise.finally(resolveLoadingState);\r\n } else {\r\n promise\r\n .then(resolveLoadingState)\r\n .catch(resolveLoadingState);\r\n }\r\n\r\n }\r\n\r\n\r\n /**\r\n * $compile and append the spinner template to the button.\r\n */\r\n appendSpinnerTpl(btnEl: HTMLElement) {\r\n // TODO add some kind of compilation later on\r\n btnEl.insertAdjacentHTML('beforeend', this.cfg.spinnerTpl as string);\r\n }\r\n\r\n /**\r\n * Limit loading state to show only for the currently clicked button.\r\n * Executed only if this.cfg.handleCurrentBtnOnly is set\r\n */\r\n @HostListener('click')\r\n handleCurrentBtnOnly() {\r\n if (!this.cfg.handleCurrentBtnOnly) {\r\n return true; // return true for testing\r\n }\r\n\r\n // Click triggers @Input update\r\n // We need to use timeout to wait for @Input to update\r\n window.setTimeout(() => {\r\n // return if something else than a promise is passed\r\n if (!this.promise) {\r\n return;\r\n }\r\n\r\n this.initLoadingState(this.btnEl);\r\n }, 0);\r\n }\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAEO,MAAM,WAAW,GAAqB;AAC3C,IAAA,UAAU,EAAE,mCAAmC;AAC/C,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,eAAe,EAAE,YAAY;AAC7B,IAAA,oBAAoB,EAAE,KAAK;AAC3B,IAAA,WAAW,EAAE,IAAI;CAClB;;MCLY,QAAQ,GAAG,IAAI,cAAc,CAAmB,uBAAuB;AAE7E,MAAM,cAAc,GAAqB;AAC9C;;AAGI,SAAU,wBAAwB,CAAC,MAAA,GAA2B,cAAc,EAAA;AAChF,IAAA,OAAO,wBAAwB,CAAC;AAC9B,QAAA,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE;AAChE,KAAA,CAAC;AACJ;;MCHa,mBAAmB,CAAA;;IAe9B,IACI,8BAA8B,CAAC,CAAU,EAAA;AAC3C,QAAA,IAAI,CAAC,wBAAwB,GAAG,CAAC;QACjC,IAAI,CAAC,EAAE;;YAEL,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC;QACjD;aAAO,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE;AACjE,YAAA,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC;QACxC;;IAEF;IAMA,WAAA,CAAY,EAAc,EACgB,GAAsB,EA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A,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;kGAhC7B,mBAAmB,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,cAAA,EAAA,MAAA,EAAA,EAAA,8BAAA,EAAA,CAAA,UAAA,EAAA,gCAAA,CAAA,EAAA,UAAA,EAAA,YAAA,EAAA,EAAA,IAAA,EAAA,EAAA,SAAA,EAAA,EAAA,OAAA,EAAA,wBAAA,EAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA,CAAA;;2FAAnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAJ/B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACP,oBAAA,QAAQ,EAAE,cAAc;AAC3B,iBAAA;;0BAkCc;;0BAAY,MAAM;2BAAC,QAAQ;;sBAjBvC,KAAK;uBAAC,UAAU;;sBAyBhB;;sBAmLA,YAAY;uBAAC,OAAO;;;ACrOvB;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-promise-buttons",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Chilled loading buttons for angular",
5
5
  "author": "meysamsahragard <contact@super-productivity.com> (http://super-productivity.com)",
6
6
  "license": "MIT",
@@ -35,4 +35,4 @@
35
35
  }
36
36
  },
37
37
  "sideEffects": false
38
- }
38
+ }
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { OnDestroy, AfterContentInit, ElementRef, ModuleWithProviders } from '@angular/core';
2
+ import { OnDestroy, AfterContentInit, ElementRef, InjectionToken, EnvironmentProviders } from '@angular/core';
3
3
 
4
4
  interface PromiseBtnConfig {
5
5
  spinnerTpl?: string;
@@ -19,7 +19,7 @@ declare class PromiseBtnDirective implements OnDestroy, AfterContentInit {
19
19
  set isDisabledFromTheOutsideSetter(v: boolean);
20
20
  isDisabledFromTheOutside: boolean;
21
21
  private _fakePromiseResolve;
22
- constructor(el: ElementRef, cfg: PromiseBtnConfig);
22
+ constructor(el: ElementRef, cfg?: PromiseBtnConfig);
23
23
  set promiseBtn(passedValue: any);
24
24
  ngAfterContentInit(): void;
25
25
  ngOnDestroy(): void;
@@ -65,15 +65,12 @@ declare class PromiseBtnDirective implements OnDestroy, AfterContentInit {
65
65
  * Executed only if this.cfg.handleCurrentBtnOnly is set
66
66
  */
67
67
  handleCurrentBtnOnly(): boolean;
68
- static ɵfac: i0.ɵɵFactoryDeclaration<PromiseBtnDirective, never>;
69
- static ɵdir: i0.ɵɵDirectiveDeclaration<PromiseBtnDirective, "[promiseBtn]", never, { "isDisabledFromTheOutsideSetter": { "alias": "disabled"; "required": false; }; "promiseBtn": { "alias": "promiseBtn"; "required": false; }; }, {}, never, never, false, never>;
68
+ static ɵfac: i0.ɵɵFactoryDeclaration<PromiseBtnDirective, [null, { optional: true; }]>;
69
+ static ɵdir: i0.ɵɵDirectiveDeclaration<PromiseBtnDirective, "[promiseBtn]", never, { "isDisabledFromTheOutsideSetter": { "alias": "disabled"; "required": false; }; "promiseBtn": { "alias": "promiseBtn"; "required": false; }; }, {}, never, never, true, never>;
70
70
  }
71
71
 
72
- declare class NgxPromiseButtonModule {
73
- static forRoot(config?: PromiseBtnConfig): ModuleWithProviders<NgxPromiseButtonModule>;
74
- static ɵfac: i0.ɵɵFactoryDeclaration<NgxPromiseButtonModule, never>;
75
- static ɵmod: i0.ɵɵNgModuleDeclaration<NgxPromiseButtonModule, [typeof PromiseBtnDirective], never, [typeof PromiseBtnDirective]>;
76
- static ɵinj: i0.ɵɵInjectorDeclaration<NgxPromiseButtonModule>;
77
- }
72
+ declare const USER_CFG: InjectionToken<PromiseBtnConfig>;
73
+ declare const DEFAULT_CONFIG: PromiseBtnConfig;
74
+ declare function provideNgxPromiseButtons(config?: PromiseBtnConfig): EnvironmentProviders;
78
75
 
79
- export { NgxPromiseButtonModule, PromiseBtnDirective };
76
+ export { DEFAULT_CONFIG, PromiseBtnDirective, USER_CFG, provideNgxPromiseButtons };