ngssm-navigation 22.1.0 → 22.2.1

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,121 +1,106 @@
1
- import * as i0 from '@angular/core';
2
- import { inject, InjectionToken, Injectable, effect, untracked, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
3
- import { Router } from '@angular/router';
4
- import { NgSsmFeatureState, Store, Logger, provideReducer } from 'ngssm-store';
5
- import { __decorate } from 'tslib';
6
- import update from 'immutability-helper';
7
-
1
+ import * as i0 from "@angular/core";
2
+ import { Injectable, InjectionToken, effect, inject, makeEnvironmentProviders, provideAppInitializer, untracked } from "@angular/core";
3
+ import { Router } from "@angular/router";
4
+ import { Logger, NgSsmFeatureState, Store, provideReducer } from "ngssm-store";
5
+ import { __decorate } from "tslib";
6
+ import update from "immutability-helper";
8
7
  const selectNavigationState = (state) => state[NavigationStateSpecification.featureStateKey];
9
- const updateNavigationState = (state, command) => update(state, {
10
- [NavigationStateSpecification.featureStateKey]: command
11
- });
8
+ const updateNavigationState = (state, command) => update(state, { [NavigationStateSpecification.featureStateKey]: command });
12
9
  let NavigationStateSpecification = class NavigationStateSpecification {
13
- static featureStateKey = 'navigation-state';
14
- static initialState = {
15
- navigationLocked: false
16
- };
10
+ static featureStateKey = "navigation-state";
11
+ static initialState = { navigationLocked: false };
17
12
  };
18
- NavigationStateSpecification = __decorate([
19
- NgSsmFeatureState({
20
- featureStateKey: NavigationStateSpecification.featureStateKey,
21
- initialState: NavigationStateSpecification.initialState
22
- })
23
- ], NavigationStateSpecification);
24
-
13
+ NavigationStateSpecification = __decorate([NgSsmFeatureState({
14
+ featureStateKey: NavigationStateSpecification.featureStateKey,
15
+ initialState: NavigationStateSpecification.initialState
16
+ })], NavigationStateSpecification);
25
17
  const isNavigationLocked = () => {
26
- const state = inject(Store).state();
27
- return selectNavigationState(state).navigationLocked;
18
+ const state = inject(Store).state();
19
+ return selectNavigationState(state).navigationLocked;
28
20
  };
29
21
  const isNavigationUnLocked = () => {
30
- const state = inject(Store).state();
31
- return !selectNavigationState(state).navigationLocked;
22
+ const state = inject(Store).state();
23
+ return !selectNavigationState(state).navigationLocked;
32
24
  };
33
-
34
25
  var NavigationActionType;
35
- (function (NavigationActionType) {
36
- NavigationActionType["lockNavigation"] = "[NavigationActionType] lockNavigation";
37
- NavigationActionType["unLockNavigation"] = "[NavigationActionType] unLockNavigation";
26
+ (function(NavigationActionType) {
27
+ NavigationActionType["lockNavigation"] = "[NavigationActionType] lockNavigation";
28
+ NavigationActionType["unLockNavigation"] = "[NavigationActionType] unLockNavigation";
38
29
  })(NavigationActionType || (NavigationActionType = {}));
39
-
40
- const NGSSM_NAVIGATION_LOCKING_CONFIG = new InjectionToken('NGSSM_NAVIGATION_LOCKING_CONFIG');
41
-
42
- class NavigationReducer {
43
- processedActions = [];
44
- configs = inject(NGSSM_NAVIGATION_LOCKING_CONFIG, {
45
- optional: true
46
- });
47
- lockingActions;
48
- unlockingActions;
49
- constructor() {
50
- this.lockingActions = new Set([NavigationActionType.lockNavigation]);
51
- this.unlockingActions = new Set([NavigationActionType.unLockNavigation]);
52
- (this.configs ?? []).forEach((config) => {
53
- (config.actionsLockingNavigation ?? []).forEach((command) => this.lockingActions.add(command));
54
- (config.actionsUnLockingNavigation ?? []).forEach((command) => this.unlockingActions.add(command));
55
- });
56
- this.processedActions = [...this.lockingActions, ...this.unlockingActions];
57
- }
58
- updateState(state, action) {
59
- if (this.lockingActions.has(action.type)) {
60
- return updateNavigationState(state, {
61
- navigationLocked: { $set: true }
62
- });
63
- }
64
- if (this.unlockingActions.has(action.type)) {
65
- return updateNavigationState(state, {
66
- navigationLocked: { $set: false }
67
- });
68
- }
69
- return state;
70
- }
71
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.1", ngImport: i0, type: NavigationReducer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
72
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.1", ngImport: i0, type: NavigationReducer });
73
- }
74
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.1", ngImport: i0, type: NavigationReducer, decorators: [{
75
- type: Injectable
76
- }], ctorParameters: () => [] });
77
-
30
+ const NGSSM_NAVIGATION_LOCKING_CONFIG = new InjectionToken("NGSSM_NAVIGATION_LOCKING_CONFIG");
31
+ var NavigationReducer = class NavigationReducer {
32
+ processedActions = [];
33
+ configs = inject(NGSSM_NAVIGATION_LOCKING_CONFIG, { optional: true });
34
+ lockingActions;
35
+ unlockingActions;
36
+ constructor() {
37
+ this.lockingActions = /* @__PURE__ */ new Set([NavigationActionType.lockNavigation]);
38
+ this.unlockingActions = /* @__PURE__ */ new Set([NavigationActionType.unLockNavigation]);
39
+ (this.configs ?? []).forEach((config) => {
40
+ (config.actionsLockingNavigation ?? []).forEach((command) => this.lockingActions.add(command));
41
+ (config.actionsUnLockingNavigation ?? []).forEach((command) => this.unlockingActions.add(command));
42
+ });
43
+ this.processedActions = [...this.lockingActions, ...this.unlockingActions];
44
+ }
45
+ updateState(state, action) {
46
+ if (this.lockingActions.has(action.type)) return updateNavigationState(state, { navigationLocked: { $set: true } });
47
+ if (this.unlockingActions.has(action.type)) return updateNavigationState(state, { navigationLocked: { $set: false } });
48
+ return state;
49
+ }
50
+ static ɵfac = i0.ɵɵngDeclareFactory({
51
+ minVersion: "12.0.0",
52
+ version: "22.2.0",
53
+ ngImport: i0,
54
+ type: NavigationReducer,
55
+ deps: [],
56
+ target: i0.ɵɵFactoryTarget.Injectable
57
+ });
58
+ static ɵprov = i0.ɵɵngDeclareInjectable({
59
+ minVersion: "12.0.0",
60
+ version: "22.2.0",
61
+ ngImport: i0,
62
+ type: NavigationReducer
63
+ });
64
+ };
65
+ i0.ɵɵngDeclareClassMetadata({
66
+ minVersion: "12.0.0",
67
+ version: "22.2.0",
68
+ ngImport: i0,
69
+ type: NavigationReducer,
70
+ decorators: [{ type: Injectable }],
71
+ ctorParameters: () => []
72
+ });
78
73
  const routingEffectInitializer = async () => {
79
- const store = inject(Store);
80
- const router = inject(Router);
81
- const logger = inject(Logger);
82
- effect(() => {
83
- const action = store.processedAction();
84
- const routingAction = action;
85
- if (routingAction.navigate) {
86
- logger.information(`[Routing Effect] Processing action ${action.type}`);
87
- try {
88
- untracked(() => routingAction.navigate?.(store.state(), router));
89
- logger.information(`[Routing Effect] Successfully navigated for action ${action.type}`);
90
- }
91
- catch (error) {
92
- logger.error(`[Routing Effect] Error while processing action ${action.type}: ${error}`);
93
- }
94
- }
95
- });
96
- return true;
74
+ const store = inject(Store);
75
+ const router = inject(Router);
76
+ const logger = inject(Logger);
77
+ effect(() => {
78
+ const action = store.processedAction();
79
+ const routingAction = action;
80
+ if (routingAction.navigate) {
81
+ logger.information(`[Routing Effect] Processing action ${action.type}`);
82
+ try {
83
+ untracked(() => routingAction.navigate?.(store.state(), router));
84
+ logger.information(`[Routing Effect] Successfully navigated for action ${action.type}`);
85
+ } catch (error) {
86
+ logger.error(`[Routing Effect] Error while processing action ${action.type}: ${error}`);
87
+ }
88
+ }
89
+ });
90
+ return true;
97
91
  };
