@ngrdt/core 0.0.2 → 0.0.3
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 +85 -0
- package/esm2022/lib/rdt-component-guard/directives/rdt-container.directive.mjs +93 -0
- package/esm2022/lib/rdt-component-guard/index.mjs +4 -0
- package/esm2022/lib/rdt-component-guard/models.mjs +21 -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 +257 -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 +23 -0
- package/lib/rdt-component-guard/directives/rdt-container.directive.d.ts +18 -0
- package/lib/rdt-component-guard/models.d.ts +19 -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/rdt-component-guard/index.ts → lib/rdt-component-guard/index.d.ts} +0 -0
- /package/{src/lib/utils/index.ts → lib/utils/index.d.ts} +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { OnInit } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export declare class RdtAutofocusableDirective implements OnInit {
|
|
4
|
+
readonly component: import("./models").RdtAutocusable | null;
|
|
5
|
+
ngOnInit(): void;
|
|
6
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RdtAutofocusableDirective, never>;
|
|
7
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<RdtAutofocusableDirective, "[rdtAutofocusable]", never, {}, {}, never, never, false, never>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DestroyRef, OnDestroy, OnInit, Type } from '@angular/core';
|
|
2
|
+
import { RdtBooleanResult } from '../../utils';
|
|
3
|
+
import { RdtCanEnterView, RdtCanLeaveView, RdtOnViewWillEnter, RdtOnViewWillLeave } from '../models';
|
|
4
|
+
import { RdtContainerDirective } from './rdt-container.directive';
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
export declare class RdtChildDirective implements OnInit, OnDestroy {
|
|
7
|
+
readonly destroyRef: DestroyRef;
|
|
8
|
+
readonly container: RdtContainerDirective | null;
|
|
9
|
+
readonly guardedComponent: RdtCanLeaveView | RdtCanEnterView | RdtOnViewWillEnter | RdtOnViewWillLeave | null;
|
|
10
|
+
private readonly willLeaveSubj$;
|
|
11
|
+
private readonly willEnterSubj$;
|
|
12
|
+
readonly willLeave$: import("rxjs").Observable<void>;
|
|
13
|
+
readonly willEnter$: import("rxjs").Observable<void>;
|
|
14
|
+
ngOnInit(): void;
|
|
15
|
+
ngOnDestroy(): void;
|
|
16
|
+
canEnterView(): RdtBooleanResult;
|
|
17
|
+
canLeaveView(): RdtBooleanResult;
|
|
18
|
+
onViewWillEnter(): void;
|
|
19
|
+
onViewWillLeave(): void;
|
|
20
|
+
getParentByClass<T extends RdtContainerDirective>(parentClass: Type<T>): T | null;
|
|
21
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RdtChildDirective, never>;
|
|
22
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<RdtChildDirective, "[rdtChild]", never, {}, {}, never, never, true, never>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Type } from '@angular/core';
|
|
2
|
+
import { RdtChildDirective } from './rdt-child.directive';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export declare class RdtContainerDirective extends RdtChildDirective {
|
|
5
|
+
readonly rdtChildren: Set<RdtChildDirective>;
|
|
6
|
+
registerChild(child: RdtChildDirective): void;
|
|
7
|
+
removeChild(child: RdtChildDirective): void;
|
|
8
|
+
checkCanLeave$(): import("rxjs").Observable<boolean>;
|
|
9
|
+
onViewWillEnter(): void;
|
|
10
|
+
onViewWillLeave(): void;
|
|
11
|
+
getChildrenRecursive(): RdtChildDirective[];
|
|
12
|
+
protected getActiveChildren(): RdtChildDirective[];
|
|
13
|
+
getChildrenByClass<T>(childClass: Type<T>): T[];
|
|
14
|
+
private _getChildrenRecursive;
|
|
15
|
+
private _getChildrenByClassRecursive;
|
|
16
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RdtContainerDirective, never>;
|
|
17
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<RdtContainerDirective, "[rdtContainer]", never, {}, {}, never, never, true, never>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { Nullable } from '@ngrdt/utils';
|
|
3
|
+
import { RdtBooleanResult } from '../utils';
|
|
4
|
+
import { RdtContainerDirective } from './directives/rdt-container.directive';
|
|
5
|
+
export interface RdtCanLeaveView {
|
|
6
|
+
rdtCanLeaveView(): RdtBooleanResult;
|
|
7
|
+
}
|
|
8
|
+
export interface RdtCanEnterView {
|
|
9
|
+
rdtCanEnterView(): RdtBooleanResult;
|
|
10
|
+
}
|
|
11
|
+
export interface RdtOnViewWillLeave {
|
|
12
|
+
rdtOnViewWillLeave(): void;
|
|
13
|
+
}
|
|
14
|
+
export interface RdtOnViewWillEnter {
|
|
15
|
+
rdtOnViewWillEnter(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare const RDT_GUARDED_COMPONENT: InjectionToken<RdtCanLeaveView | RdtCanEnterView | RdtOnViewWillEnter | RdtOnViewWillLeave>;
|
|
18
|
+
export declare const RDT_CONTAINER: InjectionToken<RdtContainerDirective>;
|
|
19
|
+
export declare function canTransition$(from: Nullable<RdtContainerDirective>, to: Nullable<RdtContainerDirective>): import("rxjs").Observable<boolean>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
export type RdtBooleanResult = Observable<boolean> | Promise<boolean> | boolean;
|
|
3
|
+
export declare function rdtGetAllResultsTrue$(inputFactories: (() => RdtBooleanResult)[]): Observable<boolean>;
|
|
4
|
+
export declare function rdtGetResult$(inputFactory: () => RdtBooleanResult): Observable<true>;
|
package/package.json
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrdt/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/core": "^18.2.0",
|
|
6
6
|
"rxjs": "~7.8.0",
|
|
7
|
-
"@ngrdt/utils": "0.0.
|
|
7
|
+
"@ngrdt/utils": "0.0.7"
|
|
8
8
|
},
|
|
9
|
-
"sideEffects": false
|
|
10
|
-
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"module": "fesm2022/ngrdt-core.mjs",
|
|
11
|
+
"typings": "index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
"./package.json": {
|
|
14
|
+
"default": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"esm2022": "./esm2022/ngrdt-core.mjs",
|
|
19
|
+
"esm": "./esm2022/ngrdt-core.mjs",
|
|
20
|
+
"default": "./fesm2022/ngrdt-core.mjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"tslib": "^2.3.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/eslint.config.js
DELETED
|
@@ -1,44 +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': [
|
|
10
|
-
'error',
|
|
11
|
-
{ ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'] },
|
|
12
|
-
],
|
|
13
|
-
},
|
|
14
|
-
languageOptions: { parser: require('jsonc-eslint-parser') },
|
|
15
|
-
},
|
|
16
|
-
...nx.configs['flat/angular'],
|
|
17
|
-
...nx.configs['flat/angular-template'],
|
|
18
|
-
{
|
|
19
|
-
files: ['**/*.ts'],
|
|
20
|
-
rules: {
|
|
21
|
-
'@angular-eslint/directive-selector': [
|
|
22
|
-
'error',
|
|
23
|
-
{
|
|
24
|
-
type: 'attribute',
|
|
25
|
-
prefix: 'lib',
|
|
26
|
-
style: 'camelCase',
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
'@angular-eslint/component-selector': [
|
|
30
|
-
'error',
|
|
31
|
-
{
|
|
32
|
-
type: 'element',
|
|
33
|
-
prefix: 'lib',
|
|
34
|
-
style: 'kebab-case',
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
files: ['**/*.html'],
|
|
41
|
-
// Override or add rules here
|
|
42
|
-
rules: {},
|
|
43
|
-
},
|
|
44
|
-
];
|
package/jest.config.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: '@ngrdt/core',
|
|
3
|
-
preset: '../../jest.preset.js',
|
|
4
|
-
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
|
5
|
-
coverageDirectory: '../../coverage/@ngrdt/core',
|
|
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": "@ngrdt/core",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "@ngrdt/core/src",
|
|
5
|
-
"prefix": "lib",
|
|
6
|
-
"projectType": "library",
|
|
7
|
-
"tags": [],
|
|
8
|
-
"targets": {
|
|
9
|
-
"build": {
|
|
10
|
-
"executor": "@nx/angular:package",
|
|
11
|
-
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
|
|
12
|
-
"options": {
|
|
13
|
-
"project": "@ngrdt/core/ng-package.json"
|
|
14
|
-
},
|
|
15
|
-
"configurations": {
|
|
16
|
-
"production": {
|
|
17
|
-
"tsConfig": "@ngrdt/core/tsconfig.lib.prod.json"
|
|
18
|
-
},
|
|
19
|
-
"development": {
|
|
20
|
-
"tsConfig": "@ngrdt/core/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": "@ngrdt/core/jest.config.ts"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"lint": {
|
|
33
|
-
"executor": "@nx/eslint:lint"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { InjectionToken } from '@angular/core';
|
|
2
|
-
import { RdtBooleanResult } from '../utils';
|
|
3
|
-
|
|
4
|
-
export interface RdtAutocusable {
|
|
5
|
-
rdtFocus(): void;
|
|
6
|
-
rdtCanFocus(): RdtBooleanResult;
|
|
7
|
-
rdtGetAutofocusPriority?(): number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const RDT_AUTOFOCUSABLE_COMPONENT = new InjectionToken<RdtAutocusable>(
|
|
11
|
-
''
|
|
12
|
-
);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Directive, inject, OnInit } from '@angular/core';
|
|
2
|
-
import { RDT_AUTOFOCUSABLE_COMPONENT } from './models';
|
|
3
|
-
|
|
4
|
-
@Directive({
|
|
5
|
-
selector: '[rdtAutofocusable]',
|
|
6
|
-
})
|
|
7
|
-
export class RdtAutofocusableDirective implements OnInit {
|
|
8
|
-
readonly component = inject(RDT_AUTOFOCUSABLE_COMPONENT, {
|
|
9
|
-
host: true,
|
|
10
|
-
optional: true,
|
|
11
|
-
self: true,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
ngOnInit() {
|
|
15
|
-
if (!this.component) {
|
|
16
|
-
throw new Error(`
|
|
17
|
-
RdtAutofocusableDirective usage:
|
|
18
|
-
Apply directive directly on component and provide the same component as RDT_AUTOFOCUSABLE_COMPONENT.
|
|
19
|
-
The component must then implement RdtAutocusable.`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { RdtAutocusable } from './models';
|
|
2
|
-
import { RdtAutofocusableDirective } from './rdt-autofocusable.directive';
|
|
3
|
-
|
|
4
|
-
export function getRdtAutofocusable(
|
|
5
|
-
src: Iterable<RdtAutofocusableDirective>
|
|
6
|
-
): RdtAutocusable | null {
|
|
7
|
-
const withPrios = Array.from(src).map((dir) => ({
|
|
8
|
-
cmp: dir.component,
|
|
9
|
-
prio: dir.component?.rdtGetAutofocusPriority?.() ?? 0,
|
|
10
|
-
}));
|
|
11
|
-
withPrios.sort((a, b) => b.prio - a.prio);
|
|
12
|
-
return withPrios[0]?.cmp;
|
|
13
|
-
}
|
|
@@ -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
|
|
File without changes
|