@ngrdt/core 0.0.2 → 0.0.4
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/esm2022/index.mjs +4 -0
- package/esm2022/lib/rdt-autofocus/index.mjs +4 -0
- package/esm2022/lib/rdt-autofocus/models.mjs +3 -0
- package/esm2022/lib/rdt-autofocus/rdt-autofocusable.directive.mjs +27 -0
- package/esm2022/lib/rdt-autofocus/utils.mjs +9 -0
- package/esm2022/lib/rdt-component-guard/directives/rdt-child.directive.mjs +88 -0
- package/esm2022/lib/rdt-component-guard/directives/rdt-container.directive.mjs +95 -0
- package/esm2022/lib/rdt-component-guard/index.mjs +5 -0
- package/esm2022/lib/rdt-component-guard/models.mjs +25 -0
- package/esm2022/lib/rdt-component-guard/services/rdt-component-guard-store.service.mjs +36 -0
- package/esm2022/lib/utils/index.mjs +2 -0
- package/esm2022/lib/utils/rdt-boolean-result.mjs +25 -0
- package/esm2022/ngrdt-core.mjs +5 -0
- package/fesm2022/ngrdt-core.mjs +299 -0
- package/fesm2022/ngrdt-core.mjs.map +1 -0
- package/lib/rdt-autofocus/models.d.ts +8 -0
- package/lib/rdt-autofocus/rdt-autofocusable.directive.d.ts +8 -0
- package/lib/rdt-autofocus/utils.d.ts +3 -0
- package/lib/rdt-component-guard/directives/rdt-child.directive.d.ts +22 -0
- package/lib/rdt-component-guard/directives/rdt-container.directive.d.ts +18 -0
- package/{src/lib/rdt-component-guard/index.ts → lib/rdt-component-guard/index.d.ts} +1 -0
- package/lib/rdt-component-guard/models.d.ts +22 -0
- package/lib/rdt-component-guard/services/rdt-component-guard-store.service.d.ts +11 -0
- package/lib/utils/rdt-boolean-result.d.ts +4 -0
- package/package.json +20 -4
- package/eslint.config.js +0 -44
- package/jest.config.ts +0 -21
- package/ng-package.json +0 -7
- package/project.json +0 -36
- package/src/lib/rdt-autofocus/models.ts +0 -12
- package/src/lib/rdt-autofocus/rdt-autofocusable.directive.ts +0 -22
- package/src/lib/rdt-autofocus/utils.ts +0 -13
- package/src/lib/rdt-component-guard/directives/rdt-child.directive.ts +0 -103
- package/src/lib/rdt-component-guard/directives/rdt-container.directive.ts +0 -90
- package/src/lib/rdt-component-guard/models.ts +0 -47
- package/src/lib/utils/rdt-boolean-result.ts +0 -38
- package/src/test-setup.ts +0 -8
- 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/{src/lib/rdt-autofocus/index.ts → lib/rdt-autofocus/index.d.ts} +0 -0
- /package/{src/lib/utils/index.ts → lib/utils/index.d.ts} +0 -0
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DestroyRef,
|
|
3
|
-
Directive,
|
|
4
|
-
inject,
|
|
5
|
-
OnDestroy,
|
|
6
|
-
OnInit,
|
|
7
|
-
Type,
|
|
8
|
-
} from '@angular/core';
|
|
9
|
-
import { Subject } from 'rxjs';
|
|
10
|
-
import { RdtBooleanResult } from '../../utils';
|
|
11
|
-
import {
|
|
12
|
-
RDT_CONTAINER,
|
|
13
|
-
RDT_GUARDED_COMPONENT,
|
|
14
|
-
RdtCanEnterView,
|
|
15
|
-
RdtCanLeaveView,
|
|
16
|
-
RdtOnViewWillEnter,
|
|
17
|
-
RdtOnViewWillLeave,
|
|
18
|
-
} from '../models';
|
|
19
|
-
import { RdtContainerDirective } from './rdt-container.directive';
|
|
20
|
-
|
|
21
|
-
@Directive({
|
|
22
|
-
selector: '[rdtChild]',
|
|
23
|
-
standalone: true,
|
|
24
|
-
})
|
|
25
|
-
export class RdtChildDirective implements OnInit, OnDestroy {
|
|
26
|
-
readonly destroyRef = inject(DestroyRef);
|
|
27
|
-
readonly container = inject(RDT_CONTAINER, {
|
|
28
|
-
optional: true,
|
|
29
|
-
skipSelf: true,
|
|
30
|
-
});
|
|
31
|
-
readonly guardedComponent = inject(RDT_GUARDED_COMPONENT, {
|
|
32
|
-
optional: true,
|
|
33
|
-
self: true,
|
|
34
|
-
host: true,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
private readonly willLeaveSubj$ = new Subject<void>();
|
|
38
|
-
private readonly willEnterSubj$ = new Subject<void>();
|
|
39
|
-
|
|
40
|
-
readonly willLeave$ = this.willLeaveSubj$.asObservable();
|
|
41
|
-
readonly willEnter$ = this.willEnterSubj$.asObservable();
|
|
42
|
-
|
|
43
|
-
ngOnInit() {
|
|
44
|
-
if (!this.guardedComponent) {
|
|
45
|
-
throw new Error(`
|
|
46
|
-
RdtChildDirective usage:
|
|
47
|
-
Apply directive directly on component and provide the same component as RDT_GUARDED_COMPONENT.
|
|
48
|
-
The component can then implement RdtCanLeaveView or RdtCanEnterView.
|
|
49
|
-
This applies to both Child and Container directives.
|
|
50
|
-
`);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.container?.registerChild(this);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
ngOnDestroy() {
|
|
57
|
-
this.willLeaveSubj$.complete();
|
|
58
|
-
this.willEnterSubj$.complete();
|
|
59
|
-
this.container?.removeChild(this);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
canEnterView(): RdtBooleanResult {
|
|
63
|
-
const comp = this.guardedComponent as RdtCanEnterView | undefined;
|
|
64
|
-
if (typeof comp?.rdtCanEnterView === 'function') {
|
|
65
|
-
return comp.rdtCanEnterView();
|
|
66
|
-
} else {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
canLeaveView(): RdtBooleanResult {
|
|
72
|
-
const comp = this.guardedComponent as RdtCanLeaveView | undefined;
|
|
73
|
-
if (typeof comp?.rdtCanLeaveView === 'function') {
|
|
74
|
-
return comp.rdtCanLeaveView();
|
|
75
|
-
} else {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
onViewWillEnter(): void {
|
|
81
|
-
this.willEnterSubj$.next();
|
|
82
|
-
const comp = this.guardedComponent as RdtOnViewWillEnter | undefined;
|
|
83
|
-
comp?.rdtOnViewWillEnter();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
onViewWillLeave(): void {
|
|
87
|
-
this.willLeaveSubj$.next();
|
|
88
|
-
const comp = this.guardedComponent as RdtOnViewWillLeave | undefined;
|
|
89
|
-
comp?.rdtOnViewWillLeave();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
getParentByClass<T extends RdtContainerDirective>(
|
|
93
|
-
parentClass: Type<T>
|
|
94
|
-
): T | null {
|
|
95
|
-
if (!this.container) {
|
|
96
|
-
return null;
|
|
97
|
-
} else if (this.container instanceof parentClass) {
|
|
98
|
-
return this.container;
|
|
99
|
-
} else {
|
|
100
|
-
return this.container.getParentByClass(parentClass);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { Directive, Type } from '@angular/core';
|
|
2
|
-
import { rdtGetAllResultsTrue$ } from '../../utils';
|
|
3
|
-
import { RDT_CONTAINER } from '../models';
|
|
4
|
-
import { RdtChildDirective } from './rdt-child.directive';
|
|
5
|
-
|
|
6
|
-
@Directive({
|
|
7
|
-
selector: '[rdtContainer]',
|
|
8
|
-
standalone: true,
|
|
9
|
-
providers: [
|
|
10
|
-
{
|
|
11
|
-
provide: RdtChildDirective,
|
|
12
|
-
useExisting: RdtContainerDirective,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
provide: RDT_CONTAINER,
|
|
16
|
-
useExisting: RdtContainerDirective,
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
})
|
|
20
|
-
export class RdtContainerDirective extends RdtChildDirective {
|
|
21
|
-
readonly rdtChildren: Set<RdtChildDirective> = new Set<RdtChildDirective>();
|
|
22
|
-
|
|
23
|
-
registerChild(child: RdtChildDirective) {
|
|
24
|
-
this.rdtChildren.add(child);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
removeChild(child: RdtChildDirective) {
|
|
28
|
-
this.rdtChildren.delete(child);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
checkCanLeave$() {
|
|
32
|
-
return rdtGetAllResultsTrue$(
|
|
33
|
-
[this, ...this.getActiveChildren()].map((ch) => () => ch.canLeaveView())
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/* TODO
|
|
38
|
-
checkCanEnter$() {
|
|
39
|
-
return getCan$(
|
|
40
|
-
[this, ...this.getActiveChildren()].map((ch) => () => ch.canEnterView())
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
override onViewWillEnter() {
|
|
46
|
-
super.onViewWillEnter();
|
|
47
|
-
this.rdtChildren.forEach((ch) => ch.onViewWillEnter());
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
override onViewWillLeave() {
|
|
51
|
-
super.onViewWillLeave();
|
|
52
|
-
this.rdtChildren.forEach((ch) => ch.onViewWillLeave());
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
getChildrenRecursive() {
|
|
56
|
-
const res: RdtChildDirective[] = [];
|
|
57
|
-
this._getChildrenRecursive(res);
|
|
58
|
-
return res;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected getActiveChildren() {
|
|
62
|
-
return this.getChildrenRecursive();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getChildrenByClass<T>(childClass: Type<T>) {
|
|
66
|
-
const res: T[] = [];
|
|
67
|
-
this._getChildrenByClassRecursive(childClass, res);
|
|
68
|
-
return res;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private _getChildrenRecursive(res: RdtChildDirective[]) {
|
|
72
|
-
res.push(...this.rdtChildren);
|
|
73
|
-
this.rdtChildren.forEach((child) => {
|
|
74
|
-
if (child instanceof RdtContainerDirective) {
|
|
75
|
-
child._getChildrenRecursive(res);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private _getChildrenByClassRecursive<T>(childClass: Type<T>, res: T[]) {
|
|
81
|
-
this.rdtChildren.forEach((child) => {
|
|
82
|
-
const comp = (child as RdtChildDirective).guardedComponent;
|
|
83
|
-
if (comp instanceof childClass) {
|
|
84
|
-
res.push(comp);
|
|
85
|
-
} else if (child instanceof RdtContainerDirective) {
|
|
86
|
-
child._getChildrenByClassRecursive(childClass, res);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { InjectionToken } from '@angular/core';
|
|
2
|
-
import { Nullable } from '@ngrdt/utils';
|
|
3
|
-
import { of } from 'rxjs';
|
|
4
|
-
import { RdtBooleanResult } from '../utils';
|
|
5
|
-
import { RdtContainerDirective } from './directives/rdt-container.directive';
|
|
6
|
-
|
|
7
|
-
export interface RdtCanLeaveView {
|
|
8
|
-
rdtCanLeaveView(): RdtBooleanResult;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface RdtCanEnterView {
|
|
12
|
-
rdtCanEnterView(): RdtBooleanResult;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface RdtOnViewWillLeave {
|
|
16
|
-
rdtOnViewWillLeave(): void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface RdtOnViewWillEnter {
|
|
20
|
-
rdtOnViewWillEnter(): void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const RDT_GUARDED_COMPONENT = new InjectionToken<
|
|
24
|
-
RdtCanLeaveView | RdtCanEnterView | RdtOnViewWillEnter | RdtOnViewWillLeave
|
|
25
|
-
>('');
|
|
26
|
-
|
|
27
|
-
export const RDT_CONTAINER = new InjectionToken<RdtContainerDirective>('');
|
|
28
|
-
|
|
29
|
-
export function canTransition$(
|
|
30
|
-
from: Nullable<RdtContainerDirective>,
|
|
31
|
-
to: Nullable<RdtContainerDirective>
|
|
32
|
-
) {
|
|
33
|
-
const canLeave$ = from ? from.checkCanLeave$() : of(true);
|
|
34
|
-
return canLeave$;
|
|
35
|
-
/*
|
|
36
|
-
const canEnter$ = to ? to.checkCanEnter$() : of(true);
|
|
37
|
-
|
|
38
|
-
return canLeave$.pipe(
|
|
39
|
-
switchMap((res) => {
|
|
40
|
-
if (res) {
|
|
41
|
-
return canEnter$;
|
|
42
|
-
} else {
|
|
43
|
-
return of(res);
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
);*/
|
|
47
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { catchError, concat, defer, filter, map, Observable, of } from 'rxjs';
|
|
2
|
-
import { fromPromise } from 'rxjs/internal/observable/innerFrom';
|
|
3
|
-
|
|
4
|
-
export type RdtBooleanResult = Observable<boolean> | Promise<boolean> | boolean;
|
|
5
|
-
|
|
6
|
-
export function rdtGetAllResultsTrue$(
|
|
7
|
-
inputFactories: (() => RdtBooleanResult)[]
|
|
8
|
-
) {
|
|
9
|
-
const can$ = inputFactories.map((fn) => rdtGetResult$(fn));
|
|
10
|
-
const last = Symbol('last');
|
|
11
|
-
|
|
12
|
-
return concat(...can$, of(last)).pipe(
|
|
13
|
-
filter((res) => res === last),
|
|
14
|
-
map(() => true),
|
|
15
|
-
catchError(() => of(false))
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function rdtGetResult$(inputFactory: () => RdtBooleanResult) {
|
|
20
|
-
return defer(() => {
|
|
21
|
-
const input = inputFactory();
|
|
22
|
-
|
|
23
|
-
if (typeof input === 'boolean') {
|
|
24
|
-
return of(input);
|
|
25
|
-
}
|
|
26
|
-
if (input instanceof Promise) {
|
|
27
|
-
return fromPromise(input);
|
|
28
|
-
}
|
|
29
|
-
return input;
|
|
30
|
-
}).pipe(
|
|
31
|
-
map((res) => {
|
|
32
|
-
if (res) {
|
|
33
|
-
return res;
|
|
34
|
-
}
|
|
35
|
-
throw res;
|
|
36
|
-
})
|
|
37
|
-
);
|
|
38
|
-
}
|
package/src/test-setup.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
|
|
2
|
-
globalThis.ngJest = {
|
|
3
|
-
testEnvironmentOptions: {
|
|
4
|
-
errorOnUnknownElements: true,
|
|
5
|
-
errorOnUnknownProperties: true,
|
|
6
|
-
},
|
|
7
|
-
};
|
|
8
|
-
import 'jest-preset-angular/setup-jest';
|
package/tsconfig.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2022",
|
|
4
|
-
"forceConsistentCasingInFileNames": true,
|
|
5
|
-
"strict": true,
|
|
6
|
-
"noImplicitOverride": true,
|
|
7
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
8
|
-
"noImplicitReturns": true,
|
|
9
|
-
"noFallthroughCasesInSwitch": true
|
|
10
|
-
},
|
|
11
|
-
"files": [],
|
|
12
|
-
"include": [],
|
|
13
|
-
"references": [
|
|
14
|
-
{
|
|
15
|
-
"path": "./tsconfig.lib.json"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"path": "./tsconfig.spec.json"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"extends": "../../tsconfig.base.json",
|
|
22
|
-
"angularCompilerOptions": {
|
|
23
|
-
"enableI18nLegacyMessageIdFormat": false,
|
|
24
|
-
"strictInjectionParameters": true,
|
|
25
|
-
"strictInputAccessModifiers": true,
|
|
26
|
-
"strictTemplates": true
|
|
27
|
-
}
|
|
28
|
-
}
|
package/tsconfig.lib.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"declarationMap": true,
|
|
7
|
-
"inlineSources": true,
|
|
8
|
-
"types": []
|
|
9
|
-
},
|
|
10
|
-
"exclude": [
|
|
11
|
-
"src/**/*.spec.ts",
|
|
12
|
-
"src/test-setup.ts",
|
|
13
|
-
"jest.config.ts",
|
|
14
|
-
"src/**/*.test.ts"
|
|
15
|
-
],
|
|
16
|
-
"include": ["src/**/*.ts"]
|
|
17
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"module": "commonjs",
|
|
6
|
-
"target": "es2016",
|
|
7
|
-
"types": ["jest", "node"]
|
|
8
|
-
},
|
|
9
|
-
"files": ["src/test-setup.ts"],
|
|
10
|
-
"include": [
|
|
11
|
-
"jest.config.ts",
|
|
12
|
-
"src/**/*.test.ts",
|
|
13
|
-
"src/**/*.spec.ts",
|
|
14
|
-
"src/**/*.d.ts"
|
|
15
|
-
]
|
|
16
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|