98
-
99
92
  const initializeNavigation = () => {
100
- inject(Router).config.forEach((route) => {
101
- route.canDeactivate = [isNavigationUnLocked, ...(route.canDeactivate ?? [])];
102
- });
93
+ inject(Router).config.forEach((route) => {
94
+ route.canDeactivate = [isNavigationUnLocked, ...route.canDeactivate ?? []];
95
+ });
103
96
  };
104
97
  const provideNgssmNavigation = () => {
105
- return makeEnvironmentProviders([
106
- provideReducer(NavigationReducer),
107
- provideAppInitializer(initializeNavigation),
108
- provideAppInitializer(routingEffectInitializer)
109
- ]);
98
+ return makeEnvironmentProviders([
99
+ provideReducer(NavigationReducer),
100
+ provideAppInitializer(initializeNavigation),
101
+ provideAppInitializer(routingEffectInitializer)
102
+ ]);
110
103
  };
111
-
112
- /*
113
- * Public API Surface of ngssm-navigation
114
- */
115
-
116
- /**
117
- * Generated bundle index. Do not edit.
118
- */
119
-
120
104
  export { NGSSM_NAVIGATION_LOCKING_CONFIG, NavigationActionType, NavigationStateSpecification, isNavigationLocked, isNavigationUnLocked, provideNgssmNavigation, routingEffectInitializer, selectNavigationState, updateNavigationState };
