ui5-lib-guard-router 1.6.2 → 1.7.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.
Files changed (67) hide show
  1. package/{dist/.ui5 → .ui5}/build-manifest.json +56 -8
  2. package/CHANGELOG.md +197 -0
  3. package/README.md +695 -327
  4. package/dist/index.d.ts +9 -5
  5. package/dist/resources/ui5/guard/router/.library +1 -1
  6. package/dist/resources/ui5/guard/router/GuardConfig-dbg.js +222 -0
  7. package/dist/resources/ui5/guard/router/GuardConfig-dbg.js.map +1 -0
  8. package/dist/resources/ui5/guard/router/GuardConfig.d.ts +89 -0
  9. package/dist/resources/ui5/guard/router/GuardConfig.d.ts.map +1 -0
  10. package/dist/resources/ui5/guard/router/GuardConfig.js +2 -0
  11. package/dist/resources/ui5/guard/router/GuardConfig.js.map +1 -0
  12. package/dist/resources/ui5/guard/router/GuardModules-dbg.js +253 -0
  13. package/dist/resources/ui5/guard/router/GuardModules-dbg.js.map +1 -0
  14. package/dist/resources/ui5/guard/router/GuardModules.d.ts +72 -0
  15. package/dist/resources/ui5/guard/router/GuardModules.d.ts.map +1 -0
  16. package/dist/resources/ui5/guard/router/GuardModules.js +2 -0
  17. package/dist/resources/ui5/guard/router/GuardModules.js.map +1 -0
  18. package/dist/resources/ui5/guard/router/GuardPipeline-dbg.js +125 -122
  19. package/dist/resources/ui5/guard/router/GuardPipeline-dbg.js.map +1 -1
  20. package/dist/resources/ui5/guard/router/GuardPipeline.d.ts +45 -26
  21. package/dist/resources/ui5/guard/router/GuardPipeline.d.ts.map +1 -1
  22. package/dist/resources/ui5/guard/router/GuardPipeline.js +1 -1
  23. package/dist/resources/ui5/guard/router/GuardPipeline.js.map +1 -1
  24. package/dist/resources/ui5/guard/router/NavigationOutcome-dbg.js +3 -3
  25. package/dist/resources/ui5/guard/router/NavigationOutcome-dbg.js.map +1 -1
  26. package/dist/resources/ui5/guard/router/NavigationOutcome.d.ts +3 -3
  27. package/dist/resources/ui5/guard/router/NavigationOutcome.d.ts.map +1 -1
  28. package/dist/resources/ui5/guard/router/NavigationOutcome.js.map +1 -1
  29. package/dist/resources/ui5/guard/router/PatternTree-dbg.js +156 -0
  30. package/dist/resources/ui5/guard/router/PatternTree-dbg.js.map +1 -0
  31. package/dist/resources/ui5/guard/router/PatternTree.d.ts +71 -0
  32. package/dist/resources/ui5/guard/router/PatternTree.d.ts.map +1 -0
  33. package/dist/resources/ui5/guard/router/PatternTree.js +2 -0
  34. package/dist/resources/ui5/guard/router/PatternTree.js.map +1 -0
  35. package/dist/resources/ui5/guard/router/RouteMeta-dbg.js +84 -0
  36. package/dist/resources/ui5/guard/router/RouteMeta-dbg.js.map +1 -0
  37. package/dist/resources/ui5/guard/router/RouteMeta.d.ts +33 -0
  38. package/dist/resources/ui5/guard/router/RouteMeta.d.ts.map +1 -0
  39. package/dist/resources/ui5/guard/router/RouteMeta.js +2 -0
  40. package/dist/resources/ui5/guard/router/RouteMeta.js.map +1 -0
  41. package/dist/resources/ui5/guard/router/Router-dbg.js +900 -1033
  42. package/dist/resources/ui5/guard/router/Router-dbg.js.map +1 -1
  43. package/dist/resources/ui5/guard/router/Router.d.ts +362 -212
  44. package/dist/resources/ui5/guard/router/Router.d.ts.map +1 -1
  45. package/dist/resources/ui5/guard/router/Router.js +1 -1
  46. package/dist/resources/ui5/guard/router/Router.js.map +1 -1
  47. package/dist/resources/ui5/guard/router/library-dbg.js +1 -1
  48. package/dist/resources/ui5/guard/router/library-dbg.js.map +1 -1
  49. package/dist/resources/ui5/guard/router/library-preload.js +8 -4
  50. package/dist/resources/ui5/guard/router/library-preload.js.map +1 -1
  51. package/dist/resources/ui5/guard/router/library.js +1 -1
  52. package/dist/resources/ui5/guard/router/library.js.map +1 -1
  53. package/dist/resources/ui5/guard/router/manifest.json +5 -2
  54. package/dist/resources/ui5/guard/router/types-dbg.js.map +1 -1
  55. package/dist/resources/ui5/guard/router/types.d.ts +94 -39
  56. package/dist/resources/ui5/guard/router/types.d.ts.map +1 -1
  57. package/package.json +10 -6
  58. package/src/GuardConfig.ts +272 -0
  59. package/src/GuardModules.ts +249 -0
  60. package/src/GuardPipeline.ts +158 -129
  61. package/src/NavigationOutcome.ts +3 -3
  62. package/src/PatternTree.ts +145 -0
  63. package/src/RouteMeta.ts +82 -0
  64. package/src/Router.ts +1110 -1150
  65. package/src/manifest.json +5 -2
  66. package/src/types.ts +79 -22
  67. package/tsconfig.json +0 -11
