@processpuzzle/base-entity 0.8.2 → 0.9.0
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, input, computed, Component, effect, InjectionToken, Inject, Directive, Injector, signal,
|
|
2
|
+
import { inject, Injectable, input, computed, Component, effect, InjectionToken, Inject, Directive, Injector, signal, HostBinding, EventEmitter, Output, ViewChild, DestroyRef, untracked, runInInjectionContext, provideAppInitializer } from '@angular/core';
|
|
3
3
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
4
4
|
import * as i1 from '@angular/common';
|
|
5
5
|
import { CommonModule, NgClass, NgStyle, NgTemplateOutlet, SlicePipe } from '@angular/common';
|
|
6
|
-
import {
|
|
6
|
+
import { Router, RouteConfigLoadEnd, NavigationEnd, ActivatedRoute, RouterOutlet, ROUTER_OUTLET_DATA } from '@angular/router';
|
|
7
7
|
import { MatTabNav, MatTabLink, MatTabNavPanel } from '@angular/material/tabs';
|
|
8
8
|
import * as i2 from '@angular/material/toolbar';
|
|
9
9
|
import { MatToolbarModule, MatToolbar } from '@angular/material/toolbar';
|
|
@@ -85,6 +85,60 @@ var BaseUrlSegments;
|
|
|
85
85
|
BaseUrlSegments["UnknownEntity"] = "unknown";
|
|
86
86
|
})(BaseUrlSegments || (BaseUrlSegments = {}));
|
|
87
87
|
|
|
88
|
+
const ENTITY_NAME_ROUTE_DATA_KEY = 'entityName';
|
|
89
|
+
class EntityRouteRegistry {
|
|
90
|
+
router = inject(Router);
|
|
91
|
+
basePaths = new Map();
|
|
92
|
+
scan() {
|
|
93
|
+
this.basePaths.clear();
|
|
94
|
+
this.walk(this.router.config, '');
|
|
95
|
+
}
|
|
96
|
+
observeLazyLoads() {
|
|
97
|
+
this.router.events.subscribe((event) => {
|
|
98
|
+
if (event instanceof RouteConfigLoadEnd)
|
|
99
|
+
this.scan();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
basePath(entityName) {
|
|
103
|
+
return this.basePaths.get(entityName);
|
|
104
|
+
}
|
|
105
|
+
listPath(entityName) {
|
|
106
|
+
const base = this.basePaths.get(entityName);
|
|
107
|
+
return base ? `${base}/list` : undefined;
|
|
108
|
+
}
|
|
109
|
+
detailsPath(entityName, id) {
|
|
110
|
+
const base = this.basePaths.get(entityName);
|
|
111
|
+
return base ? `${base}/${id}/details` : undefined;
|
|
112
|
+
}
|
|
113
|
+
registeredEntities() {
|
|
114
|
+
return [...this.basePaths.keys()];
|
|
115
|
+
}
|
|
116
|
+
walk(routes, prefix) {
|
|
117
|
+
if (!routes)
|
|
118
|
+
return;
|
|
119
|
+
for (const route of routes) {
|
|
120
|
+
const segment = this.append(prefix, route.path);
|
|
121
|
+
const entityName = route.data?.[ENTITY_NAME_ROUTE_DATA_KEY];
|
|
122
|
+
if (typeof entityName === 'string' && entityName.length > 0) {
|
|
123
|
+
this.basePaths.set(entityName, segment);
|
|
124
|
+
}
|
|
125
|
+
this.walk(route.children, segment);
|
|
126
|
+
this.walk(route._loadedRoutes, segment);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
append(prefix, path) {
|
|
130
|
+
if (!path)
|
|
131
|
+
return prefix;
|
|
132
|
+
return `${prefix}/${path}`;
|
|
133
|
+
}
|
|
134
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: EntityRouteRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
135
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: EntityRouteRegistry, providedIn: 'root' });
|
|
136
|
+
}
|
|
137
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: EntityRouteRegistry, decorators: [{
|
|
138
|
+
type: Injectable,
|
|
139
|
+
args: [{ providedIn: 'root' }]
|
|
140
|
+
}] });
|
|
141
|
+
|
|
88
142
|
var RouteSegments;
|
|
89
143
|
(function (RouteSegments) {
|
|
90
144
|
RouteSegments["LIST_ROUTE"] = "LIST_ROUTE";
|
|
@@ -130,7 +184,7 @@ function lastKeyOf(target) {
|
|
|
130
184
|
last = key;
|
|
131
185
|
return last;
|
|
132
186
|
}
|
|
133
|
-
const BaseFormNavigatorSingletonStore = signalStore({ providedIn: 'root' }, withState(INITIAL_NAVIGATION_STATE), withDevtools('Base Form Navigator'), withMethods((store, router = inject(Router), route = inject(ActivatedRoute)) => {
|
|
187
|
+
const BaseFormNavigatorSingletonStore = signalStore({ providedIn: 'root' }, withState(INITIAL_NAVIGATION_STATE), withDevtools('Base Form Navigator'), withMethods((store, router = inject(Router), route = inject(ActivatedRoute), entityRouteRegistry = inject(EntityRouteRegistry)) => {
|
|
134
188
|
let pendingNavigatorUrl;
|
|
135
189
|
let routerEventsSubscription;
|
|
136
190
|
function clearPayloadStacks() {
|
|
@@ -236,6 +290,11 @@ const BaseFormNavigatorSingletonStore = signalStore({ providedIn: 'root' }, with
|
|
|
236
290
|
async function navigateToRelated(relatedTypeName, id, returnTo, payload) {
|
|
237
291
|
patchState(store, { entityName: relatedTypeName });
|
|
238
292
|
pushPayload(payload);
|
|
293
|
+
const registeredPath = entityRouteRegistry.detailsPath(relatedTypeName, id);
|
|
294
|
+
if (registeredPath) {
|
|
295
|
+
await navigateToUrl(registeredPath, returnTo);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
239
298
|
const snakeCaseEntityName = snakeCaseName(relatedTypeName);
|
|
240
299
|
const baseUrl = determineBaseUrl();
|
|
241
300
|
const detailsFormPath = baseUrl + '/' + snakeCaseEntityName + '/' + id + '/details';
|
|
@@ -244,6 +303,11 @@ const BaseFormNavigatorSingletonStore = signalStore({ providedIn: 'root' }, with
|
|
|
244
303
|
async function navigateToRelatedList(relatedTypeName, returnTo, payload) {
|
|
245
304
|
patchState(store, { entityName: relatedTypeName });
|
|
246
305
|
pushPayload(payload);
|
|
306
|
+
const registeredPath = entityRouteRegistry.listPath(relatedTypeName);
|
|
307
|
+
if (registeredPath) {
|
|
308
|
+
await navigateToUrl(registeredPath, returnTo);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
247
311
|
const snakeCaseEntityName = snakeCaseName(relatedTypeName);
|
|
248
312
|
const baseUrl = determineBaseUrl();
|
|
249
313
|
const listPath = baseUrl + '/' + snakeCaseEntityName + '/list';
|
|
@@ -3068,6 +3132,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
|
|
|
3068
3132
|
|
|
3069
3133
|
const BASE_ENTITY_SERVICE = new InjectionToken('BASE_ENTITY_SERVICE');
|
|
3070
3134
|
|
|
3135
|
+
function provideEntityRouteRegistry() {
|
|
3136
|
+
return provideAppInitializer(() => {
|
|
3137
|
+
const registry = inject(EntityRouteRegistry);
|
|
3138
|
+
registry.scan();
|
|
3139
|
+
registry.observeLazyLoads();
|
|
3140
|
+
});
|
|
3141
|
+
}
|
|
3142
|
+
|
|
3071
3143
|
// Symbol to store entity options on instance
|
|
3072
3144
|
const ENTITY_OPTIONS_KEY = Symbol('entityOptions');
|
|
3073
3145
|
// Metadata key for storing ID properties
|
|
@@ -3156,5 +3228,5 @@ const BASE_ENTITY_ROUTES = [
|
|
|
3156
3228
|
* Generated bundle index. Do not edit.
|
|
3157
3229
|
*/
|
|
3158
3230
|
|
|
3159
|
-
export { ACTIVE_ENTITY_FACADE, AbstractAttrDescriptor, BASE_ENTITY_FACADE_REGISTRY, BASE_ENTITY_ROUTES, BASE_ENTITY_SERVICE, BASE_ENTITY_STORE, BASE_LIST_DESCRIPTORS, BaseEntityAttrDescriptor, BaseEntityContainerComponent, BaseEntityContainerStore, BaseEntityDescriptor, BaseEntityDescriptorRegistry, BaseEntityFacade, BaseEntityFirestoreService, BaseEntityFormComponent, BaseEntityListComponent, BaseEntityRestService, BaseEntityStore, BaseEntityTabsStore, BaseFormHostDirective, BaseFormNavigatorSingletonStore, BaseFormNavigatorStore, Entity, EntityRegistryComponent, FlexDirection, FlexboxDescriptor, FormControlType, Id, NavigatorCommand, OrderByDirection, RULE_ENGINE, RouteSegments, RuleViolationsSingletonStore, SimpleEntityMapper, getEntityIds, getEntityOptions, getEnumKeyByValue, getEnumValueByKey };
|
|
3231
|
+
export { ACTIVE_ENTITY_FACADE, AbstractAttrDescriptor, BASE_ENTITY_FACADE_REGISTRY, BASE_ENTITY_ROUTES, BASE_ENTITY_SERVICE, BASE_ENTITY_STORE, BASE_LIST_DESCRIPTORS, BaseEntityAttrDescriptor, BaseEntityContainerComponent, BaseEntityContainerStore, BaseEntityDescriptor, BaseEntityDescriptorRegistry, BaseEntityFacade, BaseEntityFirestoreService, BaseEntityFormComponent, BaseEntityListComponent, BaseEntityRestService, BaseEntityStore, BaseEntityTabsStore, BaseFormHostDirective, BaseFormNavigatorSingletonStore, BaseFormNavigatorStore, ENTITY_NAME_ROUTE_DATA_KEY, Entity, EntityRegistryComponent, EntityRouteRegistry, FlexDirection, FlexboxDescriptor, FormControlType, Id, NavigatorCommand, OrderByDirection, RULE_ENGINE, RouteSegments, RuleViolationsSingletonStore, SimpleEntityMapper, getEntityIds, getEntityOptions, getEnumKeyByValue, getEnumValueByKey, provideEntityRouteRegistry };
|
|
3160
3232
|
//# sourceMappingURL=processpuzzle-base-entity.mjs.map
|