121
- //# sourceMappingURL=ngssm-navigation.mjs.map
105
+
106
+ //# sourceMappingURL=ngssm-navigation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ngssm-navigation.mjs","sources":["../../../projects/ngssm-navigation/src/lib/state/navigation.state.ts","../../../projects/ngssm-navigation/src/lib/guards/navigation-guards.ts","../../../projects/ngssm-navigation/src/lib/actions/navigation-action-type.ts","../../../projects/ngssm-navigation/src/lib/model/navigation-locking-config.ts","../../../projects/ngssm-navigation/src/lib/reducers/navigation.reducer.ts","../../../projects/ngssm-navigation/src/lib/routing/routing-effect.ts","../../../projects/ngssm-navigation/src/lib/provide-ngssm-navigation.ts","../../../projects/ngssm-navigation/src/public-api.ts","../../../projects/ngssm-navigation/src/ngssm-navigation.ts"],"sourcesContent":["import update, { Spec } from 'immutability-helper';\n\nimport { NgSsmFeatureState, State } from 'ngssm-store';\n\nexport const selectNavigationState = (state: State): NavigationState =>\n state[NavigationStateSpecification.featureStateKey] as NavigationState;\n\nexport const updateNavigationState = (state: State, command: Spec<NavigationState, never>): State =>\n update(state, {\n [NavigationStateSpecification.featureStateKey]: command\n });\n\nexport interface NavigationState {\n navigationLocked: boolean;\n}\n\n@NgSsmFeatureState({\n featureStateKey: NavigationStateSpecification.featureStateKey,\n initialState: NavigationStateSpecification.initialState\n})\nexport class NavigationStateSpecification {\n public static readonly featureStateKey = 'navigation-state';\n public static readonly initialState: NavigationState = {\n navigationLocked: false\n };\n}\n","import { inject } from '@angular/core';\n\nimport { Store } from 'ngssm-store';\n\nimport { selectNavigationState } from '../state';\n\nexport const isNavigationLocked = (): boolean => {\n const state = inject(Store).state();\n return selectNavigationState(state).navigationLocked;\n};\n\nexport const isNavigationUnLocked = (): boolean => {\n const state = inject(Store).state();\n return !selectNavigationState(state).navigationLocked;\n};\n","export enum NavigationActionType {\n lockNavigation = '[NavigationActionType] lockNavigation',\n unLockNavigation = '[NavigationActionType] unLockNavigation'\n}\n","import { InjectionToken } from '@angular/core';\n\nexport interface NavigationLockingConfig {\n actionsLockingNavigation?: string[];\n actionsUnLockingNavigation?: string[];\n}\n\nexport const NGSSM_NAVIGATION_LOCKING_CONFIG = new InjectionToken<NavigationLockingConfig>('NGSSM_NAVIGATION_LOCKING_CONFIG');\n","import { inject, Injectable } from '@angular/core';\n\nimport { Reducer, State, Action } from 'ngssm-store';\n\nimport { NavigationActionType } from '../actions';\nimport { NavigationLockingConfig, NGSSM_NAVIGATION_LOCKING_CONFIG } from '../model';\nimport { updateNavigationState } from '../state';\n\n@Injectable()\nexport class NavigationReducer implements Reducer {\n public readonly processedActions: string[] = [];\n\n private readonly configs: NavigationLockingConfig[] | null = inject(NGSSM_NAVIGATION_LOCKING_CONFIG, {\n optional: true\n }) as unknown as NavigationLockingConfig[];\n\n private readonly lockingActions: Set<string>;\n private readonly unlockingActions: Set<string>;\n\n constructor() {\n this.lockingActions = new Set<string>([NavigationActionType.lockNavigation]);\n this.unlockingActions = new Set<string>([NavigationActionType.unLockNavigation]);\n\n (this.configs ?? []).forEach((config) => {\n (config.actionsLockingNavigation ?? []).forEach((command) => this.lockingActions.add(command));\n (config.actionsUnLockingNavigation ?? []).forEach((command) => this.unlockingActions.add(command));\n });\n\n this.processedActions = [...this.lockingActions, ...this.unlockingActions];\n }\n\n public updateState(state: State, action: Action): State {\n if (this.lockingActions.has(action.type)) {\n return updateNavigationState(state, {\n navigationLocked: { $set: true }\n });\n }\n\n if (this.unlockingActions.has(action.type)) {\n return updateNavigationState(state, {\n navigationLocked: { $set: false }\n });\n }\n\n return state;\n }\n}\n","import { effect, inject, untracked } from '@angular/core';\nimport { Router } from '@angular/router';\n\nimport { Logger, Store } from 'ngssm-store';\n\nimport { RoutingAction } from './routing-action';\n\nexport const routingEffectInitializer = async () => {\n const store = inject(Store);\n const router = inject(Router);\n const logger = inject(Logger);\n\n effect(() => {\n const action = store.processedAction();\n const routingAction = action as RoutingAction;\n if (routingAction.navigate) {\n logger.information(`[Routing Effect] Processing action ${action.type}`);\n try {\n untracked(() => routingAction.navigate?.(store.state(), router));\n logger.information(`[Routing Effect] Successfully navigated for action ${action.type}`);\n } catch (error) {\n logger.error(`[Routing Effect] Error while processing action ${action.type}: ${error}`);\n }\n }\n });\n\n return true;\n};\n","import { EnvironmentProviders, makeEnvironmentProviders, inject, provideAppInitializer } from '@angular/core';\nimport { Router } from '@angular/router';\n\nimport { provideReducer } from 'ngssm-store';\n\nimport { isNavigationUnLocked } from './guards';\nimport { NavigationReducer } from './reducers/navigation.reducer';\nimport { routingEffectInitializer } from './routing';\n\nconst initializeNavigation = () => {\n inject(Router).config.forEach((route) => {\n route.canDeactivate = [isNavigationUnLocked, ...(route.canDeactivate ?? [])];\n });\n};\n\nexport const provideNgssmNavigation = (): EnvironmentProviders => {\n return makeEnvironmentProviders([\n provideReducer(NavigationReducer),\n provideAppInitializer(initializeNavigation),\n provideAppInitializer(routingEffectInitializer)\n ]);\n};\n","/*\n * Public API Surface of ngssm-navigation\n */\n\nexport * from './lib/provide-ngssm-navigation';\nexport * from './lib/state';\nexport * from './lib/guards';\nexport * from './lib/actions';\nexport * from './lib/model';\nexport * from './lib/routing';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAIO,MAAM,qBAAqB,GAAG,CAAC,KAAY,KAChD,KAAK,CAAC,4BAA4B,CAAC,eAAe;AAE7C,MAAM,qBAAqB,GAAG,CAAC,KAAY,EAAE,OAAqC,KACvF,MAAM,CAAC,KAAK,EAAE;AACZ,IAAA,CAAC,4BAA4B,CAAC,eAAe,GAAG;AACjD,CAAA;AAUI,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B,CAAA;AAChC,IAAA,OAAgB,eAAe,GAAG,kBAAkB;IACpD,OAAgB,YA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 {"version":3,"file":"ngssm-navigation.mjs","names":[],"sources":["../../../projects/ngssm-navigation/src/lib/state/navigation.state.ts","../../../projects/ngssm-navigation/src/lib/guards/navigation-guards.ts","../../../projects/ngssm-navigation/src/lib/actions/navigation-action-type.ts","../../../projects/ngssm-navigation/src/lib/model/navigation-locking-config.ts","../../../projects/ngssm-navigation/src/lib/reducers/navigation.reducer.ts","../../../projects/ngssm-navigation/src/lib/routing/routing-effect.ts","../../../projects/ngssm-navigation/src/lib/provide-ngssm-navigation.ts"],"sourcesContent":["import update, { Spec } from 'immutability-helper';\n\nimport { NgSsmFeatureState, State } from 'ngssm-store';\n\nexport const selectNavigationState = (state: State): NavigationState =>\n state[NavigationStateSpecification.featureStateKey] as NavigationState;\n\nexport const updateNavigationState = (state: State, command: Spec<NavigationState, never>): State =>\n update(state, {\n [NavigationStateSpecification.featureStateKey]: command\n });\n\nexport interface NavigationState {\n navigationLocked: boolean;\n}\n\n@NgSsmFeatureState({\n featureStateKey: NavigationStateSpecification.featureStateKey,\n initialState: NavigationStateSpecification.initialState\n})\nexport class NavigationStateSpecification {\n public static readonly featureStateKey = 'navigation-state';\n public static readonly initialState: NavigationState = {\n navigationLocked: false\n };\n}\n","import { inject } from '@angular/core';\n\nimport { Store } from 'ngssm-store';\n\nimport { selectNavigationState } from '../state';\n\nexport const isNavigationLocked = (): boolean => {\n const state = inject(Store).state();\n return selectNavigationState(state).navigationLocked;\n};\n\nexport const isNavigationUnLocked = (): boolean => {\n const state = inject(Store).state();\n return !selectNavigationState(state).navigationLocked;\n};\n","export enum NavigationActionType {\n lockNavigation = '[NavigationActionType] lockNavigation',\n unLockNavigation = '[NavigationActionType] unLockNavigation'\n}\n","import { InjectionToken } from '@angular/core';\n\nexport interface NavigationLockingConfig {\n actionsLockingNavigation?: string[];\n actionsUnLockingNavigation?: string[];\n}\n\nexport const NGSSM_NAVIGATION_LOCKING_CONFIG = new InjectionToken<NavigationLockingConfig>('NGSSM_NAVIGATION_LOCKING_CONFIG');\n","import { inject, Injectable } from '@angular/core';\n\nimport { Reducer, State, Action } from 'ngssm-store';\n\nimport { NavigationActionType } from '../actions';\nimport { NavigationLockingConfig, NGSSM_NAVIGATION_LOCKING_CONFIG } from '../model';\nimport { updateNavigationState } from '../state';\n\n@Injectable()\nexport class NavigationReducer implements Reducer {\n public readonly processedActions: string[] = [];\n\n private readonly configs: NavigationLockingConfig[] | null = inject(NGSSM_NAVIGATION_LOCKING_CONFIG, {\n optional: true\n }) as unknown as NavigationLockingConfig[];\n\n private readonly lockingActions: Set<string>;\n private readonly unlockingActions: Set<string>;\n\n constructor() {\n this.lockingActions = new Set<string>([NavigationActionType.lockNavigation]);\n this.unlockingActions = new Set<string>([NavigationActionType.unLockNavigation]);\n\n (this.configs ?? []).forEach((config) => {\n (config.actionsLockingNavigation ?? []).forEach((command) => this.lockingActions.add(command));\n (config.actionsUnLockingNavigation ?? []).forEach((command) => this.unlockingActions.add(command));\n });\n\n this.processedActions = [...this.lockingActions, ...this.unlockingActions];\n }\n\n public updateState(state: State, action: Action): State {\n if (this.lockingActions.has(action.type)) {\n return updateNavigationState(state, {\n navigationLocked: { $set: true }\n });\n }\n\n if (this.unlockingActions.has(action.type)) {\n return updateNavigationState(state, {\n navigationLocked: { $set: false }\n });\n }\n\n return state;\n }\n}\n","import { effect, inject, untracked } from '@angular/core';\nimport { Router } from '@angular/router';\n\nimport { Logger, Store } from 'ngssm-store';\n\nimport { RoutingAction } from './routing-action';\n\nexport const routingEffectInitializer = async () => {\n const store = inject(Store);\n const router = inject(Router);\n const logger = inject(Logger);\n\n effect(() => {\n const action = store.processedAction();\n const routingAction = action as RoutingAction;\n if (routingAction.navigate) {\n logger.information(`[Routing Effect] Processing action ${action.type}`);\n try {\n untracked(() => routingAction.navigate?.(store.state(), router));\n logger.information(`[Routing Effect] Successfully navigated for action ${action.type}`);\n } catch (error) {\n logger.error(`[Routing Effect] Error while processing action ${action.type}: ${error}`);\n }\n }\n });\n\n return true;\n};\n","import { EnvironmentProviders, makeEnvironmentProviders, inject, provideAppInitializer } from '@angular/core';\nimport { Router } from '@angular/router';\n\nimport { provideReducer } from 'ngssm-store';\n\nimport { isNavigationUnLocked } from './guards';\nimport { NavigationReducer } from './reducers/navigation.reducer';\nimport { routingEffectInitializer } from './routing';\n\nconst initializeNavigation = () => {\n inject(Router).config.forEach((route) => {\n route.canDeactivate = [isNavigationUnLocked, ...(route.canDeactivate ?? [])];\n });\n};\n\nexport const provideNgssmNavigation = (): EnvironmentProviders => {\n return makeEnvironmentProviders([\n provideReducer(NavigationReducer),\n provideAppInitializer(initializeNavigation),\n provideAppInitializer(routingEffectInitializer)\n ]);\n};\n"],"mappings":";;;;;;AAIA,MAAa,yBAAyB,UACpC,MAAM,6BAA6B;AAErC,MAAa,yBAAyB,OAAc,YAClD,OAAO,OAAO,GACX,6BAA6B,kBAAkB,QACjD,CAAA;AAUI,IAAM,+BAAN,MAAM,6BAA4B;CAChC,OAAgB,kBAAkB;CAClC,OAAgB,eAAgC,EACrD,kBAAkB,MACnB;;AAJU,+BAA4B,WAAA,CAJxC,kBAAkB;CACjB,iBAAiB,6BAA6B;CAC9C,cAAc,6BAA6B;AAC5C,CAAA,CACY,GAAA,4BAA4B;ACdzC,MAAa,2BAAmC;CAC9C,MAAM,QAAQ,OAAO,KAAK,CAAC,CAAC,MAAK;CACjC,OAAO,sBAAsB,KAAK,CAAC,CAAC;AACtC;AAEA,MAAa,6BAAqC;CAChD,MAAM,QAAQ,OAAO,KAAK,CAAC,CAAC,MAAK;CACjC,OAAO,CAAC,sBAAsB,KAAK,CAAC,CAAC;AACvC;ACdA,IAAY;CAAZ,SAAY,sBAAoB;CAC9B,qBAAA,oBAAA;CACA,qBAAA,sBAAA;AACF,EAAA,CAHY,yBAAA,uBAAoB,CAAA,EAAA;ACOhC,MAAa,kCAAkC,IAAI,eAAwC,iCAAiC;ACE5H,IAAa,oBAAb,MAAa,kBAAiB;CACZ,mBAA6B,CAAA;CAE5B,UAA4C,OAAO,iCA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E5B,aAAY;EACV,MAAM,SAAS,MAAM,gBAAe;EACpC,MAAM,gBAAgB;EACtB,IAAI,cAAc,UAAU;GAC1B,OAAO,YAAY,sCAAsC,OAAO,MAAM;GACtE,IAAI;IACF,gBAAgB,cAAc,WAAW,MAAM,MAAK,GAAI,MAAM,CAAC;IAC/D,OAAO,YAAY,sDAAsD,OAAO,MAAM;GACxF,SAAS,OAAO;IACd,OAAO,MAAM,kDAAkD,OAAO,KAAI,IAAK,OAAO;GACxF;EACF;CACF,CAAC;CAED,OAAO;AACT;AClBA,MAAM,6BAA4B;CAChC,OAAO,MAAM,CAAC,CAAC,OAAO,SAAS,UAAS;EACtC,MAAM,gBAAgB,CAAC,sBAAsB,GAAI,MAAM,iBAAiB,CAAA,CAAG;CAC7E,CAAC;AACH;AAEA,MAAa,+BAAoD;CAC/D,OAAO,yBAAyB;EAC9B,eAAe,iBAAiB;EAChC,sBAAsB,oBAAoB;EAC1C,sBAAsB,wBAAwB;CAC/C,CAAA;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngssm-navigation",
3
- "version": "22.1.0",
3
+ "version": "22.2.1",
4
4
  "description": "NgSsm - Helpers to control angular navigation.",
