@ssv/ngx.command 3.0.0-dev.36 → 3.0.0-dev.38
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/command-ref.directive.d.ts +29 -0
- package/command.d.ts +59 -0
- package/command.directive.d.ts +24 -0
- package/command.model.d.ts +28 -0
- package/command.module.d.ts +8 -0
- package/command.options.d.ts +18 -0
- package/command.util.d.ts +15 -0
- package/esm2022/command-ref.directive.mjs +57 -0
- package/esm2022/command.directive.mjs +165 -0
- package/esm2022/command.mjs +149 -0
- package/esm2022/command.model.mjs +2 -0
- package/esm2022/command.module.mjs +23 -0
- package/esm2022/command.options.mjs +27 -0
- package/esm2022/command.util.mjs +28 -0
- package/esm2022/index.mjs +8 -0
- package/esm2022/ssv-ngx.command.mjs +5 -0
- package/esm2022/version.mjs +2 -0
- package/fesm2022/ssv-ngx.command.mjs +442 -0
- package/fesm2022/ssv-ngx.command.mjs.map +1 -0
- package/package.json +18 -3
- package/version.d.ts +1 -0
- package/eslint.config.js +0 -43
- package/index.ts +0 -1
- package/jest.config.ts +0 -21
- package/ng-package.json +0 -7
- package/project.json +0 -36
- package/src/command-ref.directive.ts +0 -57
- package/src/command.directive.ts +0 -190
- package/src/command.directive.xspec.ts +0 -105
- package/src/command.model.ts +0 -39
- package/src/command.module.ts +0 -17
- package/src/command.options.ts +0 -49
- package/src/command.spec.ts +0 -215
- package/src/command.ts +0 -208
- package/src/command.util.ts +0 -49
- package/src/test-setup.ts +0 -8
- package/src/version.ts +0 -1
- package/tsconfig.json +0 -28
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -9
- package/tsconfig.spec.json +0 -16
- /package/{src/index.ts → index.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssv/ngx.command",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.38",
|
|
4
4
|
"versionSuffix": "",
|
|
5
5
|
"description": "Command pattern implementation for angular. Command used to encapsulate information which is needed to perform an action.",
|
|
6
6
|
"keywords": [
|
|
@@ -19,11 +19,26 @@
|
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/sketch7/ssv.ngx.git"
|
|
21
21
|
},
|
|
22
|
-
"dependencies": {
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"tslib": "^2.3.0"
|
|
24
|
+
},
|
|
23
25
|
"peerDependencies": {
|
|
24
26
|
"@angular/core": ">=17.0.0",
|
|
25
27
|
"@angular/forms": ">=17.0.0",
|
|
26
28
|
"rxjs": ">=6.0.0"
|
|
27
29
|
},
|
|
28
|
-
"sideEffects": false
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"module": "fesm2022/ssv-ngx.command.mjs",
|
|
32
|
+
"typings": "index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
"./package.json": {
|
|
35
|
+
"default": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./index.d.ts",
|
|
39
|
+
"esm2022": "./esm2022/ssv-ngx.command.mjs",
|
|
40
|
+
"esm": "./esm2022/ssv-ngx.command.mjs",
|
|
41
|
+
"default": "./fesm2022/ssv-ngx.command.mjs"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
29
44
|
}
|
package/version.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "3.0.0-dev.38";
|
package/eslint.config.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const nx = require("@nx/eslint-plugin");
|
|
2
|
-
const baseConfig = require("../../eslint.config.js");
|
|
3
|
-
|
|
4
|
-
module.exports = [
|
|
5
|
-
...baseConfig,
|
|
6
|
-
{
|
|
7
|
-
files: ["**/*.json"],
|
|
8
|
-
rules: {
|
|
9
|
-
"@nx/dependency-checks": ["error", { ignoredFiles: ["{projectRoot}/eslint.config.{js,cjs,mjs}"] }],
|
|
10
|
-
},
|
|
11
|
-
languageOptions: { parser: require("jsonc-eslint-parser") },
|
|
12
|
-
},
|
|
13
|
-
...nx.configs["flat/angular"],
|
|
14
|
-
...nx.configs["flat/angular-template"],
|
|
15
|
-
{
|
|
16
|
-
files: ["**/*.ts"],
|
|
17
|
-
rules: {
|
|
18
|
-
"@angular-eslint/directive-selector": [
|
|
19
|
-
"error",
|
|
20
|
-
{
|
|
21
|
-
type: "attribute",
|
|
22
|
-
prefix: "ssv",
|
|
23
|
-
style: "camelCase",
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
"@angular-eslint/component-selector": [
|
|
27
|
-
"error",
|
|
28
|
-
{
|
|
29
|
-
type: "element",
|
|
30
|
-
prefix: "ssv",
|
|
31
|
-
style: "kebab-case",
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
"@angular-eslint/directive-selector": "off",
|
|
35
|
-
"@angular-eslint/no-input-rename": "off",
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
files: ["**/*.html"],
|
|
40
|
-
// Override or add rules here
|
|
41
|
-
rules: {},
|
|
42
|
-
},
|
|
43
|
-
];
|
package/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/jest.config.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: "@ssv/ngx.command",
|
|
3
|
-
preset: "../../jest.preset.js",
|
|
4
|
-
setupFilesAfterEnv: ["<rootDir>/src/test-setup.ts"],
|
|
5
|
-
coverageDirectory: "../../coverage/libs/ngx.command",
|
|
6
|
-
transform: {
|
|
7
|
-
"^.+\\.(ts|mjs|js|html)$": [
|
|
8
|
-
"jest-preset-angular",
|
|
9
|
-
{
|
|
10
|
-
tsconfig: "<rootDir>/tsconfig.spec.json",
|
|
11
|
-
stringifyContentPathRegex: "\\.(html|svg)$",
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
},
|
|
15
|
-
transformIgnorePatterns: ["node_modules/(?!.*\\.mjs$)"],
|
|
16
|
-
snapshotSerializers: [
|
|
17
|
-
"jest-preset-angular/build/serializers/no-ng-attributes",
|
|
18
|
-
"jest-preset-angular/build/serializers/ng-snapshot",
|
|
19
|
-
"jest-preset-angular/build/serializers/html-comment",
|
|
20
|
-
],
|
|
21
|
-
};
|
package/ng-package.json
DELETED
package/project.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@ssv/ngx.command",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/ngx.command/src",
|
|
5
|
-
"prefix": "ssv",
|
|
6
|
-
"projectType": "library",
|
|
7
|
-
"tags": [],
|
|
8
|
-
"targets": {
|
|
9
|
-
"build": {
|
|
10
|
-
"executor": "@nx/angular:package",
|
|
11
|
-
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
|
|
12
|
-
"options": {
|
|
13
|
-
"project": "libs/ngx.command/ng-package.json"
|
|
14
|
-
},
|
|
15
|
-
"configurations": {
|
|
16
|
-
"production": {
|
|
17
|
-
"tsConfig": "libs/ngx.command/tsconfig.lib.prod.json"
|
|
18
|
-
},
|
|
19
|
-
"development": {
|
|
20
|
-
"tsConfig": "libs/ngx.command/tsconfig.lib.json"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"defaultConfiguration": "production"
|
|
24
|
-
},
|
|
25
|
-
"test": {
|
|
26
|
-
"executor": "@nx/jest:jest",
|
|
27
|
-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
28
|
-
"options": {
|
|
29
|
-
"jestConfig": "libs/ngx.command/jest.config.ts"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"lint": {
|
|
33
|
-
"executor": "@nx/eslint:lint"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
import { Directive, OnInit, OnDestroy, Input } from "@angular/core";
|
|
3
|
-
|
|
4
|
-
import { ICommand, CommandCreator } from "./command.model";
|
|
5
|
-
import { isCommandCreator } from "./command.util";
|
|
6
|
-
import { Command } from "./command";
|
|
7
|
-
|
|
8
|
-
const NAME_CAMEL = "ssvCommandRef";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Command creator ref, directive which allows creating Command in the template
|
|
12
|
-
* and associate it to a command (in order to share executions).
|
|
13
|
-
* @example
|
|
14
|
-
* ### Most common usage
|
|
15
|
-
* ```html
|
|
16
|
-
* <div #actionCmd="ssvCommandRef" [ssvCommandRef]="{host: this, execute: removeHero$, canExecute: isValid$}">
|
|
17
|
-
* <button [ssvCommand]="actionCmd.command" [ssvCommandParams]="hero">
|
|
18
|
-
* Remove
|
|
19
|
-
* </button>
|
|
20
|
-
* <button [ssvCommand]="actionCmd.command" [ssvCommandParams]="hero">
|
|
21
|
-
* Remove
|
|
22
|
-
* </button>
|
|
23
|
-
* </div>
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
@Directive({
|
|
28
|
-
selector: `[${NAME_CAMEL}]`,
|
|
29
|
-
exportAs: NAME_CAMEL,
|
|
30
|
-
standalone: true,
|
|
31
|
-
})
|
|
32
|
-
export class CommandRefDirective implements OnInit, OnDestroy {
|
|
33
|
-
|
|
34
|
-
@Input(NAME_CAMEL) commandCreator: CommandCreator | undefined;
|
|
35
|
-
|
|
36
|
-
get command(): ICommand { return this._command; }
|
|
37
|
-
private _command!: ICommand;
|
|
38
|
-
|
|
39
|
-
ngOnInit(): void {
|
|
40
|
-
if (isCommandCreator(this.commandCreator)) {
|
|
41
|
-
const isAsync = this.commandCreator.isAsync || this.commandCreator.isAsync === undefined;
|
|
42
|
-
|
|
43
|
-
const execFn = this.commandCreator.execute.bind(this.commandCreator.host);
|
|
44
|
-
this._command = new Command(execFn, this.commandCreator.canExecute as Observable<boolean> | undefined, isAsync);
|
|
45
|
-
} else {
|
|
46
|
-
throw new Error(`${NAME_CAMEL}: [${NAME_CAMEL}] is not defined properly!`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
ngOnDestroy(): void {
|
|
51
|
-
// console.log("[commandRef::destroy]");
|
|
52
|
-
if (this._command) {
|
|
53
|
-
this._command.destroy();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
package/src/command.directive.ts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Directive,
|
|
3
|
-
OnInit,
|
|
4
|
-
OnDestroy,
|
|
5
|
-
Input,
|
|
6
|
-
HostListener,
|
|
7
|
-
ElementRef,
|
|
8
|
-
Renderer2,
|
|
9
|
-
ChangeDetectorRef,
|
|
10
|
-
inject,
|
|
11
|
-
} from "@angular/core";
|
|
12
|
-
import { Subject, tap, delay, takeUntil } from "rxjs";
|
|
13
|
-
|
|
14
|
-
import { type CommandOptions, COMMAND_OPTIONS } from "./command.options";
|
|
15
|
-
import { Command } from "./command";
|
|
16
|
-
import { isCommand, isCommandCreator } from "./command.util";
|
|
17
|
-
import { CommandCreator, type ICommand } from "./command.model";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Controls the state of a component in sync with `Command`.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ### Most common usage
|
|
24
|
-
* ```html
|
|
25
|
-
* <button [ssvCommand]="saveCmd">Save</button>
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* ### Usage with options
|
|
30
|
-
* ```html
|
|
31
|
-
* <button [ssvCommand]="saveCmd" [ssvCommandOptions]="{executingCssClass: 'in-progress'}">Save</button>
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* ### Usage with params
|
|
36
|
-
* This is useful for collections (loops) or using multiple actions with different args.
|
|
37
|
-
* *NOTE: This will share the `isExecuting` when used with multiple controls.*
|
|
38
|
-
*
|
|
39
|
-
* #### With single param
|
|
40
|
-
*
|
|
41
|
-
* ```html
|
|
42
|
-
* <button [ssvCommand]="saveCmd" [ssvCommandParams]="{id: 1}">Save</button>
|
|
43
|
-
* ```
|
|
44
|
-
* *NOTE: if you have only 1 argument as an array, it should be enclosed within an array e.g. `[['apple', 'banana']]`,
|
|
45
|
-
* else it will spread and you will `arg1: "apple", arg2: "banana"`*
|
|
46
|
-
*
|
|
47
|
-
* #### With multi params
|
|
48
|
-
* ```html
|
|
49
|
-
* <button [ssvCommand]="saveCmd" [ssvCommandParams]="[{id: 1}, 'hello', hero]">Save</button>
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* ### Usage with Command Creator
|
|
53
|
-
* This is useful for collections (loops) or using multiple actions with different args, whilst not sharing `isExecuting`.
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* ```html
|
|
57
|
-
* <button [ssvCommand]="{host: this, execute: removeHero$, canExecute: isValid$, params: [hero, 1337, 'xx']}">Save</button>
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
const NAME_CAMEL = "ssvCommand";
|
|
63
|
-
|
|
64
|
-
// let nextUniqueId = 0;
|
|
65
|
-
|
|
66
|
-
@Directive({
|
|
67
|
-
selector: `[${NAME_CAMEL}]`,
|
|
68
|
-
exportAs: NAME_CAMEL,
|
|
69
|
-
standalone: true,
|
|
70
|
-
})
|
|
71
|
-
export class CommandDirective implements OnInit, OnDestroy {
|
|
72
|
-
|
|
73
|
-
// readonly id = `${NAME_CAMEL}-${nextUniqueId++}`;
|
|
74
|
-
private readonly globalOptions = inject(COMMAND_OPTIONS);
|
|
75
|
-
private readonly renderer = inject(Renderer2);
|
|
76
|
-
private readonly element = inject(ElementRef);
|
|
77
|
-
private readonly cdr = inject(ChangeDetectorRef);
|
|
78
|
-
|
|
79
|
-
@Input(NAME_CAMEL) commandOrCreator: ICommand | CommandCreator | undefined;
|
|
80
|
-
|
|
81
|
-
@Input(`${NAME_CAMEL}Options`)
|
|
82
|
-
get commandOptions(): CommandOptions { return this._commandOptions; }
|
|
83
|
-
set commandOptions(value: Partial<CommandOptions>) {
|
|
84
|
-
if (value === this._commandOptions) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
this._commandOptions = {
|
|
88
|
-
...this.globalOptions,
|
|
89
|
-
...value,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
@Input(`${NAME_CAMEL}Params`) commandParams: unknown | unknown[];
|
|
94
|
-
|
|
95
|
-
get command(): ICommand { return this._command; }
|
|
96
|
-
|
|
97
|
-
private _command!: ICommand;
|
|
98
|
-
private _commandOptions: CommandOptions = this.globalOptions;
|
|
99
|
-
private _destroy$ = new Subject<void>();
|
|
100
|
-
|
|
101
|
-
ngOnInit(): void {
|
|
102
|
-
// console.log("[ssvCommand::init]", this.globalOptions);
|
|
103
|
-
if (!this.commandOrCreator) {
|
|
104
|
-
throw new Error(`${NAME_CAMEL}: [${NAME_CAMEL}] should be defined!`);
|
|
105
|
-
} else if (isCommand(this.commandOrCreator)) {
|
|
106
|
-
this._command = this.commandOrCreator;
|
|
107
|
-
} else if (isCommandCreator(this.commandOrCreator)) {
|
|
108
|
-
const isAsync = this.commandOrCreator.isAsync || this.commandOrCreator.isAsync === undefined;
|
|
109
|
-
|
|
110
|
-
// todo: find something like this for ivy (or angular10+)
|
|
111
|
-
// const hostComponent = (this.viewContainer as any)._view.component;
|
|
112
|
-
|
|
113
|
-
const execFn = this.commandOrCreator.execute.bind(this.commandOrCreator.host);
|
|
114
|
-
this.commandParams = this.commandParams || this.commandOrCreator.params;
|
|
115
|
-
|
|
116
|
-
const canExec = this.commandOrCreator.canExecute instanceof Function
|
|
117
|
-
? this.commandOrCreator.canExecute.bind(this.commandOrCreator.host, this.commandParams)()
|
|
118
|
-
: this.commandOrCreator.canExecute;
|
|
119
|
-
|
|
120
|
-
// console.log("[ssvCommand::init] command creator", {
|
|
121
|
-
// firstParam: this.commandParams ? this.commandParams[0] : null,
|
|
122
|
-
// params: this.commandParams
|
|
123
|
-
// });
|
|
124
|
-
this._command = new Command(execFn, canExec, isAsync);
|
|
125
|
-
} else {
|
|
126
|
-
throw new Error(`${NAME_CAMEL}: [${NAME_CAMEL}] is not defined properly!`);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
this._command.subscribe();
|
|
130
|
-
this._command.canExecute$.pipe(
|
|
131
|
-
this.commandOptions.hasDisabledDelay
|
|
132
|
-
? delay(1)
|
|
133
|
-
: tap(() => { /* stub */ }),
|
|
134
|
-
tap(x => {
|
|
135
|
-
this.trySetDisabled(!x);
|
|
136
|
-
// console.log("[ssvCommand::canExecute$]", { canExecute: x });
|
|
137
|
-
this.cdr.markForCheck();
|
|
138
|
-
}),
|
|
139
|
-
takeUntil(this._destroy$),
|
|
140
|
-
).subscribe();
|
|
141
|
-
|
|
142
|
-
if (this._command.isExecuting$) {
|
|
143
|
-
this._command.isExecuting$.pipe(
|
|
144
|
-
tap(x => {
|
|
145
|
-
// console.log("[ssvCommand::isExecuting$]", x, this.commandOptions);
|
|
146
|
-
if (x) {
|
|
147
|
-
this.renderer.addClass(
|
|
148
|
-
this.element.nativeElement,
|
|
149
|
-
this.commandOptions.executingCssClass
|
|
150
|
-
);
|
|
151
|
-
} else {
|
|
152
|
-
this.renderer.removeClass(
|
|
153
|
-
this.element.nativeElement,
|
|
154
|
-
this.commandOptions.executingCssClass
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}),
|
|
158
|
-
takeUntil(this._destroy$),
|
|
159
|
-
).subscribe();
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
@HostListener("click")
|
|
164
|
-
onClick(): void {
|
|
165
|
-
// console.log("[ssvCommand::onClick]", this.commandParams);
|
|
166
|
-
if (Array.isArray(this.commandParams)) {
|
|
167
|
-
this._command.execute(...this.commandParams);
|
|
168
|
-
} else {
|
|
169
|
-
this._command.execute(this.commandParams);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
ngOnDestroy(): void {
|
|
174
|
-
// console.log("[ssvCommand::destroy]");
|
|
175
|
-
this._destroy$.next();
|
|
176
|
-
this._destroy$.complete();
|
|
177
|
-
if (this._command) {
|
|
178
|
-
this._command.unsubscribe();
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
private trySetDisabled(disabled: boolean) {
|
|
183
|
-
if (this.commandOptions.handleDisabled) {
|
|
184
|
-
// console.warn(">>>> disabled", { id: this.id, disabled });
|
|
185
|
-
this.renderer.setProperty(this.element.nativeElement, "disabled", disabled);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// import {Observable} from "rxjs/Observable";
|
|
2
|
-
// import {inject, addProviders, async} from "@angular/core/testing";
|
|
3
|
-
// import {TestComponentBuilder, ComponentFixture} from "@angular/compiler/testing";
|
|
4
|
-
// import {Component, provide} from "@angular/core";
|
|
5
|
-
|
|
6
|
-
// import {Command, ICommand, CommandDirective} from "./index";
|
|
7
|
-
|
|
8
|
-
// @Component({
|
|
9
|
-
// template: `<button class="btn" [ssvCommand]="saveCmd" >Save</button>`,
|
|
10
|
-
// directives: [
|
|
11
|
-
// CommandDirective
|
|
12
|
-
// ]
|
|
13
|
-
// })
|
|
14
|
-
// class TestContainer {
|
|
15
|
-
// saveCmd = new Command(() => Observable.of("yey").delay(2000), null, true);
|
|
16
|
-
// }
|
|
17
|
-
|
|
18
|
-
// @Component({
|
|
19
|
-
// template: `<button class="btn" [ssvCommand]="emptyCmd" >Save</button>`,
|
|
20
|
-
// directives: [
|
|
21
|
-
// CommandDirective
|
|
22
|
-
// ]
|
|
23
|
-
// })
|
|
24
|
-
// class NullCommandTestContainer {
|
|
25
|
-
|
|
26
|
-
// }
|
|
27
|
-
|
|
28
|
-
// describe("CommandDirectiveSpecs", () => {
|
|
29
|
-
|
|
30
|
-
// let testComponentBuilder: TestComponentBuilder;
|
|
31
|
-
|
|
32
|
-
// beforeEach(inject([
|
|
33
|
-
// TestComponentBuilder
|
|
34
|
-
// ], (
|
|
35
|
-
// _testComponentBuilder: TestComponentBuilder
|
|
36
|
-
// ) => {
|
|
37
|
-
// testComponentBuilder = _testComponentBuilder;
|
|
38
|
-
// })
|
|
39
|
-
// );
|
|
40
|
-
|
|
41
|
-
// describe("given an undefined command", () => {
|
|
42
|
-
// xit("should throw error", async(() => {
|
|
43
|
-
// testComponentBuilder
|
|
44
|
-
// .createAsync(NullCommandTestContainer)
|
|
45
|
-
// .then((fixture: ComponentFixture<NullCommandTestContainer>) => {
|
|
46
|
-
// expect(() => {
|
|
47
|
-
// fixture.detectChanges();
|
|
48
|
-
// }).toThrowError("[commandDirective] command should be defined!");
|
|
49
|
-
// });
|
|
50
|
-
|
|
51
|
-
// }));
|
|
52
|
-
// });
|
|
53
|
-
|
|
54
|
-
// describe("given command isExecuting is set to true", () => {
|
|
55
|
-
// xit("should have element disabled", async(() => {
|
|
56
|
-
// testComponentBuilder
|
|
57
|
-
// .createAsync(TestContainer)
|
|
58
|
-
// .then((fixture: ComponentFixture<TestContainer>) => {
|
|
59
|
-
// fixture.detectChanges();
|
|
60
|
-
// let container = fixture.componentInstance as TestContainer;
|
|
61
|
-
// let element = fixture.debugElement.nativeElement.querySelector("button");
|
|
62
|
-
// element.click();
|
|
63
|
-
// fixture.detectChanges();
|
|
64
|
-
// expect(element).toBeDisabled();
|
|
65
|
-
// });
|
|
66
|
-
// }));
|
|
67
|
-
|
|
68
|
-
// xit("should have executingCssClass added", () => {
|
|
69
|
-
|
|
70
|
-
// });
|
|
71
|
-
|
|
72
|
-
// xdescribe("when isExecuting has been finished", () => {
|
|
73
|
-
// xit("should have element enabled", () => {
|
|
74
|
-
|
|
75
|
-
// });
|
|
76
|
-
|
|
77
|
-
// xit("should have executingCssClass removed", () => {
|
|
78
|
-
|
|
79
|
-
// });
|
|
80
|
-
// });
|
|
81
|
-
// });
|
|
82
|
-
|
|
83
|
-
// xdescribe("given command canExecute is set to true", () => {
|
|
84
|
-
// xit("should have element enabled", () => {
|
|
85
|
-
|
|
86
|
-
// });
|
|
87
|
-
// });
|
|
88
|
-
|
|
89
|
-
// xdescribe("given command canExecute is set to false", () => {
|
|
90
|
-
// xit("should have element disabled", () => {
|
|
91
|
-
|
|
92
|
-
// });
|
|
93
|
-
// });
|
|
94
|
-
|
|
95
|
-
// xdescribe("given commandOptions are provided", () => {
|
|
96
|
-
// xdescribe("when isExecuting is set true", () => {
|
|
97
|
-
// xit("should have executingCssClass added with the provided option", () => {
|
|
98
|
-
|
|
99
|
-
// });
|
|
100
|
-
// });
|
|
101
|
-
|
|
102
|
-
// });
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// });
|
package/src/command.model.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
|
|
3
|
-
export interface ICommand {
|
|
4
|
-
/** Determines whether the command is currently executing, as a snapshot value. */
|
|
5
|
-
readonly isExecuting: boolean;
|
|
6
|
-
/** Determines whether the command is currently executing, as an observable. */
|
|
7
|
-
readonly isExecuting$: Observable<boolean>;
|
|
8
|
-
/** Determines whether the command can execute or not, as a snapshot value. */
|
|
9
|
-
readonly canExecute: boolean;
|
|
10
|
-
/** Determines whether the command can execute or not, as an observable. */
|
|
11
|
-
readonly canExecute$: Observable<boolean>;
|
|
12
|
-
|
|
13
|
-
/** Determines whether to auto destroy when having 0 subscribers (defaults to `true`). */
|
|
14
|
-
autoDestroy: boolean;
|
|
15
|
-
|
|
16
|
-
/** Execute function to invoke. */
|
|
17
|
-
execute(...args: unknown[]): void;
|
|
18
|
-
|
|
19
|
-
/** Disposes all resources held by subscriptions. */
|
|
20
|
-
destroy(): void;
|
|
21
|
-
|
|
22
|
-
/** Subscribe listener, in order to handle auto disposing. */
|
|
23
|
-
subscribe(): void;
|
|
24
|
-
|
|
25
|
-
/** Unsubscribe listener, in order to handle auto disposing. */
|
|
26
|
-
unsubscribe(): void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface CommandCreator {
|
|
30
|
-
// todo: stricter typing
|
|
31
|
-
// execute: (...args: TParams extends unknown[] ? TParams : [TParams]) => Observable<unknown> | Promise<unknown> | void;
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
execute: (...args: any[]) => Observable<unknown> | Promise<unknown> | void;
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
35
|
-
canExecute?: Observable<boolean> | Function;
|
|
36
|
-
params?: unknown | unknown[];
|
|
37
|
-
isAsync?: boolean;
|
|
38
|
-
host: unknown;
|
|
39
|
-
}
|
package/src/command.module.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { NgModule } from "@angular/core";
|
|
2
|
-
|
|
3
|
-
import { CommandDirective } from "./command.directive";
|
|
4
|
-
import { CommandRefDirective } from "./command-ref.directive";
|
|
5
|
-
|
|
6
|
-
const EXPORTED_IMPORTS = [
|
|
7
|
-
CommandDirective,
|
|
8
|
-
CommandRefDirective
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
@NgModule({
|
|
12
|
-
imports: [EXPORTED_IMPORTS],
|
|
13
|
-
exports: [EXPORTED_IMPORTS]
|
|
14
|
-
})
|
|
15
|
-
export class SsvCommandModule {
|
|
16
|
-
|
|
17
|
-
}
|
package/src/command.options.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { type EnvironmentProviders, InjectionToken, makeEnvironmentProviders } from "@angular/core";
|
|
2
|
-
|
|
3
|
-
export interface CommandOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Css Class which gets added/removed on the Command element's host while Command `isExecuting$`.
|
|
6
|
-
*/
|
|
7
|
-
executingCssClass: string;
|
|
8
|
-
|
|
9
|
-
/** Determines whether the disabled will be handled by the directive or not.
|
|
10
|
-
* Disable handled by directive's doesn't always play nice when used with other component/pipe/directive and they also handle disabled.
|
|
11
|
-
* This disables the handling manually and need to pass explicitly `[disabled]="!saveCmd.canExecute"`.
|
|
12
|
-
*/
|
|
13
|
-
handleDisabled: boolean;
|
|
14
|
-
|
|
15
|
-
/** Determine whether to set a `delay(1)` when setting the disabled. Which might be needed when working with external
|
|
16
|
-
* components/directives (such as material button)
|
|
17
|
-
*/
|
|
18
|
-
hasDisabledDelay: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const DEFAULT_OPTIONS = Object.freeze<CommandOptions>({
|
|
22
|
-
executingCssClass: "executing",
|
|
23
|
-
handleDisabled: true,
|
|
24
|
-
hasDisabledDelay: false,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
export const COMMAND_OPTIONS = new InjectionToken<CommandOptions>("SSV_COMMAND_OPTIONS", {
|
|
28
|
-
factory: () => DEFAULT_OPTIONS,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export function provideSsvCommandOptions(
|
|
32
|
-
options: Partial<CommandOptions> | ((defaults: Readonly<CommandOptions>) => Partial<CommandOptions>)
|
|
33
|
-
): EnvironmentProviders {
|
|
34
|
-
return makeEnvironmentProviders([
|
|
35
|
-
{
|
|
36
|
-
provide: COMMAND_OPTIONS,
|
|
37
|
-
useFactory: () => {
|
|
38
|
-
let opts = typeof options === "function" ? options(DEFAULT_OPTIONS) : options;
|
|
39
|
-
opts = opts
|
|
40
|
-
? {
|
|
41
|
-
...DEFAULT_OPTIONS,
|
|
42
|
-
...opts,
|
|
43
|
-
}
|
|
44
|
-
: DEFAULT_OPTIONS;
|
|
45
|
-
return opts;
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
]);
|
|
49
|
-
}
|