@ngrdt/router 0.0.23 → 0.0.25
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/fesm2022/ngrdt-router.mjs +104 -77
- package/fesm2022/ngrdt-router.mjs.map +1 -1
- package/index.d.ts +109 -101
- package/package.json +4 -4
|
@@ -38,6 +38,9 @@ class RdtParameters extends RdtReadonlyParameters {
|
|
|
38
38
|
this.params[route.absolutePath] = params;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
function ALWAYS_TRUE() {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
41
44
|
|
|
42
45
|
const RDT_ROUTES_PROVIDER = new InjectionToken('RDT_ROUTES_PROVIDER');
|
|
43
46
|
|
|
@@ -202,6 +205,7 @@ class RdtAngularRoute {
|
|
|
202
205
|
route;
|
|
203
206
|
children = [];
|
|
204
207
|
// Must be set from component declaration files
|
|
208
|
+
loadComponent;
|
|
205
209
|
loadChildren;
|
|
206
210
|
component;
|
|
207
211
|
providers = [];
|
|
@@ -218,6 +222,10 @@ class RdtAngularRoute {
|
|
|
218
222
|
this.providers.push(...providers);
|
|
219
223
|
return this;
|
|
220
224
|
}
|
|
225
|
+
withLazyComponent(callback) {
|
|
226
|
+
this.loadComponent = callback;
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
221
229
|
withModule(callback) {
|
|
222
230
|
this.loadChildren = callback;
|
|
223
231
|
return this;
|
|
@@ -289,6 +297,9 @@ class RdtAngularRoute {
|
|
|
289
297
|
else if (this.loadChildren) {
|
|
290
298
|
res.loadChildren = this.loadChildren;
|
|
291
299
|
}
|
|
300
|
+
else if (this.loadComponent) {
|
|
301
|
+
res.loadComponent = this.loadComponent;
|
|
302
|
+
}
|
|
292
303
|
res.data = this.data ?? {
|
|
293
304
|
breadcrumb: {
|
|
294
305
|
label: this.route.name,
|
|
@@ -341,7 +352,7 @@ class RdtAngularRoute {
|
|
|
341
352
|
// ]
|
|
342
353
|
// }
|
|
343
354
|
if (this.children.length > 0) {
|
|
344
|
-
if (this.loadChildren || this.component) {
|
|
355
|
+
if (this.loadChildren || this.component || this.loadComponent) {
|
|
345
356
|
const path = res.path;
|
|
346
357
|
res.path = '';
|
|
347
358
|
res.pathMatch = 'full';
|
|
@@ -414,26 +425,40 @@ class RdtAngularRoute {
|
|
|
414
425
|
}
|
|
415
426
|
}
|
|
416
427
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
class RdtRoute {
|
|
421
|
-
orderedParams = [];
|
|
428
|
+
class RdtRouteBase {
|
|
429
|
+
_orderedParams = [];
|
|
422
430
|
_paramMap = {};
|
|
423
431
|
_regex = null;
|
|
424
|
-
|
|
425
|
-
_staticParams = {};
|
|
426
|
-
_queryParams = {};
|
|
427
|
-
_stateParams = {};
|
|
428
|
-
_data = {};
|
|
432
|
+
_paramMappings = [];
|
|
429
433
|
_name;
|
|
430
434
|
_path;
|
|
431
435
|
_parent = null;
|
|
432
436
|
_children = [];
|
|
433
437
|
_entryDisabled = false;
|
|
434
438
|
_canBeEntered = ALWAYS_TRUE;
|
|
435
|
-
|
|
436
|
-
|
|
439
|
+
_data = {};
|
|
440
|
+
/**
|
|
441
|
+
* Data that is passed to Angular route definition.
|
|
442
|
+
*/
|
|
443
|
+
get data() {
|
|
444
|
+
return this._data;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Regular expression route path relative to parent route.
|
|
448
|
+
* Hostname excluded.
|
|
449
|
+
*/
|
|
450
|
+
get regex() {
|
|
451
|
+
return this._regex;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Denotes disabled route entry.
|
|
455
|
+
* If true, route should have no NgModule
|
|
456
|
+
* or component and only serves as virtual module
|
|
457
|
+
* for breadcrumb.
|
|
458
|
+
*/
|
|
459
|
+
get entryDisabled() {
|
|
460
|
+
return this._entryDisabled;
|
|
461
|
+
}
|
|
437
462
|
/**
|
|
438
463
|
* Map of parameters and their types.
|
|
439
464
|
*/
|
|
@@ -464,6 +489,13 @@ class RdtRoute {
|
|
|
464
489
|
get children() {
|
|
465
490
|
return this._children;
|
|
466
491
|
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
class RdtRoute extends RdtRouteBase {
|
|
495
|
+
_absoluteRegex;
|
|
496
|
+
_staticParams = {};
|
|
497
|
+
_queryParams = {};
|
|
498
|
+
_stateParams = {};
|
|
467
499
|
/**
|
|
468
500
|
* Absolute path of parent route or '/' if there is no parent.
|
|
469
501
|
* Hostname excluded.
|
|
@@ -477,13 +509,6 @@ class RdtRoute {
|
|
|
477
509
|
get absolutePath() {
|
|
478
510
|
return RdtStringUtils.joinPaths(this.basePath, this._path);
|
|
479
511
|
}
|
|
480
|
-
/**
|
|
481
|
-
* Regular expression route path relative to parent route.
|
|
482
|
-
* Hostname excluded.
|
|
483
|
-
*/
|
|
484
|
-
get regex() {
|
|
485
|
-
return this._regex;
|
|
486
|
-
}
|
|
487
512
|
/**
|
|
488
513
|
* Regular expression to match only this route (not children
|
|
489
514
|
* or parent routes). Hostname excluded.
|
|
@@ -508,15 +533,6 @@ class RdtRoute {
|
|
|
508
533
|
}
|
|
509
534
|
return this._absoluteRegex;
|
|
510
535
|
}
|
|
511
|
-
/**
|
|
512
|
-
* Denotes disabled route entry.
|
|
513
|
-
* If true, route should have no NgModule
|
|
514
|
-
* or component and only serves as virtual module
|
|
515
|
-
* for breadcrumb.
|
|
516
|
-
*/
|
|
517
|
-
get entryDisabled() {
|
|
518
|
-
return this._entryDisabled;
|
|
519
|
-
}
|
|
520
536
|
/**
|
|
521
537
|
* Statically set state params used when navigating to this instance.
|
|
522
538
|
*/
|
|
@@ -545,12 +561,6 @@ class RdtRoute {
|
|
|
545
561
|
get hasCanBeEnteredGuard() {
|
|
546
562
|
return this._canBeEntered !== ALWAYS_TRUE;
|
|
547
563
|
}
|
|
548
|
-
/**
|
|
549
|
-
* Data that is passed to Angular route definition.
|
|
550
|
-
*/
|
|
551
|
-
get data() {
|
|
552
|
-
return this._data;
|
|
553
|
-
}
|
|
554
564
|
/**
|
|
555
565
|
* Meta guard that is used by [rdtRouterLink] and RdtMenu
|
|
556
566
|
* to determine if route can be entered.
|
|
@@ -587,10 +597,10 @@ class RdtRoute {
|
|
|
587
597
|
}
|
|
588
598
|
fill(values, res = {}) {
|
|
589
599
|
const params = {};
|
|
590
|
-
const reversedParams = this.
|
|
600
|
+
const reversedParams = this._orderedParams.slice().reverse();
|
|
591
601
|
for (let i = 0; i < reversedParams.length && i < values.length; i++) {
|
|
592
602
|
const key = reversedParams[i];
|
|
593
|
-
const mappedKey = this.
|
|
603
|
+
const mappedKey = this._paramMappings.find((m) => m.urlName === key)?.tableName ?? key;
|
|
594
604
|
let val = values[i];
|
|
595
605
|
if (this._paramMap[key] === 'number') {
|
|
596
606
|
val = parseInt(val);
|
|
@@ -624,7 +634,7 @@ class RdtRoute {
|
|
|
624
634
|
const paramNames = Object.keys(this._paramMap);
|
|
625
635
|
paramNames.sort((a, b) => b.length - a.length);
|
|
626
636
|
const extendedParamMap = { ...paramMap };
|
|
627
|
-
this.
|
|
637
|
+
this._paramMappings.forEach((mapping) => {
|
|
628
638
|
if (mapping.tableName in paramMap) {
|
|
629
639
|
extendedParamMap[mapping.urlName] = paramMap[mapping.tableName];
|
|
630
640
|
}
|
|
@@ -639,9 +649,6 @@ class RdtRoute {
|
|
|
639
649
|
return path;
|
|
640
650
|
}
|
|
641
651
|
toAngularRoute() {
|
|
642
|
-
if (!this._built) {
|
|
643
|
-
throw new Error('You have to first call .build() on route!');
|
|
644
|
-
}
|
|
645
652
|
return new RdtAngularRoute(this);
|
|
646
653
|
}
|
|
647
654
|
/**
|
|
@@ -652,7 +659,7 @@ class RdtRoute {
|
|
|
652
659
|
*/
|
|
653
660
|
withParamMappings(mappings) {
|
|
654
661
|
const clone = this.clone();
|
|
655
|
-
clone.
|
|
662
|
+
clone._paramMappings = mappings;
|
|
656
663
|
return clone;
|
|
657
664
|
}
|
|
658
665
|
/**
|
|
@@ -693,8 +700,8 @@ class RdtRoute {
|
|
|
693
700
|
*/
|
|
694
701
|
extractRouteParams(row) {
|
|
695
702
|
const res = {};
|
|
696
|
-
this.
|
|
697
|
-
const mapping = this.
|
|
703
|
+
this._orderedParams.forEach((param) => {
|
|
704
|
+
const mapping = this._paramMappings.find((m) => m.urlName === param);
|
|
698
705
|
const mappedParam = (mapping?.tableName ?? param);
|
|
699
706
|
if (mappedParam in row) {
|
|
700
707
|
res[mappedParam] = row[mappedParam];
|
|
@@ -712,18 +719,65 @@ class RdtRoute {
|
|
|
712
719
|
clone._parent = this._parent?.clone() ?? null;
|
|
713
720
|
clone._path = this.path;
|
|
714
721
|
clone._entryDisabled = this._entryDisabled;
|
|
715
|
-
clone.
|
|
722
|
+
clone._orderedParams = [...this._orderedParams];
|
|
716
723
|
clone._paramMap = { ...this._paramMap };
|
|
717
724
|
clone._regex = this._regex ? new RegExp(this._regex) : null;
|
|
718
|
-
clone.
|
|
725
|
+
clone._paramMappings = this._paramMappings;
|
|
719
726
|
clone._staticParams = { ...this._staticParams };
|
|
720
727
|
clone._stateParams = { ...this._stateParams };
|
|
721
728
|
return clone;
|
|
722
729
|
}
|
|
730
|
+
setRegex() {
|
|
731
|
+
const params = Object.keys(this._paramMap);
|
|
732
|
+
params.sort((a, b) => b.length - a.length);
|
|
733
|
+
let substituted = this.path;
|
|
734
|
+
params.forEach((p) => {
|
|
735
|
+
const type = this._paramMap[p];
|
|
736
|
+
if (!type) {
|
|
737
|
+
throw new Error('Params is not set i');
|
|
738
|
+
}
|
|
739
|
+
substituted = substituted.replace(`:${p}`, RdtRoute.groups[type]);
|
|
740
|
+
});
|
|
741
|
+
if (substituted === '') {
|
|
742
|
+
this._regex = null;
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
this._regex = new RegExp(substituted);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
static fromBuilder(builder) {
|
|
749
|
+
const route = new RdtRoute();
|
|
750
|
+
route._name = builder.name;
|
|
751
|
+
route._path = builder.path;
|
|
752
|
+
route._entryDisabled = builder.entryDisabled;
|
|
753
|
+
route._orderedParams = builder.orderedParams;
|
|
754
|
+
route._canBeEntered = builder.canBeEntered;
|
|
755
|
+
route._paramMap = builder.paramMap;
|
|
756
|
+
route._regex = builder.regex ? new RegExp(builder.regex) : null;
|
|
757
|
+
route._paramMappings = builder.paramMappings;
|
|
758
|
+
route._children = builder.children;
|
|
759
|
+
route._data = builder.data;
|
|
760
|
+
route._children.forEach((child) => (child._parent = route));
|
|
761
|
+
route.setRegex();
|
|
762
|
+
return route;
|
|
763
|
+
}
|
|
764
|
+
static groups = {
|
|
765
|
+
string: '(.+)',
|
|
766
|
+
number: '(\\d+)',
|
|
767
|
+
};
|
|
723
768
|
}
|
|
724
769
|
|
|
725
770
|
const DEFAULT_PARAM_TYPE = 'number';
|
|
726
|
-
class RdtRouteBuilder extends
|
|
771
|
+
class RdtRouteBuilder extends RdtRouteBase {
|
|
772
|
+
get canBeEntered() {
|
|
773
|
+
return this._canBeEntered;
|
|
774
|
+
}
|
|
775
|
+
get orderedParams() {
|
|
776
|
+
return this._orderedParams;
|
|
777
|
+
}
|
|
778
|
+
get paramMappings() {
|
|
779
|
+
return this._paramMappings;
|
|
780
|
+
}
|
|
727
781
|
/**
|
|
728
782
|
* CanBeEntered function is synchronous function which
|
|
729
783
|
* lets framework hide menu buttons and disable links.
|
|
@@ -776,7 +830,7 @@ class RdtRouteBuilder extends RdtRoute {
|
|
|
776
830
|
}
|
|
777
831
|
}
|
|
778
832
|
});
|
|
779
|
-
this.
|
|
833
|
+
this._orderedParams = params;
|
|
780
834
|
return this;
|
|
781
835
|
}
|
|
782
836
|
/**
|
|
@@ -832,9 +886,6 @@ class RdtRouteBuilder extends RdtRoute {
|
|
|
832
886
|
*/
|
|
833
887
|
withChildren(...children) {
|
|
834
888
|
this._children = children;
|
|
835
|
-
for (const child of children) {
|
|
836
|
-
child._parent = this;
|
|
837
|
-
}
|
|
838
889
|
return this;
|
|
839
890
|
}
|
|
840
891
|
/**
|
|
@@ -847,32 +898,8 @@ class RdtRouteBuilder extends RdtRoute {
|
|
|
847
898
|
if (typeof this._path !== 'string') {
|
|
848
899
|
throw new Error('Please provide path for route. Empty string is acceptable.');
|
|
849
900
|
}
|
|
850
|
-
this
|
|
851
|
-
this.setRegex();
|
|
852
|
-
return this;
|
|
853
|
-
}
|
|
854
|
-
setRegex() {
|
|
855
|
-
const params = Object.keys(this._paramMap);
|
|
856
|
-
params.sort((a, b) => b.length - a.length);
|
|
857
|
-
let substituted = this.path;
|
|
858
|
-
params.forEach((p) => {
|
|
859
|
-
const type = this._paramMap[p];
|
|
860
|
-
if (!type) {
|
|
861
|
-
throw new Error('Params is not set i');
|
|
862
|
-
}
|
|
863
|
-
substituted = substituted.replace(`:${p}`, RdtRouteBuilder.groups[type]);
|
|
864
|
-
});
|
|
865
|
-
if (substituted === '') {
|
|
866
|
-
this._regex = null;
|
|
867
|
-
}
|
|
868
|
-
else {
|
|
869
|
-
this._regex = new RegExp(substituted);
|
|
870
|
-
}
|
|
901
|
+
return RdtRoute.fromBuilder(this);
|
|
871
902
|
}
|
|
872
|
-
static groups = {
|
|
873
|
-
string: '(.+)',
|
|
874
|
-
number: '(\\d+)',
|
|
875
|
-
};
|
|
876
903
|
}
|
|
877
904
|
|
|
878
905
|
const EXACT_TRUE_OPTS = {
|
|
@@ -1204,5 +1231,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImpor
|
|
|
1204
1231
|
* Generated bundle index. Do not edit.
|
|
1205
1232
|
*/
|
|
1206
1233
|
|
|
1207
|
-
export {
|
|
1234
|
+
export { GlobalRouteGuardService, PERMISSION_DISABLED_KEY, RDT_CANNOT_BE_ENTERED_PROVIDER, RDT_CONFIRM_DATA_LOSS_SERVICE, RDT_ROUTES_PROVIDER, RdtAngularRoute, RdtAnyRouteActiveDirective, RdtBackLinkDirective, RdtConfirmDataLossService, RdtConfirmDataLossServiceAlert, RdtNavigationSource, RdtRoute, RdtRouteBuilder, RdtRouterLinkDirective, RdtRouterService, preventDataLossGuardFn };
|
|
1208
1235
|
//# sourceMappingURL=ngrdt-router.mjs.map
|