@ssv/ngx.command 2.2.0 → 2.3.0-dev.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 +7 -7
- package/command-ref.directive.d.ts +3 -0
- package/command.directive.d.ts +3 -0
- package/esm2020/command-ref.directive.mjs +54 -0
- package/esm2020/command.directive.mjs +166 -0
- package/esm2020/command.mjs +127 -0
- package/esm2020/command.model.mjs +2 -0
- package/esm2020/command.util.mjs +29 -0
- package/esm2020/config.mjs +8 -0
- package/esm2020/index.mjs +8 -0
- package/esm2020/module.mjs +49 -0
- package/esm2020/ssv-ngx.command.mjs +5 -0
- package/esm2020/version.mjs +2 -0
- package/fesm2015/{ssv-ngx.command.js → ssv-ngx.command.mjs} +66 -45
- package/fesm2015/ssv-ngx.command.mjs.map +1 -0
- package/fesm2020/ssv-ngx.command.mjs +424 -0
- package/fesm2020/ssv-ngx.command.mjs.map +1 -0
- package/module.d.ts +6 -0
- package/package.json +23 -13
- package/version.d.ts +1 -1
- package/CHANGELOG.md +0 -216
- package/bundles/ssv-ngx.command.umd.js +0 -759
- package/bundles/ssv-ngx.command.umd.js.map +0 -1
- package/bundles/ssv-ngx.command.umd.min.js +0 -16
- package/bundles/ssv-ngx.command.umd.min.js.map +0 -1
- package/esm2015/command-ref.directive.js +0 -50
- package/esm2015/command.directive.js +0 -156
- package/esm2015/command.js +0 -127
- package/esm2015/command.model.js +0 -2
- package/esm2015/command.util.js +0 -28
- package/esm2015/config.js +0 -8
- package/esm2015/index.js +0 -8
- package/esm2015/module.js +0 -36
- package/esm2015/ssv-ngx.command.js +0 -5
- package/esm2015/version.js +0 -2
- package/fesm2015/ssv-ngx.command.js.map +0 -1
- package/ssv-ngx.command.d.ts +0 -4
- package/ssv-ngx.command.metadata.json +0 -1
|
@@ -1,759 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs'), require('rxjs/operators'), require('@angular/core')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define('@ssv/ngx.command', ['exports', 'rxjs', 'rxjs/operators', '@angular/core'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ssv = global.ssv || {}, global.ssv.ngx = global.ssv.ngx || {}, global.ssv.ngx.command = {}), global.rxjs, global.rxjs.operators, global.ng.core));
|
|
5
|
-
}(this, (function (exports, rxjs, operators, core) { 'use strict';
|
|
6
|
-
|
|
7
|
-
/*! *****************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise */
|
|
22
|
-
var extendStatics = function (d, b) {
|
|
23
|
-
extendStatics = Object.setPrototypeOf ||
|
|
24
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
-
function (d, b) { for (var p in b)
|
|
26
|
-
if (Object.prototype.hasOwnProperty.call(b, p))
|
|
27
|
-
d[p] = b[p]; };
|
|
28
|
-
return extendStatics(d, b);
|
|
29
|
-
};
|
|
30
|
-
function __extends(d, b) {
|
|
31
|
-
extendStatics(d, b);
|
|
32
|
-
function __() { this.constructor = d; }
|
|
33
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
34
|
-
}
|
|
35
|
-
var __assign = function () {
|
|
36
|
-
__assign = Object.assign || function __assign(t) {
|
|
37
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
38
|
-
s = arguments[i];
|
|
39
|
-
for (var p in s)
|
|
40
|
-
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
41
|
-
t[p] = s[p];
|
|
42
|
-
}
|
|
43
|
-
return t;
|
|
44
|
-
};
|
|
45
|
-
return __assign.apply(this, arguments);
|
|
46
|
-
};
|
|
47
|
-
function __rest(s, e) {
|
|
48
|
-
var t = {};
|
|
49
|
-
for (var p in s)
|
|
50
|
-
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
-
t[p] = s[p];
|
|
52
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
-
t[p[i]] = s[p[i]];
|
|
56
|
-
}
|
|
57
|
-
return t;
|
|
58
|
-
}
|
|
59
|
-
function __decorate(decorators, target, key, desc) {
|
|
60
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
61
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
62
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
63
|
-
else
|
|
64
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
65
|
-
if (d = decorators[i])
|
|
66
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
67
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
68
|
-
}
|
|
69
|
-
function __param(paramIndex, decorator) {
|
|
70
|
-
return function (target, key) { decorator(target, key, paramIndex); };
|
|
71
|
-
}
|
|
72
|
-
function __metadata(metadataKey, metadataValue) {
|
|
73
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
74
|
-
return Reflect.metadata(metadataKey, metadataValue);
|
|
75
|
-
}
|
|
76
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
77
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
78
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
79
|
-
function fulfilled(value) { try {
|
|
80
|
-
step(generator.next(value));
|
|
81
|
-
}
|
|
82
|
-
catch (e) {
|
|
83
|
-
reject(e);
|
|
84
|
-
} }
|
|
85
|
-
function rejected(value) { try {
|
|
86
|
-
step(generator["throw"](value));
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
89
|
-
reject(e);
|
|
90
|
-
} }
|
|
91
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
92
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function __generator(thisArg, body) {
|
|
96
|
-
var _ = { label: 0, sent: function () { if (t[0] & 1)
|
|
97
|
-
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
98
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
99
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
100
|
-
function step(op) {
|
|
101
|
-
if (f)
|
|
102
|
-
throw new TypeError("Generator is already executing.");
|
|
103
|
-
while (_)
|
|
104
|
-
try {
|
|
105
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
106
|
-
return t;
|
|
107
|
-
if (y = 0, t)
|
|
108
|
-
op = [op[0] & 2, t.value];
|
|
109
|
-
switch (op[0]) {
|
|
110
|
-
case 0:
|
|
111
|
-
case 1:
|
|
112
|
-
t = op;
|
|
113
|
-
break;
|
|
114
|
-
case 4:
|
|
115
|
-
_.label++;
|
|
116
|
-
return { value: op[1], done: false };
|
|
117
|
-
case 5:
|
|
118
|
-
_.label++;
|
|
119
|
-
y = op[1];
|
|
120
|
-
op = [0];
|
|
121
|
-
continue;
|
|
122
|
-
case 7:
|
|
123
|
-
op = _.ops.pop();
|
|
124
|
-
_.trys.pop();
|
|
125
|
-
continue;
|
|
126
|
-
default:
|
|
127
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
128
|
-
_ = 0;
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
132
|
-
_.label = op[1];
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
136
|
-
_.label = t[1];
|
|
137
|
-
t = op;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
if (t && _.label < t[2]) {
|
|
141
|
-
_.label = t[2];
|
|
142
|
-
_.ops.push(op);
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
if (t[2])
|
|
146
|
-
_.ops.pop();
|
|
147
|
-
_.trys.pop();
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
op = body.call(thisArg, _);
|
|
151
|
-
}
|
|
152
|
-
catch (e) {
|
|
153
|
-
op = [6, e];
|
|
154
|
-
y = 0;
|
|
155
|
-
}
|
|
156
|
-
finally {
|
|
157
|
-
f = t = 0;
|
|
158
|
-
}
|
|
159
|
-
if (op[0] & 5)
|
|
160
|
-
throw op[1];
|
|
161
|
-
return { value: op[0] ? op[1] : void 0, done: true };
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
165
|
-
if (k2 === undefined)
|
|
166
|
-
k2 = k;
|
|
167
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
|
168
|
-
}) : (function (o, m, k, k2) {
|
|
169
|
-
if (k2 === undefined)
|
|
170
|
-
k2 = k;
|
|
171
|
-
o[k2] = m[k];
|
|
172
|
-
});
|
|
173
|
-
function __exportStar(m, o) {
|
|
174
|
-
for (var p in m)
|
|
175
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
|
176
|
-
__createBinding(o, m, p);
|
|
177
|
-
}
|
|
178
|
-
function __values(o) {
|
|
179
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
180
|
-
if (m)
|
|
181
|
-
return m.call(o);
|
|
182
|
-
if (o && typeof o.length === "number")
|
|
183
|
-
return {
|
|
184
|
-
next: function () {
|
|
185
|
-
if (o && i >= o.length)
|
|
186
|
-
o = void 0;
|
|
187
|
-
return { value: o && o[i++], done: !o };
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
191
|
-
}
|
|
192
|
-
function __read(o, n) {
|
|
193
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
194
|
-
if (!m)
|
|
195
|
-
return o;
|
|
196
|
-
var i = m.call(o), r, ar = [], e;
|
|
197
|
-
try {
|
|
198
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
|
199
|
-
ar.push(r.value);
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
e = { error: error };
|
|
203
|
-
}
|
|
204
|
-
finally {
|
|
205
|
-
try {
|
|
206
|
-
if (r && !r.done && (m = i["return"]))
|
|
207
|
-
m.call(i);
|
|
208
|
-
}
|
|
209
|
-
finally {
|
|
210
|
-
if (e)
|
|
211
|
-
throw e.error;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return ar;
|
|
215
|
-
}
|
|
216
|
-
function __spread() {
|
|
217
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
218
|
-
ar = ar.concat(__read(arguments[i]));
|
|
219
|
-
return ar;
|
|
220
|
-
}
|
|
221
|
-
function __spreadArrays() {
|
|
222
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
223
|
-
s += arguments[i].length;
|
|
224
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
225
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
226
|
-
r[k] = a[j];
|
|
227
|
-
return r;
|
|
228
|
-
}
|
|
229
|
-
;
|
|
230
|
-
function __await(v) {
|
|
231
|
-
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
232
|
-
}
|
|
233
|
-
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
234
|
-
if (!Symbol.asyncIterator)
|
|
235
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
236
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
237
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
238
|
-
function verb(n) { if (g[n])
|
|
239
|
-
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
240
|
-
function resume(n, v) { try {
|
|
241
|
-
step(g[n](v));
|
|
242
|
-
}
|
|
243
|
-
catch (e) {
|
|
244
|
-
settle(q[0][3], e);
|
|
245
|
-
} }
|
|
246
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
247
|
-
function fulfill(value) { resume("next", value); }
|
|
248
|
-
function reject(value) { resume("throw", value); }
|
|
249
|
-
function settle(f, v) { if (f(v), q.shift(), q.length)
|
|
250
|
-
resume(q[0][0], q[0][1]); }
|
|
251
|
-
}
|
|
252
|
-
function __asyncDelegator(o) {
|
|
253
|
-
var i, p;
|
|
254
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
255
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
256
|
-
}
|
|
257
|
-
function __asyncValues(o) {
|
|
258
|
-
if (!Symbol.asyncIterator)
|
|
259
|
-
throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
260
|
-
var m = o[Symbol.asyncIterator], i;
|
|
261
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
262
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
263
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
|
264
|
-
}
|
|
265
|
-
function __makeTemplateObject(cooked, raw) {
|
|
266
|
-
if (Object.defineProperty) {
|
|
267
|
-
Object.defineProperty(cooked, "raw", { value: raw });
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
cooked.raw = raw;
|
|
271
|
-
}
|
|
272
|
-
return cooked;
|
|
273
|
-
}
|
|
274
|
-
;
|
|
275
|
-
var __setModuleDefault = Object.create ? (function (o, v) {
|
|
276
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
277
|
-
}) : function (o, v) {
|
|
278
|
-
o["default"] = v;
|
|
279
|
-
};
|
|
280
|
-
function __importStar(mod) {
|
|
281
|
-
if (mod && mod.__esModule)
|
|
282
|
-
return mod;
|
|
283
|
-
var result = {};
|
|
284
|
-
if (mod != null)
|
|
285
|
-
for (var k in mod)
|
|
286
|
-
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
287
|
-
__createBinding(result, mod, k);
|
|
288
|
-
__setModuleDefault(result, mod);
|
|
289
|
-
return result;
|
|
290
|
-
}
|
|
291
|
-
function __importDefault(mod) {
|
|
292
|
-
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
293
|
-
}
|
|
294
|
-
function __classPrivateFieldGet(receiver, privateMap) {
|
|
295
|
-
if (!privateMap.has(receiver)) {
|
|
296
|
-
throw new TypeError("attempted to get private field on non-instance");
|
|
297
|
-
}
|
|
298
|
-
return privateMap.get(receiver);
|
|
299
|
-
}
|
|
300
|
-
function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
301
|
-
if (!privateMap.has(receiver)) {
|
|
302
|
-
throw new TypeError("attempted to set private field on non-instance");
|
|
303
|
-
}
|
|
304
|
-
privateMap.set(receiver, value);
|
|
305
|
-
return value;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Command object used to encapsulate information which is needed to perform an action.
|
|
310
|
-
*/
|
|
311
|
-
var Command = /** @class */ (function () {
|
|
312
|
-
/**
|
|
313
|
-
* Creates an instance of Command.
|
|
314
|
-
*
|
|
315
|
-
* @param execute Execute function to invoke - use `isAsync: true` when `Observable<any>`.
|
|
316
|
-
* @param canExecute Observable which determines whether it can execute or not.
|
|
317
|
-
* @param isAsync Indicates that the execute function is async e.g. Observable.
|
|
318
|
-
*/
|
|
319
|
-
function Command(execute, canExecute$, isAsync) {
|
|
320
|
-
var _this = this;
|
|
321
|
-
/** Determines whether to auto destroy when having 0 subscribers. */
|
|
322
|
-
this.autoDestroy = true;
|
|
323
|
-
this._isExecuting$ = new rxjs.BehaviorSubject(false);
|
|
324
|
-
this._isExecuting = false;
|
|
325
|
-
this._canExecute = true;
|
|
326
|
-
this.executionPipe$ = new rxjs.Subject();
|
|
327
|
-
this.isExecuting$$ = rxjs.Subscription.EMPTY;
|
|
328
|
-
this.canExecute$$ = rxjs.Subscription.EMPTY;
|
|
329
|
-
this.executionPipe$$ = rxjs.Subscription.EMPTY;
|
|
330
|
-
this.subscribersCount = 0;
|
|
331
|
-
if (canExecute$) {
|
|
332
|
-
this.canExecute$ = rxjs.combineLatest([
|
|
333
|
-
this._isExecuting$,
|
|
334
|
-
canExecute$
|
|
335
|
-
]).pipe(operators.map(function (_a) {
|
|
336
|
-
var _b = __read(_a, 2), isExecuting = _b[0], canExecuteResult = _b[1];
|
|
337
|
-
// console.log("[command::combineLatest$] update!", { isExecuting, canExecuteResult });
|
|
338
|
-
_this._isExecuting = isExecuting;
|
|
339
|
-
_this._canExecute = !isExecuting && !!canExecuteResult;
|
|
340
|
-
return _this._canExecute;
|
|
341
|
-
}));
|
|
342
|
-
this.canExecute$$ = this.canExecute$.subscribe();
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
this.canExecute$ = this._isExecuting$.pipe(operators.map(function (x) {
|
|
346
|
-
var canExecute = !x;
|
|
347
|
-
_this._canExecute = canExecute;
|
|
348
|
-
return canExecute;
|
|
349
|
-
}));
|
|
350
|
-
this.isExecuting$$ = this._isExecuting$
|
|
351
|
-
.pipe(operators.tap(function (x) { return _this._isExecuting = x; }))
|
|
352
|
-
.subscribe();
|
|
353
|
-
}
|
|
354
|
-
this.executionPipe$$ = this.buildExecutionPipe(execute, isAsync).subscribe();
|
|
355
|
-
}
|
|
356
|
-
Object.defineProperty(Command.prototype, "isExecuting", {
|
|
357
|
-
/** Determines whether the command is currently executing, as a snapshot value. */
|
|
358
|
-
get: function () {
|
|
359
|
-
return this._isExecuting;
|
|
360
|
-
},
|
|
361
|
-
enumerable: false,
|
|
362
|
-
configurable: true
|
|
363
|
-
});
|
|
364
|
-
Object.defineProperty(Command.prototype, "canExecute", {
|
|
365
|
-
/** Determines whether the command can execute or not, as a snapshot value. */
|
|
366
|
-
get: function () {
|
|
367
|
-
return this._canExecute;
|
|
368
|
-
},
|
|
369
|
-
enumerable: false,
|
|
370
|
-
configurable: true
|
|
371
|
-
});
|
|
372
|
-
Object.defineProperty(Command.prototype, "isExecuting$", {
|
|
373
|
-
/** Determines whether the command is currently executing, as an observable. */
|
|
374
|
-
get: function () {
|
|
375
|
-
return this._isExecuting$.asObservable();
|
|
376
|
-
},
|
|
377
|
-
enumerable: false,
|
|
378
|
-
configurable: true
|
|
379
|
-
});
|
|
380
|
-
/** Execute function to invoke. */
|
|
381
|
-
Command.prototype.execute = function () {
|
|
382
|
-
var args = [];
|
|
383
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
384
|
-
args[_i] = arguments[_i];
|
|
385
|
-
}
|
|
386
|
-
// console.warn("[command::execute]", args);
|
|
387
|
-
this.executionPipe$.next(args);
|
|
388
|
-
};
|
|
389
|
-
/** Disposes all resources held by subscriptions. */
|
|
390
|
-
Command.prototype.destroy = function () {
|
|
391
|
-
// console.warn("[command::destroy]");
|
|
392
|
-
this.executionPipe$$.unsubscribe();
|
|
393
|
-
this.canExecute$$.unsubscribe();
|
|
394
|
-
this.isExecuting$$.unsubscribe();
|
|
395
|
-
};
|
|
396
|
-
Command.prototype.subscribe = function () {
|
|
397
|
-
this.subscribersCount++;
|
|
398
|
-
};
|
|
399
|
-
Command.prototype.unsubscribe = function () {
|
|
400
|
-
this.subscribersCount--;
|
|
401
|
-
// console.log("[command::unsubscribe]", { autoDestroy: this.autoDestroy, subscribersCount: this.subscribersCount });
|
|
402
|
-
if (this.autoDestroy && this.subscribersCount <= 0) {
|
|
403
|
-
this.destroy();
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
Command.prototype.buildExecutionPipe = function (execute, isAsync) {
|
|
407
|
-
var _this = this;
|
|
408
|
-
var pipe$ = this.executionPipe$.pipe(
|
|
409
|
-
// tap(x => console.warn(">>>> executionPipe", this._canExecute)),
|
|
410
|
-
operators.filter(function () { return _this._canExecute; }), operators.tap(function () {
|
|
411
|
-
// console.log("[command::executionPipe$] do#1 - set execute", { args: x });
|
|
412
|
-
_this._isExecuting$.next(true);
|
|
413
|
-
}));
|
|
414
|
-
var execFn = isAsync
|
|
415
|
-
? operators.switchMap(function (args) {
|
|
416
|
-
if (args) {
|
|
417
|
-
return execute.apply(void 0, __spread(args));
|
|
418
|
-
}
|
|
419
|
-
return execute();
|
|
420
|
-
})
|
|
421
|
-
: operators.tap(function (args) {
|
|
422
|
-
if (args) {
|
|
423
|
-
execute.apply(void 0, __spread(args));
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
execute();
|
|
427
|
-
});
|
|
428
|
-
pipe$ = pipe$.pipe(operators.switchMap(function (args) { return rxjs.of(args).pipe(execFn, operators.finalize(function () {
|
|
429
|
-
// console.log("[command::executionPipe$] finalize inner#1 - set idle");
|
|
430
|
-
_this._isExecuting$.next(false);
|
|
431
|
-
}), operators.take(1), operators.catchError(function (error) {
|
|
432
|
-
console.error("Unhandled execute error", error);
|
|
433
|
-
return rxjs.EMPTY;
|
|
434
|
-
})); }), operators.tap(function () {
|
|
435
|
-
// console.log("[command::executionPipe$] tap#2 - set idle");
|
|
436
|
-
_this._isExecuting$.next(false);
|
|
437
|
-
}));
|
|
438
|
-
return pipe$;
|
|
439
|
-
};
|
|
440
|
-
return Command;
|
|
441
|
-
}());
|
|
442
|
-
/**
|
|
443
|
-
* Async Command object used to encapsulate information which is needed to perform an action,
|
|
444
|
-
* which takes an execute function as Observable/Promise.
|
|
445
|
-
*/
|
|
446
|
-
var CommandAsync = /** @class */ (function (_super) {
|
|
447
|
-
__extends(CommandAsync, _super);
|
|
448
|
-
function CommandAsync(execute, canExecute$) {
|
|
449
|
-
return _super.call(this, execute, canExecute$, true) || this;
|
|
450
|
-
}
|
|
451
|
-
return CommandAsync;
|
|
452
|
-
}(Command));
|
|
453
|
-
|
|
454
|
-
var COMMAND_DEFAULT_CONFIG = Object.freeze({
|
|
455
|
-
executingCssClass: "executing",
|
|
456
|
-
handleDisabled: true,
|
|
457
|
-
hasDisabledDelay: false,
|
|
458
|
-
});
|
|
459
|
-
var COMMAND_CONFIG = new core.InjectionToken("command-config");
|
|
460
|
-
|
|
461
|
-
/** Determines whether the arg object is of type `Command`. */
|
|
462
|
-
function isCommand(arg) {
|
|
463
|
-
return arg instanceof Command;
|
|
464
|
-
}
|
|
465
|
-
/** Determines whether the arg object is of type `CommandCreator`. */
|
|
466
|
-
function isCommandCreator(arg) {
|
|
467
|
-
if (arg instanceof Command) {
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
470
|
-
else if (isAssumedType(arg) && arg.execute && arg.host) {
|
|
471
|
-
return true;
|
|
472
|
-
}
|
|
473
|
-
return false;
|
|
474
|
-
}
|
|
475
|
-
/** Get form is valid as an observable. */
|
|
476
|
-
function canExecuteFromNgForm(form, options) {
|
|
477
|
-
var opts = Object.assign({ validity: true, dirty: true }, options);
|
|
478
|
-
return form.statusChanges
|
|
479
|
-
? form.statusChanges.pipe(operators.delay(0), operators.startWith(form.valid), operators.map(function () { return !!(!opts.validity || form.valid) && !!(!opts.dirty || form.dirty); }), operators.distinctUntilChanged())
|
|
480
|
-
: rxjs.of(true);
|
|
481
|
-
}
|
|
482
|
-
function isAssumedType(x) {
|
|
483
|
-
return x !== null && typeof x === "object";
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Controls the state of a component in sync with `Command`.
|
|
488
|
-
*
|
|
489
|
-
* @example
|
|
490
|
-
* ### Most common usage
|
|
491
|
-
* ```html
|
|
492
|
-
* <button [ssvCommand]="saveCmd">Save</button>
|
|
493
|
-
* ```
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
* ### Usage with options
|
|
497
|
-
* ```html
|
|
498
|
-
* <button [ssvCommand]="saveCmd" [ssvCommandOptions]="{executingCssClass: 'in-progress'}">Save</button>
|
|
499
|
-
* ```
|
|
500
|
-
*
|
|
501
|
-
*
|
|
502
|
-
* ### Usage with params
|
|
503
|
-
* This is useful for collections (loops) or using multiple actions with different args.
|
|
504
|
-
* *NOTE: This will share the `isExecuting` when used with multiple controls.*
|
|
505
|
-
*
|
|
506
|
-
* #### With single param
|
|
507
|
-
*
|
|
508
|
-
* ```html
|
|
509
|
-
* <button [ssvCommand]="saveCmd" [ssvCommandParams]="{id: 1}">Save</button>
|
|
510
|
-
* ```
|
|
511
|
-
* *NOTE: if you have only 1 argument as an array, it should be enclosed within an array e.g. `[['apple', 'banana']]`,
|
|
512
|
-
* else it will spread and you will `arg1: "apple", arg2: "banana"`*
|
|
513
|
-
*
|
|
514
|
-
* #### With multi params
|
|
515
|
-
* ```html
|
|
516
|
-
* <button [ssvCommand]="saveCmd" [ssvCommandParams]="[{id: 1}, 'hello', hero]">Save</button>
|
|
517
|
-
* ```
|
|
518
|
-
*
|
|
519
|
-
* ### Usage with Command Creator
|
|
520
|
-
* This is useful for collections (loops) or using multiple actions with different args, whilst not sharing `isExecuting`.
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
* ```html
|
|
524
|
-
* <button [ssvCommand]="{host: this, execute: removeHero$, canExecute: isValid$, params: [hero, 1337, 'xx']}">Save</button>
|
|
525
|
-
* ```
|
|
526
|
-
*
|
|
527
|
-
*/
|
|
528
|
-
var NAME_CAMEL = "ssvCommand";
|
|
529
|
-
// let nextUniqueId = 0;
|
|
530
|
-
var CommandDirective = /** @class */ (function () {
|
|
531
|
-
function CommandDirective(config, renderer, element, cdr) {
|
|
532
|
-
this.config = config;
|
|
533
|
-
this.renderer = renderer;
|
|
534
|
-
this.element = element;
|
|
535
|
-
this.cdr = cdr;
|
|
536
|
-
this._commandOptions = this.config;
|
|
537
|
-
this._destroy$ = new rxjs.Subject();
|
|
538
|
-
}
|
|
539
|
-
Object.defineProperty(CommandDirective.prototype, "commandOptions", {
|
|
540
|
-
get: function () { return this._commandOptions; },
|
|
541
|
-
set: function (value) {
|
|
542
|
-
if (value === this._commandOptions) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
this._commandOptions = Object.assign(Object.assign({}, this.config), value);
|
|
546
|
-
},
|
|
547
|
-
enumerable: false,
|
|
548
|
-
configurable: true
|
|
549
|
-
});
|
|
550
|
-
Object.defineProperty(CommandDirective.prototype, "command", {
|
|
551
|
-
get: function () { return this._command; },
|
|
552
|
-
enumerable: false,
|
|
553
|
-
configurable: true
|
|
554
|
-
});
|
|
555
|
-
CommandDirective.prototype.ngOnInit = function () {
|
|
556
|
-
var _this = this;
|
|
557
|
-
// console.log("[ssvCommand::init]", this.config);
|
|
558
|
-
if (!this.commandOrCreator) {
|
|
559
|
-
throw new Error(NAME_CAMEL + ": [" + NAME_CAMEL + "] should be defined!");
|
|
560
|
-
}
|
|
561
|
-
else if (isCommand(this.commandOrCreator)) {
|
|
562
|
-
this._command = this.commandOrCreator;
|
|
563
|
-
}
|
|
564
|
-
else if (isCommandCreator(this.commandOrCreator)) {
|
|
565
|
-
var isAsync = this.commandOrCreator.isAsync || this.commandOrCreator.isAsync === undefined;
|
|
566
|
-
// todo: find something like this for ivy (or angular10+)
|
|
567
|
-
// const hostComponent = (this.viewContainer as any)._view.component;
|
|
568
|
-
var execFn = this.commandOrCreator.execute.bind(this.commandOrCreator.host);
|
|
569
|
-
this.commandParams = this.commandParams || this.commandOrCreator.params;
|
|
570
|
-
var canExec = this.commandOrCreator.canExecute instanceof Function
|
|
571
|
-
? this.commandOrCreator.canExecute.bind(this.commandOrCreator.host, this.commandParams)()
|
|
572
|
-
: this.commandOrCreator.canExecute;
|
|
573
|
-
// console.log("[ssvCommand::init] command creator", {
|
|
574
|
-
// firstParam: this.commandParams ? this.commandParams[0] : null,
|
|
575
|
-
// params: this.commandParams
|
|
576
|
-
// });
|
|
577
|
-
this._command = new Command(execFn, canExec, isAsync);
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
throw new Error(NAME_CAMEL + ": [" + NAME_CAMEL + "] is not defined properly!");
|
|
581
|
-
}
|
|
582
|
-
this._command.subscribe();
|
|
583
|
-
this._command.canExecute$.pipe(this.commandOptions.hasDisabledDelay
|
|
584
|
-
? operators.delay(1)
|
|
585
|
-
: operators.tap(function () { }), operators.tap(function (x) {
|
|
586
|
-
_this.trySetDisabled(!x);
|
|
587
|
-
// console.log("[ssvCommand::canExecute$]", { canExecute: x });
|
|
588
|
-
_this.cdr.markForCheck();
|
|
589
|
-
}), operators.takeUntil(this._destroy$)).subscribe();
|
|
590
|
-
if (this._command.isExecuting$) {
|
|
591
|
-
this._command.isExecuting$.pipe(operators.tap(function (x) {
|
|
592
|
-
// console.log("[ssvCommand::isExecuting$]", x, this.commandOptions);
|
|
593
|
-
if (x) {
|
|
594
|
-
_this.renderer.addClass(_this.element.nativeElement, _this.commandOptions.executingCssClass);
|
|
595
|
-
}
|
|
596
|
-
else {
|
|
597
|
-
_this.renderer.removeClass(_this.element.nativeElement, _this.commandOptions.executingCssClass);
|
|
598
|
-
}
|
|
599
|
-
}), operators.takeUntil(this._destroy$)).subscribe();
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
CommandDirective.prototype.onClick = function () {
|
|
603
|
-
var _a;
|
|
604
|
-
// console.log("[ssvCommand::onClick]", this.commandParams);
|
|
605
|
-
if (Array.isArray(this.commandParams)) {
|
|
606
|
-
(_a = this._command).execute.apply(_a, __spread(this.commandParams));
|
|
607
|
-
}
|
|
608
|
-
else {
|
|
609
|
-
this._command.execute(this.commandParams);
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
CommandDirective.prototype.ngOnDestroy = function () {
|
|
613
|
-
// console.log("[ssvCommand::destroy]");
|
|
614
|
-
this._destroy$.next();
|
|
615
|
-
this._destroy$.complete();
|
|
616
|
-
if (this._command) {
|
|
617
|
-
this._command.unsubscribe();
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
CommandDirective.prototype.trySetDisabled = function (disabled) {
|
|
621
|
-
if (this.commandOptions.handleDisabled) {
|
|
622
|
-
// console.warn(">>>> disabled", { id: this.id, disabled });
|
|
623
|
-
this.renderer.setProperty(this.element.nativeElement, "disabled", disabled);
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
return CommandDirective;
|
|
627
|
-
}());
|
|
628
|
-
CommandDirective.decorators = [
|
|
629
|
-
{ type: core.Directive, args: [{
|
|
630
|
-
selector: "[" + NAME_CAMEL + "]",
|
|
631
|
-
exportAs: NAME_CAMEL
|
|
632
|
-
},] }
|
|
633
|
-
];
|
|
634
|
-
CommandDirective.ctorParameters = function () { return [
|
|
635
|
-
{ type: undefined, decorators: [{ type: core.Inject, args: [COMMAND_CONFIG,] }] },
|
|
636
|
-
{ type: core.Renderer2 },
|
|
637
|
-
{ type: core.ElementRef },
|
|
638
|
-
{ type: core.ChangeDetectorRef }
|
|
639
|
-
]; };
|
|
640
|
-
CommandDirective.propDecorators = {
|
|
641
|
-
commandOrCreator: [{ type: core.Input, args: [NAME_CAMEL,] }],
|
|
642
|
-
commandOptions: [{ type: core.Input, args: [NAME_CAMEL + "Options",] }],
|
|
643
|
-
commandParams: [{ type: core.Input, args: [NAME_CAMEL + "Params",] }],
|
|
644
|
-
onClick: [{ type: core.HostListener, args: ["click",] }]
|
|
645
|
-
};
|
|
646
|
-
|
|
647
|
-
var NAME_CAMEL$1 = "ssvCommandRef";
|
|
648
|
-
/**
|
|
649
|
-
* Command creator ref, directive which allows creating Command in the template
|
|
650
|
-
* and associate it to a command (in order to share executions).
|
|
651
|
-
* @example
|
|
652
|
-
* ### Most common usage
|
|
653
|
-
* ```html
|
|
654
|
-
* <div #actionCmd="ssvCommandRef" [ssvCommandRef]="{host: this, execute: removeHero$, canExecute: isValid$}">
|
|
655
|
-
* <button [ssvCommand]="actionCmd.command" [ssvCommandParams]="hero">
|
|
656
|
-
* Remove
|
|
657
|
-
* </button>
|
|
658
|
-
* <button [ssvCommand]="actionCmd.command" [ssvCommandParams]="hero">
|
|
659
|
-
* Remove
|
|
660
|
-
* </button>
|
|
661
|
-
* </div>
|
|
662
|
-
* ```
|
|
663
|
-
*
|
|
664
|
-
*/
|
|
665
|
-
var CommandRefDirective = /** @class */ (function () {
|
|
666
|
-
function CommandRefDirective() {
|
|
667
|
-
}
|
|
668
|
-
Object.defineProperty(CommandRefDirective.prototype, "command", {
|
|
669
|
-
get: function () { return this._command; },
|
|
670
|
-
enumerable: false,
|
|
671
|
-
configurable: true
|
|
672
|
-
});
|
|
673
|
-
CommandRefDirective.prototype.ngOnInit = function () {
|
|
674
|
-
if (isCommandCreator(this.commandCreator)) {
|
|
675
|
-
var isAsync = this.commandCreator.isAsync || this.commandCreator.isAsync === undefined;
|
|
676
|
-
var execFn = this.commandCreator.execute.bind(this.commandCreator.host);
|
|
677
|
-
this._command = new Command(execFn, this.commandCreator.canExecute, isAsync);
|
|
678
|
-
}
|
|
679
|
-
else {
|
|
680
|
-
throw new Error(NAME_CAMEL$1 + ": [" + NAME_CAMEL$1 + "] is not defined properly!");
|
|
681
|
-
}
|
|
682
|
-
};
|
|
683
|
-
CommandRefDirective.prototype.ngOnDestroy = function () {
|
|
684
|
-
// console.log("[commandRef::destroy]");
|
|
685
|
-
if (this._command) {
|
|
686
|
-
this._command.destroy();
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
return CommandRefDirective;
|
|
690
|
-
}());
|
|
691
|
-
CommandRefDirective.decorators = [
|
|
692
|
-
{ type: core.Directive, args: [{
|
|
693
|
-
selector: "[" + NAME_CAMEL$1 + "]",
|
|
694
|
-
exportAs: NAME_CAMEL$1
|
|
695
|
-
},] }
|
|
696
|
-
];
|
|
697
|
-
CommandRefDirective.propDecorators = {
|
|
698
|
-
commandCreator: [{ type: core.Input, args: [NAME_CAMEL$1,] }]
|
|
699
|
-
};
|
|
700
|
-
|
|
701
|
-
/** @internal */
|
|
702
|
-
var MODULE_CONFIG_DATA = new core.InjectionToken("@ssv/ngx.command/configData");
|
|
703
|
-
var components = [
|
|
704
|
-
CommandDirective,
|
|
705
|
-
CommandRefDirective
|
|
706
|
-
];
|
|
707
|
-
var SsvCommandModule = /** @class */ (function () {
|
|
708
|
-
function SsvCommandModule() {
|
|
709
|
-
}
|
|
710
|
-
SsvCommandModule.forRoot = function (config) {
|
|
711
|
-
return {
|
|
712
|
-
ngModule: SsvCommandModule,
|
|
713
|
-
providers: [
|
|
714
|
-
{ provide: MODULE_CONFIG_DATA, useValue: config },
|
|
715
|
-
],
|
|
716
|
-
};
|
|
717
|
-
};
|
|
718
|
-
return SsvCommandModule;
|
|
719
|
-
}());
|
|
720
|
-
SsvCommandModule.decorators = [
|
|
721
|
-
{ type: core.NgModule, args: [{
|
|
722
|
-
declarations: components,
|
|
723
|
-
providers: [
|
|
724
|
-
{ provide: COMMAND_CONFIG, useFactory: _moduleConfigFactory, deps: [[MODULE_CONFIG_DATA, new core.Optional()]] },
|
|
725
|
-
],
|
|
726
|
-
exports: __spread(components),
|
|
727
|
-
},] }
|
|
728
|
-
];
|
|
729
|
-
/** @internal */
|
|
730
|
-
function _moduleConfigFactory(config) {
|
|
731
|
-
var cfg = typeof config === "function" ? config() : config;
|
|
732
|
-
return cfg
|
|
733
|
-
? Object.assign(Object.assign({}, COMMAND_DEFAULT_CONFIG), cfg) : COMMAND_DEFAULT_CONFIG;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
var VERSION = "2.2.0";
|
|
737
|
-
|
|
738
|
-
/**
|
|
739
|
-
* Generated bundle index. Do not edit.
|
|
740
|
-
*/
|
|
741
|
-
|
|
742
|
-
exports.COMMAND_CONFIG = COMMAND_CONFIG;
|
|
743
|
-
exports.COMMAND_DEFAULT_CONFIG = COMMAND_DEFAULT_CONFIG;
|
|
744
|
-
exports.Command = Command;
|
|
745
|
-
exports.CommandAsync = CommandAsync;
|
|
746
|
-
exports.CommandDirective = CommandDirective;
|
|
747
|
-
exports.CommandRefDirective = CommandRefDirective;
|
|
748
|
-
exports.MODULE_CONFIG_DATA = MODULE_CONFIG_DATA;
|
|
749
|
-
exports.SsvCommandModule = SsvCommandModule;
|
|
750
|
-
exports.VERSION = VERSION;
|
|
751
|
-
exports._moduleConfigFactory = _moduleConfigFactory;
|
|
752
|
-
exports.canExecuteFromNgForm = canExecuteFromNgForm;
|
|
753
|
-
exports.isCommand = isCommand;
|
|
754
|
-
exports.isCommandCreator = isCommandCreator;
|
|
755
|
-
|
|
756
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
757
|
-
|
|
758
|
-
})));
|
|
759
|
-
//# sourceMappingURL=ssv-ngx.command.umd.js.map
|