ngx-promise-buttons 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +13 -0
- package/.github/FUNDING.yml +12 -0
- package/.travis.yml +21 -0
- package/CHANGELOG.md +0 -0
- package/CONTRIBUTING.md +36 -0
- package/README.md +12 -30
- package/angular.json +180 -0
- package/e2e/protractor.conf.js +32 -0
- package/e2e/src/app.e2e-spec.ts +23 -0
- package/e2e/src/app.po.ts +11 -0
- package/e2e/tsconfig.json +13 -0
- package/logo.png +0 -0
- package/package.json +87 -38
- package/projects/ngx-promise-buttons/karma.conf.js +32 -0
- package/projects/ngx-promise-buttons/ng-package.json +10 -0
- package/projects/ngx-promise-buttons/package.json +26 -0
- package/projects/ngx-promise-buttons/src/default-promise-btn-config.ts +10 -0
- package/projects/ngx-promise-buttons/src/index.ts +2 -0
- package/projects/ngx-promise-buttons/src/promise-btn-config.ts +7 -0
- package/projects/ngx-promise-buttons/src/promise-btn.directive.spec.ts +597 -0
- package/projects/ngx-promise-buttons/src/promise-btn.directive.ts +247 -0
- package/projects/ngx-promise-buttons/src/provider.ts +14 -0
- package/projects/ngx-promise-buttons/src/test.ts +16 -0
- package/projects/ngx-promise-buttons/src/user-cfg.ts +3 -0
- package/projects/ngx-promise-buttons/tsconfig.lib.json +27 -0
- package/projects/ngx-promise-buttons/tsconfig.lib.prod.json +10 -0
- package/projects/ngx-promise-buttons/tsconfig.spec.json +17 -0
- package/projects/ngx-promise-buttons/tslint.json +25 -0
- package/projects/ngx-promise-buttons/yarn.lock +9 -0
- package/projects/ngx-promise-buttons-demo/e2e/protractor.conf.js +30 -0
- package/projects/ngx-promise-buttons-demo/e2e/tsconfig.json +14 -0
- package/projects/ngx-promise-buttons-demo/karma.conf.js +56 -0
- package/projects/ngx-promise-buttons-demo/src/app/app.component.css +6 -0
- package/projects/ngx-promise-buttons-demo/src/app/app.component.html +109 -0
- package/projects/ngx-promise-buttons-demo/src/app/app.component.spec.ts +29 -0
- package/projects/ngx-promise-buttons-demo/src/app/app.component.ts +208 -0
- package/projects/ngx-promise-buttons-demo/src/assets/.gitkeep +0 -0
- package/projects/ngx-promise-buttons-demo/src/environments/environment.prod.ts +3 -0
- package/projects/ngx-promise-buttons-demo/src/environments/environment.ts +8 -0
- package/projects/ngx-promise-buttons-demo/src/favicon.ico +0 -0
- package/projects/ngx-promise-buttons-demo/src/index.html +72 -0
- package/projects/ngx-promise-buttons-demo/src/main.ts +11 -0
- package/projects/ngx-promise-buttons-demo/src/polyfills.ts +63 -0
- package/projects/ngx-promise-buttons-demo/src/styles.scss +135 -0
- package/projects/ngx-promise-buttons-demo/tsconfig.app.json +14 -0
- package/projects/ngx-promise-buttons-demo/tsconfig.spec.json +18 -0
- package/projects/ngx-promise-buttons-demo/tslint.json +156 -0
- package/scripts/copy-readme-to-demo.js +15 -0
- package/tsconfig.build-lib.json +32 -0
- package/tsconfig.json +41 -0
- package/wallaby.js +90 -0
- package/fesm2022/ngx-promise-buttons.mjs +0 -261
- package/fesm2022/ngx-promise-buttons.mjs.map +0 -1
- package/types/ngx-promise-buttons.d.ts +0 -79
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const marked = require('marked');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
const demoIndexPagePath = __dirname + '/../dist/demo/index.html';
|
|
5
|
+
const readmePath = __dirname + '/../README.md';
|
|
6
|
+
const readmeNeedle = '___README_MD_NEEDLE___';
|
|
7
|
+
const readme = fs.readFileSync(readmePath);
|
|
8
|
+
const demoIndex = fs.readFileSync(demoIndexPagePath);
|
|
9
|
+
|
|
10
|
+
const demoIndexHtml = demoIndex.toString();
|
|
11
|
+
const readmeHtml = marked(readme.toString());
|
|
12
|
+
|
|
13
|
+
const newDemoIndexHtml = demoIndexHtml.replace(readmeNeedle, readmeHtml);
|
|
14
|
+
|
|
15
|
+
fs.writeFileSync(demoIndexPagePath, newDemoIndexHtml);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"sourceMap": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"removeComments": false,
|
|
9
|
+
"noImplicitAny": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"outDir": "./dist",
|
|
12
|
+
"stripInternal": true,
|
|
13
|
+
"lib": [
|
|
14
|
+
"dom",
|
|
15
|
+
"es6"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"include": [
|
|
19
|
+
"projects/ngx-promise-buttons-demo/src/**/*"
|
|
20
|
+
],
|
|
21
|
+
"exclude": [
|
|
22
|
+
"node_modules",
|
|
23
|
+
"**/*.spec.ts"
|
|
24
|
+
],
|
|
25
|
+
"files": [
|
|
26
|
+
"./scripts/typings.d.ts",
|
|
27
|
+
"./projects/ngx-promise-buttons-demo/src/index.ts"
|
|
28
|
+
],
|
|
29
|
+
"angularCompilerOptions": {
|
|
30
|
+
"skipTemplateCodegen": true
|
|
31
|
+
}
|
|
32
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": false,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": "./",
|
|
5
|
+
"outDir": "./dist/out-tsc",
|
|
6
|
+
"sourceMap": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"declaration": false,
|
|
9
|
+
"experimentalDecorators": true,
|
|
10
|
+
"module": "es2020",
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"importHelpers": true,
|
|
13
|
+
"target": "ES2022",
|
|
14
|
+
"typeRoots": [
|
|
15
|
+
"node_modules/@types"
|
|
16
|
+
],
|
|
17
|
+
"lib": [
|
|
18
|
+
"es2018",
|
|
19
|
+
"dom"
|
|
20
|
+
],
|
|
21
|
+
"paths": {
|
|
22
|
+
"angular-material-css-variables": [
|
|
23
|
+
"dist/angular-material-css-variables"
|
|
24
|
+
],
|
|
25
|
+
"angular-material-css-variables/*": [
|
|
26
|
+
"dist/angular-material-css-variables/*"
|
|
27
|
+
],
|
|
28
|
+
"material-css-vars": [
|
|
29
|
+
"dist/material-css-vars"
|
|
30
|
+
],
|
|
31
|
+
"material-css-vars/*": [
|
|
32
|
+
"dist/material-css-vars/*"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"useDefineForClassFields": false
|
|
36
|
+
},
|
|
37
|
+
"angularCompilerOptions": {
|
|
38
|
+
"fullTemplateTypeCheck": true,
|
|
39
|
+
"strictInjectionParameters": true
|
|
40
|
+
}
|
|
41
|
+
}
|
package/wallaby.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const wallabyWebpack = require('wallaby-webpack');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const compilerOptions = Object.assign(
|
|
7
|
+
require('./tsconfig.json').compilerOptions);
|
|
8
|
+
|
|
9
|
+
// don't generate the declaration files (.d.ts)
|
|
10
|
+
compilerOptions.declaration = false;
|
|
11
|
+
|
|
12
|
+
module.exports = function (wallaby) {
|
|
13
|
+
|
|
14
|
+
const webpackPostprocessor = wallabyWebpack({
|
|
15
|
+
entryPatterns: [
|
|
16
|
+
'scripts/wallabyTest.js',
|
|
17
|
+
'src/**/*spec.js'
|
|
18
|
+
],
|
|
19
|
+
|
|
20
|
+
module: {
|
|
21
|
+
loaders: [
|
|
22
|
+
{ test: /\.css$/, loader: 'raw-loader' },
|
|
23
|
+
{ test: /\.html$/, loader: 'raw-loader' },
|
|
24
|
+
{ test: /\.js$/, loader: 'angular2-template-loader', exclude: /node_modules/ },
|
|
25
|
+
{ test: /\.json$/, loader: 'json-loader' },
|
|
26
|
+
{ test: /\.styl$/, loaders: ['raw-loader', 'stylus-loader'] },
|
|
27
|
+
{ test: /\.less$/, loaders: ['raw-loader', 'less-loader'] },
|
|
28
|
+
{ test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'sass-loader'] },
|
|
29
|
+
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' }
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
resolve: {
|
|
34
|
+
modules: [
|
|
35
|
+
path.join(wallaby.projectCacheDir, 'demo/src'),
|
|
36
|
+
path.join(wallaby.projectCacheDir, 'src')
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
files: [
|
|
43
|
+
{ pattern: 'src/**/*.ts', load: false },
|
|
44
|
+
{ pattern: 'src/**/*.d.ts', ignore: true },
|
|
45
|
+
{ pattern: 'src/**/*.css', load: false },
|
|
46
|
+
{ pattern: 'src/**/*.less', load: false },
|
|
47
|
+
{ pattern: 'src/**/*.scss', load: false },
|
|
48
|
+
{ pattern: 'src/**/*.sass', load: false },
|
|
49
|
+
{ pattern: 'src/**/*.styl', load: false },
|
|
50
|
+
{ pattern: 'src/**/*.html', load: false },
|
|
51
|
+
{ pattern: 'src/**/*.json', load: false },
|
|
52
|
+
{ pattern: 'scripts/*.ts', load: false },
|
|
53
|
+
{ pattern: 'src/**/*spec.ts', ignore: true },
|
|
54
|
+
{ pattern: 'demo/src/**/*.ts', load: false },
|
|
55
|
+
{ pattern: 'demo/src/**/*.d.ts', ignore: true },
|
|
56
|
+
{ pattern: 'demo/src/**/*.css', load: false },
|
|
57
|
+
{ pattern: 'demo/src/**/*.less', load: false },
|
|
58
|
+
{ pattern: 'demo/src/**/*.scss', load: false },
|
|
59
|
+
{ pattern: 'demo/src/**/*.sass', load: false },
|
|
60
|
+
{ pattern: 'demo/src/**/*.styl', load: false },
|
|
61
|
+
{ pattern: 'demo/src/**/*.html', load: false },
|
|
62
|
+
{ pattern: 'demo/src/**/*.json', load: false },
|
|
63
|
+
{ pattern: 'demo/src/**/*spec.ts', ignore: true }
|
|
64
|
+
],
|
|
65
|
+
|
|
66
|
+
tests: [
|
|
67
|
+
{ pattern: 'src/**/*spec.ts', load: false }
|
|
68
|
+
],
|
|
69
|
+
|
|
70
|
+
testFramework: 'jasmine',
|
|
71
|
+
preprocessors: {
|
|
72
|
+
'./scripts/test.ts': ['@angular/cli']
|
|
73
|
+
},
|
|
74
|
+
compilers: {
|
|
75
|
+
'**/*.ts': wallaby.compilers.typeScript(compilerOptions)
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
env: {
|
|
79
|
+
kind: 'electron'
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
postprocessor: webpackPostprocessor,
|
|
83
|
+
|
|
84
|
+
setup: function () {
|
|
85
|
+
window.__moduleBundler.loadTests();
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
debug: true
|
|
89
|
+
};
|
|
90
|
+
};
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, HostListener, Input, Inject, Directive, NgModule } from '@angular/core';
|
|
3
|
-
import { Observable, Subscription } from 'rxjs';
|
|
4
|
-
|
|
5
|
-
const DEFAULT_CFG = {
|
|
6
|
-
spinnerTpl: '<span class="btn-spinner"></span>',
|
|
7
|
-
disableBtn: true,
|
|
8
|
-
btnLoadingClass: 'is-loading',
|
|
9
|
-
handleCurrentBtnOnly: false,
|
|
10
|
-
minDuration: null,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const userCfg = new InjectionToken('cfg');
|
|
14
|
-
|
|
15
|
-
class PromiseBtnDirective {
|
|
16
|
-
// this is added to fix the overriding of the disabled state by the loading indicator button.
|
|
17
|
-
set isDisabledFromTheOutsideSetter(v) {
|
|
18
|
-
this.isDisabledFromTheOutside = v;
|
|
19
|
-
if (v) {
|
|
20
|
-
// disabled means always disabled
|
|
21
|
-
this.btnEl.setAttribute('disabled', 'disabled');
|
|
22
|
-
}
|
|
23
|
-
else if (this.isPromiseDone || this.isPromiseDone === undefined) {
|
|
24
|
-
this.btnEl.removeAttribute('disabled');
|
|
25
|
-
}
|
|
26
|
-
// else the button is loading, so do not change the disabled loading state.
|
|
27
|
-
}
|
|
28
|
-
constructor(el, cfg) {
|
|
29
|
-
// provide configuration
|
|
30
|
-
this.cfg = Object.assign({}, DEFAULT_CFG, cfg);
|
|
31
|
-
// save element
|
|
32
|
-
this.btnEl = el.nativeElement;
|
|
33
|
-
}
|
|
34
|
-
set promiseBtn(passedValue) {
|
|
35
|
-
const isObservable = passedValue instanceof Observable;
|
|
36
|
-
const isSubscription = passedValue instanceof Subscription;
|
|
37
|
-
const isBoolean = typeof passedValue === 'boolean';
|
|
38
|
-
const isPromise = passedValue instanceof Promise || (passedValue !== null &&
|
|
39
|
-
typeof passedValue === 'object' &&
|
|
40
|
-
typeof passedValue.then === 'function' &&
|
|
41
|
-
typeof passedValue.catch === 'function');
|
|
42
|
-
if (isObservable) {
|
|
43
|
-
throw new TypeError('promiseBtn must be an instance of Subscription, instance of Observable given');
|
|
44
|
-
}
|
|
45
|
-
else if (isSubscription) {
|
|
46
|
-
const sub = passedValue;
|
|
47
|
-
if (!sub.closed) {
|
|
48
|
-
this.promise = new Promise((resolve) => {
|
|
49
|
-
sub.add(resolve);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (isPromise) {
|
|
54
|
-
this.promise = passedValue;
|
|
55
|
-
}
|
|
56
|
-
else if (isBoolean) {
|
|
57
|
-
this.promise = this.createPromiseFromBoolean(passedValue);
|
|
58
|
-
}
|
|
59
|
-
this.checkAndInitPromiseHandler(this.btnEl);
|
|
60
|
-
}
|
|
61
|
-
ngAfterContentInit() {
|
|
62
|
-
this.prepareBtnEl(this.btnEl);
|
|
63
|
-
// trigger changes once to handle initial promises
|
|
64
|
-
this.checkAndInitPromiseHandler(this.btnEl);
|
|
65
|
-
}
|
|
66
|
-
ngOnDestroy() {
|
|
67
|
-
// cleanup
|
|
68
|
-
if (this.minDurationTimeout) {
|
|
69
|
-
clearTimeout(this.minDurationTimeout);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
createPromiseFromBoolean(val) {
|
|
73
|
-
if (val) {
|
|
74
|
-
return new Promise((resolve) => {
|
|
75
|
-
this._fakePromiseResolve = resolve;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
if (this._fakePromiseResolve) {
|
|
80
|
-
this._fakePromiseResolve();
|
|
81
|
-
}
|
|
82
|
-
return this.promise;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Initializes all html and event handlers
|
|
87
|
-
*/
|
|
88
|
-
prepareBtnEl(btnEl) {
|
|
89
|
-
// handle promises passed via promiseBtn attribute
|
|
90
|
-
this.appendSpinnerTpl(btnEl);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Checks if all required parameters are there and inits the promise handler
|
|
94
|
-
*/
|
|
95
|
-
checkAndInitPromiseHandler(btnEl) {
|
|
96
|
-
// check if element and promise is set
|
|
97
|
-
if (btnEl && this.promise) {
|
|
98
|
-
this.initPromiseHandler(btnEl);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Helper FN to add class
|
|
103
|
-
*/
|
|
104
|
-
addLoadingClass(el) {
|
|
105
|
-
if (typeof this.cfg.btnLoadingClass === 'string') {
|
|
106
|
-
el.classList.add(this.cfg.btnLoadingClass);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Helper FN to remove classes
|
|
111
|
-
*/
|
|
112
|
-
removeLoadingClass(el) {
|
|
113
|
-
if (typeof this.cfg.btnLoadingClass === 'string') {
|
|
114
|
-
el.classList.remove(this.cfg.btnLoadingClass);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Handles everything to be triggered when the button is set
|
|
119
|
-
* to loading state.
|
|
120
|
-
*/
|
|
121
|
-
initLoadingState(btnEl) {
|
|
122
|
-
this.addLoadingClass(btnEl);
|
|
123
|
-
this.disableBtn(btnEl);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Handles everything to be triggered when loading is finished
|
|
127
|
-
*/
|
|
128
|
-
cancelLoadingStateIfPromiseAndMinDurationDone(btnEl) {
|
|
129
|
-
if ((!this.cfg.minDuration || this.isMinDurationTimeoutDone) && this.isPromiseDone) {
|
|
130
|
-
this.removeLoadingClass(btnEl);
|
|
131
|
-
this.enableBtn(btnEl);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
disableBtn(btnEl) {
|
|
135
|
-
if (this.cfg.disableBtn) {
|
|
136
|
-
btnEl.setAttribute('disabled', 'disabled');
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
enableBtn(btnEl) {
|
|
140
|
-
if (this.cfg.disableBtn) {
|
|
141
|
-
if (this.isDisabledFromTheOutside) {
|
|
142
|
-
btnEl.setAttribute('disabled', 'disabled');
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
btnEl.removeAttribute('disabled');
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Initializes a watcher for the promise. Also takes
|
|
151
|
-
* this.cfg.minDuration into account if given.
|
|
152
|
-
*/
|
|
153
|
-
initPromiseHandler(btnEl) {
|
|
154
|
-
const promise = this.promise;
|
|
155
|
-
// watch promise to resolve or fail
|
|
156
|
-
this.isMinDurationTimeoutDone = false;
|
|
157
|
-
this.isPromiseDone = false;
|
|
158
|
-
// create timeout if option is set
|
|
159
|
-
if (this.cfg.minDuration) {
|
|
160
|
-
this.minDurationTimeout = window.setTimeout(() => {
|
|
161
|
-
this.isMinDurationTimeoutDone = true;
|
|
162
|
-
this.cancelLoadingStateIfPromiseAndMinDurationDone(btnEl);
|
|
163
|
-
}, this.cfg.minDuration);
|
|
164
|
-
}
|
|
165
|
-
const resolveLoadingState = () => {
|
|
166
|
-
this.isPromiseDone = true;
|
|
167
|
-
this.cancelLoadingStateIfPromiseAndMinDurationDone(btnEl);
|
|
168
|
-
};
|
|
169
|
-
if (!this.cfg.handleCurrentBtnOnly) {
|
|
170
|
-
this.initLoadingState(btnEl);
|
|
171
|
-
}
|
|
172
|
-
// native Promise doesn't have finally
|
|
173
|
-
if (promise.finally) {
|
|
174
|
-
promise.finally(resolveLoadingState);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
promise
|
|
178
|
-
.then(resolveLoadingState)
|
|
179
|
-
.catch(resolveLoadingState);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* $compile and append the spinner template to the button.
|
|
184
|
-
*/
|
|
185
|
-
appendSpinnerTpl(btnEl) {
|
|
186
|
-
// TODO add some kind of compilation later on
|
|
187
|
-
btnEl.insertAdjacentHTML('beforeend', this.cfg.spinnerTpl);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Limit loading state to show only for the currently clicked button.
|
|
191
|
-
* Executed only if this.cfg.handleCurrentBtnOnly is set
|
|
192
|
-
*/
|
|
193
|
-
handleCurrentBtnOnly() {
|
|
194
|
-
if (!this.cfg.handleCurrentBtnOnly) {
|
|
195
|
-
return true; // return true for testing
|
|
196
|
-
}
|
|
197
|
-
// Click triggers @Input update
|
|
198
|
-
// We need to use timeout to wait for @Input to update
|
|
199
|
-
window.setTimeout(() => {
|
|
200
|
-
// return if something else than a promise is passed
|
|
201
|
-
if (!this.promise) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
this.initLoadingState(this.btnEl);
|
|
205
|
-
}, 0);
|
|
206
|
-
}
|
|
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 }); }
|
|
209
|
-
}
|
|
210
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: PromiseBtnDirective, decorators: [{
|
|
211
|
-
type: Directive,
|
|
212
|
-
args: [{
|
|
213
|
-
selector: '[promiseBtn]',
|
|
214
|
-
standalone: false
|
|
215
|
-
}]
|
|
216
|
-
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: undefined, decorators: [{
|
|
217
|
-
type: Inject,
|
|
218
|
-
args: [userCfg]
|
|
219
|
-
}] }], propDecorators: { isDisabledFromTheOutsideSetter: [{
|
|
220
|
-
type: Input,
|
|
221
|
-
args: ['disabled']
|
|
222
|
-
}], promiseBtn: [{
|
|
223
|
-
type: Input
|
|
224
|
-
}], handleCurrentBtnOnly: [{
|
|
225
|
-
type: HostListener,
|
|
226
|
-
args: ['click']
|
|
227
|
-
}] } });
|
|
228
|
-
|
|
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
|
-
/**
|
|
257
|
-
* Generated bundle index. Do not edit.
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
export { NgxPromiseButtonModule, PromiseBtnDirective };
|
|
261
|
-
//# sourceMappingURL=ngx-promise-buttons.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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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,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAC;SACjD;IACH;8GARW,sBAAsB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;+GAAtB,sBAAsB,EAAA,YAAA,EAAA,CAR/B,mBAAmB,CAAA,EAAA,OAAA,EAAA,CAInB,mBAAmB,CAAA,EAAA,CAAA,CAAA;+GAIV,sBAAsB,EAAA,CAAA,CAAA;;2FAAtB,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBAVlC,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,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,79 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { OnDestroy, AfterContentInit, ElementRef, ModuleWithProviders } from '@angular/core';
|
|
3
|
-
|
|
4
|
-
interface PromiseBtnConfig {
|
|
5
|
-
spinnerTpl?: string;
|
|
6
|
-
disableBtn?: boolean;
|
|
7
|
-
btnLoadingClass?: boolean | string;
|
|
8
|
-
handleCurrentBtnOnly?: boolean;
|
|
9
|
-
minDuration?: number | null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
declare class PromiseBtnDirective implements OnDestroy, AfterContentInit {
|
|
13
|
-
cfg: PromiseBtnConfig;
|
|
14
|
-
minDurationTimeout: number;
|
|
15
|
-
isMinDurationTimeoutDone: boolean;
|
|
16
|
-
isPromiseDone: boolean;
|
|
17
|
-
btnEl: HTMLElement;
|
|
18
|
-
promise: any;
|
|
19
|
-
set isDisabledFromTheOutsideSetter(v: boolean);
|
|
20
|
-
isDisabledFromTheOutside: boolean;
|
|
21
|
-
private _fakePromiseResolve;
|
|
22
|
-
constructor(el: ElementRef, cfg: PromiseBtnConfig);
|
|
23
|
-
set promiseBtn(passedValue: any);
|
|
24
|
-
ngAfterContentInit(): void;
|
|
25
|
-
ngOnDestroy(): void;
|
|
26
|
-
createPromiseFromBoolean(val: boolean): Promise<any>;
|
|
27
|
-
/**
|
|
28
|
-
* Initializes all html and event handlers
|
|
29
|
-
*/
|
|
30
|
-
prepareBtnEl(btnEl: HTMLElement): void;
|
|
31
|
-
/**
|
|
32
|
-
* Checks if all required parameters are there and inits the promise handler
|
|
33
|
-
*/
|
|
34
|
-
checkAndInitPromiseHandler(btnEl: HTMLElement): void;
|
|
35
|
-
/**
|
|
36
|
-
* Helper FN to add class
|
|
37
|
-
*/
|
|
38
|
-
addLoadingClass(el: any): void;
|
|
39
|
-
/**
|
|
40
|
-
* Helper FN to remove classes
|
|
41
|
-
*/
|
|
42
|
-
removeLoadingClass(el: any): void;
|
|
43
|
-
/**
|
|
44
|
-
* Handles everything to be triggered when the button is set
|
|
45
|
-
* to loading state.
|
|
46
|
-
*/
|
|
47
|
-
initLoadingState(btnEl: HTMLElement): void;
|
|
48
|
-
/**
|
|
49
|
-
* Handles everything to be triggered when loading is finished
|
|
50
|
-
*/
|
|
51
|
-
cancelLoadingStateIfPromiseAndMinDurationDone(btnEl: HTMLElement): void;
|
|
52
|
-
disableBtn(btnEl: HTMLElement): void;
|
|
53
|
-
enableBtn(btnEl: HTMLElement): void;
|
|
54
|
-
/**
|
|
55
|
-
* Initializes a watcher for the promise. Also takes
|
|
56
|
-
* this.cfg.minDuration into account if given.
|
|
57
|
-
*/
|
|
58
|
-
initPromiseHandler(btnEl: HTMLElement): void;
|
|
59
|
-
/**
|
|
60
|
-
* $compile and append the spinner template to the button.
|
|
61
|
-
*/
|
|
62
|
-
appendSpinnerTpl(btnEl: HTMLElement): void;
|
|
63
|
-
/**
|
|
64
|
-
* Limit loading state to show only for the currently clicked button.
|
|
65
|
-
* Executed only if this.cfg.handleCurrentBtnOnly is set
|
|
66
|
-
*/
|
|
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>;
|
|
70
|
-
}
|
|
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
|
-
}
|
|
78
|
-
|
|
79
|
-
export { NgxPromiseButtonModule, PromiseBtnDirective };
|