@coolon/angular-ui-powerups 0.0.25 → 0.0.27
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/bundles/coolon-angular-ui-powerups.umd.js +3926 -0
- package/bundles/coolon-angular-ui-powerups.umd.js.map +1 -0
- package/bundles/coolon-angular-ui-powerups.umd.min.js +2 -0
- package/bundles/coolon-angular-ui-powerups.umd.min.js.map +1 -0
- package/coolon-angular-ui-powerups.d.ts +30 -0
- package/coolon-angular-ui-powerups.metadata.json +1 -0
- package/esm2015/coolon-angular-ui-powerups.js +33 -0
- package/esm2015/index.js +6 -0
- package/esm2015/lib/angular-ui-powerups.module.js +54 -0
- package/esm2015/lib/animations/index.js +9 -0
- package/esm2015/lib/animations/slideDownAndUpAnimation.js +30 -0
- package/esm2015/lib/components/disposable-component.js +14 -0
- package/esm2015/lib/components/forms/abstract-input.component.js +183 -0
- package/esm2015/lib/components/forms/number-input/number-input.component.js +26 -0
- package/esm2015/lib/components/forms/password-input/password-input.component.js +26 -0
- package/esm2015/lib/components/forms/select-input/select-input.component.js +60 -0
- package/esm2015/lib/components/forms/string-input/string-input.component.js +26 -0
- package/esm2015/lib/components/index.js +18 -0
- package/esm2015/lib/components/resize-aware.component.js +96 -0
- package/esm2015/lib/components/types/bounds.class.js +56 -0
- package/esm2015/lib/components/types/dimension.class.js +21 -0
- package/esm2015/lib/components/types/point.class.js +36 -0
- package/esm2015/lib/directives/command.directive.js +135 -0
- package/esm2015/lib/directives/focus-binding.directive.js +179 -0
- package/esm2015/lib/directives/index.js +10 -0
- package/esm2015/lib/interaction/abstract-activity.js +129 -0
- package/esm2015/lib/interaction/activity.js +27 -0
- package/esm2015/lib/interaction/alert.js +23 -0
- package/esm2015/lib/interaction/components/activity-container/activity-container.component.js +144 -0
- package/esm2015/lib/interaction/components/activity-outlet/activity-outlet-context.js +22 -0
- package/esm2015/lib/interaction/components/activity-outlet/activity-outlet.component.js +169 -0
- package/esm2015/lib/interaction/components/alert-dialog/alert-dialog.component.js +37 -0
- package/esm2015/lib/interaction/components/confirmation-dialog/confirmation-dialog.component.js +46 -0
- package/esm2015/lib/interaction/confirm.js +17 -0
- package/esm2015/lib/interaction/index.js +21 -0
- package/esm2015/lib/interaction/interaction-context.js +35 -0
- package/esm2015/lib/interaction/interaction.module.js +41 -0
- package/esm2015/lib/interaction/result.js +24 -0
- package/esm2015/lib/interaction/services/dialog-interaction.service.js +114 -0
- package/esm2015/lib/place/abstract-place-component.js +59 -0
- package/esm2015/lib/place/components/busy-overlay/busy-overlay.component.js +44 -0
- package/esm2015/lib/place/components/empty-state/empty-state.component.js +28 -0
- package/esm2015/lib/place/components/place-outlet/place-outlet.component.js +67 -0
- package/esm2015/lib/place/components/place-outlet/route-animations.js +35 -0
- package/esm2015/lib/place/components/tabbed-place-navigation/tabbed-place-navigation.component.js +50 -0
- package/esm2015/lib/place/guards/leave-place.guard.js +52 -0
- package/esm2015/lib/place/guards/place-route.guard.js +74 -0
- package/esm2015/lib/place/index.js +27 -0
- package/esm2015/lib/place/place-component.js +17 -0
- package/esm2015/lib/place/place.decorator.js +72 -0
- package/esm2015/lib/place/place.module.js +49 -0
- package/esm2015/lib/place/place.service.js +61 -0
- package/esm2015/lib/place/route/json-types.js +13 -0
- package/esm2015/lib/place/route/parameter-decorators.js +178 -0
- package/esm2015/lib/place/route/parameter-definition.class.js +24 -0
- package/esm2015/lib/place/route/parameter-sanitiser.js +17 -0
- package/esm2015/lib/place/route/parameter-type.js +43 -0
- package/esm2015/lib/place/route/route-parameter-bindings.js +294 -0
- package/esm2015/lib/place/route/route-parameter-sanitiser.js +280 -0
- package/esm2015/public_api.js +11 -0
- package/esm5/coolon-angular-ui-powerups.js +33 -0
- package/esm5/index.js +6 -0
- package/esm5/lib/angular-ui-powerups.module.js +58 -0
- package/esm5/lib/animations/index.js +9 -0
- package/esm5/lib/animations/slideDownAndUpAnimation.js +30 -0
- package/esm5/lib/components/disposable-component.js +24 -0
- package/esm5/lib/components/forms/abstract-input.component.js +232 -0
- package/esm5/lib/components/forms/number-input/number-input.component.js +33 -0
- package/esm5/lib/components/forms/password-input/password-input.component.js +33 -0
- package/esm5/lib/components/forms/select-input/select-input.component.js +67 -0
- package/esm5/lib/components/forms/string-input/string-input.component.js +33 -0
- package/esm5/lib/components/index.js +18 -0
- package/esm5/lib/components/resize-aware.component.js +124 -0
- package/esm5/lib/components/types/bounds.class.js +59 -0
- package/esm5/lib/components/types/dimension.class.js +19 -0
- package/esm5/lib/components/types/point.class.js +43 -0
- package/esm5/lib/directives/command.directive.js +155 -0
- package/esm5/lib/directives/focus-binding.directive.js +231 -0
- package/esm5/lib/directives/index.js +10 -0
- package/esm5/lib/interaction/abstract-activity.js +173 -0
- package/esm5/lib/interaction/activity.js +27 -0
- package/esm5/lib/interaction/alert.js +23 -0
- package/esm5/lib/interaction/components/activity-container/activity-container.component.js +181 -0
- package/esm5/lib/interaction/components/activity-outlet/activity-outlet-context.js +22 -0
- package/esm5/lib/interaction/components/activity-outlet/activity-outlet.component.js +206 -0
- package/esm5/lib/interaction/components/alert-dialog/alert-dialog.component.js +42 -0
- package/esm5/lib/interaction/components/confirmation-dialog/confirmation-dialog.component.js +54 -0
- package/esm5/lib/interaction/confirm.js +17 -0
- package/esm5/lib/interaction/index.js +21 -0
- package/esm5/lib/interaction/interaction-context.js +45 -0
- package/esm5/lib/interaction/interaction.module.js +45 -0
- package/esm5/lib/interaction/result.js +24 -0
- package/esm5/lib/interaction/services/dialog-interaction.service.js +140 -0
- package/esm5/lib/place/abstract-place-component.js +66 -0
- package/esm5/lib/place/components/busy-overlay/busy-overlay.component.js +49 -0
- package/esm5/lib/place/components/empty-state/empty-state.component.js +29 -0
- package/esm5/lib/place/components/place-outlet/place-outlet.component.js +81 -0
- package/esm5/lib/place/components/place-outlet/route-animations.js +35 -0
- package/esm5/lib/place/components/tabbed-place-navigation/tabbed-place-navigation.component.js +57 -0
- package/esm5/lib/place/guards/leave-place.guard.js +57 -0
- package/esm5/lib/place/guards/place-route.guard.js +78 -0
- package/esm5/lib/place/index.js +27 -0
- package/esm5/lib/place/place-component.js +17 -0
- package/esm5/lib/place/place.decorator.js +69 -0
- package/esm5/lib/place/place.module.js +53 -0
- package/esm5/lib/place/place.service.js +75 -0
- package/esm5/lib/place/route/json-types.js +13 -0
- package/esm5/lib/place/route/parameter-decorators.js +178 -0
- package/esm5/lib/place/route/parameter-definition.class.js +24 -0
- package/esm5/lib/place/route/parameter-sanitiser.js +17 -0
- package/esm5/lib/place/route/parameter-type.js +65 -0
- package/esm5/lib/place/route/route-parameter-bindings.js +339 -0
- package/esm5/lib/place/route/route-parameter-sanitiser.js +395 -0
- package/esm5/public_api.js +11 -0
- package/fesm2015/coolon-angular-ui-powerups.js +3145 -0
- package/fesm2015/coolon-angular-ui-powerups.js.map +1 -0
- package/fesm5/coolon-angular-ui-powerups.js +3699 -0
- package/fesm5/coolon-angular-ui-powerups.js.map +1 -0
- package/lib/angular-ui-powerups.module.d.ts +2 -0
- package/{src/lib/animations/index.ts → lib/animations/index.d.ts} +0 -1
- package/lib/animations/slideDownAndUpAnimation.d.ts +5 -0
- package/lib/components/disposable-component.d.ts +5 -0
- package/lib/components/forms/abstract-input.component.d.ts +35 -0
- package/lib/components/forms/number-input/number-input.component.d.ts +6 -0
- package/lib/components/forms/password-input/password-input.component.d.ts +6 -0
- package/lib/components/forms/select-input/select-input.component.d.ts +11 -0
- package/lib/components/forms/string-input/string-input.component.d.ts +6 -0
- package/{src/lib/components/index.ts → lib/components/index.d.ts} +0 -1
- package/lib/components/resize-aware.component.d.ts +22 -0
- package/lib/components/types/bounds.class.d.ts +16 -0
- package/lib/components/types/dimension.class.d.ts +5 -0
- package/lib/components/types/point.class.d.ts +10 -0
- package/lib/directives/command.directive.d.ts +14 -0
- package/lib/directives/focus-binding.directive.d.ts +22 -0
- package/{src/lib/directives/index.ts → lib/directives/index.d.ts} +0 -1
- package/lib/interaction/abstract-activity.d.ts +17 -0
- package/lib/interaction/activity.d.ts +11 -0
- package/lib/interaction/alert.d.ts +5 -0
- package/lib/interaction/components/activity-container/activity-container.component.d.ts +32 -0
- package/{src/lib/interaction/components/activity-outlet/activity-outlet-context.ts → lib/interaction/components/activity-outlet/activity-outlet-context.d.ts} +5 -7
- package/lib/interaction/components/activity-outlet/activity-outlet.component.d.ts +30 -0
- package/lib/interaction/components/alert-dialog/alert-dialog.component.d.ts +8 -0
- package/lib/interaction/components/confirmation-dialog/confirmation-dialog.component.d.ts +9 -0
- package/{src/lib/interaction/confirm.ts → lib/interaction/confirm.d.ts} +2 -3
- package/{src/lib/interaction/index.ts → lib/interaction/index.d.ts} +0 -1
- package/lib/interaction/interaction-context.d.ts +11 -0
- package/lib/interaction/interaction.module.d.ts +2 -0
- package/lib/interaction/result.d.ts +8 -0
- package/lib/interaction/services/dialog-interaction.service.d.ts +14 -0
- package/lib/place/abstract-place-component.d.ts +13 -0
- package/lib/place/components/busy-overlay/busy-overlay.component.d.ts +8 -0
- package/lib/place/components/empty-state/empty-state.component.d.ts +5 -0
- package/lib/place/components/place-outlet/place-outlet.component.d.ts +13 -0
- package/lib/place/components/place-outlet/route-animations.d.ts +1 -0
- package/lib/place/components/tabbed-place-navigation/tabbed-place-navigation.component.d.ts +11 -0
- package/lib/place/guards/leave-place.guard.d.ts +10 -0
- package/lib/place/guards/place-route.guard.d.ts +9 -0
- package/{src/lib/place/index.ts → lib/place/index.d.ts} +0 -1
- package/lib/place/place-component.d.ts +5 -0
- package/lib/place/place.decorator.d.ts +20 -0
- package/lib/place/place.module.d.ts +2 -0
- package/lib/place/place.service.d.ts +8 -0
- package/lib/place/route/json-types.d.ts +7 -0
- package/lib/place/route/parameter-decorators.d.ts +26 -0
- package/lib/place/route/parameter-definition.class.d.ts +11 -0
- package/{src/lib/place/route/parameter-sanitiser.ts → lib/place/route/parameter-sanitiser.d.ts} +1 -1
- package/lib/place/route/parameter-type.d.ts +16 -0
- package/lib/place/route/route-parameter-bindings.d.ts +18 -0
- package/lib/place/route/route-parameter-sanitiser.d.ts +42 -0
- package/package.json +14 -12
- package/schematics/ng-add/index.d.ts +2 -0
- package/schematics/ng-add/index.js +12 -0
- package/schematics/ng-add/index.js.map +1 -0
- package/schematics/place-routes/index.d.ts +3 -0
- package/schematics/place-routes/index.js +114 -0
- package/schematics/place-routes/index.js.map +1 -0
- package/schematics/place-routes/place-def.d.ts +34 -0
- package/schematics/place-routes/place-def.js +84 -0
- package/schematics/place-routes/place-def.js.map +1 -0
- package/schematics/place-routes/scanner.d.ts +26 -0
- package/schematics/place-routes/scanner.js +125 -0
- package/schematics/place-routes/scanner.js.map +1 -0
- package/schematics/place-routes/schema.d.ts +7 -0
- package/schematics/place-routes/schema.js +3 -0
- package/schematics/place-routes/schema.js.map +1 -0
- package/CHANGELOG.md +0 -5
- package/jest.config.js +0 -9
- package/ng-package.json +0 -13
- package/schematics/ng-add/index.ts +0 -10
- package/schematics/place-routes/index.ts +0 -152
- package/schematics/place-routes/place-def.ts +0 -93
- package/schematics/place-routes/scanner.ts +0 -145
- package/schematics/place-routes/schema.ts +0 -7
- package/src/lib/angular-ui-powerups.module.spec.ts +0 -14
- package/src/lib/angular-ui-powerups.module.ts +0 -49
- package/src/lib/animations/slideDownAndUpAnimation.ts +0 -39
- package/src/lib/components/disposable-component.ts +0 -9
- package/src/lib/components/forms/abstract-input.component.ts +0 -108
- package/src/lib/components/forms/number-input/number-input.component.html +0 -15
- package/src/lib/components/forms/number-input/number-input.component.scss +0 -3
- package/src/lib/components/forms/number-input/number-input.component.spec.ts +0 -25
- package/src/lib/components/forms/number-input/number-input.component.ts +0 -19
- package/src/lib/components/forms/password-input/password-input.component.html +0 -16
- package/src/lib/components/forms/password-input/password-input.component.scss +0 -3
- package/src/lib/components/forms/password-input/password-input.component.spec.ts +0 -25
- package/src/lib/components/forms/password-input/password-input.component.ts +0 -18
- package/src/lib/components/forms/scss/mixins.scss +0 -16
- package/src/lib/components/forms/select-input/select-input.component.html +0 -16
- package/src/lib/components/forms/select-input/select-input.component.scss +0 -7
- package/src/lib/components/forms/select-input/select-input.component.spec.ts +0 -25
- package/src/lib/components/forms/select-input/select-input.component.ts +0 -31
- package/src/lib/components/forms/string-input/string-input.component.html +0 -15
- package/src/lib/components/forms/string-input/string-input.component.scss +0 -3
- package/src/lib/components/forms/string-input/string-input.component.spec.ts +0 -25
- package/src/lib/components/forms/string-input/string-input.component.ts +0 -18
- package/src/lib/components/resize-aware.component.ts +0 -52
- package/src/lib/components/types/bounds.class.ts +0 -25
- package/src/lib/components/types/dimension.class.ts +0 -3
- package/src/lib/components/types/point.class.ts +0 -13
- package/src/lib/directives/command.directive.spec.ts +0 -73
- package/src/lib/directives/command.directive.ts +0 -81
- package/src/lib/directives/focus-binding.directive.spec.ts +0 -8
- package/src/lib/directives/focus-binding.directive.ts +0 -108
- package/src/lib/interaction/abstract-activity.ts +0 -57
- package/src/lib/interaction/activity.ts +0 -17
- package/src/lib/interaction/alert.ts +0 -6
- package/src/lib/interaction/components/activity-container/activity-container.component.html +0 -8
- package/src/lib/interaction/components/activity-container/activity-container.component.scss +0 -3
- package/src/lib/interaction/components/activity-container/activity-container.component.spec.ts +0 -25
- package/src/lib/interaction/components/activity-container/activity-container.component.ts +0 -93
- package/src/lib/interaction/components/activity-outlet/activity-outlet.component.scss +0 -3
- package/src/lib/interaction/components/activity-outlet/activity-outlet.component.spec.ts +0 -25
- package/src/lib/interaction/components/activity-outlet/activity-outlet.component.ts +0 -96
- package/src/lib/interaction/components/alert-dialog/alert-dialog.component.html +0 -7
- package/src/lib/interaction/components/alert-dialog/alert-dialog.component.scss +0 -7
- package/src/lib/interaction/components/alert-dialog/alert-dialog.component.spec.ts +0 -25
- package/src/lib/interaction/components/alert-dialog/alert-dialog.component.ts +0 -20
- package/src/lib/interaction/components/confirmation-dialog/confirmation-dialog.component.html +0 -9
- package/src/lib/interaction/components/confirmation-dialog/confirmation-dialog.component.scss +0 -8
- package/src/lib/interaction/components/confirmation-dialog/confirmation-dialog.component.spec.ts +0 -25
- package/src/lib/interaction/components/confirmation-dialog/confirmation-dialog.component.ts +0 -26
- package/src/lib/interaction/interaction-context.ts +0 -16
- package/src/lib/interaction/interaction.module.ts +0 -35
- package/src/lib/interaction/result.ts +0 -16
- package/src/lib/interaction/services/dialog-interaction.service.scss +0 -11
- package/src/lib/interaction/services/dialog-interaction.service.spec.ts +0 -12
- package/src/lib/interaction/services/dialog-interaction.service.ts +0 -63
- package/src/lib/place/abstract-place-component.ts +0 -33
- package/src/lib/place/components/busy-overlay/busy-overlay.component.html +0 -4
- package/src/lib/place/components/busy-overlay/busy-overlay.component.scss +0 -27
- package/src/lib/place/components/busy-overlay/busy-overlay.component.spec.ts +0 -25
- package/src/lib/place/components/busy-overlay/busy-overlay.component.ts +0 -23
- package/src/lib/place/components/empty-state/empty-state.component.scss +0 -15
- package/src/lib/place/components/empty-state/empty-state.component.spec.ts +0 -25
- package/src/lib/place/components/empty-state/empty-state.component.ts +0 -19
- package/src/lib/place/components/place-outlet/place-outlet.component.html +0 -7
- package/src/lib/place/components/place-outlet/place-outlet.component.scss +0 -12
- package/src/lib/place/components/place-outlet/place-outlet.component.spec.ts +0 -25
- package/src/lib/place/components/place-outlet/place-outlet.component.ts +0 -37
- package/src/lib/place/components/place-outlet/route-animations.ts +0 -30
- package/src/lib/place/components/tabbed-place-navigation/tabbed-place-navigation.component.html +0 -7
- package/src/lib/place/components/tabbed-place-navigation/tabbed-place-navigation.component.scss +0 -100
- package/src/lib/place/components/tabbed-place-navigation/tabbed-place-navigation.component.spec.ts +0 -25
- package/src/lib/place/components/tabbed-place-navigation/tabbed-place-navigation.component.ts +0 -30
- package/src/lib/place/guards/leave-place.guard.spec.ts +0 -15
- package/src/lib/place/guards/leave-place.guard.ts +0 -18
- package/src/lib/place/guards/place-route.guard.ts +0 -37
- package/src/lib/place/place-component.ts +0 -6
- package/src/lib/place/place.decorator.ts +0 -40
- package/src/lib/place/place.module.ts +0 -44
- package/src/lib/place/place.service.spec.ts +0 -12
- package/src/lib/place/place.service.ts +0 -29
- package/src/lib/place/route/json-types.ts +0 -5
- package/src/lib/place/route/parameter-decorators.ts +0 -99
- package/src/lib/place/route/parameter-definition.class.ts +0 -12
- package/src/lib/place/route/parameter-type.ts +0 -31
- package/src/lib/place/route/route-parameter-bindings.ts +0 -140
- package/src/lib/place/route/route-parameter-sanitiser.ts +0 -135
- package/src/test-setup.ts +0 -1
- package/tsconfig.json +0 -7
- package/tsconfig.lib.json +0 -20
- package/tsconfig.schematics.json +0 -35
- package/tsconfig.spec.json +0 -10
- package/tslint.json +0 -7
- /package/{src/index.ts → index.d.ts} +0 -0
- /package/{src/public_api.ts → public_api.d.ts} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SchematicContext } from '@angular-devkit/schematics';
|
|
2
|
+
import { ClassDeclaration, Decorator, ObjectLiteralExpression, PropertyDeclaration } from 'ts-morph';
|
|
3
|
+
import { PlaceDef } from './place-def';
|
|
4
|
+
export declare class Scanner {
|
|
5
|
+
private readonly classDecl;
|
|
6
|
+
readonly context: SchematicContext;
|
|
7
|
+
private placeAnnotation;
|
|
8
|
+
constructor(classDecl: ClassDeclaration, context: SchematicContext);
|
|
9
|
+
isPlace(): boolean;
|
|
10
|
+
onMatch(callback: (scan: Scanner) => void): void;
|
|
11
|
+
createDefinition(moduleImportPath: string): PlaceDef;
|
|
12
|
+
protected getPlaceOptions(): PlaceDef.Options;
|
|
13
|
+
protected getRouteIdParameter(): PlaceDef.Parameter;
|
|
14
|
+
protected getQueryParameters(): PlaceDef.Parameter[];
|
|
15
|
+
protected getDecoratedProperties(annotation: string): {
|
|
16
|
+
decorator: Decorator;
|
|
17
|
+
property: PropertyDeclaration;
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
20
|
+
export declare namespace Scanner {
|
|
21
|
+
function getObjectLiteralArgument(annotation: Decorator, position: number): ObjectLiteralExpression;
|
|
22
|
+
function getOptionsArg<T extends {}>(annotation: Decorator, defaults: T, options?: {
|
|
23
|
+
position: number;
|
|
24
|
+
required: boolean;
|
|
25
|
+
}): T;
|
|
26
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ts_morph_1 = require("ts-morph");
|
|
4
|
+
const place_def_1 = require("./place-def");
|
|
5
|
+
function isDecoratorNode(node, name) {
|
|
6
|
+
return node.getKind() === ts_morph_1.SyntaxKind.Decorator && node.getText().startsWith(`${name}(`); // NOTE: I'm only supporting the @Decorator(...) style of usage (i.e. decorator factories).
|
|
7
|
+
}
|
|
8
|
+
class Scanner {
|
|
9
|
+
constructor(classDecl, context) {
|
|
10
|
+
this.classDecl = classDecl;
|
|
11
|
+
this.context = context;
|
|
12
|
+
classDecl.forEachChild((node) => {
|
|
13
|
+
if (isDecoratorNode(node, '@Place')) {
|
|
14
|
+
this.placeAnnotation = node;
|
|
15
|
+
// stop iterating when the node is a class declaration
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
isPlace() {
|
|
21
|
+
return !!this.placeAnnotation;
|
|
22
|
+
}
|
|
23
|
+
onMatch(callback) {
|
|
24
|
+
if (this.isPlace()) {
|
|
25
|
+
callback(this);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
createDefinition(moduleImportPath) {
|
|
29
|
+
this.getRouteIdParameter();
|
|
30
|
+
return new place_def_1.PlaceDef(moduleImportPath, this.classDecl.getName(), this.getPlaceOptions(), this.getRouteIdParameter(), this.getQueryParameters());
|
|
31
|
+
}
|
|
32
|
+
getPlaceOptions() {
|
|
33
|
+
// const args = this.placeAnnotation.getArguments();
|
|
34
|
+
// if (args.length !== 1) {
|
|
35
|
+
// console.error('@Place() accepts a single Options argument. got', args);
|
|
36
|
+
// }
|
|
37
|
+
return Scanner.getOptionsArg(this.placeAnnotation, {
|
|
38
|
+
title: '',
|
|
39
|
+
path: '',
|
|
40
|
+
order: -1,
|
|
41
|
+
authenticate: 'true'
|
|
42
|
+
}, {
|
|
43
|
+
position: 0,
|
|
44
|
+
required: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getRouteIdParameter() {
|
|
48
|
+
const routeProperties = this.getDecoratedProperties('@RouteId');
|
|
49
|
+
if (routeProperties.length === 1) {
|
|
50
|
+
const route = routeProperties[0];
|
|
51
|
+
const routeOptions = Scanner.getOptionsArg(route.decorator, { as: 'id' }, {
|
|
52
|
+
position: 1,
|
|
53
|
+
required: false
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
modelName: route.property.getName(),
|
|
57
|
+
parameterName: routeOptions.as
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
else if (routeProperties.length > 1) {
|
|
61
|
+
this.context.logger.error(`There an only be one @RouteId(), got ${routeProperties.length}`);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
getQueryParameters() {
|
|
66
|
+
return this.getDecoratedProperties('@QueryParameter')
|
|
67
|
+
.map(p => {
|
|
68
|
+
const options = Scanner.getOptionsArg(p.decorator, { as: p.property.getName() }, {
|
|
69
|
+
position: 1,
|
|
70
|
+
required: false
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
modelName: p.property.getName(),
|
|
74
|
+
parameterName: options.as
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
getDecoratedProperties(annotation) {
|
|
79
|
+
return this.classDecl.getProperties().map(p => {
|
|
80
|
+
let result = null;
|
|
81
|
+
p.forEachChild((child) => {
|
|
82
|
+
if (isDecoratorNode(child, annotation)) {
|
|
83
|
+
result = {
|
|
84
|
+
decorator: child,
|
|
85
|
+
property: p
|
|
86
|
+
};
|
|
87
|
+
// stop traversal
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return result;
|
|
92
|
+
}).filter(r => !!r);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.Scanner = Scanner;
|
|
96
|
+
(function (Scanner) {
|
|
97
|
+
function getObjectLiteralArgument(annotation, position) {
|
|
98
|
+
const args = annotation.getArguments();
|
|
99
|
+
if (args.length > position && args[position] instanceof ts_morph_1.ObjectLiteralExpression) {
|
|
100
|
+
return args[position];
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
Scanner.getObjectLiteralArgument = getObjectLiteralArgument;
|
|
105
|
+
function getOptionsArg(annotation, defaults, options = {
|
|
106
|
+
position: 0,
|
|
107
|
+
required: true
|
|
108
|
+
}) {
|
|
109
|
+
const objectLiteralArgument = getObjectLiteralArgument(annotation, options.position);
|
|
110
|
+
if (!objectLiteralArgument) {
|
|
111
|
+
if (options.required) {
|
|
112
|
+
console.error(`expected object literal arg at position ${options.position}`, { expectedType: defaults });
|
|
113
|
+
}
|
|
114
|
+
return defaults;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return objectLiteralArgument.getProperties().reduce((result, p) => {
|
|
118
|
+
const structure = p.getStructure();
|
|
119
|
+
return Object.assign({}, result, { [structure.name]: structure.initializer });
|
|
120
|
+
}, Object.assign({}, defaults));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
Scanner.getOptionsArg = getOptionsArg;
|
|
124
|
+
})(Scanner = exports.Scanner || (exports.Scanner = {}));
|
|
125
|
+
//# sourceMappingURL=scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../../../../libs/angular-ui-powerups/schematics/place-routes/scanner.ts"],"names":[],"mappings":";;AACA,uCAQkB;AAClB,2CAAuC;AAEvC,SAAS,eAAe,CAAC,IAAU,EAAE,IAAY;IAC/C,OAAO,IAAI,CAAC,OAAO,EAAE,KAAK,qBAAU,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC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E,MAAM,SAAS,GAAG,CAAC,CAAC,YAAY,EAAiC,CAAC;gBAClE,yBAAY,MAAM,IAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,WAAqB,IAAG;YAC1E,CAAC,oBAAO,QAAQ,EAAG,CAAC;SACrB;IACH,CAAC;IAhBe,qBAAa,gBAgB5B,CAAA;AACH,CAAC,EA3BgB,OAAO,GAAP,eAAO,KAAP,eAAO,QA2BvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../libs/angular-ui-powerups/schematics/place-routes/schema.ts"],"names":[],"mappings":""}
|
package/CHANGELOG.md
DELETED
package/jest.config.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
name: 'angular-ui-powerups',
|
|
3
|
-
preset: '../../jest.config.js',
|
|
4
|
-
coverageDirectory: '../../coverage/libs/angular-ui-powerups',
|
|
5
|
-
snapshotSerializers: [
|
|
6
|
-
'jest-preset-angular/AngularSnapshotSerializer.js',
|
|
7
|
-
'jest-preset-angular/HTMLCommentSerializer.js'
|
|
8
|
-
]
|
|
9
|
-
};
|
package/ng-package.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
|
|
3
|
-
"dest": "../../dist/libs/angular-ui-powerups",
|
|
4
|
-
"lib": {
|
|
5
|
-
"entryFile": "src/index.ts"
|
|
6
|
-
},
|
|
7
|
-
"whitelistedNonPeerDependencies": [
|
|
8
|
-
"ts-morph",
|
|
9
|
-
"@typescript-plus/fast-memoize-decorator",
|
|
10
|
-
"@coolon/typescript-utilities",
|
|
11
|
-
"json5"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
|
|
2
|
-
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
|
|
3
|
-
|
|
4
|
-
// Just return the tree
|
|
5
|
-
export function ngAdd(_options: any): Rule {
|
|
6
|
-
return (tree: Tree, _context: SchematicContext) => {
|
|
7
|
-
_context.addTask(new NodePackageInstallTask());
|
|
8
|
-
return tree;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { experimental, strings } from '@angular-devkit/core';
|
|
2
|
-
import {
|
|
3
|
-
apply,
|
|
4
|
-
applyTemplates,
|
|
5
|
-
FileEntry,
|
|
6
|
-
forEach,
|
|
7
|
-
mergeWith,
|
|
8
|
-
Rule,
|
|
9
|
-
SchematicContext,
|
|
10
|
-
Tree,
|
|
11
|
-
url,
|
|
12
|
-
move
|
|
13
|
-
} from '@angular-devkit/schematics';
|
|
14
|
-
import { scanForRouteEntryPoints } from '@angular/compiler-cli/src/ngtsc/routing/src/lazy';
|
|
15
|
-
import { fileExists } from '@nrwl/workspace/src/utils/fileutils';
|
|
16
|
-
import * as JSON5 from 'json5';
|
|
17
|
-
import { ClassDeclaration, Project } from 'ts-morph';
|
|
18
|
-
import { PlaceDef } from './place-def';
|
|
19
|
-
import { Schema } from './schema';
|
|
20
|
-
|
|
21
|
-
const PLACE_ANNOTATION = /@Place\({([^})]*)}\)/m;
|
|
22
|
-
|
|
23
|
-
export function generateRoutes(options: Schema): Rule {
|
|
24
|
-
|
|
25
|
-
return (tree: Tree, context: SchematicContext) => {
|
|
26
|
-
|
|
27
|
-
const workspaceConfig = tree.read('/angular.json');
|
|
28
|
-
if (!workspaceConfig) {
|
|
29
|
-
throw new Error('Could not find Angular workspace configuration');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// convert workspace to string
|
|
33
|
-
const workspaceContent = workspaceConfig.toString();
|
|
34
|
-
|
|
35
|
-
// parse workspace string into JSON object
|
|
36
|
-
const workspace: experimental.workspace.WorkspaceSchema = JSON.parse(workspaceContent);
|
|
37
|
-
|
|
38
|
-
if (!options.project) {
|
|
39
|
-
options.project = workspace.defaultProject;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const projectName = options.project as string;
|
|
43
|
-
const project = workspace.projects[projectName];
|
|
44
|
-
const config = loadConfig(project, tree, context);
|
|
45
|
-
const placeDefs = extractPlaces(project, options, tree, context);
|
|
46
|
-
const projectType = project.projectType === 'application' ? 'app' : 'lib';
|
|
47
|
-
|
|
48
|
-
const files = apply(
|
|
49
|
-
url('./templates'),
|
|
50
|
-
[
|
|
51
|
-
applyTemplates({
|
|
52
|
-
...options,
|
|
53
|
-
placeDefs,
|
|
54
|
-
config,
|
|
55
|
-
...strings
|
|
56
|
-
}),
|
|
57
|
-
move(`${project.sourceRoot}/${projectType}`),
|
|
58
|
-
// @see https://github.com/angular/angular-cli/issues/11337#issuecomment-448259549
|
|
59
|
-
forEach((fileEntry: FileEntry) => {
|
|
60
|
-
if (tree.exists(fileEntry.path)) {
|
|
61
|
-
tree.overwrite(fileEntry.path, fileEntry.content);
|
|
62
|
-
}
|
|
63
|
-
return fileEntry;
|
|
64
|
-
})
|
|
65
|
-
]);
|
|
66
|
-
|
|
67
|
-
return mergeWith(files);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// function applyWithOverwrite(source: Source, rules: Rule[]): Rule {
|
|
75
|
-
// return (tree: Tree, _context: SchematicContext) => {
|
|
76
|
-
// const rule = mergeWith(
|
|
77
|
-
// apply(source, [
|
|
78
|
-
// ...rules,
|
|
79
|
-
// forEach((fileEntry) => {
|
|
80
|
-
// if (tree.exists(fileEntry.path)) {
|
|
81
|
-
// tree.overwrite(fileEntry.path, fileEntry.content);
|
|
82
|
-
// return null;
|
|
83
|
-
// }
|
|
84
|
-
// return fileEntry;
|
|
85
|
-
// })
|
|
86
|
-
// ])
|
|
87
|
-
// );
|
|
88
|
-
//
|
|
89
|
-
// return rule(tree, _context);
|
|
90
|
-
// };
|
|
91
|
-
// }
|
|
92
|
-
|
|
93
|
-
function createProject(project: any, context: SchematicContext) {
|
|
94
|
-
const tsConfigPath = project.architect.build.options.tsConfig;
|
|
95
|
-
context.logger.info(`loading tsConfig from -> ${tsConfigPath}`);
|
|
96
|
-
try {
|
|
97
|
-
return new Project({
|
|
98
|
-
tsConfigFilePath: `./${tsConfigPath}`
|
|
99
|
-
});
|
|
100
|
-
} catch (error) {
|
|
101
|
-
context.logger.fatal(`Failed to load typescript project form: ${project.root} You probably need to specify the --project option?`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function loadConfig(project: any, tree: Tree, context: SchematicContext) {
|
|
106
|
-
context.logger.info(`loading places config from -> ${project.root}/places.json (or places.json5)`);
|
|
107
|
-
const fileEntry = tree.get(`${project.root}/places.json5`) || tree.get(`${project.root}/places.json5`);
|
|
108
|
-
if (!fileEntry) {
|
|
109
|
-
throw new Error(`Unable to find config file at '${project.root}/places.json' or '${project.root}/places.json5'`);
|
|
110
|
-
}
|
|
111
|
-
const config = JSON5.parse(fileEntry.content.toString('utf-8'));
|
|
112
|
-
return config;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function extractPlaces(project: any, schema: Schema, tree: Tree, context: SchematicContext): PlaceDef[] {
|
|
116
|
-
const projectType = project.projectType === 'application' ? 'app' : 'lib';
|
|
117
|
-
const projectRoot = `${project.root}`;
|
|
118
|
-
const sourceRoot = `${project.sourceRoot}/${projectType}`;
|
|
119
|
-
const importPrefix = `./${sourceRoot}`;
|
|
120
|
-
const tsProject = createProject(project, context);
|
|
121
|
-
const placeDefs: PlaceDef[] = [];
|
|
122
|
-
context.logger.info(`Scanning sources in -> ${sourceRoot}`);
|
|
123
|
-
tree.getDir(sourceRoot).visit(filePath => {
|
|
124
|
-
if (!filePath.endsWith('.ts')) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const content = tree.read(filePath);
|
|
129
|
-
if (!content) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const sourceText = content.toString('utf-8');
|
|
133
|
-
|
|
134
|
-
if (sourceText.match(PLACE_ANNOTATION)) {
|
|
135
|
-
|
|
136
|
-
const sourceFile = tsProject.getSourceFileOrThrow(`./${filePath}`);
|
|
137
|
-
|
|
138
|
-
sourceFile.getClasses().forEach((classDecl: ClassDeclaration) => {
|
|
139
|
-
|
|
140
|
-
PlaceDef.scan(classDecl, context).onMatch(result => {
|
|
141
|
-
// context.logger.info(`filePath=${filePath}`);
|
|
142
|
-
const moduleImportPath = `./${filePath.substr(importPrefix.length, filePath.length - importPrefix.length - '.ts'.length)}`;
|
|
143
|
-
const definition = result.createDefinition(moduleImportPath);
|
|
144
|
-
context.logger.info(`${moduleImportPath} -> ${classDecl.getName()}(route: /${definition.fullPath})`);
|
|
145
|
-
placeDefs.push(definition);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
return placeDefs;
|
|
152
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { SchematicContext } from '@angular-devkit/schematics';
|
|
2
|
-
import { Memoize } from '@typescript-plus/fast-memoize-decorator/dist/src';
|
|
3
|
-
import { ClassDeclaration } from 'ts-morph';
|
|
4
|
-
import { Scanner } from './scanner';
|
|
5
|
-
|
|
6
|
-
export class PlaceDef {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
readonly importPath: string,
|
|
11
|
-
readonly componentClass: string,
|
|
12
|
-
readonly properties: PlaceDef.Options,
|
|
13
|
-
readonly routeDef: PlaceDef.Parameter,
|
|
14
|
-
readonly queryParameters: PlaceDef.Parameter[]
|
|
15
|
-
) {
|
|
16
|
-
// console.log({ properties, routeDef });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@Memoize()
|
|
20
|
-
get path() {
|
|
21
|
-
return this.stripEnclosingQuotes(this.properties.path);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@Memoize()
|
|
25
|
-
get routeIdentifier() {
|
|
26
|
-
return this.routeDef ? this.stripEnclosingQuotes(this.routeDef.parameterName) : null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get fullPath() {
|
|
30
|
-
return !!this.routeIdentifier ?
|
|
31
|
-
`${this.path}/:${this.routeIdentifier}` :
|
|
32
|
-
this.path;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@Memoize()
|
|
36
|
-
get placeName() {
|
|
37
|
-
return this.componentClass.replace(/Component$/, "")
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get order() {
|
|
41
|
-
return this.properties.order
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@Memoize()
|
|
45
|
-
get activateGuardNames() {
|
|
46
|
-
const activateGuards = [];
|
|
47
|
-
if (this.authenticate) {
|
|
48
|
-
activateGuards.push('AuthGuard');
|
|
49
|
-
}
|
|
50
|
-
if (this.requiresRouteGuard()) {
|
|
51
|
-
activateGuards.push('PlaceRouteGuard');
|
|
52
|
-
}
|
|
53
|
-
return activateGuards;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private requiresRouteGuard() {
|
|
57
|
-
return this.routeIdentifier || this.queryParameters.length > 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@Memoize()
|
|
61
|
-
get routeModelName() {
|
|
62
|
-
return this.routeDef ? this.stripEnclosingQuotes(this.routeDef.modelName) : null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get authenticate() {
|
|
66
|
-
return this.properties.authenticate === 'true';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
stripEnclosingQuotes(value: string): string {
|
|
70
|
-
const cooked = value.replace(/(^["'])|(["']$)/g, '');
|
|
71
|
-
// console.log({ raw: value, cooked: cooked });
|
|
72
|
-
return cooked;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export namespace PlaceDef {
|
|
77
|
-
|
|
78
|
-
export interface Options {
|
|
79
|
-
title: string;
|
|
80
|
-
path: string;
|
|
81
|
-
order: number;
|
|
82
|
-
authenticate: string;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface Parameter {
|
|
86
|
-
parameterName: string;
|
|
87
|
-
modelName: string;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function scan(classDecl: ClassDeclaration, context: SchematicContext): Scanner {
|
|
91
|
-
return new Scanner(classDecl, context);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { SchematicContext } from '@angular-devkit/schematics';
|
|
2
|
-
import {
|
|
3
|
-
ClassDeclaration,
|
|
4
|
-
Decorator,
|
|
5
|
-
Node,
|
|
6
|
-
ObjectLiteralExpression,
|
|
7
|
-
PropertyAssignmentStructure,
|
|
8
|
-
PropertyDeclaration,
|
|
9
|
-
SyntaxKind
|
|
10
|
-
} from 'ts-morph';
|
|
11
|
-
import { PlaceDef } from './place-def';
|
|
12
|
-
|
|
13
|
-
function isDecoratorNode(node: Node, name: string): node is Decorator {
|
|
14
|
-
return node.getKind() === SyntaxKind.Decorator && node.getText().startsWith(`${name}(`); // NOTE: I'm only supporting the @Decorator(...) style of usage (i.e. decorator factories).
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class Scanner {
|
|
18
|
-
|
|
19
|
-
private placeAnnotation: Decorator;
|
|
20
|
-
|
|
21
|
-
constructor(private readonly classDecl: ClassDeclaration, readonly context: SchematicContext) {
|
|
22
|
-
classDecl.forEachChild((node) => {
|
|
23
|
-
if (isDecoratorNode(node, '@Place')) {
|
|
24
|
-
this.placeAnnotation = node as Decorator;
|
|
25
|
-
// stop iterating when the node is a class declaration
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
isPlace() {
|
|
32
|
-
return !!this.placeAnnotation;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
onMatch(callback: (scan: Scanner) => void) {
|
|
36
|
-
if (this.isPlace()) {
|
|
37
|
-
callback(this);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
createDefinition(moduleImportPath: string): PlaceDef {
|
|
42
|
-
this.getRouteIdParameter();
|
|
43
|
-
return new PlaceDef(moduleImportPath,
|
|
44
|
-
this.classDecl.getName(),
|
|
45
|
-
this.getPlaceOptions(),
|
|
46
|
-
this.getRouteIdParameter(),
|
|
47
|
-
this.getQueryParameters()
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected getPlaceOptions(): PlaceDef.Options {
|
|
52
|
-
// const args = this.placeAnnotation.getArguments();
|
|
53
|
-
// if (args.length !== 1) {
|
|
54
|
-
// console.error('@Place() accepts a single Options argument. got', args);
|
|
55
|
-
// }
|
|
56
|
-
return Scanner.getOptionsArg(this.placeAnnotation, {
|
|
57
|
-
title: '',
|
|
58
|
-
path: '',
|
|
59
|
-
order: -1,
|
|
60
|
-
authenticate: 'true'
|
|
61
|
-
}, {
|
|
62
|
-
position: 0,
|
|
63
|
-
required: true
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
protected getRouteIdParameter(): PlaceDef.Parameter {
|
|
68
|
-
const routeProperties = this.getDecoratedProperties('@RouteId');
|
|
69
|
-
if (routeProperties.length === 1) {
|
|
70
|
-
const route = routeProperties[0];
|
|
71
|
-
const routeOptions = Scanner.getOptionsArg(route.decorator, { as: 'id' }, {
|
|
72
|
-
position: 1,
|
|
73
|
-
required: false
|
|
74
|
-
});
|
|
75
|
-
return {
|
|
76
|
-
modelName: route.property.getName(),
|
|
77
|
-
parameterName: routeOptions.as
|
|
78
|
-
};
|
|
79
|
-
} else if (routeProperties.length > 1) {
|
|
80
|
-
this.context.logger.error(`There an only be one @RouteId(), got ${routeProperties.length}`);
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
protected getQueryParameters(): PlaceDef.Parameter[] {
|
|
86
|
-
return this.getDecoratedProperties('@QueryParameter')
|
|
87
|
-
.map(p => {
|
|
88
|
-
const options = Scanner.getOptionsArg(p.decorator, { as: p.property.getName() }, {
|
|
89
|
-
position: 1,
|
|
90
|
-
required: false
|
|
91
|
-
});
|
|
92
|
-
return {
|
|
93
|
-
modelName: p.property.getName(),
|
|
94
|
-
parameterName: options.as
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
protected getDecoratedProperties(annotation: string): { decorator: Decorator, property: PropertyDeclaration }[] {
|
|
100
|
-
return this.classDecl.getProperties().map(p => {
|
|
101
|
-
let result: { decorator: Decorator, property: PropertyDeclaration } = null;
|
|
102
|
-
p.forEachChild((child) => {
|
|
103
|
-
if (isDecoratorNode(child, annotation)) {
|
|
104
|
-
result = {
|
|
105
|
-
decorator: child,
|
|
106
|
-
property: p
|
|
107
|
-
};
|
|
108
|
-
// stop traversal
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return result;
|
|
113
|
-
}).filter(r => !!r);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export namespace Scanner {
|
|
119
|
-
|
|
120
|
-
export function getObjectLiteralArgument(annotation: Decorator, position: number): ObjectLiteralExpression {
|
|
121
|
-
const args = annotation.getArguments();
|
|
122
|
-
if (args.length > position && args[position] instanceof ObjectLiteralExpression) {
|
|
123
|
-
return args[position] as ObjectLiteralExpression;
|
|
124
|
-
}
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function getOptionsArg<T extends {}>(annotation: Decorator, defaults: T, options: { position: number, required: boolean } = {
|
|
129
|
-
position: 0,
|
|
130
|
-
required: true
|
|
131
|
-
}): T {
|
|
132
|
-
const objectLiteralArgument = getObjectLiteralArgument(annotation, options.position);
|
|
133
|
-
if (!objectLiteralArgument) {
|
|
134
|
-
if (options.required) {
|
|
135
|
-
console.error(`expected object literal arg at position ${options.position}`, { expectedType: defaults });
|
|
136
|
-
}
|
|
137
|
-
return defaults;
|
|
138
|
-
} else {
|
|
139
|
-
return objectLiteralArgument.getProperties().reduce((result, p) => {
|
|
140
|
-
const structure = p.getStructure() as PropertyAssignmentStructure;
|
|
141
|
-
return { ...result, [structure.name]: structure.initializer as string };
|
|
142
|
-
}, { ...defaults });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { async, TestBed } from '@angular/core/testing';
|
|
2
|
-
import { AngularUiPowerupsModule } from './angular-ui-powerups.module';
|
|
3
|
-
|
|
4
|
-
describe('AngularUiPowerupsModule', () => {
|
|
5
|
-
beforeEach(async(() => {
|
|
6
|
-
TestBed.configureTestingModule({
|
|
7
|
-
imports: [AngularUiPowerupsModule]
|
|
8
|
-
}).compileComponents();
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
it('should create', () => {
|
|
12
|
-
expect(AngularUiPowerupsModule).toBeDefined();
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { CommonModule } from '@angular/common';
|
|
2
|
-
import { NgModule } from '@angular/core';
|
|
3
|
-
import { FormsModule } from '@angular/forms';
|
|
4
|
-
import { MatFormFieldModule, MatInputModule, MatSelectModule } from '@angular/material';
|
|
5
|
-
import { BrowserModule } from '@angular/platform-browser';
|
|
6
|
-
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|
7
|
-
import { NumberInputComponent} from './components/forms/number-input/number-input.component';
|
|
8
|
-
import { CommandDirective } from './directives/command.directive';
|
|
9
|
-
import { FocusBindingDirective } from './directives/focus-binding.directive';
|
|
10
|
-
import { StringInputComponent } from './components/forms/string-input/string-input.component';
|
|
11
|
-
import { PasswordInputComponent } from './components/forms/password-input/password-input.component';
|
|
12
|
-
import { SelectInputComponent } from './components/forms/select-input/select-input.component';
|
|
13
|
-
import { InteractionModule } from './interaction/interaction.module';
|
|
14
|
-
import { PlaceModule } from './place/place.module';
|
|
15
|
-
|
|
16
|
-
@NgModule({
|
|
17
|
-
declarations: [
|
|
18
|
-
CommandDirective,
|
|
19
|
-
FocusBindingDirective,
|
|
20
|
-
NumberInputComponent,
|
|
21
|
-
StringInputComponent,
|
|
22
|
-
PasswordInputComponent,
|
|
23
|
-
SelectInputComponent,
|
|
24
|
-
],
|
|
25
|
-
imports: [
|
|
26
|
-
CommonModule,
|
|
27
|
-
BrowserModule,
|
|
28
|
-
BrowserAnimationsModule,
|
|
29
|
-
FormsModule,
|
|
30
|
-
MatInputModule,
|
|
31
|
-
MatFormFieldModule,
|
|
32
|
-
MatSelectModule,
|
|
33
|
-
PlaceModule,
|
|
34
|
-
InteractionModule
|
|
35
|
-
],
|
|
36
|
-
exports: [
|
|
37
|
-
CommandDirective,
|
|
38
|
-
FocusBindingDirective,
|
|
39
|
-
NumberInputComponent,
|
|
40
|
-
StringInputComponent,
|
|
41
|
-
PasswordInputComponent,
|
|
42
|
-
SelectInputComponent,
|
|
43
|
-
InteractionModule,
|
|
44
|
-
PlaceModule,
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
})
|
|
48
|
-
export class AngularUiPowerupsModule {
|
|
49
|
-
}
|