5
5
  "author": "Lion Marc",
6
6
  "license": "MIT",
@@ -1,39 +1,29 @@
1
- import { EnvironmentProviders, InjectionToken } from '@angular/core';
2
- import { Spec } from 'immutability-helper';
3
- import { State } from 'ngssm-store';
4
- import { Router } from '@angular/router';
5
-
6
- declare const provideNgssmNavigation: () => EnvironmentProviders;
7
-
8
- declare const selectNavigationState: (state: State) => NavigationState;
9
- declare const updateNavigationState: (state: State, command: Spec<NavigationState, never>) => State;
10
- interface NavigationState {
11
- navigationLocked: boolean;
1
+ import { EnvironmentProviders, InjectionToken } from "@angular/core";
2
+ import { Spec } from "immutability-helper";
3
+ import { State } from "ngssm-store";
4
+ import { Router } from "@angular/router";
5
+ export declare const provideNgssmNavigation: () => EnvironmentProviders;
6
+ export declare const selectNavigationState: (state: State) => NavigationState;
7
+ export declare const updateNavigationState: (state: State, command: Spec<NavigationState, never>) => State;
8
+ export interface NavigationState {
9
+ navigationLocked: boolean;
12
10
  }
13
- declare class NavigationStateSpecification {
14
- static readonly featureStateKey = "navigation-state";
15
- static readonly initialState: NavigationState;
11
+ export declare class NavigationStateSpecification {
12
+ static readonly featureStateKey = "navigation-state";
13
+ static readonly initialState: NavigationState;
16
14
  }
17
-
18
- declare const isNavigationLocked: () => boolean;
19
- declare const isNavigationUnLocked: () => boolean;
20
-
21
- declare enum NavigationActionType {
22
- lockNavigation = "[NavigationActionType] lockNavigation",
23
- unLockNavigation = "[NavigationActionType] unLockNavigation"
15
+ export declare const isNavigationLocked: () => boolean;
16
+ export declare const isNavigationUnLocked: () => boolean;
17
+ export declare enum NavigationActionType {
18
+ lockNavigation = "[NavigationActionType] lockNavigation",
19
+ unLockNavigation = "[NavigationActionType] unLockNavigation"
24
20
  }
25
-
26
- interface NavigationLockingConfig {
27
- actionsLockingNavigation?: string[];
28
- actionsUnLockingNavigation?: string[];
21
+ export interface NavigationLockingConfig {
22
+ actionsLockingNavigation?: string[];
23
+ actionsUnLockingNavigation?: string[];
29
24
  }
30
- declare const NGSSM_NAVIGATION_LOCKING_CONFIG: InjectionToken<NavigationLockingConfig>;
31
-
32
- interface RoutingAction {
33
- navigate?(state: State, router: Router): void;
25
+ export declare const NGSSM_NAVIGATION_LOCKING_CONFIG: InjectionToken<NavigationLockingConfig>;
26
+ export interface RoutingAction {
27
+ navigate?(state: State, router: Router): void;
34
28
  }
35
-
36
- declare const routingEffectInitializer: () => Promise<boolean>;
37
-
38
- export { NGSSM_NAVIGATION_LOCKING_CONFIG, NavigationActionType, NavigationStateSpecification, isNavigationLocked, isNavigationUnLocked, provideNgssmNavigation, routingEffectInitializer, selectNavigationState, updateNavigationState };
39
- export type { NavigationLockingConfig, NavigationState, RoutingAction };
29
+ export declare const routingEffectInitializer: () => Promise<boolean>;