package/src/manifest.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "id": "ui5.guard.router",
5
5
  "type": "library",
6
6
  "applicationVersion": {
7
- "version": "1.6.2"
7
+ "version": "1.7.1"
8
8
  },
9
9
  "title": "UI5 Router extension with async navigation guards",
10
10
  "description": "Extends sap.m.routing.Router with async navigation guards, running before route matching begins."
@@ -18,12 +18,15 @@
18
18
  }
19
19
  },
20
20
  "sap.ui5": {
21
+ "library": {
22
+ "i18n": false
23
+ },
21
24
  "contentDensities": {
22
25
  "compact": true,
23
26
  "cozy": true
24
27
  },
25
28
  "dependencies": {
26
- "minUI5Version": "1.144.0",
29
+ "minUI5Version": "1.136.0",
27
30
  "libs": {
28
31
  "sap.ui.core": {},
29
32
  "sap.m": {}
package/src/types.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type Event from "sap/ui/base/Event";
2
2
  import type MobileRouter from "sap/m/routing/Router";
3
3
  import type { ComponentTargetParameters, RouteInfo } from "sap/ui/core/routing/Router";
4
+ import type UIComponent from "sap/ui/core/UIComponent";
4
5
  import type NavigationOutcome from "./NavigationOutcome";
5
6
 
6
7
  /**
@@ -26,11 +27,17 @@ export interface GuardRedirect {
26
27
  *
27
28
  * - `true`: Allow navigation to proceed.
28
29
  * - `false`: Block navigation. For programmatic `navTo()`, no hash change
29
- * or history entry occurs. For browser-initiated navigation (back/forward,
30
- * URL bar), the hash is restored via `replaceHash()` (best-effort repair).
31
- * - `string`: Redirect to this route name. For programmatic `navTo()`,
32
- * navigation goes directly to the target with no intermediate history entry.
33
- * For browser-initiated navigation, the redirect replaces the current entry.
30
+ * or history entry occurs. A step through the browser history (back,
31
+ * forward) is taken back, which leaves the history as it was. Any other
32
+ * hash change (URL bar, link) has its history entry replaced with the
33
+ * previous hash.
34
+ * - `string`: Redirect to this route name. For programmatic `navTo()`, the
35
+ * guarded hash is never written: the target is, the way the call asked
36
+ * for (a new history entry unless it passed `bReplace`), so that Back
37
+ * returns to where the navigation started. A hash change that has reached
38
+ * the browser has its history entry replaced with the target. A redirect
39
+ * to the route that is displayed settles as `Redirected` without matching
40
+ * the route again.
34
41
  * - `GuardRedirect`: Redirect with route name, parameters, and optional
35
42
  * component target info. Same history semantics as string redirect.
36
43
  *
@@ -44,7 +51,13 @@ export type GuardResult = boolean | string | GuardRedirect;
44
51
  * @since 1.0.1
45
52
  */
46
53
  export interface GuardContext {
47
- /** Target route name (empty string if no route matched / bypassed) @since 1.0.1 */
54
+ /**
55
+ * Target route name (empty string if no route matched / bypassed): the first route that
56
+ * matches the hash. The guards of greedy routes (`greedy: true`) that match it as well run
57
+ * after those of this route, with the same context.
58
+ *
59
+ * @since 1.0.1
60
+ */
48
61
  toRoute: string;
49
62
  /** Raw hash being navigated to @since 1.0.1 */
50
63
  toHash: string;
@@ -56,7 +69,13 @@ export interface GuardContext {
56
69
  * @since 1.0.1
57
70
  */
58
71
  toArguments: RouteInfo["arguments"];
59
- /** Current route name (empty string on initial navigation) @since 1.0.1 */
72
+ /**
73
+ * Current route name (empty string on initial navigation): the first route that matches the
74
+ * current hash. The leave guards of greedy routes that match it as well run after those of
75
+ * this route, with the same context.
76
+ *
77
+ * @since 1.0.1
78
+ */
60
79
  fromRoute: string;
61
80
  /** Current hash @since 1.0.1 */
62
81
  fromHash: string;
@@ -93,6 +112,14 @@ export interface GuardContext {
93
112
  * @since 1.6.0
94
113
  */
95
114
  fromMeta: Readonly<Record<string, unknown>>;
115
+ /**
116
+ * Component that owns the router. Gives guards without a closure over the
117
+ * component (e.g. manifest-declared guards) access to its models and services.
118
+ * `undefined` when the router has no owner.
119
+ *
120
+ * @since 1.7.0
121
+ */
122
+ ownerComponent?: UIComponent;
96
123
  }
97
124
 
98
125
  /**
@@ -140,7 +167,8 @@ export interface RouteGuardConfig {
140
167
  *
141
168
  * - `"ignore"`: Register silently.
142
169
  * - `"warn"`: Log a warning and still register (default).
143
- * - `"throw"`: Throw synchronously; guard is not registered.
170
+ * - `"throw"`: Throw synchronously; guard is not registered. A manifest guard has no caller
171
+ * to catch the error, so it is logged instead and the guard is skipped; the router still starts.
144
172
  *
145
173
  * @since 1.5.0
146
174
  */
@@ -179,15 +207,29 @@ export type GuardLoading = "block" | "lazy";
179
207
  */
180
208
  export type Inheritance = "none" | "pattern-tree";
181
209
 
210
+ /**
211
+ * Log level for the router's log component `ui5.guard.router.Router`.
212
+ *
213
+ * Raises the level only: a more verbose level that is set already, e.g. by
214
+ * `sap-ui-log-level`, is kept. The level applies to the whole page, so with
215
+ * several routers the most verbose one wins; `destroy()` does not restore it.
216
+ *
217
+ * @since 1.7.0
218
+ */
219
+ export type GuardRouterLogLevel = "error" | "warning" | "info" | "debug";
220
+
182
221
  /**
183
222
  * Per-route guard declaration in the manifest.
184
223
  *
185
224
  * @since 1.5.0
186
225
  */
187
226
  export interface ManifestRouteGuardConfig {
188
- /** Enter guard module paths (dot notation, relative to component namespace). */
227
+ /**
228
+ * Enter guard module paths: in dot notation relative to the component namespace, or absolute
229
+ * with a `module:` prefix. An optional `#export` suffix picks one export of the module.
230
+ */
189
231
  enter?: string[];
190
- /** Leave guard module paths (dot notation, relative to component namespace). */
232
+ /** Leave guard module paths, in the same forms as `enter`. */
191
233
  leave?: string[];
192
234
  }
193
235
 
@@ -219,14 +261,16 @@ export interface GuardRouterOptions {
219
261
  /**
220
262
  * Strategy for loading manifest-declared guard modules. Defaults to `"lazy"`.
221
263
  *
222
- * In `"lazy"` mode, if the preload hint has not completed before the first
223
- * navigation, multi-export module guards beyond the first are appended after
224
- * any imperatively registered guards. Use `"block"` for strict declaration-order
225
- * guarantees.
264
+ * In `"lazy"` mode, a module already cached at `initialize()` has its guards
265
+ * registered one by one, in order. Otherwise one wrapper at the module's
266
+ * position loads it on first navigation, runs all of its guards in order and
267
+ * keeps them for later navigations. Either way the declared order holds.
226
268
  */
227
269
  guardLoading?: GuardLoading;
228
270
  /** Strategy for inheriting guards and metadata down the URL pattern tree. Defaults to `"none"`. @since 1.6.0 */
229
271
  inheritance?: Inheritance;
272
+ /** Log level for the router's log component. Leaves `sap/base/Log` untouched when not set. @since 1.7.0 */
273
+ logLevel?: GuardRouterLogLevel;
230
274
  /** Declarative guard declarations indexed by route name or `"*"` for globals. */
231
275
  guards?: ManifestGuardConfig;
232
276
  /**
@@ -239,6 +283,20 @@ export interface GuardRouterOptions {
239
283
  routeMeta?: Record<string, Record<string, unknown>>;
240
284
  }
241
285
 
286
+ /**
287
+ * Router constructor config: the standard `sap.m.routing.Router` config
288
+ * (`async`, `controlId`, `viewType`, ...) plus the guard router options.
289
+ *
290
+ * @since 1.7.0
291
+ */
292
+ export interface GuardRouterConfig {
293
+ /** Load views and targets asynchronously, as `sap.m.routing.Router` recommends. */
294
+ async?: boolean;
295
+ /** Guard router options, set in the manifest under `sap.ui5.routing.config.guardRouter`. */
296
+ guardRouter?: GuardRouterOptions;
297
+ [key: string]: unknown;
298
+ }
299
+
242
300
  /**
243
301
  * Per-navigation overrides for programmatic `navTo()` calls.
244
302
  *
@@ -268,8 +326,9 @@ export interface NavigationResult {
268
326
  route: string;
269
327
  /**
270
328
  * Hash associated with the settled state.
271
- * For blocked, error, or cancelled navigations this is usually the hash the router stayed on;
272
- * for committed, bypassed, and redirected navigations it is the hash from the winning path.
329
+ * For blocked, error, or cancelled navigations it is the hash the router stayed on (`""` before
330
+ * the first commit); for committed, bypassed, and redirected navigations it is the hash from the
331
+ * winning path.
273
332
  */
274
333
  hash: string;
275
334
  /**
@@ -283,11 +342,8 @@ export interface NavigationResult {
283
342
 
284
343
  /**
285
344
  * Event object passed to `attachNavigationSettled` handlers.
286
- * Parameters are identical to {@link NavigationResult}.
287
- *
288
- * The source type uses {@link GuardRouter} (the public interface) rather
289
- * than the concrete Router class to avoid a circular import between
290
- * `types.ts` and `Router.ts`.
345
+ * Parameters are identical to {@link NavigationResult}. The event source is typed as the
346
+ * public {@link GuardRouter} interface.
291
347
  *
292
348
  * @since 1.3.0
293
349
  */
@@ -416,7 +472,8 @@ export interface GuardRouter extends MobileRouter {
416
472
  * If no navigation is pending, this resolves immediately with the most
417
473
  * recent settlement result. Before any navigation has settled, it falls back
418
474
  * to a synthetic `Committed` result derived from the router's current route/hash state.
419
- * After `stop()`, that idle fallback reports empty route/hash values until a new navigation settles.
475
+ * After `stop()`, that idle fallback reports empty route/hash values until a new navigation settles,
476
+ * or `initialize(true)` resumes the route.
420
477
  *
421
478
  * @returns Promise that resolves with a {@link NavigationResult} once the pipeline settles.
422
479
  * @since 1.2.0
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "rootDir": ".",
5
- "paths": {
6
- "ui5/guard/router/*": ["./src/*"]
7
- },
8
- "types": ["@openui5/types"]
9
- },
10
- "include": ["src/**/*.ts"]
11
- }